diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index ea9d69a2..1e5bbb23 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -7,6 +7,7 @@ mod request; mod widget; use bookmark::Bookmark; +use gtk::Button; use history::History; use home::Home; use reload::Reload; @@ -18,11 +19,8 @@ use sqlite::Transaction; use std::rc::Rc; pub struct Navigation { - pub bookmark: Rc, pub history: Rc, - pub home: Rc, pub profile: Rc, - pub reload: Rc, pub request: Rc, pub widget: Rc, } @@ -39,27 +37,21 @@ impl Navigation { // init children components let history = Rc::new(History::build(window_action)); - let reload = Rc::new(Reload::build(window_action)); let request = Rc::new(Request::build((browser_action, tab_action))); - let bookmark = Rc::new(Bookmark::build(window_action)); - let home = Rc::new(Home::build(window_action)); // init main widget let widget = Rc::new(Widget::build( - &home.button, - &history.widget.g_box, - &reload.widget.button, - &request.widget.entry, - &bookmark.widget.button, + &Button::home(window_action), + &history.widget.g_box, // @TODO + &Button::reload(window_action), + &request.widget.entry, // @TODO + &Button::bookmark(window_action), )); // done Self { - bookmark, history, - home, profile: profile.clone(), - reload, request, widget, } @@ -68,6 +60,7 @@ impl Navigation { // Actions pub fn update(&self) { + /* @TODO // init shared request value let request = self.request.strip_prefix(); @@ -86,7 +79,7 @@ impl Navigation { self.request .home() .is_some_and(|home| home.to_string() != request), - ); + );*/ } 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 21408d2c..2e224984 100644 --- a/src/app/browser/window/tab/item/page/navigation/bookmark.rs +++ b/src/app/browser/window/tab/item/page/navigation/bookmark.rs @@ -1,26 +1,32 @@ -mod widget; - -use widget::Widget; - -use crate::app::browser::window::action::Action as WindowAction; +use super::WindowAction; +use gtk::{ + prelude::{ActionExt, ButtonExt}, + Button, +}; use std::rc::Rc; -pub struct Bookmark { - pub widget: Rc, -} +const ICON_YES: &str = "starred-symbolic"; +const ICON_NON: &str = "non-starred-symbolic"; -impl Bookmark { - // Constructors +pub trait Bookmark { + fn bookmark(action: &Rc) -> Self; + fn _update(&self, has_bookmark: bool); // @TODO +} - /// Build new `Self` - pub fn build(action: &Rc) -> Self { - Self { - widget: Rc::new(Widget::build(action)), - } +impl Bookmark for Button { + fn bookmark(action: &Rc) -> Self { + Button::builder() + .action_name(format!( + "{}.{}", + action.id, + action.bookmark.simple_action.name() + )) // @TODO + .icon_name(ICON_NON) + .tooltip_text("Bookmark") + .build() } - // Actions - pub fn update(&self, has_bookmark: bool) { - self.widget.update(has_bookmark); + fn _update(&self, has_bookmark: bool) { + self.set_icon_name(if has_bookmark { ICON_YES } else { ICON_NON }); } } 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 deleted file mode 100644 index c46fa897..00000000 --- a/src/app/browser/window/tab/item/page/navigation/bookmark/widget.rs +++ /dev/null @@ -1,40 +0,0 @@ -use gtk::{prelude::ButtonExt, Button}; - -use super::WindowAction; -use std::rc::Rc; - -const ICON_YES: &str = "starred-symbolic"; -const ICON_NON: &str = "non-starred-symbolic"; - -pub struct Widget { - pub button: Button, -} - -impl Widget { - // Constructors - - /// Build new `Self` - pub fn build(action: &Rc) -> Self { - // Init gobject - let button = Button::builder() - .icon_name(ICON_NON) - .tooltip_text("Bookmark") - .build(); - - // Init events - button.connect_clicked({ - let action = action.clone(); - move |_| action.bookmark.activate() - }); - - // Return activated `Self` - Self { button } - } - - // Actions - - pub fn update(&self, has_bookmark: bool) { - self.button - .set_icon_name(if has_bookmark { ICON_YES } else { ICON_NON }); - } -} diff --git a/src/app/browser/window/tab/item/page/navigation/history.rs b/src/app/browser/window/tab/item/page/navigation/history.rs index dd1f8caa..165d4e74 100644 --- a/src/app/browser/window/tab/item/page/navigation/history.rs +++ b/src/app/browser/window/tab/item/page/navigation/history.rs @@ -7,7 +7,7 @@ use forward::Forward; use widget::Widget; use super::WindowAction; -use gtk::glib::GString; +use gtk::{glib::GString, Button}; use std::{cell::RefCell, rc::Rc}; struct Memory { @@ -16,9 +16,6 @@ struct Memory { } pub struct History { - // Components - back: Rc, - forward: Rc, // Extras memory: RefCell>, index: RefCell>, @@ -31,12 +28,11 @@ impl History { /// Build new `Self` pub fn build(action: &Rc) -> Self { - // init components - let back = Rc::new(Back::build(action)); - let forward = Rc::new(Forward::build(action)); - // Init widget - let widget = Rc::new(Widget::build(&back.button, &forward.button)); + let widget = Rc::new(Widget::build( + &Button::back(action), + &Button::forward(action), + )); // Init memory let memory = RefCell::new(Vec::new()); @@ -45,8 +41,6 @@ impl History { let index = RefCell::new(None); Self { - back, - forward, memory, index, widget, @@ -110,16 +104,4 @@ impl History { } None } - - pub fn update(&self) { - match self.back(false) { - Some(_) => self.back.update(true), - None => self.back.update(false), - }; - - match self.forward(false) { - Some(_) => self.forward.update(true), - None => self.forward.update(false), - }; - } } diff --git a/src/app/browser/window/tab/item/page/navigation/history/back.rs b/src/app/browser/window/tab/item/page/navigation/history/back.rs index 208e26ba..e6196f64 100644 --- a/src/app/browser/window/tab/item/page/navigation/history/back.rs +++ b/src/app/browser/window/tab/item/page/navigation/history/back.rs @@ -1,44 +1,21 @@ use super::WindowAction; -use gtk::{ - prelude::{ButtonExt, WidgetExt}, - Button, -}; +use gtk::{prelude::ActionExt, Button}; use std::rc::Rc; -pub struct Back { - action: Rc, - pub button: Button, +pub trait Back { + fn back(action: &Rc) -> Self; } -impl Back { - // Constructors - - /// Build new `Self` - pub fn build(action: &Rc) -> Self { - // Init gobject - let button = Button::builder() +impl Back for Button { + fn back(action: &Rc) -> Self { + Button::builder() + .action_name(format!( + "{}.{}", + action.id, + action.history_back.simple_action.name() + )) // @TODO .icon_name("go-previous-symbolic") .tooltip_text("Back") - .sensitive(false) - .build(); - - // Init events - button.connect_clicked({ - let action = action.clone(); - move |_| action.history_back.activate() - }); - - // Return activated `Self` - Self { - action: action.clone(), - button, - } - } - - // Actions - - pub fn update(&self, status: bool) { - self.action.history_back.simple_action.set_enabled(status); - self.button.set_sensitive(status); + .build() } } diff --git a/src/app/browser/window/tab/item/page/navigation/history/forward.rs b/src/app/browser/window/tab/item/page/navigation/history/forward.rs index 03243de2..8cbfd58f 100644 --- a/src/app/browser/window/tab/item/page/navigation/history/forward.rs +++ b/src/app/browser/window/tab/item/page/navigation/history/forward.rs @@ -1,48 +1,21 @@ -use gtk::{ - prelude::{ButtonExt, WidgetExt}, - Button, -}; - use super::WindowAction; +use gtk::{prelude::ActionExt, Button}; use std::rc::Rc; -pub struct Forward { - action: Rc, - pub button: Button, +pub trait Forward { + fn forward(action: &Rc) -> Self; } -impl Forward { - // Constructors - - /// Build new `Self` - pub fn build(action: &Rc) -> Self { - // Init gobject - let button = Button::builder() +impl Forward for Button { + fn forward(action: &Rc) -> Self { + Button::builder() + .action_name(format!( + "{}.{}", + action.id, + action.history_back.simple_action.name() + )) // @TODO .icon_name("go-next-symbolic") .tooltip_text("Forward") - .sensitive(false) - .build(); - - // Init events - button.connect_clicked({ - let action = action.clone(); - move |_| action.history_forward.activate() - }); - - // Return activated `Self` - Self { - action: action.clone(), - button, - } - } - - // Actions - pub fn update(&self, status: bool) { - self.action - .history_forward - .simple_action - .set_enabled(status); - - self.button.set_sensitive(status); + .build() } } diff --git a/src/app/browser/window/tab/item/page/navigation/home.rs b/src/app/browser/window/tab/item/page/navigation/home.rs index c7f1ff57..454d0e71 100644 --- a/src/app/browser/window/tab/item/page/navigation/home.rs +++ b/src/app/browser/window/tab/item/page/navigation/home.rs @@ -1,41 +1,21 @@ use super::WindowAction; -use gtk::{ - prelude::{ButtonExt, WidgetExt}, - Button, -}; +use gtk::{prelude::ActionExt, Button}; use std::rc::Rc; -pub struct Home { - action: Rc, - pub button: Button, +pub trait Home { + fn home(action: &Rc) -> Self; } -impl Home { - // Construct - pub fn build(action: &Rc) -> Self { - // Init gobject - let button = Button::builder() +impl Home for Button { + fn home(action: &Rc) -> Self { + Button::builder() + .action_name(format!( + "{}.{}", + action.id, + action.home.simple_action.name() + )) // @TODO .icon_name("go-home-symbolic") .tooltip_text("Home") - .sensitive(false) - .build(); - - // Init events - button.connect_clicked({ - let action = action.clone(); - move |_| action.home.activate() - }); - - // Return activated `Self` - Self { - action: action.clone(), - button, - } - } - - // Actions - pub fn update(&self, has_home: bool) { - self.action.home.simple_action.set_enabled(has_home); - self.button.set_sensitive(has_home); + .build() } } diff --git a/src/app/browser/window/tab/item/page/navigation/reload.rs b/src/app/browser/window/tab/item/page/navigation/reload.rs index 4ed134c0..10e32401 100644 --- a/src/app/browser/window/tab/item/page/navigation/reload.rs +++ b/src/app/browser/window/tab/item/page/navigation/reload.rs @@ -1,33 +1,21 @@ -mod widget; - -use widget::Widget; - use super::WindowAction; +use gtk::{prelude::ActionExt, Button}; use std::rc::Rc; -pub struct Reload { - action: Rc, - pub widget: Rc, +pub trait Reload { + fn reload(action: &Rc) -> Self; } -impl Reload { - // Constructors - - /// Build new `Self` - pub fn build(action: &Rc) -> Self { - Self { - action: action.clone(), - widget: Rc::new(Widget::build(action)), - } - } - - // Actions - - pub fn update(&self, is_enabled: bool) { - // Update actions - self.action.reload.simple_action.set_enabled(is_enabled); - - // Update child components - self.widget.update(is_enabled); +impl Reload for Button { + fn reload(action: &Rc) -> Self { + Button::builder() + .action_name(format!( + "{}.{}", + action.id, + action.reload.simple_action.name() + )) // @TODO + .icon_name("view-refresh-symbolic") + .tooltip_text("Reload") + .build() } } diff --git a/src/app/browser/window/tab/item/page/navigation/reload/widget.rs b/src/app/browser/window/tab/item/page/navigation/reload/widget.rs deleted file mode 100644 index 8841e3b8..00000000 --- a/src/app/browser/window/tab/item/page/navigation/reload/widget.rs +++ /dev/null @@ -1,38 +0,0 @@ -use super::WindowAction; -use gtk::{ - prelude::{ButtonExt, WidgetExt}, - Button, -}; -use std::rc::Rc; - -pub struct Widget { - pub button: Button, -} - -impl Widget { - // Constructors - - /// Build new `Self` - pub fn build(action: &Rc) -> Self { - // Init gobject - let button = Button::builder() - .icon_name("view-refresh-symbolic") - .tooltip_text("Reload") - .sensitive(false) - .build(); - - // Init events - button.connect_clicked({ - let action = action.clone(); - move |_| action.reload.activate() - }); - - // Return activated `Self` - Self { button } - } - - // Actions - pub fn update(&self, is_sensitive: bool) { - self.button.set_sensitive(is_sensitive); - } -}