From ff3f06453450ba05b545736ef8968e18d0f7a174 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 9 Dec 2024 21:26:47 +0200 Subject: [PATCH] remove extra getters, give names to gobjects --- src/app/browser/window/tab/item.rs | 4 ++-- src/app/browser/window/tab/item/action.rs | 16 ++-------------- src/app/browser/window/tab/item/action/ident.rs | 14 ++++---------- src/app/browser/window/tab/item/action/load.rs | 8 ++++---- src/app/browser/window/tab/item/page.rs | 4 ++-- .../tab/item/page/content/status/identity.rs | 2 +- .../tab/item/page/content/text/gemini/reader.rs | 2 +- .../window/tab/item/page/input/response.rs | 2 +- .../window/tab/item/page/input/sensitive.rs | 2 +- .../window/tab/item/page/navigation/identity.rs | 2 +- .../tab/item/page/navigation/identity/widget.rs | 2 +- .../tab/item/page/navigation/request/widget.rs | 4 ++-- 12 files changed, 22 insertions(+), 40 deletions(-) diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index f4b72c38..701a495f 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -74,7 +74,7 @@ impl Item { } // Show identity selection for item - action.ident().connect_activate({ + action.ident.connect_activate({ let browser_action = actions.0.clone(); let window_action = actions.1.clone(); let page = page.clone(); @@ -98,7 +98,7 @@ impl Item { }); // Load new request for item - action.load().connect_activate({ + action.load.connect_activate({ let page = page.clone(); move |request, is_history| { if let Some(text) = request { diff --git a/src/app/browser/window/tab/item/action.rs b/src/app/browser/window/tab/item/action.rs index e8ce29b4..f1c39d50 100644 --- a/src/app/browser/window/tab/item/action.rs +++ b/src/app/browser/window/tab/item/action.rs @@ -8,8 +8,8 @@ use std::rc::Rc; /// [SimpleActionGroup](https://docs.gtk.org/gio/class.SimpleActionGroup.html) wrapper for `Browser` actions pub struct Action { - ident: Rc, - load: Rc, + pub ident: Rc, + pub load: Rc, } impl Action { @@ -22,16 +22,4 @@ impl Action { load: Rc::new(Load::new()), } } - - // Getters - - /// Get reference to `Ident` action - pub fn ident(&self) -> &Rc { - &self.ident - } - - /// Get reference to `Load` action - pub fn load(&self) -> &Rc { - &self.load - } } diff --git a/src/app/browser/window/tab/item/action/ident.rs b/src/app/browser/window/tab/item/action/ident.rs index 43654e3f..dfb50c3a 100644 --- a/src/app/browser/window/tab/item/action/ident.rs +++ b/src/app/browser/window/tab/item/action/ident.rs @@ -2,7 +2,7 @@ use gtk::{gio::SimpleAction, glib::uuid_string_random, prelude::ActionExt}; /// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Ident` action of `Item` group pub struct Ident { - gobject: SimpleAction, + pub simple_action: SimpleAction, } impl Ident { @@ -11,7 +11,7 @@ impl Ident { /// Create new `Self` pub fn new() -> Self { Self { - gobject: SimpleAction::new(&uuid_string_random(), None), + simple_action: SimpleAction::new(&uuid_string_random(), None), } } @@ -20,7 +20,7 @@ impl Ident { /// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal /// with formatted for this action [Variant](https://docs.gtk.org/glib/struct.Variant.html) value pub fn activate(&self) { - self.gobject.activate(None); + self.simple_action.activate(None); } // Events @@ -28,12 +28,6 @@ impl Ident { /// Define callback function for /// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal pub fn connect_activate(&self, callback: impl Fn() + 'static) { - self.gobject.connect_activate(move |_, _| callback()); - } - - // Getters - - pub fn gobject(&self) -> &SimpleAction { - &self.gobject + self.simple_action.connect_activate(move |_, _| callback()); } } diff --git a/src/app/browser/window/tab/item/action/load.rs b/src/app/browser/window/tab/item/action/load.rs index 0a728aa9..f680738e 100644 --- a/src/app/browser/window/tab/item/action/load.rs +++ b/src/app/browser/window/tab/item/action/load.rs @@ -6,7 +6,7 @@ use gtk::{ /// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Load` action of `Item` group pub struct Load { - gobject: SimpleAction, + pub simple_action: SimpleAction, } impl Load { @@ -15,7 +15,7 @@ impl Load { /// Create new `Self` pub fn new() -> Self { Self { - gobject: SimpleAction::new( + simple_action: SimpleAction::new( &uuid_string_random(), Some(&<(String, bool)>::static_variant_type()), ), @@ -27,7 +27,7 @@ impl Load { /// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal /// with formatted for this action [Variant](https://docs.gtk.org/glib/struct.Variant.html) value pub fn activate(&self, request: Option<&str>, is_history: bool) { - self.gobject.activate(Some( + self.simple_action.activate(Some( &( match request { Some(value) => String::from(value), @@ -44,7 +44,7 @@ impl Load { /// Define callback function for /// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal pub fn connect_activate(&self, callback: impl Fn(Option, bool) + 'static) { - self.gobject.connect_activate(move |_, this| { + self.simple_action.connect_activate(move |_, this| { let (request, is_history) = this .expect("Expected (`request`,`is_history`) variant") .get::<(String, bool)>() diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 182fd447..2e6e26f2 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -116,7 +116,7 @@ impl Page { pub fn home(&self) { if let Some(url) = self.navigation.home.url() { // Update with history record - self.tab_action.load().activate(Some(&url), true); + self.tab_action.load.activate(Some(&url), true); } } @@ -802,7 +802,7 @@ impl Page { .set_title("Redirect"); // Reload page to apply redirection (without history record request) - tab_action.load().activate(None, false); + tab_action.load.activate(None, false); } }, Err(reason) => { diff --git a/src/app/browser/window/tab/item/page/content/status/identity.rs b/src/app/browser/window/tab/item/page/content/status/identity.rs index fb01923f..bedce5ef 100644 --- a/src/app/browser/window/tab/item/page/content/status/identity.rs +++ b/src/app/browser/window/tab/item/page/content/status/identity.rs @@ -24,7 +24,7 @@ pub fn new_gobject(action: Rc) -> StatusPage { .build(); // Init events - button.connect_clicked(move |_| action.ident().activate()); + button.connect_clicked(move |_| action.ident.activate()); // Init status page StatusPage::builder() diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs index 14fa468b..43562f58 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs @@ -346,7 +346,7 @@ impl Reader { return match uri.scheme().as_str() { "gemini" => { // Open new page in browser - actions.1.load().activate(Some(&uri.to_str()), true); + actions.1.load.activate(Some(&uri.to_str()), true); } // Scheme not supported, delegate _ => UriLauncher::new(&uri.to_str()).launch( diff --git a/src/app/browser/window/tab/item/page/input/response.rs b/src/app/browser/window/tab/item/page/input/response.rs index a8142ad3..109ba12e 100644 --- a/src/app/browser/window/tab/item/page/input/response.rs +++ b/src/app/browser/window/tab/item/page/input/response.rs @@ -62,7 +62,7 @@ impl Response { action_send.connect_activate({ let form = form.clone(); move |_, _| { - tab_action.load().activate( + tab_action.load.activate( Some(&format!( "{}?{}", base.to_string_partial(UriHideFlags::QUERY), diff --git a/src/app/browser/window/tab/item/page/input/sensitive.rs b/src/app/browser/window/tab/item/page/input/sensitive.rs index cf90d95a..99428c11 100644 --- a/src/app/browser/window/tab/item/page/input/sensitive.rs +++ b/src/app/browser/window/tab/item/page/input/sensitive.rs @@ -44,7 +44,7 @@ impl Sensitive { action_send.connect_activate({ let form = form.clone(); move |_, _| { - tab_action.load().activate( + tab_action.load.activate( Some(&format!( "{}?{}", base.to_string_partial(UriHideFlags::QUERY), diff --git a/src/app/browser/window/tab/item/page/navigation/identity.rs b/src/app/browser/window/tab/item/page/navigation/identity.rs index 52d8985b..d3ebbfd0 100644 --- a/src/app/browser/window/tab/item/page/navigation/identity.rs +++ b/src/app/browser/window/tab/item/page/navigation/identity.rs @@ -21,7 +21,7 @@ impl Identity { // Actions pub fn update(&self, is_auth: bool, is_enabled: bool) { // Update action status - self.action.ident().gobject().set_enabled(is_enabled); + self.action.ident.simple_action.set_enabled(is_enabled); // Update widget self.widget.update(is_auth, is_enabled) diff --git a/src/app/browser/window/tab/item/page/navigation/identity/widget.rs b/src/app/browser/window/tab/item/page/navigation/identity/widget.rs index 460861da..08d2935b 100644 --- a/src/app/browser/window/tab/item/page/navigation/identity/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/identity/widget.rs @@ -20,7 +20,7 @@ impl Widget { .build(); // Init events @TODO dialog window required - gobject.connect_clicked(move |_| action.ident().activate()); + gobject.connect_clicked(move |_| action.ident.activate()); // Return activated `Self` Self { gobject } diff --git a/src/app/browser/window/tab/item/page/navigation/request/widget.rs b/src/app/browser/window/tab/item/page/navigation/request/widget.rs index ea8d23ab..4c09eb2a 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/widget.rs @@ -70,7 +70,7 @@ impl Widget { EntryIconPosition::Primary => todo!(), EntryIconPosition::Secondary => { if go.is_some() { - tab_action.load().activate(Some(&this.text()), true); + tab_action.load.activate(Some(&this.text()), true); } } _ => println!("Undefined icon position"), // drop notice @TODO @@ -82,7 +82,7 @@ impl Widget { }); entry.connect_activate(move |entry| { - tab_action.load().activate(Some(&entry.text()), true); + tab_action.load.activate(Some(&entry.text()), true); }); entry.connect_state_flags_changed({