rename constructors

This commit is contained in:
yggverse 2025-01-15 00:25:33 +02:00
parent 941b1cc283
commit edb385f903
36 changed files with 266 additions and 180 deletions

View file

@ -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)),
}
}

View file

@ -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 });
}
}

View file

@ -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());

View file

@ -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)),
}
}

View file

@ -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);
}
}

View file

@ -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)),
}
}

View file

@ -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);
}
}

View file

@ -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 }
}
}

View file

@ -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)),
}
}

View file

@ -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);
}
}

View file

@ -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)),
}
}

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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({

View file

@ -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>,