From edb385f903721d6d68e57a6fb2a7c6e6eebd17d4 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 15 Jan 2025 00:25:33 +0200 Subject: [PATCH] rename constructors --- src/app.rs | 10 +++-- src/app/browser.rs | 8 ++-- src/app/browser/window.rs | 19 ++++++---- src/app/browser/window/header.rs | 11 ++++-- src/app/browser/window/header/bar.rs | 7 ++-- src/app/browser/window/header/bar/menu.rs | 5 ++- src/app/browser/window/header/bar/tab.rs | 4 +- .../browser/window/header/bar/tab/append.rs | 10 +++-- .../window/header/bar/tab/append/widget.rs | 19 ++++++---- .../browser/window/header/bar/tab/widget.rs | 6 ++- src/app/browser/window/header/bar/widget.rs | 16 ++++++-- src/app/browser/window/header/widget.rs | 16 ++++---- src/app/browser/window/tab.rs | 8 ++-- src/app/browser/window/tab/item.rs | 12 +++--- src/app/browser/window/tab/item/page.rs | 16 +++----- .../browser/window/tab/item/page/content.rs | 6 +-- .../window/tab/item/page/navigation.rs | 37 ++++++++++--------- .../tab/item/page/navigation/bookmark.rs | 8 ++-- .../item/page/navigation/bookmark/widget.rs | 18 +++++---- .../tab/item/page/navigation/history.rs | 14 ++++--- .../tab/item/page/navigation/history/back.rs | 9 +++-- .../page/navigation/history/back/widget.rs | 21 +++++++---- .../item/page/navigation/history/forward.rs | 12 +++--- .../page/navigation/history/forward/widget.rs | 21 +++++++---- .../item/page/navigation/history/widget.rs | 19 +++++----- .../window/tab/item/page/navigation/home.rs | 6 +-- .../tab/item/page/navigation/home/widget.rs | 21 +++++++---- .../window/tab/item/page/navigation/reload.rs | 10 +++-- .../tab/item/page/navigation/reload/widget.rs | 21 +++++++---- .../tab/item/page/navigation/request.rs | 9 +++-- .../item/page/navigation/request/widget.rs | 23 +++++++----- .../window/tab/item/page/navigation/widget.rs | 6 ++- .../browser/window/tab/item/page/widget.rs | 6 ++- src/app/browser/window/tab/item/widget.rs | 3 +- src/app/browser/window/widget.rs | 7 +++- src/main.rs | 2 +- 36 files changed, 266 insertions(+), 180 deletions(-) diff --git a/src/app.rs b/src/app.rs index ad328091..8c46d969 100644 --- a/src/app.rs +++ b/src/app.rs @@ -20,15 +20,17 @@ pub struct App { } impl App { - // Construct - pub fn new(profile: Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(profile: &Rc) -> Self { // Init GTK let application = Application::builder() .application_id(APPLICATION_ID) .build(); // Init components - let browser = Rc::new(Browser::new(profile.clone())); + let browser = Rc::new(Browser::build(profile)); // Init events application.connect_activate({ @@ -250,7 +252,7 @@ impl App { // Return activated App struct Self { - profile, + profile: profile.clone(), application, } } diff --git a/src/app/browser.rs b/src/app/browser.rs index 526bd596..1fb9a3cf 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -25,11 +25,13 @@ pub struct Browser { } impl Browser { - // Construct - pub fn new(profile: Rc) -> Browser { + // Constructors + + /// Build new `Self` + pub fn build(profile: &Rc) -> Browser { // Init components let action = Rc::new(Action::new()); - let window = Rc::new(Window::new(profile.clone(), action.clone())); + let window = Rc::new(Window::build(profile, &action)); // Init widget let widget = Rc::new(Widget::new( diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 9187af39..81bfe0c4 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -22,19 +22,24 @@ pub struct Window { } impl Window { - // Construct - pub fn new(profile: Rc, browser_action: Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(profile: &Rc, browser_action: &Rc) -> Self { // Init local actions let action = Rc::new(Action::new()); // Init components - let tab = Rc::new(Tab::new(&profile, (&browser_action, &action))); - let header = Rc::new(Header::new( - (&browser_action, &action), - &profile, + let tab = Rc::new(Tab::build(profile, (browser_action, &action))); + let header = Rc::new(Header::build( + (browser_action, &action), + profile, + &tab.widget.tab_view, + )); + let widget = Rc::new(Widget::build( + &header.widget.toolbar_view, &tab.widget.tab_view, )); - let widget = Rc::new(Widget::new(&header.widget.gobject, &tab.widget.tab_view)); // Init events action.append.connect_activate({ diff --git a/src/app/browser/window/header.rs b/src/app/browser/window/header.rs index ef0a714e..ca6a847d 100644 --- a/src/app/browser/window/header.rs +++ b/src/app/browser/window/header.rs @@ -15,17 +15,22 @@ pub struct Header { impl Header { // Constructors - pub fn new( + /// Build new `Self` + pub fn build( (browser_action, window_action): (&Rc, &Rc), profile: &Rc, tab_view: &TabView, ) -> Self { // Init components - let bar = Rc::new(Bar::new((browser_action, window_action), profile, tab_view)); + let bar = Rc::new(Bar::build( + (browser_action, window_action), + profile, + tab_view, + )); // Return new struct Self { - widget: Rc::new(Widget::new(&bar.widget.g_box)), + widget: Rc::new(Widget::build(&bar.widget.g_box)), } } } diff --git a/src/app/browser/window/header/bar.rs b/src/app/browser/window/header/bar.rs index 99ccc97c..54ab1879 100644 --- a/src/app/browser/window/header/bar.rs +++ b/src/app/browser/window/header/bar.rs @@ -19,16 +19,17 @@ pub struct Bar { impl Bar { // Constructors - pub fn new( + /// Build new `Self` + pub fn build( (browser_action, window_action): (&Rc, &Rc), profile: &Rc, view: &TabView, ) -> Self { let control = Control::new(); let tab = Tab::new(window_action, view); - let menu = Rc::new(Menu::new((browser_action, window_action), profile)); + let menu = Rc::new(Menu::build((browser_action, window_action), profile)); Self { - widget: Rc::new(Widget::new( + widget: Rc::new(Widget::build( &control.window_controls, &menu.menu_button, &tab.widget.tab_bar, diff --git a/src/app/browser/window/header/bar/menu.rs b/src/app/browser/window/header/bar/menu.rs index d6c92713..806c9ffe 100644 --- a/src/app/browser/window/header/bar/menu.rs +++ b/src/app/browser/window/header/bar/menu.rs @@ -17,7 +17,10 @@ pub struct Menu { #[rustfmt::skip] // @TODO template builder? impl Menu { - pub fn new( + // Constructors + + /// Build new `Self` + pub fn build( (browser_action, window_action): (&Rc, &Rc), profile: &Rc, ) -> Self { diff --git a/src/app/browser/window/header/bar/tab.rs b/src/app/browser/window/header/bar/tab.rs index ef5381ed..b01b3ec6 100644 --- a/src/app/browser/window/header/bar/tab.rs +++ b/src/app/browser/window/header/bar/tab.rs @@ -16,9 +16,9 @@ impl Tab { // Construct pub fn new(window_action: &Rc, view: &TabView) -> Self { Self { - widget: Rc::new(Widget::new( + widget: Rc::new(Widget::build( view, - &Append::new(window_action).widget.gobject, + &Append::build(window_action).widget.button, )), } } diff --git a/src/app/browser/window/header/bar/tab/append.rs b/src/app/browser/window/header/bar/tab/append.rs index 16c958c7..376d9d4b 100644 --- a/src/app/browser/window/header/bar/tab/append.rs +++ b/src/app/browser/window/header/bar/tab/append.rs @@ -2,7 +2,7 @@ mod widget; use widget::Widget; -use crate::app::browser::window::action::Action as WindowAction; +use super::WindowAction; use std::rc::Rc; pub struct Append { @@ -10,10 +10,12 @@ pub struct Append { } impl Append { - // Construct - pub fn new(window_action: &Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(window_action: &Rc) -> Self { Self { - widget: Rc::new(Widget::new(window_action.clone())), + widget: Rc::new(Widget::build(window_action)), } } } diff --git a/src/app/browser/window/header/bar/tab/append/widget.rs b/src/app/browser/window/header/bar/tab/append/widget.rs index fd4340bd..065342c3 100644 --- a/src/app/browser/window/header/bar/tab/append/widget.rs +++ b/src/app/browser/window/header/bar/tab/append/widget.rs @@ -1,16 +1,18 @@ -use crate::app::browser::window::action::Action as WindowAction; +use super::WindowAction; use gtk::{prelude::ButtonExt, Align, Button}; use std::rc::Rc; pub struct Widget { - pub gobject: Button, + pub button: Button, } impl Widget { - // Construct - pub fn new(window_action: Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(window_action: &Rc) -> Self { // Init gobject - let gobject = Button::builder() + let button = Button::builder() .icon_name("tab-new-symbolic") .css_classes(["flat"]) .valign(Align::Center) @@ -18,8 +20,11 @@ impl Widget { .build(); // Init events - gobject.connect_clicked(move |_| window_action.append.activate_default_once()); + button.connect_clicked({ + let window_action = window_action.clone(); + move |_| window_action.append.activate_default_once() + }); - Self { gobject } + Self { button } } } diff --git a/src/app/browser/window/header/bar/tab/widget.rs b/src/app/browser/window/header/bar/tab/widget.rs index e972772b..6c50708e 100644 --- a/src/app/browser/window/header/bar/tab/widget.rs +++ b/src/app/browser/window/header/bar/tab/widget.rs @@ -6,8 +6,10 @@ pub struct Widget { } impl Widget { - // Construct - pub fn new(view: &TabView, start_action_widget: &impl IsA) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(view: &TabView, start_action_widget: &impl IsA) -> Self { Self { tab_bar: TabBar::builder() .autohide(false) diff --git a/src/app/browser/window/header/bar/widget.rs b/src/app/browser/window/header/bar/widget.rs index 2004aedf..16dd8bde 100644 --- a/src/app/browser/window/header/bar/widget.rs +++ b/src/app/browser/window/header/bar/widget.rs @@ -1,13 +1,21 @@ -use adw::TabBar; -use gtk::{prelude::BoxExt, Box, MenuButton, Orientation, WindowControls}; +use gtk::{ + prelude::{BoxExt, IsA}, + Box, Orientation, +}; pub struct Widget { pub g_box: Box, } impl Widget { - // Construct - pub fn new(control: &WindowControls, menu: &MenuButton, tab: &TabBar) -> Self { + // Constructors + + /// Build new `Self` + pub fn build( + control: &impl IsA, + menu: &impl IsA, + tab: &impl IsA, + ) -> Self { let g_box = Box::builder() .orientation(Orientation::Horizontal) .spacing(8) diff --git a/src/app/browser/window/header/widget.rs b/src/app/browser/window/header/widget.rs index c03add89..8499c1cd 100644 --- a/src/app/browser/window/header/widget.rs +++ b/src/app/browser/window/header/widget.rs @@ -1,17 +1,19 @@ use adw::ToolbarView; -use gtk::Box; +use gtk::prelude::IsA; pub struct Widget { - pub gobject: ToolbarView, + pub toolbar_view: ToolbarView, } impl Widget { - // Construct - pub fn new(top_bar: &Box) -> Self { - let gobject = ToolbarView::builder().build(); + // Constructors - gobject.add_top_bar(top_bar); + /// Build new `Self` + pub fn build(top_bar: &impl IsA) -> Self { + let toolbar_view = ToolbarView::builder().build(); - Self { gobject } + toolbar_view.add_top_bar(top_bar); + + Self { toolbar_view } } } diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index d65c0205..0bbfb6e4 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -31,8 +31,10 @@ pub struct Tab { } impl Tab { - // Construct - pub fn new( + // Constructors + + /// Build new `Self` + pub fn build( profile: &Rc, (browser_action, window_action): (&Rc, &Rc), ) -> Self { @@ -154,7 +156,7 @@ impl Tab { is_load: bool, ) -> Rc { // Init new tab item - let item = Rc::new(Item::new( + let item = Rc::new(Item::build( &self.widget.tab_view, &self.profile, // Actions diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index b2df51c1..a6049604 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -31,8 +31,10 @@ pub struct Item { } impl Item { - // Construct - pub fn new( + // Constructors + + /// Build new `Self` + pub fn build( tab_view: &TabView, profile: &Rc, (browser_action, window_action): (&Rc, &Rc), @@ -52,13 +54,13 @@ impl Item { let action = Rc::new(Action::new()); - let page = Rc::new(Page::new( + let page = Rc::new(Page::build( &id, profile, (browser_action, window_action, &action), )); - let widget = Rc::new(Widget::new( + let widget = Rc::new(Widget::build( id.as_str(), tab_view, &page.widget.g_box, @@ -166,7 +168,7 @@ impl Item { Ok(records) => { for record in records { // Construct new item object - let item = Rc::new(Item::new( + let item = Rc::new(Item::build( tab_view, profile, // Actions diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 919d6df7..bab8dca6 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -60,7 +60,7 @@ pub struct Page { impl Page { // Constructors - pub fn new( + pub fn build( id: &Rc, profile: &Rc, (browser_action, window_action, tab_action): ( @@ -70,22 +70,18 @@ impl Page { ), ) -> Self { // Init components - let content = Rc::new(Content::new((window_action.clone(), tab_action.clone()))); + let content = Rc::new(Content::build((window_action, tab_action))); let search = Rc::new(Search::new()); - let navigation = Rc::new(Navigation::new( - profile.clone(), - ( - browser_action.clone(), - window_action.clone(), - tab_action.clone(), - ), + let navigation = Rc::new(Navigation::build( + profile, + (browser_action, window_action, tab_action), )); let input = Rc::new(Input::new()); - let widget = Rc::new(Widget::new( + let widget = Rc::new(Widget::build( id, &navigation.widget.g_box, &content.g_box, diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index 29618873..5b205bd8 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -26,11 +26,11 @@ impl Content { // Construct /// Create new container for different components - pub fn new((window_action, tab_action): (Rc, Rc)) -> Self { + pub fn build((window_action, tab_action): (&Rc, &Rc)) -> Self { Self { g_box: Box::builder().orientation(Orientation::Vertical).build(), - window_action, - tab_action, + window_action: window_action.clone(), + tab_action: tab_action.clone(), } } diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 8a47fccb..2210136d 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -13,10 +13,7 @@ use reload::Reload; use request::Request; use widget::Widget; -use crate::app::browser::window::tab::item::Action as TabAction; -use crate::app::browser::window::Action as WindowAction; -use crate::app::browser::Action as BrowserAction; -use crate::Profile; +use super::{BrowserAction, Profile, TabAction, WindowAction}; use sqlite::Transaction; use std::rc::Rc; @@ -31,24 +28,28 @@ pub struct Navigation { } impl Navigation { - pub fn new( - profile: Rc, - action: (Rc, Rc, Rc), + pub fn build( + profile: &Rc, + (browser_action, window_action, tab_action): ( + &Rc, + &Rc, + &Rc, + ), ) -> Self { // init children components - let home = Rc::new(Home::new(action.1.clone())); - let history = Rc::new(History::new(action.1.clone())); - let reload = Rc::new(Reload::new(action.1.clone())); - let request = Rc::new(Request::new((action.0, action.2))); - let bookmark = Rc::new(Bookmark::new(action.1)); + let home = Rc::new(Home::build(window_action)); + 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)); // init main widget - let widget = Rc::new(Widget::new( - &home.widget.gobject, - &history.widget.gobject, - &reload.widget.gobject, + let widget = Rc::new(Widget::build( + &home.widget.button, + &history.widget.g_box, + &reload.widget.button, &request.widget.entry, - &bookmark.widget.gobject, + &bookmark.widget.button, )); // done @@ -56,7 +57,7 @@ impl Navigation { bookmark, history, home, - profile, + profile: profile.clone(), reload, request, widget, 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 b911e4ac..21408d2c 100644 --- a/src/app/browser/window/tab/item/page/navigation/bookmark.rs +++ b/src/app/browser/window/tab/item/page/navigation/bookmark.rs @@ -10,10 +10,12 @@ pub struct Bookmark { } impl Bookmark { - // Construct - pub fn new(action: Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(action: &Rc) -> Self { Self { - widget: Rc::new(Widget::new(action.clone())), + widget: Rc::new(Widget::build(action)), } } 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 06eb227c..c46fa897 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,36 +1,40 @@ use gtk::{prelude::ButtonExt, Button}; -use crate::app::browser::window::Action; +use super::WindowAction; use std::rc::Rc; const ICON_YES: &str = "starred-symbolic"; const ICON_NON: &str = "non-starred-symbolic"; pub struct Widget { - pub gobject: Button, + pub button: Button, } impl Widget { // Constructors - pub fn new(action: Rc) -> Self { + /// Build new `Self` + pub fn build(action: &Rc) -> Self { // Init gobject - let gobject = Button::builder() + let button = Button::builder() .icon_name(ICON_NON) .tooltip_text("Bookmark") .build(); // Init events - gobject.connect_clicked(move |_| action.bookmark.activate()); + button.connect_clicked({ + let action = action.clone(); + move |_| action.bookmark.activate() + }); // Return activated `Self` - Self { gobject } + Self { button } } // Actions pub fn update(&self, has_bookmark: bool) { - self.gobject + 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 97062d63..6f78b250 100644 --- a/src/app/browser/window/tab/item/page/navigation/history.rs +++ b/src/app/browser/window/tab/item/page/navigation/history.rs @@ -6,7 +6,7 @@ use back::Back; use forward::Forward; use widget::Widget; -use crate::app::browser::window::action::Action as WindowAction; +use super::WindowAction; use gtk::glib::GString; use std::{cell::RefCell, rc::Rc}; @@ -27,14 +27,16 @@ pub struct History { } impl History { - // Construct - pub fn new(window_action: Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(action: &Rc) -> Self { // init components - let back = Rc::new(Back::new(window_action.clone())); - let forward = Rc::new(Forward::new(window_action)); + let back = Rc::new(Back::build(action)); + let forward = Rc::new(Forward::build(action)); // Init widget - let widget = Rc::new(Widget::new(&back.widget.gobject, &forward.widget.gobject)); + let widget = Rc::new(Widget::build(&back.widget.button, &forward.widget.button)); // Init memory let memory = RefCell::new(Vec::new()); 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 07cd3c48..5cd9dbdd 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 @@ -2,21 +2,22 @@ mod widget; use widget::Widget; -use crate::app::browser::window::Action; +use super::WindowAction; use std::rc::Rc; pub struct Back { - pub action: Rc, + action: Rc, pub widget: Rc, } impl Back { // Constructors - pub fn new(action: Rc) -> Self { + /// Build new `Self` + pub fn build(action: &Rc) -> Self { Self { action: action.clone(), - widget: Rc::new(Widget::new(action)), + widget: Rc::new(Widget::build(action)), } } diff --git a/src/app/browser/window/tab/item/page/navigation/history/back/widget.rs b/src/app/browser/window/tab/item/page/navigation/history/back/widget.rs index 9f67d840..f35f82c6 100644 --- a/src/app/browser/window/tab/item/page/navigation/history/back/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/history/back/widget.rs @@ -1,4 +1,4 @@ -use crate::app::browser::window::Action; +use super::WindowAction; use gtk::{ prelude::{ButtonExt, WidgetExt}, Button, @@ -6,28 +6,33 @@ use gtk::{ use std::rc::Rc; pub struct Widget { - pub gobject: Button, + pub button: Button, } impl Widget { - // Construct - pub fn new(action: Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(action: &Rc) -> Self { // Init gobject - let gobject = Button::builder() + let button = Button::builder() .icon_name("go-previous-symbolic") .tooltip_text("Back") .sensitive(false) .build(); // Init events - gobject.connect_clicked(move |_| action.history_back.activate()); + button.connect_clicked({ + let action = action.clone(); + move |_| action.history_back.activate() + }); // Return activated `Self` - Self { gobject } + Self { button } } // Actions pub fn update(&self, is_sensitive: bool) { - self.gobject.set_sensitive(is_sensitive); + self.button.set_sensitive(is_sensitive); } } 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 bce6def5..cdd743e0 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 @@ -2,20 +2,22 @@ mod widget; use widget::Widget; -use crate::app::browser::window::Action; +use super::WindowAction; use std::rc::Rc; pub struct Forward { - pub action: Rc, + action: Rc, pub widget: Rc, } impl Forward { - // Construct - pub fn new(action: Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(action: &Rc) -> Self { Self { action: action.clone(), - widget: Rc::new(Widget::new(action)), + widget: Rc::new(Widget::build(action)), } } diff --git a/src/app/browser/window/tab/item/page/navigation/history/forward/widget.rs b/src/app/browser/window/tab/item/page/navigation/history/forward/widget.rs index aac2bf01..496bd85f 100644 --- a/src/app/browser/window/tab/item/page/navigation/history/forward/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/history/forward/widget.rs @@ -1,4 +1,4 @@ -use crate::app::browser::window::Action; +use super::WindowAction; use gtk::{ prelude::{ButtonExt, WidgetExt}, Button, @@ -6,28 +6,33 @@ use gtk::{ use std::rc::Rc; pub struct Widget { - pub gobject: Button, + pub button: Button, } impl Widget { - // Construct - pub fn new(action: Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(action: &Rc) -> Self { // Init gobject - let gobject = Button::builder() + let button = Button::builder() .icon_name("go-next-symbolic") .tooltip_text("Forward") .sensitive(false) .build(); // Init events - gobject.connect_clicked(move |_| action.history_forward.activate()); + button.connect_clicked({ + let action = action.clone(); + move |_| action.history_forward.activate() + }); // Return activated `Self` - Self { gobject } + Self { button } } // Actions pub fn update(&self, is_sensitive: bool) { - self.gobject.set_sensitive(is_sensitive); + self.button.set_sensitive(is_sensitive); } } diff --git a/src/app/browser/window/tab/item/page/navigation/history/widget.rs b/src/app/browser/window/tab/item/page/navigation/history/widget.rs index ff00af9e..71f6f648 100644 --- a/src/app/browser/window/tab/item/page/navigation/history/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/history/widget.rs @@ -4,25 +4,24 @@ use gtk::{ }; pub struct Widget { - pub gobject: Box, + pub g_box: Box, } impl Widget { - // Construct - pub fn new(back: &impl IsA, forward: &impl IsA) -> Self { - // Init widget - let gobject = Box::builder() + // Constructors + + /// Build new `Self` + pub fn build(back: &impl IsA, forward: &impl IsA) -> Self { + let g_box = Box::builder() .orientation(Orientation::Horizontal) .css_classes([ "linked", // merge childs ]) .build(); - // Compose childs - gobject.append(back); - gobject.append(forward); + g_box.append(back); + g_box.append(forward); - // Return activated `Self` - Self { gobject } + Self { g_box } } } 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 573a8767..f090ea61 100644 --- a/src/app/browser/window/tab/item/page/navigation/home.rs +++ b/src/app/browser/window/tab/item/page/navigation/home.rs @@ -2,7 +2,7 @@ mod widget; use widget::Widget; -use crate::app::browser::window::action::Action as WindowAction; +use super::WindowAction; use gtk::glib::{gformat, GString, Uri}; use std::{cell::RefCell, rc::Rc}; @@ -14,11 +14,11 @@ pub struct Home { impl Home { // Construct - pub fn new(action: Rc) -> Self { + pub fn build(action: &Rc) -> Self { Self { action: action.clone(), uri: RefCell::new(None), - widget: Rc::new(Widget::new(action)), + widget: Rc::new(Widget::build(action)), } } diff --git a/src/app/browser/window/tab/item/page/navigation/home/widget.rs b/src/app/browser/window/tab/item/page/navigation/home/widget.rs index 8df4a6e1..cb142905 100644 --- a/src/app/browser/window/tab/item/page/navigation/home/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/home/widget.rs @@ -1,4 +1,4 @@ -use crate::app::browser::window::Action; +use super::WindowAction; use gtk::{ prelude::{ButtonExt, WidgetExt}, Button, @@ -6,28 +6,33 @@ use gtk::{ use std::rc::Rc; pub struct Widget { - pub gobject: Button, + pub button: Button, } impl Widget { - // Construct - pub fn new(action: Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(action: &Rc) -> Self { // Init gobject - let gobject = Button::builder() + let button = Button::builder() .icon_name("go-home-symbolic") .tooltip_text("Home") .sensitive(false) .build(); // Init events - gobject.connect_clicked(move |_| action.home.activate()); + button.connect_clicked({ + let action = action.clone(); + move |_| action.home.activate() + }); // Return activated `Self` - Self { gobject } + Self { button } } // Actions pub fn update(&self, is_sensitive: bool) { - self.gobject.set_sensitive(is_sensitive); + self.button.set_sensitive(is_sensitive); } } 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 7bd497a3..4ed134c0 100644 --- a/src/app/browser/window/tab/item/page/navigation/reload.rs +++ b/src/app/browser/window/tab/item/page/navigation/reload.rs @@ -2,7 +2,7 @@ mod widget; use widget::Widget; -use crate::app::browser::window::action::Action as WindowAction; +use super::WindowAction; use std::rc::Rc; pub struct Reload { @@ -11,11 +11,13 @@ pub struct Reload { } impl Reload { - // Construct - pub fn new(action: Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(action: &Rc) -> Self { Self { action: action.clone(), - widget: Rc::new(Widget::new(action)), + widget: Rc::new(Widget::build(action)), } } 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 index 7bebeb35..8841e3b8 100644 --- a/src/app/browser/window/tab/item/page/navigation/reload/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/reload/widget.rs @@ -1,4 +1,4 @@ -use crate::app::browser::window::Action; +use super::WindowAction; use gtk::{ prelude::{ButtonExt, WidgetExt}, Button, @@ -6,28 +6,33 @@ use gtk::{ use std::rc::Rc; pub struct Widget { - pub gobject: Button, + pub button: Button, } impl Widget { - // Construct - pub fn new(action: Rc) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(action: &Rc) -> Self { // Init gobject - let gobject = Button::builder() + let button = Button::builder() .icon_name("view-refresh-symbolic") .tooltip_text("Reload") .sensitive(false) .build(); // Init events - gobject.connect_clicked(move |_| action.reload.activate()); + button.connect_clicked({ + let action = action.clone(); + move |_| action.reload.activate() + }); // Return activated `Self` - Self { gobject } + Self { button } } // Actions pub fn update(&self, is_sensitive: bool) { - self.gobject.set_sensitive(is_sensitive); + self.button.set_sensitive(is_sensitive); } } diff --git a/src/app/browser/window/tab/item/page/navigation/request.rs b/src/app/browser/window/tab/item/page/navigation/request.rs index 2d2d24c7..f29e1155 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -19,14 +19,17 @@ pub struct Request { } impl Request { - // Construct - pub fn new(action: (Rc, Rc)) -> Self { + // Constructors + + /// Build new `Self` + pub fn build((browser_action, tab_action): (&Rc, &Rc)) -> Self { Self { - widget: Rc::new(Widget::new(action)), + widget: Rc::new(Widget::build((browser_action, tab_action))), } } // Actions + pub fn update(&self, progress_fraction: Option, is_identity_active: bool) { self.widget.update(progress_fraction, is_identity_active); } diff --git a/src/app/browser/window/tab/item/page/navigation/request/widget.rs b/src/app/browser/window/tab/item/page/navigation/request/widget.rs index 24fcb9fa..3746a9b8 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/widget.rs @@ -3,7 +3,7 @@ mod primary_icon; use primary_icon::PrimaryIcon; -use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction}; +use super::{BrowserAction, TabAction}; use gtk::{ glib::{timeout_add_local, ControlFlow, SourceId}, prelude::{EditableExt, EntryExt, WidgetExt}, @@ -33,11 +33,10 @@ pub struct Widget { } impl Widget { - // Construct - pub fn new(action: (Rc, Rc)) -> Self { - // Set actions name - let (browser_action, tab_action) = action; + // Constructors + /// Build new `Self` + pub fn build((browser_action, tab_action): (&Rc, &Rc)) -> Self { // Init animated progress bar state let progress = Rc::new(Progress { fraction: RefCell::new(0.0), @@ -70,12 +69,18 @@ impl Widget { } }); - entry.connect_changed(move |_| { - browser_action.update.activate(None); + entry.connect_changed({ + let browser_action = browser_action.clone(); + move |_| { + browser_action.update.activate(None); + } }); - entry.connect_activate(move |entry| { - tab_action.load.activate(Some(&entry.text()), true); + entry.connect_activate({ + let tab_action = tab_action.clone(); + move |entry| { + tab_action.load.activate(Some(&entry.text()), true); + } }); entry.connect_state_flags_changed({ diff --git a/src/app/browser/window/tab/item/page/navigation/widget.rs b/src/app/browser/window/tab/item/page/navigation/widget.rs index c5c83280..113b20ee 100644 --- a/src/app/browser/window/tab/item/page/navigation/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/widget.rs @@ -11,8 +11,10 @@ pub struct Widget { } impl Widget { - // Construct - pub fn new( + // Constructors + + /// Build new `Self` + pub fn build( base: &impl IsA, history: &impl IsA, reload: &impl IsA, diff --git a/src/app/browser/window/tab/item/page/widget.rs b/src/app/browser/window/tab/item/page/widget.rs index 10304df7..ce6fed29 100644 --- a/src/app/browser/window/tab/item/page/widget.rs +++ b/src/app/browser/window/tab/item/page/widget.rs @@ -8,8 +8,10 @@ pub struct Widget { } impl Widget { - // Construct - pub fn new( + // Constructors + + /// Build new `Self` + pub fn build( name: &str, // Components navigation: &impl IsA, diff --git a/src/app/browser/window/tab/item/widget.rs b/src/app/browser/window/tab/item/widget.rs index e670620a..5f93baca 100644 --- a/src/app/browser/window/tab/item/widget.rs +++ b/src/app/browser/window/tab/item/widget.rs @@ -14,7 +14,8 @@ pub struct Widget { impl Widget { // Constructors - pub fn new( + /// Build new `Self` + pub fn build( keyword: &str, // ID tab_view: &TabView, child: &impl IsA, diff --git a/src/app/browser/window/widget.rs b/src/app/browser/window/widget.rs index 027940fd..5b1b2bd4 100644 --- a/src/app/browser/window/widget.rs +++ b/src/app/browser/window/widget.rs @@ -6,9 +6,12 @@ pub struct Widget { } impl Widget { - // Construct - pub fn new(header: &ToolbarView, tab: &TabView) -> Self { + // Constructors + + /// Build new `Self` + pub fn build(header: &ToolbarView, tab: &TabView) -> Self { let g_box = Box::builder().orientation(Orientation::Vertical).build(); + g_box.append(header); g_box.append(tab); diff --git a/src/main.rs b/src/main.rs index c3adb2fd..48cd3423 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ use std::rc::Rc; fn main() -> ExitCode { match gtk::init() { - Ok(_) => App::new(Rc::new(Profile::new())).run(), + Ok(_) => App::build(&Rc::new(Profile::new())).run(), Err(_) => ExitCode::FAILURE, } }