From 5058c1be8a3e7c3e126582df8e5176a180b8d275 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 4 Nov 2024 20:22:27 +0200 Subject: [PATCH] add page position for close action --- src/app/browser.rs | 4 ++-- src/app/browser/window.rs | 15 ++++++++------- src/app/browser/window/tab.rs | 12 ++++++------ src/app/browser/window/tab/widget.rs | 13 ++++++++----- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/app/browser.rs b/src/app/browser.rs index 8b61bc07..bda34b03 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -133,8 +133,8 @@ impl Browser { action_page_close.connect_activate({ let window = window.clone(); - move |_, _| { - window.tab_close(); + move |this, _| { + window.tab_close(page_position_from_action_state(this)); } }); diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 584d655d..b817aae6 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -76,8 +76,8 @@ impl Window { } // Actions - pub fn tab_append(&self, position: Option) { - self.tab.append(position); + pub fn tab_append(&self, page_position: Option) { + self.tab.append(page_position); } pub fn tab_page_navigation_home(&self) { @@ -92,13 +92,14 @@ impl Window { self.tab.page_navigation_history_forward(); } - /// Reload page at `i32` position or selected page on `None` given - pub fn tab_page_navigation_reload(&self, page_position: Option) { - self.tab.page_navigation_reload(page_position); + /// Reload page at given position or selected page on `None` given + pub fn tab_page_navigation_reload(&self, position: Option) { + self.tab.page_navigation_reload(position); } - pub fn tab_close(&self) { - self.tab.close(); + /// Close page at given position or selected page on `None` given + pub fn tab_close(&self, page_position: Option) { + self.tab.close(page_position); } pub fn tab_close_all(&self) { diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 4d08f1b1..8c0781f2 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -197,12 +197,12 @@ impl Tab { item } - // Close active tab - pub fn close(&self) { - self.widget.close(); + /// Close page at given `position`, `None` to close selected page (if available) + pub fn close(&self, position: Option) { + self.widget.close(position); } - // Close all tabs + // Close all pages pub fn close_all(&self) { self.widget.close_all(); } @@ -241,8 +241,8 @@ impl Tab { } /// Reload page at `i32` position or selected page on `None` given - pub fn page_navigation_reload(&self, page_position: Option) { - if let Some(id) = self.widget.page_keyword(page_position) { + 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(); } diff --git a/src/app/browser/window/tab/widget.rs b/src/app/browser/window/tab/widget.rs index 9bc54b5e..a2abed02 100644 --- a/src/app/browser/window/tab/widget.rs +++ b/src/app/browser/window/tab/widget.rs @@ -32,17 +32,19 @@ impl Widget { // Actions - pub fn close(&self) { - if let Some(selected_page) = self.gobject.selected_page() { - self.gobject.close_page(&selected_page); + /// Close page at given `position`, `None` to close selected page (if available) + pub fn close(&self, position: Option) { + if let Some(page) = self.page(position) { + self.gobject.close_page(&page); } } + /// Close all pages, including selected one pub fn close_all(&self) { // @TODO skip pinned or make confirmation alert (GTK>=4.10) if let Some(selected_page) = self.gobject.selected_page() { self.gobject.close_other_pages(&selected_page); - self.close(); + self.close(None); } } @@ -54,7 +56,7 @@ impl Widget { Some(id) } // @TODO remove as deprecated - /// Get **keyword** for page position, `None` for selected page + /// 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() @@ -69,6 +71,7 @@ impl Widget { } } + /// Get reference of [TabView](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabView.html) `GObject` pub fn gobject(&self) -> &TabView { &self.gobject }