From 47b2be986b6a02b7290d65e6dfdb2835c313f9fc Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 12 Nov 2024 08:23:19 +0200 Subject: [PATCH] implement is_history record argument for load action --- src/app/browser/window/tab/item.rs | 4 +- .../browser/window/tab/item/action/load.rs | 43 +++++++++++-------- src/app/browser/window/tab/item/page.rs | 6 +-- .../item/page/content/text/gemini/reader.rs | 2 +- .../window/tab/item/page/input/response.rs | 13 +++--- .../window/tab/item/page/input/sensitive.rs | 13 +++--- .../item/page/navigation/request/widget.rs | 2 +- 7 files changed, 49 insertions(+), 34 deletions(-) diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index 7fb9f747..a119dbc1 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -81,7 +81,7 @@ impl Item { action.load().connect_activate({ let page = page.clone(); - move |request| { + move |request, is_history| { if let Some(text) = request { page.navigation() .request() @@ -89,7 +89,7 @@ impl Item { .gobject() .set_text(&text); } - page.load(true); + page.load(is_history); } }); diff --git a/src/app/browser/window/tab/item/action/load.rs b/src/app/browser/window/tab/item/action/load.rs index 06366ff1..0a728aa9 100644 --- a/src/app/browser/window/tab/item/action/load.rs +++ b/src/app/browser/window/tab/item/action/load.rs @@ -15,7 +15,10 @@ impl Load { /// Create new `Self` pub fn new() -> Self { Self { - gobject: SimpleAction::new(&uuid_string_random(), Some(&String::static_variant_type())), + gobject: SimpleAction::new( + &uuid_string_random(), + Some(&<(String, bool)>::static_variant_type()), + ), } } @@ -23,13 +26,16 @@ 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>) { + pub fn activate(&self, request: Option<&str>, is_history: bool) { self.gobject.activate(Some( - &match request { - Some(value) => String::from(value), - None => String::new(), - } - .to_variant(), + &( + match request { + Some(value) => String::from(value), + None => String::new(), + }, + is_history, + ) + .to_variant(), )); } @@ -37,17 +43,20 @@ 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) + 'static) { - self.gobject.connect_activate(move |_, variant| { - let request = variant - .expect("Parameter value required") - .get::() - .expect("Parameter type does not match `String`"); + pub fn connect_activate(&self, callback: impl Fn(Option, bool) + 'static) { + self.gobject.connect_activate(move |_, this| { + let (request, is_history) = this + .expect("Expected (`request`,`is_history`) variant") + .get::<(String, bool)>() + .expect("Parameter type does not match (`String`,`bool`) tuple"); - callback(match request.is_empty() { - true => None, - false => Some(request.into()), - }) + callback( + match request.is_empty() { + true => None, + false => Some(request.into()), + }, + is_history, + ) }); } } diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 2fef0ab0..3b4b99cd 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -94,7 +94,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)); + self.tab_action.load().activate(Some(&url), true); } } @@ -748,8 +748,8 @@ impl Page { .set_status(Status::Redirect) // @TODO is this status really wanted? .set_title("Redirect"); - // Reload page to apply redirection - tab_action.load().activate(None); + // Reload page to apply redirection (without history record request) + tab_action.load().activate(None, false); } }, Err(reason) => { 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 6d3e94c8..9f3f1f69 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 @@ -247,7 +247,7 @@ impl Reader { return match uri.scheme().as_str() { "gemini" => { // Open new page in browser - actions.1.load().activate(Some(&uri.to_str())); + 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 1e846b29..035a8c28 100644 --- a/src/app/browser/window/tab/item/page/input/response.rs +++ b/src/app/browser/window/tab/item/page/input/response.rs @@ -63,11 +63,14 @@ impl Response { action_send.connect_activate({ let form = form.clone(); move |_, _| { - tab_action.load().activate(Some(&format!( - "{}?{}", - base.to_string_partial(UriHideFlags::QUERY), - Uri::escape_string(form.text().as_str(), None, false), - ))); + tab_action.load().activate( + Some(&format!( + "{}?{}", + base.to_string_partial(UriHideFlags::QUERY), + Uri::escape_string(form.text().as_str(), None, false), + )), + true, + ); } }); 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 4aa0de5a..64c67784 100644 --- a/src/app/browser/window/tab/item/page/input/sensitive.rs +++ b/src/app/browser/window/tab/item/page/input/sensitive.rs @@ -44,11 +44,14 @@ impl Sensitive { action_send.connect_activate({ let form = form.clone(); move |_, _| { - tab_action.load().activate(Some(&format!( - "{}?{}", - base.to_string_partial(UriHideFlags::QUERY), - Uri::escape_string(form.text().as_str(), None, false), - ))); + tab_action.load().activate( + Some(&format!( + "{}?{}", + base.to_string_partial(UriHideFlags::QUERY), + Uri::escape_string(form.text().as_str(), None, false), + )), + true, + ); } }); 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 b46d1c3c..5c53cd39 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 @@ -48,7 +48,7 @@ impl Widget { }); gobject.connect_activate(move |this| { - tab_action.load().activate(Some(&this.text())); + tab_action.load().activate(Some(&this.text()), true); }); gobject.connect_state_flags_changed({