connect navigation widget to bookmark action

This commit is contained in:
yggverse 2024-11-12 18:13:32 +02:00
parent ad89d08f0f
commit 367b4d017b
3 changed files with 52 additions and 21 deletions

View File

@ -21,9 +21,9 @@ use sqlite::Transaction;
use std::rc::Rc; use std::rc::Rc;
pub struct Navigation { pub struct Navigation {
home: Rc<Home>,
bookmark: Rc<Bookmark>, bookmark: Rc<Bookmark>,
history: Rc<History>, history: Rc<History>,
home: Rc<Home>,
reload: Rc<Reload>, reload: Rc<Reload>,
request: Rc<Request>, request: Rc<Request>,
widget: Rc<Widget>, widget: Rc<Widget>,
@ -38,9 +38,9 @@ impl Navigation {
// Init components // Init components
let home = Rc::new(Home::new(window_action.clone())); let home = Rc::new(Home::new(window_action.clone()));
let history = Rc::new(History::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 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 // Init widget
let widget = Rc::new(Widget::new( let widget = Rc::new(Widget::new(
@ -53,24 +53,24 @@ impl Navigation {
// Done // Done
Self { Self {
widget, bookmark,
home,
history, history,
home,
reload, reload,
request, request,
bookmark, widget,
} }
} }
// Actions // Actions
pub fn update(&self, progress_fraction: Option<f64>) { pub fn update(&self, progress_fraction: Option<f64>) {
self.home.update(self.request.uri()); self.bookmark.update();
self.history.update(); self.history.update();
self.home.update(self.request.uri());
self.reload self.reload
.update(!self.request.widget().gobject().text().is_empty()); .update(!self.request.widget().gobject().text().is_empty());
self.request.update(progress_fraction); self.request.update(progress_fraction);
self.bookmark.update();
} }
pub fn clean( pub fn clean(

View File

@ -2,23 +2,35 @@ mod widget;
use widget::Widget; use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction;
use std::rc::Rc; use std::rc::Rc;
pub struct Bookmark { pub struct Bookmark {
window_action: Rc<WindowAction>,
widget: Rc<Widget>, widget: Rc<Widget>,
} }
impl Bookmark { impl Bookmark {
// Construct // Construct
pub fn new() -> Self { pub fn new(window_action: Rc<WindowAction>) -> Self {
Self { Self {
widget: Rc::new(Widget::new()), widget: Rc::new(Widget::new(window_action.clone())),
window_action,
} }
} }
// Actions // Actions
pub fn update(&self) { 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 // Getters

View File

@ -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 { pub struct Widget {
gobject: Button, gobject: Button,
} }
impl Widget { impl Widget {
// Construct // Constructors
pub fn new() -> Self {
Self { pub fn new(window_action: Rc<WindowAction>) -> Self {
gobject: Button::builder() // Init gobject
.icon_name("starred-symbolic") let gobject = Button::builder()
.tooltip_text("Bookmark") .icon_name("starred-symbolic")
.sensitive(false) .tooltip_text("Bookmark")
.build(), .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 // Getters
pub fn gobject(&self) -> &Button { pub fn gobject(&self) -> &Button {
&self.gobject &self.gobject
} }