optimize clone semantics, enshort namespaces

This commit is contained in:
yggverse 2025-01-11 20:56:53 +02:00
parent fd9f69a9f0
commit eabd16aaf7
20 changed files with 134 additions and 114 deletions

View File

@ -28,8 +28,8 @@ impl Window {
let action = Rc::new(Action::new()); let action = Rc::new(Action::new());
// Init components // Init components
let tab = Rc::new(Tab::new(profile, (browser_action.clone(), action.clone()))); let tab = Rc::new(Tab::new(&profile, (&browser_action, &action)));
let header = Header::new(browser_action, action.clone(), &tab.widget.tab_view); let header = Header::new((&browser_action, &action), &profile, &tab.widget.tab_view);
let widget = Rc::new(Widget::new(&header.widget.gobject, &tab.widget.tab_view)); let widget = Rc::new(Widget::new(&header.widget.gobject, &tab.widget.tab_view));
// Init events // Init events

View File

@ -4,7 +4,7 @@ mod widget;
use bar::Bar; use bar::Bar;
use widget::Widget; use widget::Widget;
use super::{Action as WindowAction, BrowserAction}; use super::{Action as WindowAction, BrowserAction, Profile};
use adw::TabView; use adw::TabView;
use std::rc::Rc; use std::rc::Rc;
@ -15,14 +15,12 @@ pub struct Header {
impl Header { impl Header {
// Construct // Construct
pub fn new( pub fn new(
// Actions (browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
browser_action: Rc<BrowserAction>, profile: &Rc<Profile>,
window_action: Rc<WindowAction>,
// Widgets
tab_view: &TabView, tab_view: &TabView,
) -> Self { ) -> Self {
// Init components // Init components
let bar = Bar::new(browser_action, window_action, tab_view); let bar = Bar::new((browser_action, window_action), profile, tab_view);
// Return new struct // Return new struct
Self { Self {

View File

@ -8,8 +8,7 @@ use menu::Menu;
use tab::Tab; use tab::Tab;
use widget::Widget; use widget::Widget;
use crate::app::browser::action::Action as BrowserAction; use super::{BrowserAction, Profile, WindowAction};
use crate::app::browser::window::action::Action as WindowAction;
use adw::TabView; use adw::TabView;
use std::rc::Rc; use std::rc::Rc;
@ -21,13 +20,13 @@ impl Bar {
// Constructors // Constructors
pub fn new( pub fn new(
browser_action: Rc<BrowserAction>, (browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
window_action: Rc<WindowAction>, profile: &Rc<Profile>,
view: &TabView, view: &TabView,
) -> Self { ) -> Self {
let control = Control::new(); let control = Control::new();
let tab = Tab::new(window_action.clone(), view); let tab = Tab::new(window_action, view);
let menu = Menu::new(browser_action, window_action); let menu = Menu::new((browser_action, window_action), profile);
Self { Self {
widget: Rc::new(Widget::new( widget: Rc::new(Widget::new(
&control.widget.gobject, &control.widget.gobject,

View File

@ -2,8 +2,7 @@ mod widget;
use widget::Widget; use widget::Widget;
use crate::app::browser::action::Action as BrowserAction; use super::{BrowserAction, Profile, WindowAction};
use crate::app::browser::window::action::Action as WindowAction;
use gtk::{ use gtk::{
gio::{self}, gio::{self},
prelude::ActionExt, prelude::ActionExt,
@ -16,8 +15,8 @@ pub struct Menu {
#[rustfmt::skip] // @TODO template builder? #[rustfmt::skip] // @TODO template builder?
impl Menu { impl Menu {
pub fn new( pub fn new(
browser_action: Rc<BrowserAction>, (browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
window_action: Rc<WindowAction>, _profile: &Rc<Profile>,
) -> Self { ) -> Self {
// Main // Main
let main = gio::Menu::new(); let main = gio::Menu::new();

View File

@ -14,7 +14,7 @@ pub struct Tab {
impl Tab { impl Tab {
// Construct // Construct
pub fn new(window_action: Rc<WindowAction>, view: &TabView) -> Self { pub fn new(window_action: &Rc<WindowAction>, view: &TabView) -> Self {
Self { Self {
widget: Rc::new(Widget::new( widget: Rc::new(Widget::new(
view, view,

View File

@ -11,9 +11,9 @@ pub struct Append {
impl Append { impl Append {
// Construct // Construct
pub fn new(window_action: Rc<WindowAction>) -> Self { pub fn new(window_action: &Rc<WindowAction>) -> Self {
Self { Self {
widget: Rc::new(Widget::new(window_action)), widget: Rc::new(Widget::new(window_action.clone())),
} }
} }
} }

View File

@ -23,28 +23,32 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc};
// Main // Main
pub struct Tab { pub struct Tab {
browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>,
profile: Rc<Profile>, profile: Rc<Profile>,
actions: (Rc<BrowserAction>, Rc<WindowAction>),
index: Rc<RefCell<HashMap<Rc<GString>, Rc<Item>>>>, index: Rc<RefCell<HashMap<Rc<GString>, Rc<Item>>>>,
pub widget: Rc<Widget>, pub widget: Rc<Widget>,
} }
impl Tab { impl Tab {
// Construct // Construct
pub fn new(profile: Rc<Profile>, action: (Rc<BrowserAction>, Rc<WindowAction>)) -> Self { pub fn new(
profile: &Rc<Profile>,
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
) -> Self {
// Init empty HashMap index // Init empty HashMap index
let index: Rc<RefCell<HashMap<Rc<GString>, Rc<Item>>>> = let index: Rc<RefCell<HashMap<Rc<GString>, Rc<Item>>>> =
Rc::new(RefCell::new(HashMap::new())); Rc::new(RefCell::new(HashMap::new()));
// Init context menu // Init context menu
let menu = Menu::new(action.1.clone()); let menu = Menu::new(window_action);
// Init widget // Init widget
let widget = Rc::new(Widget::new(&menu.main)); let widget = Rc::new(Widget::new(&menu.main));
// Init events // Init events
widget.tab_view.connect_setup_menu({ widget.tab_view.connect_setup_menu({
let action = action.1.clone(); let action = window_action.clone();
let index = index.clone(); let index = index.clone();
let widget = widget.clone(); let widget = widget.clone();
move |tab_view, tab_page| { move |tab_view, tab_page| {
@ -122,8 +126,9 @@ impl Tab {
// Return activated `Self` // Return activated `Self`
Self { Self {
profile, profile: profile.clone(),
actions: (action.0, action.1), browser_action: browser_action.clone(),
window_action: window_action.clone(),
index, index,
widget, widget,
} }
@ -142,9 +147,9 @@ impl Tab {
// Init new tab item // Init new tab item
let item = Rc::new(Item::new( let item = Rc::new(Item::new(
&self.widget.tab_view, &self.widget.tab_view,
self.profile.clone(), &self.profile,
// Actions // Actions
(self.actions.0.clone(), self.actions.1.clone()), (&self.browser_action, &self.window_action),
// Options // Options
( (
position, position,
@ -329,8 +334,8 @@ impl Tab {
&self.widget.tab_view, &self.widget.tab_view,
transaction, transaction,
&record.id, &record.id,
self.profile.clone(), &self.profile,
(self.actions.0.clone(), self.actions.1.clone()), (&self.browser_action, &self.window_action),
) { ) {
Ok(items) => { Ok(items) => {
for item in items { for item in items {

View File

@ -34,13 +34,17 @@ impl Item {
// Construct // Construct
pub fn new( pub fn new(
tab_view: &TabView, tab_view: &TabView,
profile: Rc<Profile>, profile: &Rc<Profile>,
actions: (Rc<BrowserAction>, Rc<WindowAction>), (browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
options: (Position, Option<String>, bool, bool, bool, bool), (position, request, is_pinned, is_selected, is_attention, is_load): (
Position,
Option<String>,
bool,
bool,
bool,
bool,
),
) -> Self { ) -> Self {
// Get item options from tuple
let (position, request, is_pinned, is_selected, is_attention, is_load) = options;
// Generate unique ID for new page components // Generate unique ID for new page components
let id = Rc::new(uuid_string_random()); let id = Rc::new(uuid_string_random());
@ -49,9 +53,9 @@ impl Item {
let action = Rc::new(Action::new()); let action = Rc::new(Action::new());
let page = Rc::new(Page::new( let page = Rc::new(Page::new(
id.clone(), &id,
profile.clone(), profile,
(actions.0.clone(), actions.1.clone(), action.clone()), (browser_action, window_action, &action),
)); ));
let widget = Rc::new(Widget::new( let widget = Rc::new(Widget::new(
@ -75,19 +79,20 @@ impl Item {
// Show identity selection for item // Show identity selection for item
action.ident.connect_activate({ action.ident.connect_activate({
let browser_action = actions.0.clone(); let browser_action = browser_action.clone();
let window_action = actions.1.clone();
let page = page.clone(); let page = page.clone();
let parent = tab_view.clone().upcast::<gtk::Widget>(); let parent = tab_view.clone().upcast::<gtk::Widget>();
let profile = profile.clone();
let window_action = window_action.clone();
move || { move || {
// Request should match valid URI for all drivers supported // Request should match valid URI for all drivers supported
if let Some(uri) = page.navigation.request.uri() { if let Some(uri) = page.navigation.request.uri() {
// Rout by scheme // Rout by scheme
if uri.scheme().to_lowercase() == "gemini" { if uri.scheme().to_lowercase() == "gemini" {
return identity::new_gemini( return identity::new_gemini(
(browser_action.clone(), window_action.clone()), (&browser_action, &window_action),
profile.clone(), &profile,
uri, &uri,
) )
.present(Some(&parent)); .present(Some(&parent));
} }
@ -151,9 +156,9 @@ impl Item {
tab_view: &TabView, tab_view: &TabView,
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_id: &i64, app_browser_window_tab_id: &i64,
profile: Rc<Profile>, profile: &Rc<Profile>,
// Actions // Actions
action: (Rc<BrowserAction>, Rc<WindowAction>), (browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
) -> Result<Vec<Rc<Item>>, String> { ) -> Result<Vec<Rc<Item>>, String> {
let mut items = Vec::new(); let mut items = Vec::new();
@ -163,9 +168,9 @@ impl Item {
// Construct new item object // Construct new item object
let item = Rc::new(Item::new( let item = Rc::new(Item::new(
tab_view, tab_view,
profile.clone(), profile,
// Actions // Actions
(action.0.clone(), action.1.clone()), (browser_action, window_action),
// Options tuple // Options tuple
( (
Position::End, Position::End,

View File

@ -4,17 +4,15 @@ mod unsupported;
use gemini::Gemini; use gemini::Gemini;
use unsupported::Unsupported; use unsupported::Unsupported;
use crate::app::browser::action::Action as BrowserAction; use super::{BrowserAction, Profile, WindowAction};
use crate::app::browser::window::action::Action as WindowAction;
use crate::profile::Profile;
use gtk::glib::Uri; use gtk::glib::Uri;
use std::rc::Rc; use std::rc::Rc;
/// Create new identity widget for Gemini protocol match given URI /// Create new identity widget for Gemini protocol match given URI
pub fn new_gemini( pub fn new_gemini(
action: (Rc<BrowserAction>, Rc<WindowAction>), action: (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: Rc<Profile>, profile: &Rc<Profile>,
auth_uri: Uri, auth_uri: &Uri,
) -> Gemini { ) -> Gemini {
Gemini::new(action, profile, auth_uri) Gemini::new(action, profile, auth_uri)
} }

View File

@ -1,9 +1,7 @@
mod widget; mod widget;
use widget::{form::list::item::value::Value, Widget}; use widget::{form::list::item::value::Value, Widget};
use crate::app::browser::action::Action as BrowserAction; use super::{BrowserAction, Profile, WindowAction};
use crate::app::browser::window::action::Action as WindowAction;
use crate::profile::Profile;
use gtk::{glib::Uri, prelude::IsA}; use gtk::{glib::Uri, prelude::IsA};
use std::rc::Rc; use std::rc::Rc;
@ -17,25 +15,30 @@ impl Gemini {
/// Create new `Self` for given `Profile` /// Create new `Self` for given `Profile`
pub fn new( pub fn new(
action: (Rc<BrowserAction>, Rc<WindowAction>), (browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: Rc<Profile>, profile: &Rc<Profile>,
auth_uri: Uri, auth_uri: &Uri,
) -> Self { ) -> Self {
// Init shared URL string from URI // Init shared URL string from URI
let auth_url = auth_uri.to_string(); let auth_url = auth_uri.to_string();
// Init widget // Init widget
let widget = Rc::new(Widget::new( let widget = Rc::new(Widget::new(
(action.0.clone(), action.1.clone()), (browser_action, window_action),
profile.clone(), profile,
auth_uri.clone(), auth_uri,
)); ));
// Init events // Init events
widget.on_cancel(move || action.0.update.activate(None)); widget.on_cancel({
let browser_action = browser_action.clone();
move || browser_action.update.activate(None)
});
widget.on_apply({ widget.on_apply({
let profile = profile.clone();
let widget = widget.clone(); let widget = widget.clone();
let window_action = window_action.clone();
move |response| { move |response| {
// Get option match user choice // Get option match user choice
let option = match response { let option = match response {
@ -85,7 +88,7 @@ impl Gemini {
} }
// Reload page to apply changes // Reload page to apply changes
action.1.reload.activate(); window_action.reload.activate();
} }
}); });

View File

@ -37,16 +37,16 @@ impl Widget {
/// Create new `Self` /// Create new `Self`
pub fn new( pub fn new(
action: (Rc<BrowserAction>, Rc<WindowAction>), (browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: Rc<Profile>, profile: &Rc<Profile>,
auth_uri: Uri, auth_uri: &Uri,
) -> Self { ) -> Self {
// Init actions // Init actions
let widget_action = Rc::new(WidgetAction::new()); let widget_action = Rc::new(WidgetAction::new());
// Init child container // Init child container
let form = Rc::new(Form::new( let form = Rc::new(Form::new(
(action.0.clone(), action.1.clone(), widget_action.clone()), (browser_action, window_action, &widget_action),
profile, profile,
auth_uri, auth_uri,
)); ));

View File

@ -38,25 +38,25 @@ impl Form {
/// Create new `Self` /// Create new `Self`
pub fn new( pub fn new(
action: (Rc<BrowserAction>, Rc<WindowAction>, Rc<WidgetAction>), (browser_action, _window_action, widget_action): (
profile: Rc<Profile>, &Rc<BrowserAction>,
auth_uri: Uri, &Rc<WindowAction>,
&Rc<WidgetAction>,
),
profile: &Rc<Profile>,
auth_uri: &Uri,
) -> Self { ) -> Self {
// Init components // Init components
let list = Rc::new(List::new( let list = Rc::new(List::new(widget_action, profile, auth_uri));
action.2.clone(), let file = Rc::new(File::new(widget_action));
profile.clone(), let name = Rc::new(Name::new(widget_action));
auth_uri.clone(), let save = Rc::new(Save::new(profile, &list));
)); let drop = Rc::new(Drop::new(profile, &list));
let file = Rc::new(File::new(action.2.clone()));
let name = Rc::new(Name::new(action.2.clone()));
let save = Rc::new(Save::new(profile.clone(), list.clone()));
let drop = Rc::new(Drop::new(profile.clone(), list.clone()));
let exit = Rc::new(Exit::new( let exit = Rc::new(Exit::new(
(action.0.clone(), action.2.clone()), (browser_action, widget_action),
profile.clone(), profile,
list.clone(), &list,
auth_uri.clone(), auth_uri,
)); ));
// Init main container // Init main container
@ -79,8 +79,8 @@ impl Form {
name, name,
save, save,
g_box, g_box,
auth_uri, auth_uri: auth_uri.clone(),
profile, profile: profile.clone(),
} }
} }

View File

@ -29,7 +29,7 @@ impl Drop {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(profile: Rc<Profile>, list: Rc<List>) -> Self { pub fn new(profile: &Rc<Profile>, list: &Rc<List>) -> Self {
// Init main widget // Init main widget
let button = Button::builder() let button = Button::builder()
.label(LABEL) .label(LABEL)
@ -42,6 +42,7 @@ impl Drop {
button.connect_clicked({ button.connect_clicked({
let button = button.clone(); let button = button.clone();
let list = list.clone(); let list = list.clone();
let profile = profile.clone();
move |_| { move |_| {
match list.selected().value_enum() { match list.selected().value_enum() {
Value::ProfileIdentityGeminiId(profile_identity_gemini_id) => { Value::ProfileIdentityGeminiId(profile_identity_gemini_id) => {

View File

@ -34,10 +34,10 @@ impl Exit {
/// Create new `Self` /// Create new `Self`
pub fn new( pub fn new(
action: (Rc<BrowserAction>, Rc<WidgetAction>), (browser_action, widget_action): (&Rc<BrowserAction>, &Rc<WidgetAction>),
profile: Rc<Profile>, profile: &Rc<Profile>,
list: Rc<List>, list: &Rc<List>,
auth_uri: Uri, auth_uri: &Uri,
) -> Self { ) -> Self {
// Init main widget // Init main widget
let button = Button::builder() let button = Button::builder()
@ -50,7 +50,11 @@ impl Exit {
// Init events // Init events
button.connect_clicked({ button.connect_clicked({
let auth_uri = auth_uri.clone(); let auth_uri = auth_uri.clone();
let browser_action = browser_action.clone();
let button = button.clone(); let button = button.clone();
let list = list.clone();
let profile = profile.clone();
let widget_action = widget_action.clone();
move |_| { move |_| {
// Get selected identity from holder // Get selected identity from holder
match list.selected().value_enum() { match list.selected().value_enum() {
@ -84,8 +88,8 @@ impl Exit {
let button = button.clone(); let button = button.clone();
let list = list.clone(); let list = list.clone();
let profile = profile.clone(); let profile = profile.clone();
let browser_action = action.0.clone(); let browser_action = browser_action.clone();
let widget_action = action.1.clone(); let widget_action = widget_action.clone();
move |_, _| { move |_, _| {
match profile match profile
.identity .identity

View File

@ -21,7 +21,7 @@ impl File {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(widget_action: Rc<WidgetAction>) -> Self { pub fn new(widget_action: &Rc<WidgetAction>) -> Self {
// Init PEM // Init PEM
let pem = Rc::new(RefCell::new(None)); let pem = Rc::new(RefCell::new(None));

View File

@ -25,7 +25,7 @@ impl List {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(widget_action: Rc<WidgetAction>, profile: Rc<Profile>, auth_uri: Uri) -> Self { pub fn new(widget_action: &Rc<WidgetAction>, profile: &Rc<Profile>, auth_uri: &Uri) -> Self {
// Init dropdown items // Init dropdown items
let guest_session = Item::new_guest_session(); let guest_session = Item::new_guest_session();
let generate_pem = Item::new_generate_pem(); let generate_pem = Item::new_generate_pem();
@ -43,7 +43,7 @@ impl List {
let mut is_guest_session = true; let mut is_guest_session = true;
for identity in identities { for identity in identities {
match Item::new_profile_identity_gemini_id( match Item::new_profile_identity_gemini_id(
&profile, profile,
identity.id, identity.id,
&auth_uri.to_string(), &auth_uri.to_string(),
) { ) {
@ -164,7 +164,10 @@ impl List {
.build(); .build();
// Connect events // Connect events
dropdown.connect_selected_notify(move |_| widget_action.update.activate()); dropdown.connect_selected_notify({
let widget_action = widget_action.clone();
move |_| widget_action.update.activate()
});
// Return activated `Self` // Return activated `Self`
Self { Self {

View File

@ -19,7 +19,7 @@ impl Name {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(widget_action: Rc<WidgetAction>) -> Self { pub fn new(widget_action: &Rc<WidgetAction>) -> Self {
// Init main gobject // Init main gobject
let entry = Entry::builder() let entry = Entry::builder()
.margin_top(MARGIN) .margin_top(MARGIN)
@ -29,7 +29,10 @@ impl Name {
.build(); .build();
// Init events // Init events
entry.connect_changed(move |_| widget_action.update.activate()); entry.connect_changed({
let widget_action = widget_action.clone();
move |_| widget_action.update.activate()
});
// Return activated `Self` // Return activated `Self`
Self { entry } Self { entry }

View File

@ -23,7 +23,7 @@ impl Save {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(profile: Rc<Profile>, list: Rc<List>) -> Self { pub fn new(profile: &Rc<Profile>, list: &Rc<List>) -> Self {
// Init main widget // Init main widget
let button = Button::builder() let button = Button::builder()
.label(LABEL) .label(LABEL)
@ -35,6 +35,8 @@ impl Save {
// Init events // Init events
button.connect_clicked({ button.connect_clicked({
let button = button.clone(); let button = button.clone();
let list = list.clone();
let profile = profile.clone();
move |_| { move |_| {
// Get selected identity from holder // Get selected identity from holder
match list.selected().value_enum() { match list.selected().value_enum() {

View File

@ -55,12 +55,12 @@ impl Page {
// Constructors // Constructors
pub fn new( pub fn new(
id: Rc<GString>, id: &Rc<GString>,
profile: Rc<Profile>, profile: &Rc<Profile>,
(browser_action, window_action, tab_action): ( (browser_action, window_action, tab_action): (
Rc<BrowserAction>, &Rc<BrowserAction>,
Rc<WindowAction>, &Rc<WindowAction>,
Rc<TabAction>, &Rc<TabAction>,
), ),
) -> Self { ) -> Self {
// Init components // Init components
@ -80,7 +80,7 @@ impl Page {
let input = Rc::new(Input::new()); let input = Rc::new(Input::new());
let widget = Rc::new(Widget::new( let widget = Rc::new(Widget::new(
&id, id,
&navigation.widget.g_box, &navigation.widget.g_box,
&content.g_box, &content.g_box,
&search.g_box, &search.g_box,
@ -91,12 +91,12 @@ impl Page {
// Done // Done
Self { Self {
id, id: id.clone(),
profile, profile: profile.clone(),
// Actions // Actions
browser_action, browser_action: browser_action.clone(),
tab_action, tab_action: tab_action.clone(),
window_action, window_action: window_action.clone(),
// Components // Components
client: Rc::new(Client::new()), client: Rc::new(Client::new()),
content, content,

View File

@ -13,7 +13,7 @@ impl Menu {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(window_action: Rc<WindowAction>) -> Self { pub fn new(window_action: &Rc<WindowAction>) -> Self {
let main = gtk::gio::Menu::new(); let main = gtk::gio::Menu::new();
main.append( main.append(