diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 9c058bb1..578b9827 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -38,6 +38,7 @@ impl Window { ) -> Self { // Init components let tab = Tab::new_arc( + action_tab_append.clone(), action_tab_page_navigation_base.clone(), action_tab_page_navigation_history_back.clone(), action_tab_page_navigation_history_forward.clone(), diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index bd5e477a..9206c5c7 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -17,6 +17,7 @@ use std::{cell::RefCell, collections::HashMap, sync::Arc}; // Main pub struct Tab { // Actions + action_tab_append: Arc, action_tab_page_navigation_base: Arc, action_tab_page_navigation_history_back: Arc, action_tab_page_navigation_history_forward: Arc, @@ -32,6 +33,7 @@ impl Tab { // Construct pub fn new_arc( // Actions + action_tab_append: Arc, action_tab_page_navigation_base: Arc, action_tab_page_navigation_history_back: Arc, action_tab_page_navigation_history_forward: Arc, @@ -67,6 +69,7 @@ impl Tab { // Return activated struct Arc::new(Self { // Define action links + action_tab_append, action_tab_page_navigation_base, action_tab_page_navigation_history_back, action_tab_page_navigation_history_forward, @@ -85,6 +88,7 @@ impl Tab { let item = Item::new_arc( self.gobject(), // Actions + self.action_tab_append.clone(), self.action_tab_page_navigation_base.clone(), self.action_tab_page_navigation_history_back.clone(), self.action_tab_page_navigation_history_forward.clone(), @@ -206,6 +210,7 @@ impl Tab { self.gobject(), transaction, &record.id, + self.action_tab_append.clone(), self.action_tab_page_navigation_base.clone(), self.action_tab_page_navigation_history_back.clone(), self.action_tab_page_navigation_history_forward.clone(), diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index 376e978a..8d494572 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -28,6 +28,7 @@ impl Item { pub fn new_arc( tab_view: &TabView, // Actions + action_tab_append: Arc, action_tab_page_navigation_base: Arc, action_tab_page_navigation_history_back: Arc, action_tab_page_navigation_history_forward: Arc, @@ -43,6 +44,7 @@ impl Item { // Init components let page = Page::new_arc( id.clone(), + action_tab_append.clone(), action_tab_page_navigation_base.clone(), action_tab_page_navigation_history_back.clone(), action_tab_page_navigation_history_forward.clone(), @@ -123,6 +125,7 @@ impl Item { transaction: &Transaction, app_browser_window_tab_id: &i64, // Actions + action_tab_append: Arc, action_tab_page_navigation_base: Arc, action_tab_page_navigation_history_back: Arc, action_tab_page_navigation_history_forward: Arc, @@ -138,6 +141,7 @@ impl Item { let item = Item::new_arc( tab_view, // Actions + action_tab_append.clone(), action_tab_page_navigation_base.clone(), action_tab_page_navigation_history_back.clone(), action_tab_page_navigation_history_forward.clone(), diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index e1a42b2c..58f5be4f 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -41,6 +41,7 @@ impl Page { // Construct pub fn new_arc( name: GString, + action_tab_append: Arc, action_tab_page_navigation_base: Arc, action_tab_page_navigation_history_back: Arc, action_tab_page_navigation_history_forward: Arc, @@ -54,7 +55,10 @@ impl Page { )); // 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( action_tab_page_navigation_base.clone(), action_tab_page_navigation_history_back.clone(), diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index d92a368d..b3cfaa30 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -25,14 +25,16 @@ pub struct Content { // GTK widget: Box, // Actions + action_tab_append: Arc, action_page_open: Arc, } impl Content { // Construct - pub fn new(action_page_open: Arc) -> Self { + pub fn new(action_tab_append: Arc, action_page_open: Arc) -> Self { Self { widget: Box::builder().orientation(Orientation::Vertical).build(), + action_tab_append, action_page_open, } } @@ -47,7 +49,12 @@ impl Content { // Re-compose match mime { 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()); diff --git a/src/app/browser/window/tab/item/page/content/text.rs b/src/app/browser/window/tab/item/page/content/text.rs index 222b61ec..bc1b7c2f 100644 --- a/src/app/browser/window/tab/item/page/content/text.rs +++ b/src/app/browser/window/tab/item/page/content/text.rs @@ -21,9 +21,14 @@ pub struct Text { impl Text { // Construct - pub fn gemini(gemtext: &str, base: &Uri, action_page_open: Arc) -> Self { + pub fn gemini( + gemtext: &str, + base: &Uri, + action_tab_append: Arc, + action_page_open: Arc, + ) -> Self { // 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 let meta = Meta { diff --git a/src/app/browser/window/tab/item/page/content/text/gemini.rs b/src/app/browser/window/tab/item/page/content/text/gemini.rs index a72d5505..b0a687d0 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini.rs @@ -20,9 +20,14 @@ pub struct Gemini { impl Gemini { // Construct - pub fn new(gemtext: &str, base: &Uri, action_page_open: Arc) -> Self { + pub fn new( + gemtext: &str, + base: &Uri, + action_tab_append: Arc, + action_page_open: Arc, + ) -> Self { // 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()); diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs index 23d4bfcc..b1091afc 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs @@ -23,7 +23,12 @@ pub struct Reader { impl Reader { // Construct - pub fn new_arc(gemtext: &str, base: &Uri, action_page_open: Arc) -> Arc { + pub fn new_arc( + gemtext: &str, + base: &Uri, + action_tab_append: Arc, + action_page_open: Arc, + ) -> Arc { // Init default values let mut title = None; @@ -162,7 +167,7 @@ impl Reader { if let Some(iter) = gobject.iter_at_location(buffer_x, buffer_y) { for tag in iter.tags() { - // Detect links on tag contain URI + // Tag is link if let Some(uri) = _links_.get(&tag) { // Select handler by scheme 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({ let gobject = widget.gobject().clone(); let _links_ = links.clone(); // is copy @@ -191,7 +217,7 @@ impl Reader { if let Some(iter) = gobject.iter_at_location(buffer_x, buffer_y) { for tag in iter.tags() { - // Tag contain URI (is link) + // Tag is link if let Some(uri) = _links_.get(&tag) { // Toggle cursor gobject.set_cursor_from_name(Some("pointer")); @@ -214,9 +240,6 @@ impl Reader { } }); // @TODO may be expensive for CPU, add timeout? - // @TODO - // middle_button_controller(|_, _, _, _| {}); - // Result Arc::new(Self { title, widget }) }