define ptr container outside

This commit is contained in:
yggverse 2024-11-11 01:14:09 +02:00
parent 7b2c07ac45
commit a5fc2a7475
58 changed files with 230 additions and 272 deletions

View File

@ -32,8 +32,8 @@ impl Window {
let action = Rc::new(Action::new()); let action = Rc::new(Action::new());
// Init components // Init components
let tab = Tab::new_rc(browser_action.clone(), action.clone()); let tab = Rc::new(Tab::new(browser_action.clone(), action.clone()));
let header = Header::new_rc(browser_action, action.clone(), tab.gobject()); let header = Header::new(browser_action, action.clone(), tab.gobject());
// GTK // GTK
let widget = Rc::new(Widget::new(header.gobject(), tab.gobject())); let widget = Rc::new(Widget::new(header.gobject(), tab.gobject()));

View File

@ -15,20 +15,20 @@ pub struct Header {
impl Header { impl Header {
// Construct // Construct
pub fn new_rc( pub fn new(
// Actions // Actions
browser_action: Rc<BrowserAction>, browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>, window_action: Rc<WindowAction>,
// Widgets // Widgets
tab_view: &TabView, tab_view: &TabView,
) -> Rc<Self> { ) -> Self {
// Init components // Init components
let bar = Bar::new_rc(browser_action, window_action, tab_view); let bar = Bar::new(browser_action, window_action, tab_view);
// Return new struct // Return new struct
Rc::new(Self { Self {
widget: Widget::new_rc(bar.gobject()), widget: Rc::new(Widget::new(bar.gobject())),
}) }
} }
// Getters // Getters

View File

@ -19,24 +19,27 @@ pub struct Bar {
} }
impl Bar { impl Bar {
// Construct // Constructors
pub fn new_rc(
pub fn new(
browser_action: Rc<BrowserAction>, browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>, window_action: Rc<WindowAction>,
view: &TabView, view: &TabView,
) -> Rc<Self> { ) -> Self {
// Init components let control = Control::new();
let control = Control::new_rc(); let tab = Tab::new(window_action.clone(), view);
let tab = Tab::new_rc(window_action.clone(), view); let menu = Menu::new(browser_action, window_action);
let menu = Menu::new_rc(browser_action, window_action); Self {
widget: Rc::new(Widget::new(
// Build result control.gobject(),
Rc::new(Self { menu.gobject(),
widget: Widget::new_rc(control.gobject(), menu.gobject(), tab.gobject()), tab.gobject(),
}) )),
}
} }
// Getters // Getters
pub fn gobject(&self) -> &Box { pub fn gobject(&self) -> &Box {
self.widget.gobject() self.widget.gobject()
} }

View File

@ -11,10 +11,10 @@ pub struct Control {
impl Control { impl Control {
// Construct // Construct
pub fn new_rc() -> Rc<Self> { pub fn new() -> Self {
Rc::new(Self { Self {
widget: Widget::new_rc(), widget: Rc::new(Widget::new()),
}) }
} }
// Getters // Getters

View File

@ -1,5 +1,4 @@
use gtk::{PackType, WindowControls}; use gtk::{PackType, WindowControls};
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: WindowControls, gobject: WindowControls,
@ -7,13 +6,13 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc() -> Rc<Self> { pub fn new() -> Self {
Rc::new(Self { Self {
gobject: WindowControls::builder() gobject: WindowControls::builder()
.side(PackType::End) .side(PackType::End)
.margin_end(4) .margin_end(4)
.build(), .build(),
}) }
} }
// Getters // Getters

View File

@ -15,10 +15,10 @@ pub struct Menu {
} }
#[rustfmt::skip] // @TODO template builder? #[rustfmt::skip] // @TODO template builder?
impl Menu { impl Menu {
pub fn new_rc( pub fn new(
browser_action: Rc<BrowserAction>, browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>, window_action: Rc<WindowAction>,
) -> Rc<Self> { ) -> Self {
// Main // Main
let main = gio::Menu::new(); let main = gio::Menu::new();
@ -120,7 +120,7 @@ impl Menu {
))); )));
// Result // Result
Rc::new(Self { widget:Widget::new_rc(&main) }) Self { widget:Rc::new(Widget::new(&main)) }
} }
// Getters // Getters

View File

@ -1,5 +1,4 @@
use gtk::{gio::Menu, Align, MenuButton}; use gtk::{gio::Menu, Align, MenuButton};
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: MenuButton, gobject: MenuButton,
@ -7,8 +6,8 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(model: &Menu) -> Rc<Self> { pub fn new(model: &Menu) -> Self {
Rc::new(Self { Self {
gobject: MenuButton::builder() gobject: MenuButton::builder()
.css_classes(["flat"]) .css_classes(["flat"])
.icon_name("open-menu-symbolic") .icon_name("open-menu-symbolic")
@ -16,7 +15,7 @@ impl Widget {
.tooltip_text("Menu") .tooltip_text("Menu")
.valign(Align::Center) .valign(Align::Center)
.build(), .build(),
}) }
} }
// Getters // Getters

View File

@ -14,10 +14,10 @@ pub struct Tab {
impl Tab { impl Tab {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>, view: &TabView) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>, view: &TabView) -> Self {
Rc::new(Self { Self {
widget: Widget::new_rc(view, Append::new_rc(window_action).gobject()), widget: Rc::new(Widget::new(view, Append::new(window_action).gobject())),
}) }
} }
// Getters // Getters

View File

@ -12,10 +12,10 @@ pub struct Append {
impl Append { impl Append {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>) -> Self {
Rc::new(Self { Self {
widget: Widget::new_rc(window_action), widget: Rc::new(Widget::new(window_action)),
}) }
} }
// Getters // Getters

View File

@ -8,7 +8,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>) -> Self {
// Init gobject // Init gobject
let gobject = Button::builder() let gobject = Button::builder()
.icon_name("tab-new-symbolic") .icon_name("tab-new-symbolic")
@ -20,7 +20,7 @@ impl Widget {
// Init events // Init events
gobject.connect_clicked(move |_| window_action.append().activate()); gobject.connect_clicked(move |_| window_action.append().activate());
Rc::new(Self { gobject }) Self { gobject }
} }
// Getters // Getters

View File

@ -1,6 +1,5 @@
use adw::{TabBar, TabView}; use adw::{TabBar, TabView};
use gtk::prelude::IsA; use gtk::prelude::IsA;
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: TabBar, gobject: TabBar,
@ -8,15 +7,15 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(view: &TabView, start_action_widget: &impl IsA<gtk::Widget>) -> Rc<Self> { pub fn new(view: &TabView, start_action_widget: &impl IsA<gtk::Widget>) -> Self {
Rc::new(Self { Self {
gobject: TabBar::builder() gobject: TabBar::builder()
.autohide(false) .autohide(false)
.expand_tabs(false) .expand_tabs(false)
.end_action_widget(start_action_widget) // @TODO find solution to append after tabs .end_action_widget(start_action_widget) // @TODO find solution to append after tabs
.view(view) .view(view)
.build(), .build(),
}) }
} }
// Getters // Getters

View File

@ -1,6 +1,5 @@
use adw::TabBar; use adw::TabBar;
use gtk::{prelude::BoxExt, Box, MenuButton, Orientation, WindowControls}; use gtk::{prelude::BoxExt, Box, MenuButton, Orientation, WindowControls};
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: Box, gobject: Box,
@ -8,7 +7,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(control: &WindowControls, menu: &MenuButton, tab: &TabBar) -> Rc<Self> { pub fn new(control: &WindowControls, menu: &MenuButton, tab: &TabBar) -> Self {
let gobject = Box::builder() let gobject = Box::builder()
.orientation(Orientation::Horizontal) .orientation(Orientation::Horizontal)
.spacing(8) .spacing(8)
@ -18,7 +17,7 @@ impl Widget {
gobject.append(menu); gobject.append(menu);
gobject.append(control); gobject.append(control);
Rc::new(Self { gobject }) Self { gobject }
} }
// Getters // Getters

View File

@ -1,6 +1,5 @@
use adw::ToolbarView; use adw::ToolbarView;
use gtk::Box; use gtk::Box;
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: ToolbarView, gobject: ToolbarView,
@ -8,12 +7,12 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(top_bar: &Box) -> Rc<Self> { pub fn new(top_bar: &Box) -> Self {
let gobject = ToolbarView::builder().build(); let gobject = ToolbarView::builder().build();
gobject.add_top_bar(top_bar); gobject.add_top_bar(top_bar);
Rc::new(Self { gobject }) Self { gobject }
} }
// Getters // Getters

View File

@ -33,7 +33,7 @@ pub struct Tab {
impl Tab { impl Tab {
// Construct // Construct
pub fn new_rc(browser_action: Rc<BrowserAction>, window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(browser_action: Rc<BrowserAction>, window_action: Rc<WindowAction>) -> Self {
// Init local actions // Init local actions
let action = Rc::new(Action::new()); let action = Rc::new(Action::new());
@ -115,14 +115,14 @@ impl Tab {
} }
}); // @TODO fix new item on middle click }); // @TODO fix new item on middle click
// Return activated struct // Return activated `Self`
Rc::new(Self { Self {
browser_action, browser_action,
window_action, window_action,
index, index,
action, action,
widget, widget,
}) }
} }
// Actions // Actions

View File

@ -51,7 +51,7 @@ impl Item {
tab_action, tab_action,
); );
let widget = Widget::new_rc( let widget = Rc::new(Widget::new(
id.as_str(), id.as_str(),
tab_view, tab_view,
page.gobject(), page.gobject(),
@ -59,7 +59,7 @@ impl Item {
position, position,
is_pinned, is_pinned,
is_selected, is_selected,
); // @TODO )); // @TODO
// Return struct // Return struct
Rc::new(Self { id, page, widget }) Rc::new(Self { id, page, widget })

View File

@ -67,25 +67,25 @@ impl Page {
SimpleAction::new(&uuid_string_random(), Some(&String::static_variant_type())); SimpleAction::new(&uuid_string_random(), Some(&String::static_variant_type()));
// Init components // Init components
let content = Content::new_rc(tab_action.clone(), action_page_open.clone()); let content = Rc::new(Content::new(tab_action.clone(), action_page_open.clone()));
let navigation = Navigation::new_rc( let navigation = Rc::new(Navigation::new(
browser_action.clone(), browser_action.clone(),
window_action.clone(), window_action.clone(),
action_page_open.clone(), action_page_open.clone(),
); ));
let input = Input::new_rc(); let input = Rc::new(Input::new());
let widget = Widget::new_rc( let widget = Rc::new(Widget::new(
&id, &id,
action_page_open.clone(), action_page_open.clone(),
navigation.widget().gobject(), navigation.widget().gobject(),
content.gobject(), content.gobject(),
input.gobject(), input.gobject(),
); ));
let meta = Meta::new_rc(Status::New, gformat!("New page")); let meta = Rc::new(Meta::new(Status::New, gformat!("New page")));
// Init `Self` // Init `Self`
let this = Rc::new(Self { let this = Rc::new(Self {

View File

@ -28,12 +28,12 @@ impl Content {
// Construct // Construct
/// Create new container for different components /// Create new container for different components
pub fn new_rc(tab_action: Rc<TabAction>, action_page_open: SimpleAction) -> Rc<Self> { pub fn new(tab_action: Rc<TabAction>, action_page_open: SimpleAction) -> Self {
Rc::new(Self { Self {
gobject: Box::builder().orientation(Orientation::Vertical).build(), gobject: Box::builder().orientation(Orientation::Vertical).build(),
tab_action, tab_action,
action_page_open, action_page_open,
}) }
} }
// Actions // Actions

View File

@ -26,9 +26,8 @@ impl Gemini {
action_page_open: SimpleAction, action_page_open: SimpleAction,
) -> Self { ) -> Self {
// Init components // Init components
let reader = Reader::new_rc(gemtext, base, tab_action, action_page_open); let reader = Rc::new(Reader::new(gemtext, base, tab_action, action_page_open));
let widget = Rc::new(Widget::new(reader.gobject()));
let widget = Widget::new_rc(reader.gobject());
// Result // Result
Self { reader, widget } Self { reader, widget }

View File

@ -30,12 +30,12 @@ pub struct Reader {
impl Reader { impl Reader {
// Construct // Construct
pub fn new_rc( pub fn new(
gemtext: &str, gemtext: &str,
base: &Uri, base: &Uri,
tab_action: Rc<TabAction>, tab_action: Rc<TabAction>,
action_page_open: SimpleAction, action_page_open: SimpleAction,
) -> Rc<Self> { ) -> Self {
// Init default values // Init default values
let mut title = None; let mut title = None;
@ -223,12 +223,12 @@ impl Reader {
let motion_controller = EventControllerMotion::new(); let motion_controller = EventControllerMotion::new();
// Init widget // Init widget
let widget = Widget::new_rc( let widget = Rc::new(Widget::new(
&buffer, &buffer,
primary_button_controller.clone(), primary_button_controller.clone(),
middle_button_controller.clone(), middle_button_controller.clone(),
motion_controller.clone(), motion_controller.clone(),
); ));
// Init events // Init events
primary_button_controller.connect_released({ primary_button_controller.connect_released({
@ -346,7 +346,7 @@ impl Reader {
}); // @TODO may be expensive for CPU, add timeout? }); // @TODO may be expensive for CPU, add timeout?
// Result // Result
Rc::new(Self { title, widget }) Self { title, widget }
} }
// Getters // Getters

View File

@ -1,7 +1,6 @@
use gtk::{ use gtk::{
prelude::WidgetExt, EventControllerMotion, GestureClick, TextBuffer, TextView, WrapMode, prelude::WidgetExt, EventControllerMotion, GestureClick, TextBuffer, TextView, WrapMode,
}; };
use std::rc::Rc;
const MARGIN: i32 = 8; const MARGIN: i32 = 8;
@ -11,12 +10,12 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc( pub fn new(
buffer: &TextBuffer, buffer: &TextBuffer,
primary_button_controller: GestureClick, primary_button_controller: GestureClick,
middle_button_controller: GestureClick, middle_button_controller: GestureClick,
motion_controller: EventControllerMotion, motion_controller: EventControllerMotion,
) -> Rc<Self> { ) -> Self {
let gobject = TextView::builder() let gobject = TextView::builder()
.bottom_margin(MARGIN) .bottom_margin(MARGIN)
.buffer(buffer) .buffer(buffer)
@ -33,7 +32,7 @@ impl Widget {
gobject.add_controller(middle_button_controller); gobject.add_controller(middle_button_controller);
gobject.add_controller(motion_controller); gobject.add_controller(motion_controller);
Rc::new(Self { gobject }) Self { gobject }
} }
// Getters // Getters

View File

@ -1,6 +1,5 @@
use adw::ClampScrollable; use adw::ClampScrollable;
use gtk::TextView; use gtk::TextView;
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: ClampScrollable, gobject: ClampScrollable,
@ -8,14 +7,14 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(child: &TextView) -> Rc<Self> { pub fn new(child: &TextView) -> Self {
Rc::new(Self { Self {
gobject: ClampScrollable::builder() gobject: ClampScrollable::builder()
.child(child) .child(child)
.css_classes(["view"]) .css_classes(["view"])
.maximum_size(800) .maximum_size(800)
.build(), .build(),
}) }
} }
// Getters // Getters

View File

@ -17,12 +17,12 @@ pub struct Input {
impl Input { impl Input {
// Construct // Construct
pub fn new_rc() -> Rc<Self> { pub fn new() -> Self {
// Init widget // Init widget
let widget = Widget::new_rc(); let widget = Rc::new(Widget::new());
// Result // Result
Rc::new(Self { widget }) Self { widget }
} }
// Actions // Actions
@ -39,7 +39,7 @@ impl Input {
size_limit: Option<usize>, size_limit: Option<usize>,
) { ) {
self.widget.update(Some( self.widget.update(Some(
Response::new_rc(action, base, title, size_limit).gobject(), Response::new(action, base, title, size_limit).gobject(),
)); ));
} }
@ -51,7 +51,7 @@ impl Input {
max_length: Option<i32>, max_length: Option<i32>,
) { ) {
self.widget.update(Some( self.widget.update(Some(
Sensitive::new_rc(action, base, title, max_length).gobject(), Sensitive::new(action, base, title, max_length).gobject(),
)); ));
} }

View File

@ -24,23 +24,27 @@ pub struct Response {
impl Response { impl Response {
// Construct // Construct
pub fn new_rc( pub fn new(
tab_action: Rc<TabAction>, tab_action: Rc<TabAction>,
base: Uri, base: Uri,
title: Option<&str>, title: Option<&str>,
size_limit: Option<usize>, size_limit: Option<usize>,
) -> Rc<Self> { ) -> Self {
// Init local actions // Init local actions
let action_update = SimpleAction::new(&uuid_string_random(), None); let action_update = SimpleAction::new(&uuid_string_random(), None);
let action_send = SimpleAction::new(&uuid_string_random(), None); let action_send = SimpleAction::new(&uuid_string_random(), None);
// Init components // Init components
let control = Control::new_rc(action_send.clone()); let control = Rc::new(Control::new(action_send.clone()));
let form = Form::new_rc(action_update.clone()); let form = Rc::new(Form::new(action_update.clone()));
let title = Title::new_rc(title); let title = Rc::new(Title::new(title));
// Init widget // Init widget
let widget = Widget::new_rc(title.gobject(), form.gobject(), control.gobject()); let widget = Rc::new(Widget::new(
title.gobject(),
form.gobject(),
control.gobject(),
));
// Init events // Init events
action_update.connect_activate({ action_update.connect_activate({
@ -70,7 +74,7 @@ impl Response {
widget.gobject().connect_realize(move |_| form.focus()); widget.gobject().connect_realize(move |_| form.focus());
// Return activated struct // Return activated struct
Rc::new(Self { widget }) Self { widget }
} }
// Getters // Getters

View File

@ -17,20 +17,20 @@ pub struct Control {
impl Control { impl Control {
// Construct // Construct
pub fn new_rc(action_send: SimpleAction) -> Rc<Self> { pub fn new(action_send: SimpleAction) -> Self {
// Init components // Init components
let counter = Counter::new_rc(); let counter = Rc::new(Counter::new());
let send = Send::new_rc(action_send); let send = Rc::new(Send::new(action_send));
// Init widget // Init widget
let widget = Widget::new_rc(counter.gobject(), send.gobject()); let widget = Rc::new(Widget::new(counter.gobject(), send.gobject()));
// Return activated struct // Return activated struct
Rc::new(Self { Self {
counter, counter,
send, send,
widget, widget,
}) }
} }
// Actions // Actions

View File

@ -11,12 +11,10 @@ pub struct Counter {
impl Counter { impl Counter {
// Construct // Construct
pub fn new_rc() -> Rc<Self> { pub fn new() -> Self {
// Init widget Self {
let widget = Widget::new_rc(); widget: Rc::new(Widget::new()),
}
// Result
Rc::new(Self { widget })
} }
// Actions // Actions

View File

@ -1,5 +1,4 @@
use gtk::{prelude::WidgetExt, Label}; use gtk::{prelude::WidgetExt, Label};
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: Label, gobject: Label,
@ -7,10 +6,10 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc() -> Rc<Self> { pub fn new() -> Self {
let gobject = Label::builder().build(); Self {
gobject: Label::builder().build(),
Rc::new(Self { gobject }) }
} }
// Actions // Actions

View File

@ -1,5 +1,4 @@
mod widget; mod widget;
use widget::Widget; use widget::Widget;
use gtk::{gio::SimpleAction, Button}; use gtk::{gio::SimpleAction, Button};
@ -11,12 +10,12 @@ pub struct Send {
impl Send { impl Send {
// Construct // Construct
pub fn new_rc(action_send: SimpleAction) -> Rc<Self> { pub fn new(action_send: SimpleAction) -> Self {
// Init widget // Init widget
let widget = Widget::new_rc(action_send); let widget = Rc::new(Widget::new(action_send));
// Result // Result
Rc::new(Self { widget }) Self { widget }
} }
// Actions // Actions

View File

@ -3,7 +3,6 @@ use gtk::{
prelude::{ActionExt, ButtonExt, WidgetExt}, prelude::{ActionExt, ButtonExt, WidgetExt},
Button, Button,
}; };
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: Button, gobject: Button,
@ -11,7 +10,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(action_send: SimpleAction) -> Rc<Self> { pub fn new(action_send: SimpleAction) -> Self {
// Init gobject // Init gobject
let gobject = Button::builder() let gobject = Button::builder()
//.css_classes(["accent"]) //.css_classes(["accent"])
@ -25,8 +24,8 @@ impl Widget {
} }
}); });
// Return activated struct // Return activated `Self`
Rc::new(Self { gobject }) Self { gobject }
} }
// Actions // Actions

View File

@ -1,5 +1,4 @@
use gtk::{prelude::BoxExt, Align, Box, Button, Label, Orientation}; use gtk::{prelude::BoxExt, Align, Box, Button, Label, Orientation};
use std::rc::Rc;
const SPACING: i32 = 8; const SPACING: i32 = 8;
@ -9,7 +8,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(limit: &Label, send: &Button) -> Rc<Self> { pub fn new(limit: &Label, send: &Button) -> Self {
// Init gobject // Init gobject
let gobject = Box::builder() let gobject = Box::builder()
.halign(Align::End) .halign(Align::End)
@ -20,8 +19,8 @@ impl Widget {
gobject.append(limit); gobject.append(limit);
gobject.append(send); gobject.append(send);
// Return new struct // Return new `Self`
Rc::new(Self { gobject }) Self { gobject }
} }
// Getters // Getters

View File

@ -11,12 +11,10 @@ pub struct Form {
impl Form { impl Form {
// Construct // Construct
pub fn new_rc(action_update: SimpleAction) -> Rc<Self> { pub fn new(action_update: SimpleAction) -> Self {
// Init widget Self {
let widget = Widget::new_rc(action_update); widget: Rc::new(Widget::new(action_update)),
}
// Result
Rc::new(Self { widget })
} }
// Actions // Actions

View File

@ -4,7 +4,6 @@ use gtk::{
prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt}, prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt},
TextView, WrapMode, TextView, WrapMode,
}; };
use std::rc::Rc;
const MARGIN: i32 = 8; const MARGIN: i32 = 8;
@ -14,7 +13,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(action_update: SimpleAction) -> Rc<Self> { pub fn new(action_update: SimpleAction) -> Self {
// Init gobject // Init gobject
let gobject = TextView::builder() let gobject = TextView::builder()
.bottom_margin(MARGIN) .bottom_margin(MARGIN)
@ -29,8 +28,8 @@ impl Widget {
action_update.activate(None); action_update.activate(None);
}); });
// Return activated struct // Return activated `Self`
Rc::new(Self { gobject }) Self { gobject }
} }
// Actions // Actions

View File

@ -11,12 +11,10 @@ pub struct Title {
impl Title { impl Title {
// Construct // Construct
pub fn new_rc(title: Option<&str>) -> Rc<Self> { pub fn new(title: Option<&str>) -> Self {
// Init widget Self {
let widget = Widget::new_rc(title); widget: Rc::new(Widget::new(title)),
}
// Result
Rc::new(Self { widget })
} }
// Getters // Getters

View File

@ -1,5 +1,4 @@
use gtk::{prelude::WidgetExt, Align, Label}; use gtk::{prelude::WidgetExt, Align, Label};
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: Label, gobject: Label,
@ -7,7 +6,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(title: Option<&str>) -> Rc<Self> { pub fn new(title: Option<&str>) -> Self {
let gobject = Label::builder() let gobject = Label::builder()
.css_classes(["heading"]) .css_classes(["heading"])
.halign(Align::Start) .halign(Align::Start)
@ -23,7 +22,7 @@ impl Widget {
} }
} }
Rc::new(Self { gobject }) Self { gobject }
} }
// Getters // Getters

View File

@ -1,5 +1,4 @@
use gtk::{prelude::BoxExt, Box, Label, Orientation, TextView}; use gtk::{prelude::BoxExt, Box, Label, Orientation, TextView};
use std::rc::Rc;
const MARGIN: i32 = 6; const MARGIN: i32 = 6;
const SPACING: i32 = 8; const SPACING: i32 = 8;
@ -10,7 +9,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(title: &Label, response: &TextView, control: &Box) -> Rc<Self> { pub fn new(title: &Label, response: &TextView, control: &Box) -> Self {
let gobject = Box::builder() let gobject = Box::builder()
.margin_bottom(MARGIN) .margin_bottom(MARGIN)
.margin_end(MARGIN) .margin_end(MARGIN)
@ -24,7 +23,7 @@ impl Widget {
gobject.append(response); gobject.append(response);
gobject.append(control); gobject.append(control);
Rc::new(Self { gobject }) Self { gobject }
} }
// Getters // Getters

View File

@ -20,25 +20,25 @@ pub struct Sensitive {
impl Sensitive { impl Sensitive {
// Construct // Construct
pub fn new_rc( pub fn new(
tab_action: Rc<TabAction>, tab_action: Rc<TabAction>,
base: Uri, base: Uri,
title: Option<&str>, title: Option<&str>,
max_length: Option<i32>, max_length: Option<i32>,
) -> Rc<Self> { ) -> Self {
// Init local actions // Init local actions
let action_send = SimpleAction::new(&uuid_string_random(), None); let action_send = SimpleAction::new(&uuid_string_random(), None);
// Init components // Init components
let form = Form::new_rc( let form = Rc::new(Form::new(
action_send.clone(), action_send.clone(),
title, title,
max_length max_length
.map(|value| value - base.to_string_partial(UriHideFlags::QUERY).len() as i32), .map(|value| value - base.to_string_partial(UriHideFlags::QUERY).len() as i32),
); ));
// Init widget // Init widget
let widget = Widget::new_rc(form.gobject()); let widget = Rc::new(Widget::new(form.gobject()));
// Init events // Init events
action_send.connect_activate({ action_send.connect_activate({
@ -55,7 +55,7 @@ impl Sensitive {
widget.gobject().connect_realize(move |_| form.focus()); widget.gobject().connect_realize(move |_| form.focus());
// Return activated struct // Return activated struct
Rc::new(Self { widget }) Self { widget }
} }
// Getters // Getters

View File

@ -12,16 +12,12 @@ pub struct Form {
impl Form { impl Form {
// Construct // Construct
pub fn new_rc( pub fn new(action_send: SimpleAction, title: Option<&str>, max_length: Option<i32>) -> Self {
action_send: SimpleAction,
title: Option<&str>,
max_length: Option<i32>,
) -> Rc<Self> {
// Init widget // Init widget
let widget = Widget::new_rc(action_send, title, max_length); let widget = Rc::new(Widget::new(action_send, title, max_length));
// Result // Result
Rc::new(Self { widget }) Self { widget }
} }
// Actions // Actions

View File

@ -7,7 +7,6 @@ use gtk::{
glib::GString, glib::GString,
prelude::{ActionExt, EditableExt, WidgetExt}, prelude::{ActionExt, EditableExt, WidgetExt},
}; };
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: PasswordEntryRow, gobject: PasswordEntryRow,
@ -15,11 +14,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc( pub fn new(action_send: SimpleAction, title: Option<&str>, max_length: Option<i32>) -> Self {
action_send: SimpleAction,
title: Option<&str>,
max_length: Option<i32>,
) -> Rc<Self> {
// Init gobject // Init gobject
let gobject = PasswordEntryRow::builder().show_apply_button(true).build(); let gobject = PasswordEntryRow::builder().show_apply_button(true).build();
@ -37,7 +32,7 @@ impl Widget {
}); });
// Return activated struct // Return activated struct
Rc::new(Self { gobject }) Self { gobject }
} }
// Actions // Actions

View File

@ -1,6 +1,5 @@
use adw::PasswordEntryRow; use adw::PasswordEntryRow;
use gtk::{prelude::BoxExt, Box, Orientation}; use gtk::{prelude::BoxExt, Box, Orientation};
use std::rc::Rc;
const MARGIN: i32 = 6; const MARGIN: i32 = 6;
const SPACING: i32 = 8; const SPACING: i32 = 8;
@ -11,7 +10,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(response: &PasswordEntryRow) -> Rc<Self> { pub fn new(response: &PasswordEntryRow) -> Self {
let gobject = Box::builder() let gobject = Box::builder()
.margin_bottom(MARGIN) .margin_bottom(MARGIN)
.margin_end(MARGIN) .margin_end(MARGIN)
@ -23,7 +22,7 @@ impl Widget {
gobject.append(response); gobject.append(response);
Rc::new(Self { gobject }) Self { gobject }
} }
// Getters // Getters

View File

@ -1,6 +1,5 @@
use adw::Clamp; use adw::Clamp;
use gtk::{prelude::WidgetExt, Box}; use gtk::{prelude::WidgetExt, Box};
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: Clamp, gobject: Clamp,
@ -8,14 +7,14 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc() -> Rc<Self> { pub fn new() -> Self {
let gobject = Clamp::builder() let gobject = Clamp::builder()
.css_classes(["app-notification"]) .css_classes(["app-notification"])
.maximum_size(800) .maximum_size(800)
.visible(false) .visible(false)
.build(); .build();
Rc::new(Self { gobject }) Self { gobject }
} }
// Actions // Actions

View File

@ -6,7 +6,7 @@ use redirect::Redirect;
use gtk::glib::GString; use gtk::glib::GString;
use sqlite::Transaction; use sqlite::Transaction;
use std::{cell::RefCell, rc::Rc}; use std::cell::RefCell;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Status { pub enum Status {
@ -39,13 +39,13 @@ pub struct Meta {
impl Meta { impl Meta {
// Constructors // Constructors
pub fn new_rc(status: Status, title: GString) -> Rc<Self> { pub fn new(status: Status, title: GString) -> Self {
Rc::new(Self { Self {
status: RefCell::new(status), status: RefCell::new(status),
title: RefCell::new(title), title: RefCell::new(title),
redirect: RefCell::new(None), redirect: RefCell::new(None),
redirect_count: RefCell::new(None), redirect_count: RefCell::new(None),
}) }
} }
// Setters // Setters

View File

@ -30,36 +30,36 @@ pub struct Navigation {
} }
impl Navigation { impl Navigation {
pub fn new_rc( pub fn new(
browser_action: Rc<BrowserAction>, browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>, window_action: Rc<WindowAction>,
action_page_open: SimpleAction, action_page_open: SimpleAction,
) -> Rc<Self> { ) -> Self {
// Init components // Init components
let home = Home::new_rc(window_action.clone()); let home = Rc::new(Home::new(window_action.clone()));
let history = History::new_rc(window_action.clone()); let history = Rc::new(History::new(window_action.clone()));
let reload = Reload::new_rc(window_action); let reload = Rc::new(Reload::new(window_action));
let request = Request::new_rc(browser_action, action_page_open.clone()); let request = Rc::new(Request::new(browser_action, action_page_open.clone()));
let bookmark = Bookmark::new_rc(); let bookmark = Rc::new(Bookmark::new());
// Init widget // Init widget
let widget = Widget::new_rc( let widget = Rc::new(Widget::new(
home.gobject(), home.gobject(),
history.gobject(), history.gobject(),
reload.gobject(), reload.gobject(),
request.widget().gobject(), request.widget().gobject(),
bookmark.gobject(), bookmark.gobject(),
); ));
// Result // Done
Rc::new(Self { Self {
widget, widget,
home, home,
history, history,
reload, reload,
request, request,
bookmark, bookmark,
}) }
} }
// Actions // Actions

View File

@ -11,10 +11,10 @@ pub struct Bookmark {
impl Bookmark { impl Bookmark {
// Construct // Construct
pub fn new_rc() -> Rc<Self> { pub fn new() -> Self {
Rc::new(Self { Self {
widget: Widget::new_rc(), widget: Rc::new(Widget::new()),
}) }
} }
// Actions // Actions

View File

@ -1,5 +1,4 @@
use gtk::Button; use gtk::Button;
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: Button, gobject: Button,
@ -7,14 +6,14 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc() -> Rc<Self> { pub fn new() -> Self {
Rc::new(Self { Self {
gobject: Button::builder() gobject: Button::builder()
.icon_name("starred-symbolic") .icon_name("starred-symbolic")
.tooltip_text("Bookmark") .tooltip_text("Bookmark")
.sensitive(false) .sensitive(false)
.build(), .build(),
}) }
} }
// Getters // Getters

View File

@ -28,13 +28,13 @@ pub struct History {
impl History { impl History {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>) -> Self {
// init components // init components
let back = Back::new_rc(window_action.clone()); let back = Rc::new(Back::new(window_action.clone()));
let forward = Forward::new_rc(window_action); let forward = Rc::new(Forward::new(window_action));
// Init widget // Init widget
let widget = Widget::new_rc(back.gobject(), forward.gobject()); let widget = Rc::new(Widget::new(back.gobject(), forward.gobject()));
// Init memory // Init memory
let memory = RefCell::new(Vec::new()); let memory = RefCell::new(Vec::new());
@ -42,13 +42,13 @@ impl History {
// Init index // Init index
let index = RefCell::new(None); let index = RefCell::new(None);
Rc::new(Self { Self {
back, back,
forward, forward,
memory, memory,
index, index,
widget, widget,
}) }
} }
// Actions // Actions

View File

@ -13,12 +13,11 @@ pub struct Back {
impl Back { impl Back {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>) -> Self {
// Return activated struct Self {
Rc::new(Self {
window_action: window_action.clone(), window_action: window_action.clone(),
widget: Widget::new_rc(window_action), widget: Rc::new(Widget::new(window_action)),
}) }
} }
// Actions // Actions

View File

@ -11,7 +11,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>) -> Self {
// Init gobject // Init gobject
let gobject = Button::builder() let gobject = Button::builder()
.icon_name("go-previous-symbolic") .icon_name("go-previous-symbolic")
@ -20,15 +20,10 @@ impl Widget {
.build(); .build();
// Init events // Init events
gobject.connect_clicked({ gobject.connect_clicked(move |_| window_action.history_back().activate());
let window_action = window_action.clone();
move |_| {
window_action.history_back().activate();
}
});
// Return activated struct // Return activated `Self`
Rc::new(Self { gobject }) Self { gobject }
} }
// Actions // Actions

View File

@ -13,12 +13,11 @@ pub struct Forward {
impl Forward { impl Forward {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>) -> Self {
// Return activated struct Self {
Rc::new(Self {
window_action: window_action.clone(), window_action: window_action.clone(),
widget: Widget::new_rc(window_action), widget: Rc::new(Widget::new(window_action)),
}) }
} }
// Actions // Actions

View File

@ -11,7 +11,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>) -> Self {
// Init gobject // Init gobject
let gobject = Button::builder() let gobject = Button::builder()
.icon_name("go-next-symbolic") .icon_name("go-next-symbolic")
@ -20,15 +20,10 @@ impl Widget {
.build(); .build();
// Init events // Init events
gobject.connect_clicked({ gobject.connect_clicked(move |_| window_action.history_forward().activate());
let window_action = window_action.clone();
move |_| {
window_action.history_forward().activate();
}
});
// Return activated struct // Return activated `Self`
Rc::new(Self { gobject }) Self { gobject }
} }
// Actions // Actions

View File

@ -2,7 +2,6 @@ use gtk::{
prelude::{BoxExt, IsA}, prelude::{BoxExt, IsA},
Box, Orientation, Box, Orientation,
}; };
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: Box, gobject: Box,
@ -10,7 +9,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(back: &impl IsA<gtk::Widget>, forward: &impl IsA<gtk::Widget>) -> Rc<Self> { pub fn new(back: &impl IsA<gtk::Widget>, forward: &impl IsA<gtk::Widget>) -> Self {
// Init widget // Init widget
let gobject = Box::builder() let gobject = Box::builder()
.orientation(Orientation::Horizontal) .orientation(Orientation::Horizontal)
@ -23,8 +22,8 @@ impl Widget {
gobject.append(back); gobject.append(back);
gobject.append(forward); gobject.append(forward);
// Return activated struct // Return activated `Self`
Rc::new(Self { gobject }) Self { gobject }
} }
// Getters // Getters

View File

@ -17,12 +17,12 @@ pub struct Home {
impl Home { impl Home {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>) -> Self {
Rc::new(Self { Self {
window_action: window_action.clone(), window_action: window_action.clone(),
uri: RefCell::new(None), uri: RefCell::new(None),
widget: Widget::new_rc(window_action), widget: Rc::new(Widget::new(window_action)),
}) }
} }
// Actions // Actions

View File

@ -11,7 +11,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>) -> Self {
// Init gobject // Init gobject
let gobject = Button::builder() let gobject = Button::builder()
.icon_name("go-home-symbolic") .icon_name("go-home-symbolic")
@ -22,8 +22,8 @@ impl Widget {
// Init events // Init events
gobject.connect_clicked(move |_| window_action.home().activate()); gobject.connect_clicked(move |_| window_action.home().activate());
// Return activated struct // Return activated `Self`
Rc::new(Self { gobject }) Self { gobject }
} }
// Actions // Actions

View File

@ -13,11 +13,11 @@ pub struct Reload {
impl Reload { impl Reload {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>) -> Self {
Rc::new(Self { Self {
window_action: window_action.clone(), window_action: window_action.clone(),
widget: Widget::new_rc(window_action), widget: Rc::new(Widget::new(window_action)),
}) }
} }
// Actions // Actions

View File

@ -11,7 +11,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(window_action: Rc<WindowAction>) -> Rc<Self> { pub fn new(window_action: Rc<WindowAction>) -> Self {
// Init gobject // Init gobject
let gobject = Button::builder() let gobject = Button::builder()
.icon_name("view-refresh-symbolic") .icon_name("view-refresh-symbolic")
@ -22,8 +22,8 @@ impl Widget {
// Init events // Init events
gobject.connect_clicked(move |_| window_action.reload().activate()); gobject.connect_clicked(move |_| window_action.reload().activate());
// Return activated struct // Return activated `Self`
Rc::new(Self { gobject }) Self { gobject }
} }
// Actions // Actions

View File

@ -20,14 +20,14 @@ pub struct Request {
impl Request { impl Request {
// Construct // Construct
pub fn new_rc( pub fn new(
// Actions // Actions
browser_action: Rc<BrowserAction>, browser_action: Rc<BrowserAction>,
action_page_reload: SimpleAction, // @TODO local `action_page_open`? action_page_reload: SimpleAction, // @TODO local `action_page_open`?
) -> Rc<Self> { ) -> Self {
Rc::new(Self { Self {
widget: Widget::new_rc(browser_action, action_page_reload), widget: Rc::new(Widget::new(browser_action, action_page_reload)),
}) }
} }
// Actions // Actions

View File

@ -30,7 +30,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc(browser_action: Rc<BrowserAction>, action_page_open: SimpleAction) -> Rc<Self> { pub fn new(browser_action: Rc<BrowserAction>, action_page_open: SimpleAction) -> Self {
// Init animated progress bar state // Init animated progress bar state
let progress = Rc::new(Progress { let progress = Rc::new(Progress {
fraction: RefCell::new(0.0), fraction: RefCell::new(0.0),
@ -73,8 +73,8 @@ impl Widget {
} }
}); });
// Return activated struct // Return activated `Self`
Rc::new(Self { gobject, progress }) Self { gobject, progress }
} }
// Actions // Actions

View File

@ -2,7 +2,6 @@ use gtk::{
prelude::{BoxExt, IsA}, prelude::{BoxExt, IsA},
Box, Orientation, Box, Orientation,
}; };
use std::rc::Rc;
const MARGIN: i32 = 6; const MARGIN: i32 = 6;
const SPACING: i32 = 6; const SPACING: i32 = 6;
@ -13,13 +12,13 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc( pub fn new(
base: &impl IsA<gtk::Widget>, base: &impl IsA<gtk::Widget>,
history: &impl IsA<gtk::Widget>, history: &impl IsA<gtk::Widget>,
reload: &impl IsA<gtk::Widget>, reload: &impl IsA<gtk::Widget>,
request: &impl IsA<gtk::Widget>, request: &impl IsA<gtk::Widget>,
bookmark: &impl IsA<gtk::Widget>, bookmark: &impl IsA<gtk::Widget>,
) -> Rc<Self> { ) -> Self {
let gobject = Box::builder() let gobject = Box::builder()
.orientation(Orientation::Horizontal) .orientation(Orientation::Horizontal)
.spacing(SPACING) .spacing(SPACING)
@ -34,7 +33,7 @@ impl Widget {
gobject.append(request); gobject.append(request);
gobject.append(bookmark); gobject.append(bookmark);
Rc::new(Self { gobject }) Self { gobject }
} }
// Getters // Getters

View File

@ -4,7 +4,6 @@ use gtk::{
prelude::{ActionMapExt, BoxExt, IsA, WidgetExt}, prelude::{ActionMapExt, BoxExt, IsA, WidgetExt},
Box, Orientation, Box, Orientation,
}; };
use std::rc::Rc;
pub struct Widget { pub struct Widget {
gobject: Box, gobject: Box,
@ -12,7 +11,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc( pub fn new(
name: &str, name: &str,
// Actions // Actions
action_page_open: SimpleAction, action_page_open: SimpleAction,
@ -20,7 +19,7 @@ impl Widget {
navigation: &impl IsA<gtk::Widget>, navigation: &impl IsA<gtk::Widget>,
content: &impl IsA<gtk::Widget>, content: &impl IsA<gtk::Widget>,
input: &impl IsA<gtk::Widget>, input: &impl IsA<gtk::Widget>,
) -> Rc<Self> { ) -> Self {
// Init additional action group // Init additional action group
let action_group = SimpleActionGroup::new(); let action_group = SimpleActionGroup::new();
action_group.add_action(&action_page_open); action_group.add_action(&action_page_open);
@ -37,7 +36,7 @@ impl Widget {
gobject.insert_action_group(&uuid_string_random(), Some(&action_group)); gobject.insert_action_group(&uuid_string_random(), Some(&action_group));
Rc::new(Self { gobject }) Self { gobject }
} }
// Getters // Getters

View File

@ -5,7 +5,6 @@ use database::Database;
use adw::{TabPage, TabView}; use adw::{TabPage, TabView};
use gtk::prelude::IsA; use gtk::prelude::IsA;
use sqlite::Transaction; use sqlite::Transaction;
use std::rc::Rc;
const DEFAULT_TITLE: &str = "New page"; const DEFAULT_TITLE: &str = "New page";
@ -15,7 +14,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_rc( pub fn new(
keyword: &str, // ID keyword: &str, // ID
tab_view: &TabView, tab_view: &TabView,
child: &impl IsA<gtk::Widget>, child: &impl IsA<gtk::Widget>,
@ -23,7 +22,7 @@ impl Widget {
position: Option<i32>, position: Option<i32>,
is_pinned: bool, is_pinned: bool,
is_selected: bool, is_selected: bool,
) -> Rc<Self> { ) -> Self {
let gobject = match position { let gobject = match position {
Some(value) => { Some(value) => {
// If given `position` match pinned tab, GTK will panic with notice: // If given `position` match pinned tab, GTK will panic with notice:
@ -51,7 +50,7 @@ impl Widget {
tab_view.set_selected_page(&gobject); tab_view.set_selected_page(&gobject);
} }
Rc::new(Self { gobject }) Self { gobject }
} }
// Actions // Actions