mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-24 18:14:14 +00:00
rename constructors
This commit is contained in:
parent
941b1cc283
commit
edb385f903
10
src/app.rs
10
src/app.rs
@ -20,15 +20,17 @@ pub struct App {
|
||||
}
|
||||
|
||||
impl App {
|
||||
// Construct
|
||||
pub fn new(profile: Rc<Profile>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(profile: &Rc<Profile>) -> 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,
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,13 @@ pub struct Browser {
|
||||
}
|
||||
|
||||
impl Browser {
|
||||
// Construct
|
||||
pub fn new(profile: Rc<Profile>) -> Browser {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(profile: &Rc<Profile>) -> 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(
|
||||
|
@ -22,19 +22,24 @@ pub struct Window {
|
||||
}
|
||||
|
||||
impl Window {
|
||||
// Construct
|
||||
pub fn new(profile: Rc<Profile>, browser_action: Rc<BrowserAction>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(profile: &Rc<Profile>, browser_action: &Rc<BrowserAction>) -> 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({
|
||||
|
@ -15,17 +15,22 @@ pub struct Header {
|
||||
impl Header {
|
||||
// Constructors
|
||||
|
||||
pub fn new(
|
||||
/// Build new `Self`
|
||||
pub fn build(
|
||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
profile: &Rc<Profile>,
|
||||
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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,16 +19,17 @@ pub struct Bar {
|
||||
impl Bar {
|
||||
// Constructors
|
||||
|
||||
pub fn new(
|
||||
/// Build new `Self`
|
||||
pub fn build(
|
||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
profile: &Rc<Profile>,
|
||||
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,
|
||||
|
@ -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<BrowserAction>, &Rc<WindowAction>),
|
||||
profile: &Rc<Profile>,
|
||||
) -> Self {
|
||||
|
@ -16,9 +16,9 @@ impl Tab {
|
||||
// Construct
|
||||
pub fn new(window_action: &Rc<WindowAction>, 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,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
@ -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<WindowAction>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(window_action: &Rc<WindowAction>) -> Self {
|
||||
Self {
|
||||
widget: Rc::new(Widget::new(window_action.clone())),
|
||||
widget: Rc::new(Widget::build(window_action)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<WindowAction>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(window_action: &Rc<WindowAction>) -> 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 }
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,10 @@ pub struct Widget {
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new(view: &TabView, start_action_widget: &impl IsA<gtk::Widget>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(view: &TabView, start_action_widget: &impl IsA<gtk::Widget>) -> Self {
|
||||
Self {
|
||||
tab_bar: TabBar::builder()
|
||||
.autohide(false)
|
||||
|
@ -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<gtk::Widget>,
|
||||
menu: &impl IsA<gtk::Widget>,
|
||||
tab: &impl IsA<gtk::Widget>,
|
||||
) -> Self {
|
||||
let g_box = Box::builder()
|
||||
.orientation(Orientation::Horizontal)
|
||||
.spacing(8)
|
||||
|
@ -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<gtk::Widget>) -> Self {
|
||||
let toolbar_view = ToolbarView::builder().build();
|
||||
|
||||
Self { gobject }
|
||||
toolbar_view.add_top_bar(top_bar);
|
||||
|
||||
Self { toolbar_view }
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,10 @@ pub struct Tab {
|
||||
}
|
||||
|
||||
impl Tab {
|
||||
// Construct
|
||||
pub fn new(
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(
|
||||
profile: &Rc<Profile>,
|
||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
) -> Self {
|
||||
@ -154,7 +156,7 @@ impl Tab {
|
||||
is_load: bool,
|
||||
) -> Rc<Item> {
|
||||
// Init new tab item
|
||||
let item = Rc::new(Item::new(
|
||||
let item = Rc::new(Item::build(
|
||||
&self.widget.tab_view,
|
||||
&self.profile,
|
||||
// Actions
|
||||
|
@ -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<Profile>,
|
||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
@ -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
|
||||
|
@ -60,7 +60,7 @@ pub struct Page {
|
||||
impl Page {
|
||||
// Constructors
|
||||
|
||||
pub fn new(
|
||||
pub fn build(
|
||||
id: &Rc<GString>,
|
||||
profile: &Rc<Profile>,
|
||||
(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,
|
||||
|
@ -26,11 +26,11 @@ impl Content {
|
||||
// Construct
|
||||
|
||||
/// Create new container for different components
|
||||
pub fn new((window_action, tab_action): (Rc<WindowAction>, Rc<TabAction>)) -> Self {
|
||||
pub fn build((window_action, tab_action): (&Rc<WindowAction>, &Rc<TabAction>)) -> Self {
|
||||
Self {
|
||||
g_box: Box::builder().orientation(Orientation::Vertical).build(),
|
||||
window_action,
|
||||
tab_action,
|
||||
window_action: window_action.clone(),
|
||||
tab_action: tab_action.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Profile>,
|
||||
action: (Rc<BrowserAction>, Rc<WindowAction>, Rc<TabAction>),
|
||||
pub fn build(
|
||||
profile: &Rc<Profile>,
|
||||
(browser_action, window_action, tab_action): (
|
||||
&Rc<BrowserAction>,
|
||||
&Rc<WindowAction>,
|
||||
&Rc<TabAction>,
|
||||
),
|
||||
) -> 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,
|
||||
|
@ -10,10 +10,12 @@ pub struct Bookmark {
|
||||
}
|
||||
|
||||
impl Bookmark {
|
||||
// Construct
|
||||
pub fn new(action: Rc<WindowAction>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action: &Rc<WindowAction>) -> Self {
|
||||
Self {
|
||||
widget: Rc::new(Widget::new(action.clone())),
|
||||
widget: Rc::new(Widget::build(action)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Action>) -> Self {
|
||||
/// Build new `Self`
|
||||
pub fn build(action: &Rc<WindowAction>) -> 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 });
|
||||
}
|
||||
}
|
||||
|
@ -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<WindowAction>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action: &Rc<WindowAction>) -> 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());
|
||||
|
@ -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>,
|
||||
action: Rc<WindowAction>,
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Back {
|
||||
// Constructors
|
||||
|
||||
pub fn new(action: Rc<Action>) -> Self {
|
||||
/// Build new `Self`
|
||||
pub fn build(action: &Rc<WindowAction>) -> Self {
|
||||
Self {
|
||||
action: action.clone(),
|
||||
widget: Rc::new(Widget::new(action)),
|
||||
widget: Rc::new(Widget::build(action)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Action>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action: &Rc<WindowAction>) -> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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>,
|
||||
action: Rc<WindowAction>,
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Forward {
|
||||
// Construct
|
||||
pub fn new(action: Rc<Action>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action: &Rc<WindowAction>) -> Self {
|
||||
Self {
|
||||
action: action.clone(),
|
||||
widget: Rc::new(Widget::new(action)),
|
||||
widget: Rc::new(Widget::build(action)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Action>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action: &Rc<WindowAction>) -> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<gtk::Widget>, forward: &impl IsA<gtk::Widget>) -> Self {
|
||||
// Init widget
|
||||
let gobject = Box::builder()
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(back: &impl IsA<gtk::Widget>, forward: &impl IsA<gtk::Widget>) -> 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 }
|
||||
}
|
||||
}
|
||||
|
@ -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<WindowAction>) -> Self {
|
||||
pub fn build(action: &Rc<WindowAction>) -> Self {
|
||||
Self {
|
||||
action: action.clone(),
|
||||
uri: RefCell::new(None),
|
||||
widget: Rc::new(Widget::new(action)),
|
||||
widget: Rc::new(Widget::build(action)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Action>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action: &Rc<WindowAction>) -> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<WindowAction>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action: &Rc<WindowAction>) -> Self {
|
||||
Self {
|
||||
action: action.clone(),
|
||||
widget: Rc::new(Widget::new(action)),
|
||||
widget: Rc::new(Widget::build(action)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Action>) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action: &Rc<WindowAction>) -> 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);
|
||||
}
|
||||
}
|
||||
|
@ -19,14 +19,17 @@ pub struct Request {
|
||||
}
|
||||
|
||||
impl Request {
|
||||
// Construct
|
||||
pub fn new(action: (Rc<BrowserAction>, Rc<TabAction>)) -> Self {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build((browser_action, tab_action): (&Rc<BrowserAction>, &Rc<TabAction>)) -> 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<f64>, is_identity_active: bool) {
|
||||
self.widget.update(progress_fraction, is_identity_active);
|
||||
}
|
||||
|
@ -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<BrowserAction>, Rc<TabAction>)) -> Self {
|
||||
// Set actions name
|
||||
let (browser_action, tab_action) = action;
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build((browser_action, tab_action): (&Rc<BrowserAction>, &Rc<TabAction>)) -> 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({
|
||||
|
@ -11,8 +11,10 @@ pub struct Widget {
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new(
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(
|
||||
base: &impl IsA<gtk::Widget>,
|
||||
history: &impl IsA<gtk::Widget>,
|
||||
reload: &impl IsA<gtk::Widget>,
|
||||
|
@ -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<gtk::Widget>,
|
||||
|
@ -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<gtk::Widget>,
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user