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({
let window = window.clone();
move |_, _| {
window.tab_close();
move |this, _| {
window.tab_close(page_position_from_action_state(this));
}
});

View File

@ -76,8 +76,8 @@ impl Window {
}
// Actions
pub fn tab_append(&self, position: Option<i32>) {
self.tab.append(position);
pub fn tab_append(&self, page_position: Option<i32>) {
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<i32>) {
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<i32>) {
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<i32>) {
self.tab.close(page_position);
}
pub fn tab_close_all(&self) {

View File

@ -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<i32>) {
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<i32>) {
if let Some(id) = self.widget.page_keyword(page_position) {
pub fn page_navigation_reload(&self, position: Option<i32>) {
if let Some(id) = self.widget.page_keyword(position) {
if let Some(item) = self.index.borrow().get(&id) {
item.page_navigation_reload();
}

View File

@ -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<i32>) {
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<i32>) -> Option<GString> {
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
}