diff --git a/src/app/browser.rs b/src/app/browser.rs index bda34b03..0d14d719 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -147,8 +147,8 @@ impl Browser { action_page_home.connect_activate({ let window = window.clone(); - move |_, _| { - window.tab_page_navigation_home(); + move |this, _| { + window.tab_page_navigation_home(page_position_from_action_state(this)); } }); @@ -173,8 +173,8 @@ impl Browser { action_page_pin.connect_activate({ let window = window.clone(); - move |_, _| { - window.tab_pin(); + move |this, _| { + window.tab_pin(page_position_from_action_state(this)); } }); diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 6f4a8dd6..1ada0d9c 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -44,6 +44,7 @@ impl Window { action_page_home.clone(), action_page_history_back.clone(), action_page_history_forward.clone(), + action_page_pin.clone(), action_page_reload.clone(), action_update.clone(), ); @@ -82,8 +83,8 @@ impl Window { self.tab.append(page_position); } - pub fn tab_page_navigation_home(&self) { - self.tab.page_navigation_home(); + pub fn tab_page_navigation_home(&self, page_position: Option) { + self.tab.page_navigation_home(page_position); } pub fn tab_page_navigation_history_back(&self) { @@ -108,8 +109,8 @@ impl Window { self.tab.close_all(); } - pub fn tab_pin(&self) { - self.tab.pin(); + pub fn tab_pin(&self, page_position: Option) { + self.tab.pin(page_position); } pub fn update(&self, id: &str) { diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 715dfee7..ca689ef9 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -39,6 +39,7 @@ impl Tab { action_page_home: SimpleAction, action_page_history_back: SimpleAction, action_page_history_forward: SimpleAction, + action_page_pin: SimpleAction, action_page_reload: SimpleAction, action_update: SimpleAction, ) -> Arc { @@ -55,7 +56,12 @@ impl Tab { menu.append( Some("Reload"), Some(&gformat!("win.{}", action_page_reload.name())), - ); // @TODO resolve namespace outside + ); + + menu.append( + Some("Pin"), + Some(&gformat!("win.{}", action_page_pin.name())), + ); let navigation = Menu::new(); @@ -89,6 +95,7 @@ impl Tab { // Clone actions to update let action_page_close = action_page_close.clone(); let action_page_home = action_page_home.clone(); + let action_page_pin = action_page_pin.clone(); let action_page_reload = action_page_reload.clone(); move |tab_view, tab_page| { // Setup state for selected page @@ -102,6 +109,7 @@ impl Tab { // Update actions action_page_close.change_state(&state); action_page_home.change_state(&state); + action_page_pin.change_state(&state); action_page_reload.change_state(&state); } }); @@ -223,16 +231,12 @@ impl Tab { } // Toggle pin status for active tab - pub fn pin(&self) { - if let Some(page) = self.widget.gobject().selected_page() { - self.widget - .gobject() - .set_page_pinned(&page, !page.is_pinned()); // toggle - } + pub fn pin(&self, page_position: Option) { + self.widget.pin(page_position); } - pub fn page_navigation_home(&self) { - if let Some(id) = self.widget.current_page_keyword() { + pub fn page_navigation_home(&self, page_position: Option) { + if let Some(id) = self.widget.page_keyword(page_position) { if let Some(item) = self.index.borrow().get(&id) { item.page_navigation_home(); } diff --git a/src/app/browser/window/tab/widget.rs b/src/app/browser/window/tab/widget.rs index 037c9755..3e0a0d64 100644 --- a/src/app/browser/window/tab/widget.rs +++ b/src/app/browser/window/tab/widget.rs @@ -32,7 +32,7 @@ impl Widget { // Actions - /// Close page at given `position`, `None` to close selected page + /// Close page at given `position`, `None` to close selected page (if available) /// * this action includes `pinned` pages, to prevent that: /// * deactivate [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) outside if selected page should not be closed /// * use native [TabView](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabView.html) API with `GObject` reference getter @@ -54,6 +54,13 @@ impl Widget { } } + /// Toggle pin for page at given `position`, `None` to pin selected page (if available) + pub fn pin(&self, position: Option) { + if let Some(page) = self.page(position) { + self.gobject.set_page_pinned(&page, !page.is_pinned()); // toggle + } + } + // Getters pub fn current_page_keyword(&self) -> Option {