fix bookmark update action

This commit is contained in:
yggverse 2024-11-14 08:59:48 +02:00
parent d0a7c3079d
commit feca899c5b
3 changed files with 12 additions and 18 deletions

View File

@ -70,7 +70,7 @@ impl Navigation {
let request = self.request.widget().gobject().text(); let request = self.request.widget().gobject().text();
self.bookmark self.bookmark
.update(!self.profile.bookmark.has_request(&request, true)); .update(self.profile.bookmark.has_request(&request, true));
self.history.update(); self.history.update();
self.home.update(self.request.uri()); self.home.update(self.request.uri());
self.reload.update(!request.is_empty()); self.reload.update(!request.is_empty());

View File

@ -6,7 +6,6 @@ use crate::app::browser::window::action::Action as WindowAction;
use std::rc::Rc; use std::rc::Rc;
pub struct Bookmark { pub struct Bookmark {
action: Rc<WindowAction>,
widget: Rc<Widget>, widget: Rc<Widget>,
} }
@ -15,17 +14,12 @@ impl Bookmark {
pub fn new(action: Rc<WindowAction>) -> Self { pub fn new(action: Rc<WindowAction>) -> Self {
Self { Self {
widget: Rc::new(Widget::new(action.clone())), widget: Rc::new(Widget::new(action.clone())),
action,
} }
} }
// Actions // Actions
pub fn update(&self, is_enabled: bool) { pub fn update(&self, has_bookmark: bool) {
// Update actions self.widget.update(has_bookmark);
self.action.bookmark().gobject().set_enabled(is_enabled);
// Update child components
self.widget.update(is_enabled);
} }
// Getters // Getters

View File

@ -1,11 +1,11 @@
use gtk::{ use gtk::{prelude::ButtonExt, Button};
prelude::{ButtonExt, WidgetExt},
Button,
};
use crate::app::browser::window::action::Action as WindowAction; use crate::app::browser::window::action::Action as WindowAction;
use std::rc::Rc; use std::rc::Rc;
const ICON_YES: &str = "starred-symbolic";
const ICON_NON: &str = "non-starred-symbolic";
pub struct Widget { pub struct Widget {
gobject: Button, gobject: Button,
} }
@ -16,13 +16,12 @@ impl Widget {
pub fn new(action: Rc<WindowAction>) -> Self { pub fn new(action: Rc<WindowAction>) -> Self {
// Init gobject // Init gobject
let gobject = Button::builder() let gobject = Button::builder()
.icon_name("starred-symbolic") .icon_name(ICON_NON)
.tooltip_text("Bookmark") .tooltip_text("Bookmark")
.sensitive(false)
.build(); .build();
// Init events // Init events
gobject.connect_clicked(move |_| action.home().activate()); gobject.connect_clicked(move |_| action.bookmark().activate());
// Return activated `Self` // Return activated `Self`
Self { gobject } Self { gobject }
@ -30,8 +29,9 @@ impl Widget {
// Actions // Actions
pub fn update(&self, is_sensitive: bool) { pub fn update(&self, has_bookmark: bool) {
self.gobject.set_sensitive(is_sensitive); self.gobject
.set_icon_name(if has_bookmark { ICON_YES } else { ICON_NON });
} }
// Getters // Getters