mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-09-11 22:42:00 +00:00
draft new tab open on middle click
This commit is contained in:
parent
0d55d492f3
commit
8f1e94dd68
@ -38,6 +38,7 @@ impl Window {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
// Init components
|
// Init components
|
||||||
let tab = Tab::new_arc(
|
let tab = Tab::new_arc(
|
||||||
|
action_tab_append.clone(),
|
||||||
action_tab_page_navigation_base.clone(),
|
action_tab_page_navigation_base.clone(),
|
||||||
action_tab_page_navigation_history_back.clone(),
|
action_tab_page_navigation_history_back.clone(),
|
||||||
action_tab_page_navigation_history_forward.clone(),
|
action_tab_page_navigation_history_forward.clone(),
|
||||||
|
@ -17,6 +17,7 @@ use std::{cell::RefCell, collections::HashMap, sync::Arc};
|
|||||||
// Main
|
// Main
|
||||||
pub struct Tab {
|
pub struct Tab {
|
||||||
// Actions
|
// Actions
|
||||||
|
action_tab_append: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
@ -32,6 +33,7 @@ impl Tab {
|
|||||||
// Construct
|
// Construct
|
||||||
pub fn new_arc(
|
pub fn new_arc(
|
||||||
// Actions
|
// Actions
|
||||||
|
action_tab_append: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
@ -67,6 +69,7 @@ impl Tab {
|
|||||||
// Return activated struct
|
// Return activated struct
|
||||||
Arc::new(Self {
|
Arc::new(Self {
|
||||||
// Define action links
|
// Define action links
|
||||||
|
action_tab_append,
|
||||||
action_tab_page_navigation_base,
|
action_tab_page_navigation_base,
|
||||||
action_tab_page_navigation_history_back,
|
action_tab_page_navigation_history_back,
|
||||||
action_tab_page_navigation_history_forward,
|
action_tab_page_navigation_history_forward,
|
||||||
@ -85,6 +88,7 @@ impl Tab {
|
|||||||
let item = Item::new_arc(
|
let item = Item::new_arc(
|
||||||
self.gobject(),
|
self.gobject(),
|
||||||
// Actions
|
// Actions
|
||||||
|
self.action_tab_append.clone(),
|
||||||
self.action_tab_page_navigation_base.clone(),
|
self.action_tab_page_navigation_base.clone(),
|
||||||
self.action_tab_page_navigation_history_back.clone(),
|
self.action_tab_page_navigation_history_back.clone(),
|
||||||
self.action_tab_page_navigation_history_forward.clone(),
|
self.action_tab_page_navigation_history_forward.clone(),
|
||||||
@ -206,6 +210,7 @@ impl Tab {
|
|||||||
self.gobject(),
|
self.gobject(),
|
||||||
transaction,
|
transaction,
|
||||||
&record.id,
|
&record.id,
|
||||||
|
self.action_tab_append.clone(),
|
||||||
self.action_tab_page_navigation_base.clone(),
|
self.action_tab_page_navigation_base.clone(),
|
||||||
self.action_tab_page_navigation_history_back.clone(),
|
self.action_tab_page_navigation_history_back.clone(),
|
||||||
self.action_tab_page_navigation_history_forward.clone(),
|
self.action_tab_page_navigation_history_forward.clone(),
|
||||||
|
@ -28,6 +28,7 @@ impl Item {
|
|||||||
pub fn new_arc(
|
pub fn new_arc(
|
||||||
tab_view: &TabView,
|
tab_view: &TabView,
|
||||||
// Actions
|
// Actions
|
||||||
|
action_tab_append: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
@ -43,6 +44,7 @@ impl Item {
|
|||||||
// Init components
|
// Init components
|
||||||
let page = Page::new_arc(
|
let page = Page::new_arc(
|
||||||
id.clone(),
|
id.clone(),
|
||||||
|
action_tab_append.clone(),
|
||||||
action_tab_page_navigation_base.clone(),
|
action_tab_page_navigation_base.clone(),
|
||||||
action_tab_page_navigation_history_back.clone(),
|
action_tab_page_navigation_history_back.clone(),
|
||||||
action_tab_page_navigation_history_forward.clone(),
|
action_tab_page_navigation_history_forward.clone(),
|
||||||
@ -123,6 +125,7 @@ impl Item {
|
|||||||
transaction: &Transaction,
|
transaction: &Transaction,
|
||||||
app_browser_window_tab_id: &i64,
|
app_browser_window_tab_id: &i64,
|
||||||
// Actions
|
// Actions
|
||||||
|
action_tab_append: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
@ -138,6 +141,7 @@ impl Item {
|
|||||||
let item = Item::new_arc(
|
let item = Item::new_arc(
|
||||||
tab_view,
|
tab_view,
|
||||||
// Actions
|
// Actions
|
||||||
|
action_tab_append.clone(),
|
||||||
action_tab_page_navigation_base.clone(),
|
action_tab_page_navigation_base.clone(),
|
||||||
action_tab_page_navigation_history_back.clone(),
|
action_tab_page_navigation_history_back.clone(),
|
||||||
action_tab_page_navigation_history_forward.clone(),
|
action_tab_page_navigation_history_forward.clone(),
|
||||||
|
@ -41,6 +41,7 @@ impl Page {
|
|||||||
// Construct
|
// Construct
|
||||||
pub fn new_arc(
|
pub fn new_arc(
|
||||||
name: GString,
|
name: GString,
|
||||||
|
action_tab_append: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
@ -54,7 +55,10 @@ impl Page {
|
|||||||
));
|
));
|
||||||
|
|
||||||
// Init components
|
// Init components
|
||||||
let content = Arc::new(Content::new(action_page_open.clone()));
|
let content = Arc::new(Content::new(
|
||||||
|
action_tab_append.clone(),
|
||||||
|
action_page_open.clone(),
|
||||||
|
));
|
||||||
let navigation = Navigation::new_arc(
|
let navigation = Navigation::new_arc(
|
||||||
action_tab_page_navigation_base.clone(),
|
action_tab_page_navigation_base.clone(),
|
||||||
action_tab_page_navigation_history_back.clone(),
|
action_tab_page_navigation_history_back.clone(),
|
||||||
|
@ -25,14 +25,16 @@ pub struct Content {
|
|||||||
// GTK
|
// GTK
|
||||||
widget: Box,
|
widget: Box,
|
||||||
// Actions
|
// Actions
|
||||||
|
action_tab_append: Arc<SimpleAction>,
|
||||||
action_page_open: Arc<SimpleAction>,
|
action_page_open: Arc<SimpleAction>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Content {
|
impl Content {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(action_page_open: Arc<SimpleAction>) -> Self {
|
pub fn new(action_tab_append: Arc<SimpleAction>, action_page_open: Arc<SimpleAction>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
widget: Box::builder().orientation(Orientation::Vertical).build(),
|
widget: Box::builder().orientation(Orientation::Vertical).build(),
|
||||||
|
action_tab_append,
|
||||||
action_page_open,
|
action_page_open,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,7 +49,12 @@ impl Content {
|
|||||||
// Re-compose
|
// Re-compose
|
||||||
match mime {
|
match mime {
|
||||||
Mime::TextGemini => {
|
Mime::TextGemini => {
|
||||||
let child = Text::gemini(data, base, self.action_page_open.clone());
|
let child = Text::gemini(
|
||||||
|
data,
|
||||||
|
base,
|
||||||
|
self.action_tab_append.clone(),
|
||||||
|
self.action_page_open.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
self.widget.append(child.widget());
|
self.widget.append(child.widget());
|
||||||
|
|
||||||
|
@ -21,9 +21,14 @@ pub struct Text {
|
|||||||
|
|
||||||
impl Text {
|
impl Text {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn gemini(gemtext: &str, base: &Uri, action_page_open: Arc<SimpleAction>) -> Self {
|
pub fn gemini(
|
||||||
|
gemtext: &str,
|
||||||
|
base: &Uri,
|
||||||
|
action_tab_append: Arc<SimpleAction>,
|
||||||
|
action_page_open: Arc<SimpleAction>,
|
||||||
|
) -> Self {
|
||||||
// Init components
|
// Init components
|
||||||
let gemini = Gemini::new(gemtext, base, action_page_open);
|
let gemini = Gemini::new(gemtext, base, action_tab_append, action_page_open);
|
||||||
|
|
||||||
// Init meta
|
// Init meta
|
||||||
let meta = Meta {
|
let meta = Meta {
|
||||||
|
@ -20,9 +20,14 @@ pub struct Gemini {
|
|||||||
|
|
||||||
impl Gemini {
|
impl Gemini {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(gemtext: &str, base: &Uri, action_page_open: Arc<SimpleAction>) -> Self {
|
pub fn new(
|
||||||
|
gemtext: &str,
|
||||||
|
base: &Uri,
|
||||||
|
action_tab_append: Arc<SimpleAction>,
|
||||||
|
action_page_open: Arc<SimpleAction>,
|
||||||
|
) -> Self {
|
||||||
// Init components
|
// Init components
|
||||||
let reader = Reader::new_arc(gemtext, base, action_page_open);
|
let reader = Reader::new_arc(gemtext, base, action_tab_append, action_page_open);
|
||||||
|
|
||||||
let widget = Widget::new_arc(&reader.gobject());
|
let widget = Widget::new_arc(&reader.gobject());
|
||||||
|
|
||||||
|
@ -23,7 +23,12 @@ pub struct Reader {
|
|||||||
|
|
||||||
impl Reader {
|
impl Reader {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new_arc(gemtext: &str, base: &Uri, action_page_open: Arc<SimpleAction>) -> Arc<Self> {
|
pub fn new_arc(
|
||||||
|
gemtext: &str,
|
||||||
|
base: &Uri,
|
||||||
|
action_tab_append: Arc<SimpleAction>,
|
||||||
|
action_page_open: Arc<SimpleAction>,
|
||||||
|
) -> Arc<Self> {
|
||||||
// Init default values
|
// Init default values
|
||||||
let mut title = None;
|
let mut title = None;
|
||||||
|
|
||||||
@ -162,7 +167,7 @@ impl Reader {
|
|||||||
|
|
||||||
if let Some(iter) = gobject.iter_at_location(buffer_x, buffer_y) {
|
if let Some(iter) = gobject.iter_at_location(buffer_x, buffer_y) {
|
||||||
for tag in iter.tags() {
|
for tag in iter.tags() {
|
||||||
// Detect links on tag contain URI
|
// Tag is link
|
||||||
if let Some(uri) = _links_.get(&tag) {
|
if let Some(uri) = _links_.get(&tag) {
|
||||||
// Select handler by scheme
|
// Select handler by scheme
|
||||||
match uri.scheme().as_str() {
|
match uri.scheme().as_str() {
|
||||||
@ -178,6 +183,27 @@ impl Reader {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
middle_button_controller.connect_pressed({
|
||||||
|
let gobject = widget.gobject().clone();
|
||||||
|
let _links_ = links.clone(); // is copy
|
||||||
|
move |_, _, window_x, window_y| {
|
||||||
|
// Detect tag match current coords hovered
|
||||||
|
let (buffer_x, buffer_y) = gobject.window_to_buffer_coords(
|
||||||
|
TextWindowType::Widget,
|
||||||
|
window_x as i32,
|
||||||
|
window_y as i32,
|
||||||
|
);
|
||||||
|
if let Some(iter) = gobject.iter_at_location(buffer_x, buffer_y) {
|
||||||
|
for tag in iter.tags() {
|
||||||
|
// Tag is link
|
||||||
|
if let Some(_) = _links_.get(&tag) {
|
||||||
|
action_tab_append.activate(None); // @TODO implement URI option
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
motion_controller.connect_motion({
|
motion_controller.connect_motion({
|
||||||
let gobject = widget.gobject().clone();
|
let gobject = widget.gobject().clone();
|
||||||
let _links_ = links.clone(); // is copy
|
let _links_ = links.clone(); // is copy
|
||||||
@ -191,7 +217,7 @@ impl Reader {
|
|||||||
|
|
||||||
if let Some(iter) = gobject.iter_at_location(buffer_x, buffer_y) {
|
if let Some(iter) = gobject.iter_at_location(buffer_x, buffer_y) {
|
||||||
for tag in iter.tags() {
|
for tag in iter.tags() {
|
||||||
// Tag contain URI (is link)
|
// Tag is link
|
||||||
if let Some(uri) = _links_.get(&tag) {
|
if let Some(uri) = _links_.get(&tag) {
|
||||||
// Toggle cursor
|
// Toggle cursor
|
||||||
gobject.set_cursor_from_name(Some("pointer"));
|
gobject.set_cursor_from_name(Some("pointer"));
|
||||||
@ -214,9 +240,6 @@ impl Reader {
|
|||||||
}
|
}
|
||||||
}); // @TODO may be expensive for CPU, add timeout?
|
}); // @TODO may be expensive for CPU, add timeout?
|
||||||
|
|
||||||
// @TODO
|
|
||||||
// middle_button_controller(|_, _, _, _| {});
|
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
Arc::new(Self { title, widget })
|
Arc::new(Self { title, widget })
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user