From ab73b9de5b99cb44314fafa668bf5fc23d6e8ba9 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 14 Oct 2024 05:57:33 +0300 Subject: [PATCH] register new local action --- src/app/browser/window.rs | 1 - src/app/browser/window/tab.rs | 52 ++++++++++++++++--- src/app/browser/window/tab/item.rs | 9 ++-- src/app/browser/window/tab/item/page.rs | 4 +- .../browser/window/tab/item/page/content.rs | 8 +-- .../tab/item/page/content/text/gemini.rs | 4 +- .../item/page/content/text/gemini/reader.rs | 6 +-- 7 files changed, 60 insertions(+), 24 deletions(-) diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 578b9827..9c058bb1 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -38,7 +38,6 @@ 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 49b98b74..264738a6 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -17,8 +17,9 @@ use std::{cell::RefCell, collections::HashMap, sync::Arc}; // Main pub struct Tab { - // Actions - action_tab_append: Arc, + // Local actions + action_tab_open: Arc, + // Global actions action_tab_page_navigation_base: Arc, action_tab_page_navigation_history_back: Arc, action_tab_page_navigation_history_forward: Arc, @@ -34,7 +35,6 @@ 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, @@ -73,10 +73,45 @@ impl Tab { } }); + action_tab_open.connect_activate({ + let index = index.clone(); + let gobject = widget.gobject().clone(); + // Actions + let action_tab_open = action_tab_open.clone(); + let action_tab_page_navigation_base = action_tab_page_navigation_base.clone(); + let action_tab_page_navigation_history_back = + action_tab_page_navigation_history_back.clone(); + let action_tab_page_navigation_history_forward = + action_tab_page_navigation_history_forward.clone(); + let action_tab_page_navigation_reload = action_tab_page_navigation_reload.clone(); + let action_update = action_update.clone(); + move |_, _| { + // Init new tab item + let item = Item::new_arc( + &gobject, + // Local actions + action_tab_open.clone(), + // Global actions + action_tab_page_navigation_base.clone(), + action_tab_page_navigation_history_back.clone(), + action_tab_page_navigation_history_forward.clone(), + action_tab_page_navigation_reload.clone(), + action_update.clone(), + // Options + false, + false, // open on background + ); + + // Register dynamically created tab components in the HashMap index + index.borrow_mut().insert(item.id(), item.clone()); + } + }); + // Return activated struct Arc::new(Self { - // Define action links - action_tab_append, + // Local actions + action_tab_open, + // Global actions action_tab_page_navigation_base, action_tab_page_navigation_history_back, action_tab_page_navigation_history_forward, @@ -94,8 +129,9 @@ impl Tab { // Init new tab item let item = Item::new_arc( self.gobject(), - // Actions - self.action_tab_append.clone(), + // Local actions + self.action_tab_open.clone(), + // Global actions self.action_tab_page_navigation_base.clone(), self.action_tab_page_navigation_history_back.clone(), self.action_tab_page_navigation_history_forward.clone(), @@ -217,7 +253,7 @@ impl Tab { self.gobject(), transaction, &record.id, - self.action_tab_append.clone(), + self.action_tab_open.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 8d494572..c4a8328f 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -28,7 +28,7 @@ impl Item { pub fn new_arc( tab_view: &TabView, // Actions - action_tab_append: Arc, + action_tab_open: Arc, action_tab_page_navigation_base: Arc, action_tab_page_navigation_history_back: Arc, action_tab_page_navigation_history_forward: Arc, @@ -44,7 +44,8 @@ impl Item { // Init components let page = Page::new_arc( id.clone(), - action_tab_append.clone(), + // Actions + action_tab_open.clone(), action_tab_page_navigation_base.clone(), action_tab_page_navigation_history_back.clone(), action_tab_page_navigation_history_forward.clone(), @@ -125,7 +126,7 @@ impl Item { transaction: &Transaction, app_browser_window_tab_id: &i64, // Actions - action_tab_append: Arc, + action_tab_open: Arc, action_tab_page_navigation_base: Arc, action_tab_page_navigation_history_back: Arc, action_tab_page_navigation_history_forward: Arc, @@ -141,7 +142,7 @@ impl Item { let item = Item::new_arc( tab_view, // Actions - action_tab_append.clone(), + action_tab_open.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 b1369e8d..cb4c6aa8 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -44,7 +44,7 @@ impl Page { // Construct pub fn new_arc( id: GString, - action_tab_append: Arc, + action_tab_open: Arc, action_tab_page_navigation_base: Arc, action_tab_page_navigation_history_back: Arc, action_tab_page_navigation_history_forward: Arc, @@ -59,7 +59,7 @@ impl Page { // Init components let content = Arc::new(Content::new( - action_tab_append.clone(), + action_tab_open.clone(), action_page_open.clone(), )); diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index b3cfaa30..b4f15529 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -25,16 +25,16 @@ pub struct Content { // GTK widget: Box, // Actions - action_tab_append: Arc, + action_tab_open: Arc, action_page_open: Arc, } impl Content { // Construct - pub fn new(action_tab_append: Arc, action_page_open: Arc) -> Self { + pub fn new(action_tab_open: Arc, action_page_open: Arc) -> Self { Self { widget: Box::builder().orientation(Orientation::Vertical).build(), - action_tab_append, + action_tab_open, action_page_open, } } @@ -52,7 +52,7 @@ impl Content { let child = Text::gemini( data, base, - self.action_tab_append.clone(), + self.action_tab_open.clone(), self.action_page_open.clone(), ); 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 b0a687d0..7dd5f415 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 @@ -23,11 +23,11 @@ impl Gemini { pub fn new( gemtext: &str, base: &Uri, - action_tab_append: Arc, + action_tab_open: Arc, action_page_open: Arc, ) -> Self { // Init components - let reader = Reader::new_arc(gemtext, base, action_tab_append, action_page_open); + let reader = Reader::new_arc(gemtext, base, action_tab_open, 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 f3b134b9..9321819d 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 @@ -26,7 +26,7 @@ impl Reader { pub fn new_arc( gemtext: &str, base: &Uri, - action_tab_append: Arc, + action_tab_open: Arc, action_page_open: Arc, ) -> Arc { // Init default values @@ -197,8 +197,8 @@ impl Reader { for tag in iter.tags() { // Tag is link if let Some(_) = _links_.get(&tag) { - return action_tab_append.activate(None); // @TODO implement URI option - // @TODO action does not work after focus out + return action_tab_open.activate(None); // @TODO implement URI option + // @TODO action does not work after focus out } } }