From b3b2763af1edff5088049debb029ef1daaf02e24 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 27 Jan 2025 13:40:10 +0200 Subject: [PATCH] remove extra update actions --- src/app/browser/window/tab/item.rs | 19 ------------ src/app/browser/window/tab/item/page.rs | 7 ----- .../window/tab/item/page/navigation.rs | 11 +------ .../tab/item/page/navigation/bookmark.rs | 31 ++++++++++++------- 4 files changed, 21 insertions(+), 47 deletions(-) diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index dd3d3bf3..cc3b0c40 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -154,25 +154,6 @@ impl Item { } } - // Actions - pub fn update(&self) { - // Update self actions - self.action.home.set_enabled( - self.page - .navigation - .request - .home() - .is_some_and(|home| home.to_string() != self.page.navigation.request.entry.text()), - ); - - self.action - .reload - .set_enabled(!self.page.navigation.request.entry.text().is_empty()); - - // Update child components - self.page.update(); - } - pub fn clean( &self, transaction: &Transaction, diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 192cd7e9..d9047aaa 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -97,7 +97,6 @@ impl Page { Ok(result) => Ok(result), Err(_) => Err(Error::Bookmark), // @TODO }; - self.update(); result } @@ -111,12 +110,6 @@ impl Page { self.search.show() } - /// Update `Self` witch children components - pub fn update(&self) { - // Update children components - self.navigation.update(); - } - /// Cleanup session for `Self` pub fn clean( &self, diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 95af45c7..1990970e 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -41,7 +41,7 @@ impl Navigation { let request = Rc::new(Request::build(item_action, profile)); let reload = Button::reload((window_action, tab_action, item_action), &request); let home = Button::home((window_action, tab_action, item_action), &request); - let bookmark = Button::bookmark(window_action); + let bookmark = Button::bookmark(window_action, profile, &request); // init main widget let widget = Rc::new(Widget::build( @@ -65,15 +65,6 @@ impl Navigation { // Actions - pub fn update(&self) { - // init shared request value - let request = self.request.strip_prefix(); - - // update children components - self.bookmark - .update(self.profile.bookmark.get(&request).is_ok()); - } - pub fn clean( &self, transaction: &Transaction, diff --git a/src/app/browser/window/tab/item/page/navigation/bookmark.rs b/src/app/browser/window/tab/item/page/navigation/bookmark.rs index fc19b736..30a8b870 100644 --- a/src/app/browser/window/tab/item/page/navigation/bookmark.rs +++ b/src/app/browser/window/tab/item/page/navigation/bookmark.rs @@ -1,6 +1,6 @@ -use super::WindowAction; +use super::{Profile, Request, WindowAction}; use gtk::{ - prelude::{ActionExt, ButtonExt}, + prelude::{ActionExt, ButtonExt, EditableExt}, Button, }; use std::rc::Rc; @@ -9,24 +9,33 @@ const ICON_YES: &str = "starred-symbolic"; const ICON_NON: &str = "non-starred-symbolic"; pub trait Bookmark { - fn bookmark(action: &Rc) -> Self; - fn update(&self, has_bookmark: bool); + fn bookmark(action: &Rc, profile: &Rc, request: &Rc) -> Self; } impl Bookmark for Button { - fn bookmark(action: &Rc) -> Self { - Button::builder() + fn bookmark(action: &Rc, profile: &Rc, request: &Rc) -> Self { + let has_bookmark = profile.bookmark.get(&request.entry.text()).is_ok(); + + let button = Button::builder() .action_name(format!( "{}.{}", action.id, action.bookmark.simple_action.name() )) // @TODO - .icon_name(ICON_NON) + .icon_name(icon_name(has_bookmark)) .tooltip_text("Bookmark") - .build() - } + .build(); - fn update(&self, has_bookmark: bool) { - self.set_icon_name(if has_bookmark { ICON_YES } else { ICON_NON }); + button.connect_clicked(move |this| this.set_icon_name(icon_name(has_bookmark))); + + button + } +} + +fn icon_name(has_bookmark: bool) -> &'static str { + if has_bookmark { + ICON_YES + } else { + ICON_NON } }