From 3ce272cd70f194b76c755b3efede67f45ef5c5fe Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 28 Nov 2024 00:53:06 +0200 Subject: [PATCH] remove extra getters --- src/app/browser/window/tab.rs | 7 +-- src/app/browser/window/tab/item.rs | 6 +-- src/app/browser/window/tab/item/page.rs | 50 +++++++------------ .../window/tab/item/page/navigation.rs | 48 ++++-------------- .../tab/item/page/navigation/request.rs | 8 +-- .../item/page/navigation/request/widget.rs | 34 ++++++------- .../window/tab/item/page/navigation/widget.rs | 7 +-- 7 files changed, 48 insertions(+), 112 deletions(-) diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 8f570bfc..0f8b5bcc 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -137,12 +137,7 @@ impl Tab { .borrow_mut() .insert(item.id.clone(), item.clone()); - item.page - .navigation - .request() - .widget() - .gobject() - .grab_focus(); + item.page.navigation.request.widget.entry.grab_focus(); item } diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index f5f6d388..1752e84e 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -66,7 +66,7 @@ impl Item { // Init events if let Some(text) = request { - page.navigation.request().widget().gobject().set_text(&text); + page.navigation.request.widget.entry.set_text(&text); if is_load { page.load(true); @@ -79,7 +79,7 @@ impl Item { let parent = tab_view.clone().upcast::(); move || { // 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 if uri.scheme().to_lowercase() == "gemini" { return identity::new_gemini(profile.clone(), actions.1.clone(), uri) @@ -96,7 +96,7 @@ impl Item { let page = page.clone(); move |request, is_history| { if let Some(text) = request { - page.navigation.request().widget().gobject().set_text(&text); + page.navigation.request.widget.entry.set_text(&text); } page.load(is_history); } diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 0385c3e4..664e087f 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -69,7 +69,7 @@ impl Page { let widget = Rc::new(Widget::new( &id, - navigation.widget().gobject(), + &navigation.widget.gobject, content.gobject(), input.gobject(), )); @@ -102,7 +102,7 @@ impl Page { let result = match self .profile .bookmark - .toggle(self.navigation.request().widget().gobject().text().as_str()) + .toggle(self.navigation.request.widget.entry.text().as_str()) { Ok(result) => Ok(result), Err(_) => Err(Error::Bookmark), // @TODO @@ -114,7 +114,7 @@ impl Page { /// Navigate home URL (parsed from current navigation entry) /// * this method create new history record in memory as defined in `action_page_open` action pub fn home(&self) { - if let Some(url) = self.navigation.home().url() { + if let Some(url) = self.navigation.home.url() { // Update with history record self.tab_action.load().activate(Some(&url), true); } @@ -123,13 +123,9 @@ impl Page { /// Navigate back in history /// * this method does not create new history record in memory pub fn history_back(&self) { - if let Some(request) = self.navigation.history().back(true) { + if let Some(request) = self.navigation.history.back(true) { // Update navigation entry - self.navigation - .request() - .widget() - .gobject() - .set_text(&request); + self.navigation.request.widget.entry.set_text(&request); // Load page (without history record) self.load(false); @@ -139,13 +135,9 @@ impl Page { /// Navigate forward in history /// * this method does not create new history record in memory pub fn history_forward(&self) { - if let Some(request) = self.navigation.history().forward(true) { + if let Some(request) = self.navigation.history.forward(true) { // Update navigation entry - self.navigation - .request() - .widget() - .gobject() - .set_text(&request); + self.navigation.request.widget.entry.set_text(&request); // Load page (without history record) self.load(false); @@ -200,9 +192,9 @@ impl Page { // Update navigation on redirect `is_foreground` if redirect.is_foreground() { self.navigation - .request() - .widget() - .gobject() + .request + .widget + .entry .set_text(redirect.request().as_str()); } @@ -213,7 +205,7 @@ impl Page { self.meta.unset_redirect_count(); // Return value from navigation entry - self.navigation.request().widget().gobject().text() + self.navigation.request.widget.entry.text() }; // Update @@ -267,11 +259,7 @@ impl Page { match Uri::parse(&request, UriFlags::NONE) { Ok(_) => { // Update navigation entry - self.navigation - .request() - .widget() - .gobject() - .set_text(&request); + self.navigation.request.widget.entry.set_text(&request); // Load page (without history record) self.load(false); @@ -288,11 +276,7 @@ impl Page { ); // Update navigation entry - self.navigation - .request() - .widget() - .gobject() - .set_text(&request); + self.navigation.request.widget.entry.set_text(&request); // Load page (without history record) self.load(false); @@ -422,7 +406,7 @@ impl Page { .profile .identity .gemini - .match_priority(&self.navigation.request().widget().gobject().text()) + .match_priority(&self.navigation.request.widget.entry.text()) { Some(identity) => { match gemini::client::Certificate::from_pem(&identity.pem, &identity.scope) { @@ -929,14 +913,14 @@ fn is_external_uri(subject: &Uri, base: &Uri) -> bool { /// Make new history record for given `navigation` object /// * applies on shared conditions match only fn snap_history(navigation: Rc) { - let request = navigation.request().widget().gobject().text(); + let request = navigation.request.widget.entry.text(); // Apply additional filters - if match navigation.history().current() { + if match navigation.history.current() { Some(current) => current != request, None => true, } { // Add new record match conditions - navigation.history().add(request, true) + navigation.history.add(request, true) } } diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 37f28592..8e9adc0e 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -24,14 +24,14 @@ use sqlite::Transaction; use std::rc::Rc; pub struct Navigation { - bookmark: Rc, - history: Rc, - home: Rc, - identity: Rc, - profile: Rc, - reload: Rc, - request: Rc, - widget: Rc, + pub bookmark: Rc, + pub history: Rc, + pub home: Rc, + pub identity: Rc, + pub profile: Rc, + pub reload: Rc, + pub request: Rc, + pub widget: Rc, } impl Navigation { @@ -53,7 +53,7 @@ impl Navigation { home.widget().gobject(), history.widget().gobject(), reload.widget().gobject(), - request.widget().gobject(), + &request.widget.entry, // @TODO remove extra getters from other components bookmark.widget().gobject(), )); @@ -73,7 +73,7 @@ impl Navigation { // Actions pub fn update(&self, progress_fraction: Option) { - let request_text = self.request.widget().gobject().text(); + let request_text = self.request.widget.entry.text(); self.identity.update( self.profile @@ -151,34 +151,6 @@ impl Navigation { Ok(()) } - - // Getters - - pub fn home(&self) -> &Rc { - &self.home - } - - pub fn history(&self) -> &Rc { - &self.history - } - - /* - pub fn reload(&self) -> &Rc { - &self.reload - } */ - - pub fn request(&self) -> &Rc { - &self.request - } - - /* - pub fn bookmark(&self) -> &Rc { - &self.bookmark - } */ - - pub fn widget(&self) -> &Rc { - &self.widget - } } // Tools diff --git a/src/app/browser/window/tab/item/page/navigation/request.rs b/src/app/browser/window/tab/item/page/navigation/request.rs index 0c6a4886..961269f1 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -13,7 +13,7 @@ use std::rc::Rc; // Main pub struct Request { - widget: Rc, + pub widget: Rc, } impl Request { @@ -90,12 +90,8 @@ impl Request { // Getters - pub fn widget(&self) -> &Rc { - &self.widget - } - pub fn uri(&self) -> Option { - match Uri::parse(&self.widget.gobject().text(), UriFlags::NONE) { + match Uri::parse(&self.widget.entry.text(), UriFlags::NONE) { Ok(uri) => Some(uri), _ => None, } 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 234bd67f..b0adf17d 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 @@ -21,7 +21,7 @@ struct Progress { } pub struct Widget { - gobject: Entry, + pub entry: Entry, progress: Rc, } @@ -35,21 +35,21 @@ impl Widget { }); // Init widget - let gobject = Entry::builder() + let entry = Entry::builder() .placeholder_text(PLACEHOLDER_TEXT) .hexpand(true) .build(); // Connect events - gobject.connect_changed(move |_| { + entry.connect_changed(move |_| { action.0.update().activate(None); }); - gobject.connect_activate(move |this| { + entry.connect_activate(move |this| { action.1.load().activate(Some(&this.text()), true); }); - gobject.connect_state_flags_changed({ + entry.connect_state_flags_changed({ // Define last focus state container let has_focus = RefCell::new(false); move |this, state| { @@ -71,7 +71,7 @@ impl Widget { }); // Return activated `Self` - Self { gobject, progress } + Self { entry, progress } } // Actions @@ -113,7 +113,7 @@ impl Widget { Ok(records) => { for record in records { if let Some(text) = record.text { - self.gobject.set_text(&text); + self.entry.set_text(&text); } // Delegate restore action to the item childs @@ -132,7 +132,7 @@ impl Widget { app_browser_window_tab_item_page_navigation_request_id: &i64, ) -> Result<(), String> { // Keep value in memory until operation complete - let text = self.gobject.text(); + let text = self.entry.text(); match database::insert( transaction, @@ -167,16 +167,16 @@ impl Widget { Duration::from_millis(PROGRESS_ANIMATION_TIME), { // Clone async pointers dependency - let gobject = self.gobject.clone(); + let entry = self.entry.clone(); let progress = self.progress.clone(); // Frame move || { // Animate - if *progress.fraction.borrow() > gobject.progress_fraction() { - gobject.set_progress_fraction( + if *progress.fraction.borrow() > entry.progress_fraction() { + entry.set_progress_fraction( // Currently, here is no outrange validation, seems that wrapper make this work @TODO - gobject.progress_fraction() + PROGRESS_ANIMATION_STEP, + entry.progress_fraction() + PROGRESS_ANIMATION_STEP, ); return ControlFlow::Continue; } @@ -185,8 +185,8 @@ impl Widget { // Reset on 100% (to hide progress bar) // or, just await for new value request - if gobject.progress_fraction() == 1.0 { - gobject.set_progress_fraction(0.0); + if entry.progress_fraction() == 1.0 { + entry.set_progress_fraction(0.0); } // Stop iteration @@ -198,12 +198,6 @@ impl Widget { } } } - - // Getters - - pub fn gobject(&self) -> &Entry { - &self.gobject - } } // Tools diff --git a/src/app/browser/window/tab/item/page/navigation/widget.rs b/src/app/browser/window/tab/item/page/navigation/widget.rs index daa975f4..fc51628f 100644 --- a/src/app/browser/window/tab/item/page/navigation/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/widget.rs @@ -7,7 +7,7 @@ const MARGIN: i32 = 6; const SPACING: i32 = 6; pub struct Widget { - gobject: Box, + pub gobject: Box, } impl Widget { @@ -37,9 +37,4 @@ impl Widget { Self { gobject } } - - // Getters - pub fn gobject(&self) -> &Box { - &self.gobject - } }