add page position for close action

This commit is contained in:
yggverse 2024-11-04 20:22:27 +02:00
parent 985230de46
commit 5058c1be8a
4 changed files with 24 additions and 20 deletions

View File

@ -133,8 +133,8 @@ impl Browser {
action_page_close.connect_activate({ action_page_close.connect_activate({
let window = window.clone(); let window = window.clone();
move |_, _| { move |this, _| {
window.tab_close(); window.tab_close(page_position_from_action_state(this));
} }
}); });

View File

@ -76,8 +76,8 @@ impl Window {
} }
// Actions // Actions
pub fn tab_append(&self, position: Option<i32>) { pub fn tab_append(&self, page_position: Option<i32>) {
self.tab.append(position); self.tab.append(page_position);
} }
pub fn tab_page_navigation_home(&self) { pub fn tab_page_navigation_home(&self) {
@ -92,13 +92,14 @@ impl Window {
self.tab.page_navigation_history_forward(); self.tab.page_navigation_history_forward();
} }
/// Reload page at `i32` position or selected page on `None` given /// Reload page at given position or selected page on `None` given
pub fn tab_page_navigation_reload(&self, page_position: Option<i32>) { pub fn tab_page_navigation_reload(&self, position: Option<i32>) {
self.tab.page_navigation_reload(page_position); self.tab.page_navigation_reload(position);
} }
pub fn tab_close(&self) { /// Close page at given position or selected page on `None` given
self.tab.close(); pub fn tab_close(&self, page_position: Option<i32>) {
self.tab.close(page_position);
} }
pub fn tab_close_all(&self) { pub fn tab_close_all(&self) {

View File

@ -197,12 +197,12 @@ impl Tab {
item item
} }
// Close active tab /// Close page at given `position`, `None` to close selected page (if available)
pub fn close(&self) { pub fn close(&self, position: Option<i32>) {
self.widget.close(); self.widget.close(position);
} }
// Close all tabs // Close all pages
pub fn close_all(&self) { pub fn close_all(&self) {
self.widget.close_all(); self.widget.close_all();
} }
@ -241,8 +241,8 @@ impl Tab {
} }
/// Reload page at `i32` position or selected page on `None` given /// Reload page at `i32` position or selected page on `None` given
pub fn page_navigation_reload(&self, page_position: Option<i32>) { pub fn page_navigation_reload(&self, position: Option<i32>) {
if let Some(id) = self.widget.page_keyword(page_position) { if let Some(id) = self.widget.page_keyword(position) {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.page_navigation_reload(); item.page_navigation_reload();
} }

View File

@ -32,17 +32,19 @@ impl Widget {
// Actions // Actions
pub fn close(&self) { /// Close page at given `position`, `None` to close selected page (if available)
if let Some(selected_page) = self.gobject.selected_page() { pub fn close(&self, position: Option<i32>) {
self.gobject.close_page(&selected_page); if let Some(page) = self.page(position) {
self.gobject.close_page(&page);
} }
} }
/// Close all pages, including selected one
pub fn close_all(&self) { pub fn close_all(&self) {
// @TODO skip pinned or make confirmation alert (GTK>=4.10) // @TODO skip pinned or make confirmation alert (GTK>=4.10)
if let Some(selected_page) = self.gobject.selected_page() { if let Some(selected_page) = self.gobject.selected_page() {
self.gobject.close_other_pages(&selected_page); self.gobject.close_other_pages(&selected_page);
self.close(); self.close(None);
} }
} }
@ -54,7 +56,7 @@ impl Widget {
Some(id) Some(id)
} // @TODO remove as deprecated } // @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 /// * return `None` if requested page or selected not found
pub fn page_keyword(&self, position: Option<i32>) -> Option<GString> { pub fn page_keyword(&self, position: Option<i32>) -> Option<GString> {
self.page(position)?.keyword() 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 { pub fn gobject(&self) -> &TabView {
&self.gobject &self.gobject
} }