From 35491c3ef676edbd05c30e0eaf0502ce13299dc7 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 4 Nov 2024 18:35:37 +0200 Subject: [PATCH] enshort constructions --- src/app/browser/window/tab.rs | 17 +++-------------- src/app/browser/window/tab/widget.rs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 8bad75a6..4d08f1b1 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -242,20 +242,9 @@ impl Tab { /// Reload page at `i32` position or selected page on `None` given pub fn page_navigation_reload(&self, page_position: Option) { - match page_position { - Some(value) => { - if let Some(id) = self.widget.gobject().nth_page(value).keyword() { - if let Some(item) = self.index.borrow().get(&id) { - item.page_navigation_reload(); - } - } - } - None => { - if let Some(id) = self.widget.current_page_keyword() { - if let Some(item) = self.index.borrow().get(&id) { - item.page_navigation_reload(); - } - } + if let Some(id) = self.widget.page_keyword(page_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 657f031f..9379a8fe 100644 --- a/src/app/browser/window/tab/widget.rs +++ b/src/app/browser/window/tab/widget.rs @@ -1,4 +1,4 @@ -use adw::TabView; +use adw::{TabPage, TabView}; use gtk::{ gio::{Icon, MenuModel}, glib::GString, @@ -52,6 +52,21 @@ impl Widget { let page = self.gobject.selected_page()?; let id = page.keyword()?; Some(id) + } // @TODO remove as deprecated + + /// Get **keyword** for page position, `None` for selected page + /// * return `None` if requested page 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 page not found + pub fn page(&self, position: Option) -> Option { + match position { + Some(value) => Some(self.gobject.nth_page(value)), + None => self.gobject.selected_page(), + } } pub fn gobject(&self) -> &TabView {