implement is_history record argument for load action

This commit is contained in:
yggverse 2024-11-12 08:23:19 +02:00
parent 60d4a94ff3
commit 47b2be986b
7 changed files with 49 additions and 34 deletions

View File

@ -81,7 +81,7 @@ impl Item {
action.load().connect_activate({ action.load().connect_activate({
let page = page.clone(); let page = page.clone();
move |request| { move |request, is_history| {
if let Some(text) = request { if let Some(text) = request {
page.navigation() page.navigation()
.request() .request()
@ -89,7 +89,7 @@ impl Item {
.gobject() .gobject()
.set_text(&text); .set_text(&text);
} }
page.load(true); page.load(is_history);
} }
}); });

View File

@ -15,7 +15,10 @@ impl Load {
/// Create new `Self` /// Create new `Self`
pub fn new() -> Self { pub fn new() -> Self {
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,12 +26,15 @@ impl Load {
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal /// 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 /// 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( self.gobject.activate(Some(
&match request { &(
match request {
Some(value) => String::from(value), Some(value) => String::from(value),
None => String::new(), None => String::new(),
} },
is_history,
)
.to_variant(), .to_variant(),
)); ));
} }
@ -37,17 +43,20 @@ impl Load {
/// Define callback function for /// Define callback function for
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal /// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
pub fn connect_activate(&self, callback: impl Fn(Option<GString>) + 'static) { pub fn connect_activate(&self, callback: impl Fn(Option<GString>, bool) + 'static) {
self.gobject.connect_activate(move |_, variant| { self.gobject.connect_activate(move |_, this| {
let request = variant let (request, is_history) = this
.expect("Parameter value required") .expect("Expected (`request`,`is_history`) variant")
.get::<String>() .get::<(String, bool)>()
.expect("Parameter type does not match `String`"); .expect("Parameter type does not match (`String`,`bool`) tuple");
callback(match request.is_empty() { callback(
match request.is_empty() {
true => None, true => None,
false => Some(request.into()), false => Some(request.into()),
}) },
is_history,
)
}); });
} }
} }

View File

@ -94,7 +94,7 @@ impl Page {
pub fn home(&self) { pub fn home(&self) {
if let Some(url) = self.navigation.home().url() { if let Some(url) = self.navigation.home().url() {
// Update with history record // 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_status(Status::Redirect) // @TODO is this status really wanted?
.set_title("Redirect"); .set_title("Redirect");
// Reload page to apply redirection // Reload page to apply redirection (without history record request)
tab_action.load().activate(None); tab_action.load().activate(None, false);
} }
}, },
Err(reason) => { Err(reason) => {

View File

@ -247,7 +247,7 @@ impl Reader {
return match uri.scheme().as_str() { return match uri.scheme().as_str() {
"gemini" => { "gemini" => {
// Open new page in browser // 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 // Scheme not supported, delegate
_ => UriLauncher::new(&uri.to_str()).launch( _ => UriLauncher::new(&uri.to_str()).launch(

View File

@ -63,11 +63,14 @@ impl Response {
action_send.connect_activate({ action_send.connect_activate({
let form = form.clone(); let form = form.clone();
move |_, _| { move |_, _| {
tab_action.load().activate(Some(&format!( tab_action.load().activate(
Some(&format!(
"{}?{}", "{}?{}",
base.to_string_partial(UriHideFlags::QUERY), base.to_string_partial(UriHideFlags::QUERY),
Uri::escape_string(form.text().as_str(), None, false), Uri::escape_string(form.text().as_str(), None, false),
))); )),
true,
);
} }
}); });

View File

@ -44,11 +44,14 @@ impl Sensitive {
action_send.connect_activate({ action_send.connect_activate({
let form = form.clone(); let form = form.clone();
move |_, _| { move |_, _| {
tab_action.load().activate(Some(&format!( tab_action.load().activate(
Some(&format!(
"{}?{}", "{}?{}",
base.to_string_partial(UriHideFlags::QUERY), base.to_string_partial(UriHideFlags::QUERY),
Uri::escape_string(form.text().as_str(), None, false), Uri::escape_string(form.text().as_str(), None, false),
))); )),
true,
);
} }
}); });

View File

@ -48,7 +48,7 @@ impl Widget {
}); });
gobject.connect_activate(move |this| { 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({ gobject.connect_state_flags_changed({