remove extra update actions

This commit is contained in:
yggverse 2025-01-27 13:40:10 +02:00
parent d0287695ff
commit b3b2763af1
4 changed files with 21 additions and 47 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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<WindowAction>) -> Self;
fn update(&self, has_bookmark: bool);
fn bookmark(action: &Rc<WindowAction>, profile: &Rc<Profile>, request: &Rc<Request>) -> Self;
}
impl Bookmark for Button {
fn bookmark(action: &Rc<WindowAction>) -> Self {
Button::builder()
fn bookmark(action: &Rc<WindowAction>, profile: &Rc<Profile>, request: &Rc<Request>) -> 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
}
}