From 2d81cf7954d3719370400b3df63c76b9fe4815cb Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 4 Nov 2024 23:31:34 +0200 Subject: [PATCH] add history submenu --- src/app/browser.rs | 8 ++-- src/app/browser/window.rs | 8 ++-- src/app/browser/window/tab.rs | 56 ++++++++++++++++++++-------- src/app/browser/window/tab/widget.rs | 13 ------- 4 files changed, 49 insertions(+), 36 deletions(-) diff --git a/src/app/browser.rs b/src/app/browser.rs index 0d14d719..b3588d10 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -154,15 +154,15 @@ impl Browser { action_page_history_back.connect_activate({ let window = window.clone(); - move |_, _| { - window.tab_page_navigation_history_back(); + move |this, _| { + window.tab_page_navigation_history_back(page_position_from_action_state(this)); } }); action_page_history_forward.connect_activate({ let window = window.clone(); - move |_, _| { - window.tab_page_navigation_history_forward(); + move |this, _| { + window.tab_page_navigation_history_forward(page_position_from_action_state(this)); } }); diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 1ada0d9c..519e0330 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -87,12 +87,12 @@ impl Window { self.tab.page_navigation_home(page_position); } - pub fn tab_page_navigation_history_back(&self) { - self.tab.page_navigation_history_back(); + pub fn tab_page_navigation_history_back(&self, page_position: Option) { + self.tab.page_navigation_history_back(page_position); } - pub fn tab_page_navigation_history_forward(&self) { - self.tab.page_navigation_history_forward(); + pub fn tab_page_navigation_history_forward(&self, page_position: Option) { + self.tab.page_navigation_history_forward(page_position); } /// Reload page at given position or selected page on `None` given diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index ca689ef9..81fd5a60 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -72,6 +72,20 @@ impl Tab { menu.append_section(None, &navigation); + let history = Menu::new(); + + history.append( + Some("Back"), + Some(&gformat!("win.{}", action_page_history_back.name())), + ); + + history.append( + Some("Forward"), + Some(&gformat!("win.{}", action_page_history_forward.name())), + ); + + menu.append_submenu(Some("History"), &history); + let close = Menu::new(); close.append( @@ -94,6 +108,8 @@ impl Tab { widget.gobject().connect_setup_menu({ // Clone actions to update let action_page_close = action_page_close.clone(); + let action_page_history_back = action_page_history_back.clone(); + let action_page_history_forward = action_page_history_forward.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(); @@ -108,6 +124,8 @@ impl Tab { // Update actions action_page_close.change_state(&state); + action_page_history_back.change_state(&state); + action_page_history_forward.change_state(&state); action_page_home.change_state(&state); action_page_pin.change_state(&state); action_page_reload.change_state(&state); @@ -236,34 +254,42 @@ impl Tab { } 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(); + if let Some(page) = self.widget.page(page_position) { + if let Some(id) = page.keyword() { + if let Some(item) = self.index.borrow().get(&id) { + item.page_navigation_home(); + } } } } - pub fn page_navigation_history_back(&self) { - if let Some(id) = self.widget.current_page_keyword() { - if let Some(item) = self.index.borrow().get(&id) { - item.page_navigation_history_back(); + pub fn page_navigation_history_back(&self, page_position: Option) { + if let Some(page) = self.widget.page(page_position) { + if let Some(id) = page.keyword() { + if let Some(item) = self.index.borrow().get(&id) { + item.page_navigation_history_back(); + } } } } - pub fn page_navigation_history_forward(&self) { - if let Some(id) = self.widget.current_page_keyword() { - if let Some(item) = self.index.borrow().get(&id) { - item.page_navigation_history_forward(); + pub fn page_navigation_history_forward(&self, page_position: Option) { + if let Some(page) = self.widget.page(page_position) { + if let Some(id) = page.keyword() { + if let Some(item) = self.index.borrow().get(&id) { + item.page_navigation_history_forward(); + } } } } /// Reload page at `i32` position or selected page on `None` given - pub fn page_navigation_reload(&self, position: Option) { - if let Some(id) = self.widget.page_keyword(position) { - if let Some(item) = self.index.borrow().get(&id) { - item.page_navigation_reload(); + pub fn page_navigation_reload(&self, page_position: Option) { + if let Some(page) = self.widget.page(page_position) { + if let Some(id) = page.keyword() { + if let Some(item) = self.index.borrow().get(&id) { + item.page_navigation_reload(); + } } } } diff --git a/src/app/browser/window/tab/widget.rs b/src/app/browser/window/tab/widget.rs index c04e9a68..ab4ac889 100644 --- a/src/app/browser/window/tab/widget.rs +++ b/src/app/browser/window/tab/widget.rs @@ -1,7 +1,6 @@ use adw::{TabPage, TabView}; use gtk::{ gio::{Icon, MenuModel}, - glib::GString, prelude::IsA, }; @@ -65,18 +64,6 @@ impl Widget { // Getters - pub fn current_page_keyword(&self) -> Option { - let page = self.gobject.selected_page()?; - let id = page.keyword()?; - Some(id) - } // @TODO remove as deprecated - - /// Get **keyword** for page at given position, `None` for selected page - /// * return `None` if requested page or selected not found - pub fn page_keyword(&self, position: Option) -> Option { - self.page(position)?.keyword() - } - /// Get tab page by position, `None` for selected page /// * return `None` if requested or selected page not found pub fn page(&self, position: Option) -> Option {