From 367b4d017bc4790d19a275432b9ceb80fb7e5f1c Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 12 Nov 2024 18:13:32 +0200 Subject: [PATCH] connect navigation widget to bookmark action --- .../window/tab/item/page/navigation.rs | 16 ++++---- .../tab/item/page/navigation/bookmark.rs | 18 +++++++-- .../item/page/navigation/bookmark/widget.rs | 39 ++++++++++++++----- 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index ac50e987..3fa30903 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -21,9 +21,9 @@ use sqlite::Transaction; use std::rc::Rc; pub struct Navigation { - home: Rc, bookmark: Rc, history: Rc, + home: Rc, reload: Rc, request: Rc, widget: Rc, @@ -38,9 +38,9 @@ impl Navigation { // Init components let home = Rc::new(Home::new(window_action.clone())); let history = Rc::new(History::new(window_action.clone())); - let reload = Rc::new(Reload::new(window_action)); + let reload = Rc::new(Reload::new(window_action.clone())); let request = Rc::new(Request::new(browser_action, tab_action)); - let bookmark = Rc::new(Bookmark::new()); + let bookmark = Rc::new(Bookmark::new(window_action)); // Init widget let widget = Rc::new(Widget::new( @@ -53,24 +53,24 @@ impl Navigation { // Done Self { - widget, - home, + bookmark, history, + home, reload, request, - bookmark, + widget, } } // Actions pub fn update(&self, progress_fraction: Option) { - self.home.update(self.request.uri()); + self.bookmark.update(); self.history.update(); + self.home.update(self.request.uri()); self.reload .update(!self.request.widget().gobject().text().is_empty()); self.request.update(progress_fraction); - self.bookmark.update(); } pub fn clean( 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 39f15a40..83536611 100644 --- a/src/app/browser/window/tab/item/page/navigation/bookmark.rs +++ b/src/app/browser/window/tab/item/page/navigation/bookmark.rs @@ -2,23 +2,35 @@ mod widget; use widget::Widget; +use crate::app::browser::window::action::Action as WindowAction; use std::rc::Rc; pub struct Bookmark { + window_action: Rc, widget: Rc, } impl Bookmark { // Construct - pub fn new() -> Self { + pub fn new(window_action: Rc) -> Self { Self { - widget: Rc::new(Widget::new()), + widget: Rc::new(Widget::new(window_action.clone())), + window_action, } } // Actions pub fn update(&self) { - // @TODO + let is_enabled = false; // @TODO DB + + // Update actions + self.window_action + .bookmark() + .gobject() + .set_enabled(is_enabled); + + // Update child components + self.widget.update(is_enabled); } // Getters diff --git a/src/app/browser/window/tab/item/page/navigation/bookmark/widget.rs b/src/app/browser/window/tab/item/page/navigation/bookmark/widget.rs index d0e904d1..2e533b5d 100644 --- a/src/app/browser/window/tab/item/page/navigation/bookmark/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/bookmark/widget.rs @@ -1,22 +1,41 @@ -use gtk::Button; +use gtk::{ + prelude::{ButtonExt, WidgetExt}, + Button, +}; + +use crate::app::browser::window::action::Action as WindowAction; +use std::rc::Rc; pub struct Widget { gobject: Button, } impl Widget { - // Construct - pub fn new() -> Self { - Self { - gobject: Button::builder() - .icon_name("starred-symbolic") - .tooltip_text("Bookmark") - .sensitive(false) - .build(), - } + // Constructors + + pub fn new(window_action: Rc) -> Self { + // Init gobject + let gobject = Button::builder() + .icon_name("starred-symbolic") + .tooltip_text("Bookmark") + .sensitive(false) + .build(); + + // Init events + gobject.connect_clicked(move |_| window_action.home().activate()); + + // Return activated `Self` + Self { gobject } + } + + // Actions + + pub fn update(&self, is_sensitive: bool) { + self.gobject.set_sensitive(is_sensitive); } // Getters + pub fn gobject(&self) -> &Button { &self.gobject }