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());
// Init components
let tab = Rc::new(Tab::new(profile, (browser_action.clone(), action.clone())));
let header = Header::new(browser_action, action.clone(), &tab.widget.tab_view);
let tab = Rc::new(Tab::new(&profile, (&browser_action, &action)));
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));
// Init events

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -29,7 +29,7 @@ impl Drop {
// Constructors
/// 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
let button = Button::builder()
.label(LABEL)
@ -42,6 +42,7 @@ impl Drop {
button.connect_clicked({
let button = button.clone();
let list = list.clone();
let profile = profile.clone();
move |_| {
match list.selected().value_enum() {
Value::ProfileIdentityGeminiId(profile_identity_gemini_id) => {

View File

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

View File

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

View File

@ -25,7 +25,7 @@ impl List {
// Constructors
/// 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
let guest_session = Item::new_guest_session();
let generate_pem = Item::new_generate_pem();
@ -43,7 +43,7 @@ impl List {
let mut is_guest_session = true;
for identity in identities {
match Item::new_profile_identity_gemini_id(
&profile,
profile,
identity.id,
&auth_uri.to_string(),
) {
@ -164,7 +164,10 @@ impl List {
.build();
// 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`
Self {

View File

@ -19,7 +19,7 @@ impl Name {
// Constructors
/// Create new `Self`
pub fn new(widget_action: Rc<WidgetAction>) -> Self {
pub fn new(widget_action: &Rc<WidgetAction>) -> Self {
// Init main gobject
let entry = Entry::builder()
.margin_top(MARGIN)
@ -29,7 +29,10 @@ impl Name {
.build();
// 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`
Self { entry }

View File

@ -23,7 +23,7 @@ impl Save {
// Constructors
/// 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
let button = Button::builder()
.label(LABEL)
@ -35,6 +35,8 @@ impl Save {
// Init events
button.connect_clicked({
let button = button.clone();
let list = list.clone();
let profile = profile.clone();
move |_| {
// Get selected identity from holder
match list.selected().value_enum() {

View File

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

View File

@ -13,7 +13,7 @@ impl Menu {
// Constructors
/// 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();
main.append(