diff --git a/src/app/browser/window/tab/item/identity/gemini.rs b/src/app/browser/window/tab/item/identity/gemini.rs index 80988611..6d9f7f0d 100644 --- a/src/app/browser/window/tab/item/identity/gemini.rs +++ b/src/app/browser/window/tab/item/identity/gemini.rs @@ -23,6 +23,15 @@ impl Gemini { let widget = Rc::new(Widget::new(profile.clone(), &auth_url)); // Init events + widget.on_cancel({ + let action = action.clone(); + move |is_reload_request| { + if is_reload_request { + action.reload.activate(); + } + } + }); + widget.on_apply({ let widget = widget.clone(); move |response| { diff --git a/src/app/browser/window/tab/item/identity/gemini/widget.rs b/src/app/browser/window/tab/item/identity/gemini/widget.rs index 94657f87..283af6e0 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget.rs @@ -10,7 +10,7 @@ use adw::{ AlertDialog, ResponseAppearance, }; use gtk::prelude::IsA; -use std::rc::Rc; +use std::{cell::Cell, rc::Rc}; // Defaults const HEADING: &str = "Ident"; @@ -27,6 +27,7 @@ pub struct Widget { // pub action: Rc, pub form: Rc
, pub alert_dialog: AlertDialog, + pub is_reload_request: Rc>, } impl Widget { @@ -37,6 +38,9 @@ impl Widget { // Init actions let action = Rc::new(Action::new()); + // Page may require reload for some widget actions + let is_reload_request = Rc::new(Cell::new(false)); + // Init child container let form = Rc::new(Form::new(profile, action.clone(), auth_url)); @@ -67,7 +71,11 @@ impl Widget { action.update.connect_activate({ let form = form.clone(); let alert_dialog = alert_dialog.clone(); - move || { + let is_reload_request = is_reload_request.clone(); + move |_is_reload_request| { + // Update reload state + is_reload_request.replace(_is_reload_request); + // Update child components form.update(); @@ -81,13 +89,14 @@ impl Widget { // action, form, alert_dialog, + is_reload_request, } } // Actions - /// Callback wrapper for `apply` [response](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/signal.AlertDialog.response.html) - /// * return `Value` enum or new record request on `None` + /// Callback wrapper to apply + /// [response](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/signal.AlertDialog.response.html) pub fn on_apply(&self, callback: impl Fn(Value) + 'static) { self.alert_dialog.connect_response(Some(RESPONSE_APPLY.0), { let form = self.form.clone(); @@ -101,6 +110,23 @@ impl Widget { }); } + /// Callback wrapper to cancel + /// [response](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/signal.AlertDialog.response.html) + /// * return require reload state + pub fn on_cancel(&self, callback: impl Fn(bool) + 'static) { + self.alert_dialog + .connect_response(Some(RESPONSE_CANCEL.0), { + let is_reload_request = self.is_reload_request.take(); + move |this, response| { + // Prevent double-click action + this.set_response_enabled(response, false); + + // Result + callback(is_reload_request) + } + }); + } + /// Show dialog with new preset pub fn present(&self, parent: Option<&impl IsA>) { self.form.update(); diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/action/update.rs b/src/app/browser/window/tab/item/identity/gemini/widget/action/update.rs index d0ad0355..75021613 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/action/update.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/action/update.rs @@ -1,4 +1,8 @@ -use gtk::{gio::SimpleAction, glib::uuid_string_random, prelude::ActionExt}; +use gtk::{ + gio::SimpleAction, + glib::uuid_string_random, + prelude::{ActionExt, StaticVariantType, ToVariant}, +}; /// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Update` action pub struct Update { @@ -11,7 +15,7 @@ impl Update { /// Create new `Self` pub fn new() -> Self { Self { - gobject: SimpleAction::new(&uuid_string_random(), None), + gobject: SimpleAction::new(&uuid_string_random(), Some(&bool::static_variant_type())), } } @@ -19,15 +23,21 @@ impl Update { /// 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); + pub fn activate(&self, is_reload_request: bool) { + self.gobject.activate(Some(&is_reload_request.to_variant())); } // Events /// 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()); + pub fn connect_activate(&self, callback: impl Fn(bool) + 'static) { + self.gobject.connect_activate(move |_, this| { + callback( + this.expect("Expected `is_reload_request` variant") + .get::() + .expect("Parameter type does not match `bool` type"), + ) + }); } } diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs index 54617b23..e440a509 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs @@ -89,7 +89,7 @@ impl File { } } button.set_sensitive(true); // unlock - action_widget.update.activate() + action_widget.update.activate(true) } }); } diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs index e32145b8..42ca629a 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs @@ -134,7 +134,7 @@ impl List { .build(); // Connect events - dropdown.connect_selected_notify(move |_| action_widget.update.activate()); + dropdown.connect_selected_notify(move |_| action_widget.update.activate(false)); // Return activated `Self` Self { diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs index 7fc2bb82..23541576 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs @@ -29,7 +29,7 @@ impl Name { .build(); // Init events - entry.connect_changed(move |_| action_widget.update.activate()); + entry.connect_changed(move |_| action_widget.update.activate(false)); // Return activated `Self` Self { entry }