mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-29 20:44:25 +00:00
replace reload request feature with global update action
This commit is contained in:
parent
9368a2a315
commit
483be18b17
@ -51,7 +51,7 @@ impl Item {
|
|||||||
let page = Rc::new(Page::new(
|
let page = Rc::new(Page::new(
|
||||||
id.clone(),
|
id.clone(),
|
||||||
profile.clone(),
|
profile.clone(),
|
||||||
(actions.0, actions.1.clone(), action.clone()),
|
(actions.0.clone(), actions.1.clone(), action.clone()),
|
||||||
));
|
));
|
||||||
|
|
||||||
let widget = Rc::new(Widget::new(
|
let widget = Rc::new(Widget::new(
|
||||||
@ -75,6 +75,8 @@ impl Item {
|
|||||||
|
|
||||||
// Show identity selection for 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();
|
let page = page.clone();
|
||||||
let parent = tab_view.clone().upcast::<gtk::Widget>();
|
let parent = tab_view.clone().upcast::<gtk::Widget>();
|
||||||
move || {
|
move || {
|
||||||
@ -82,8 +84,12 @@ impl Item {
|
|||||||
if let Some(uri) = page.navigation.request.uri() {
|
if let Some(uri) = page.navigation.request.uri() {
|
||||||
// Rout by scheme
|
// Rout by scheme
|
||||||
if uri.scheme().to_lowercase() == "gemini" {
|
if uri.scheme().to_lowercase() == "gemini" {
|
||||||
return identity::new_gemini(profile.clone(), actions.1.clone(), uri)
|
return identity::new_gemini(
|
||||||
.present(Some(&parent));
|
(browser_action.clone(), window_action.clone()),
|
||||||
|
profile.clone(),
|
||||||
|
uri,
|
||||||
|
)
|
||||||
|
.present(Some(&parent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Show dialog with unsupported request message
|
// Show dialog with unsupported request message
|
||||||
|
@ -4,14 +4,19 @@ mod unsupported;
|
|||||||
use gemini::Gemini;
|
use gemini::Gemini;
|
||||||
use unsupported::Unsupported;
|
use unsupported::Unsupported;
|
||||||
|
|
||||||
use crate::app::browser::window::Action;
|
use crate::app::browser::action::Action as BrowserAction;
|
||||||
|
use crate::app::browser::window::action::Action as WindowAction;
|
||||||
use crate::profile::Profile;
|
use crate::profile::Profile;
|
||||||
use gtk::glib::Uri;
|
use gtk::glib::Uri;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// Create new identity widget for Gemini protocol match given URI
|
/// Create new identity widget for Gemini protocol match given URI
|
||||||
pub fn new_gemini(profile: Rc<Profile>, action: Rc<Action>, auth_uri: Uri) -> Gemini {
|
pub fn new_gemini(
|
||||||
Gemini::new(profile, action, auth_uri)
|
action: (Rc<BrowserAction>, Rc<WindowAction>),
|
||||||
|
profile: Rc<Profile>,
|
||||||
|
auth_uri: Uri,
|
||||||
|
) -> Gemini {
|
||||||
|
Gemini::new(action, profile, auth_uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create new identity widget for unknown request
|
/// Create new identity widget for unknown request
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
mod widget;
|
mod widget;
|
||||||
use widget::{form::list::item::value::Value, Widget};
|
use widget::{form::list::item::value::Value, Widget};
|
||||||
|
|
||||||
use crate::app::browser::window::Action;
|
use crate::app::browser::action::Action as BrowserAction;
|
||||||
|
use crate::app::browser::window::action::Action as WindowAction;
|
||||||
use crate::profile::Profile;
|
use crate::profile::Profile;
|
||||||
use gtk::{glib::Uri, prelude::IsA};
|
use gtk::{glib::Uri, prelude::IsA};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@ -15,7 +16,11 @@ impl Gemini {
|
|||||||
// Construct
|
// Construct
|
||||||
|
|
||||||
/// Create new `Self` for given `Profile`
|
/// Create new `Self` for given `Profile`
|
||||||
pub fn new(profile: Rc<Profile>, action: Rc<Action>, auth_uri: Uri) -> Self {
|
pub fn new(
|
||||||
|
action: (Rc<BrowserAction>, Rc<WindowAction>),
|
||||||
|
profile: Rc<Profile>,
|
||||||
|
auth_uri: Uri,
|
||||||
|
) -> Self {
|
||||||
// Init shared URL string from URI
|
// Init shared URL string from URI
|
||||||
let auth_url = auth_uri.to_string();
|
let auth_url = auth_uri.to_string();
|
||||||
|
|
||||||
@ -24,11 +29,8 @@ impl Gemini {
|
|||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
widget.on_cancel({
|
widget.on_cancel({
|
||||||
let action = action.clone();
|
move || {
|
||||||
move |is_reload_request| {
|
action.0.update.activate(None);
|
||||||
if is_reload_request {
|
|
||||||
action.reload.activate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -83,7 +85,7 @@ impl Gemini {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reload page to apply changes
|
// Reload page to apply changes
|
||||||
action.reload.activate();
|
action.1.reload.activate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ use adw::{
|
|||||||
AlertDialog, ResponseAppearance,
|
AlertDialog, ResponseAppearance,
|
||||||
};
|
};
|
||||||
use gtk::prelude::IsA;
|
use gtk::prelude::IsA;
|
||||||
use std::{cell::Cell, rc::Rc};
|
use std::rc::Rc;
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
const HEADING: &str = "Ident";
|
const HEADING: &str = "Ident";
|
||||||
@ -27,7 +27,6 @@ pub struct Widget {
|
|||||||
// pub action: Rc<Action>,
|
// pub action: Rc<Action>,
|
||||||
pub form: Rc<Form>,
|
pub form: Rc<Form>,
|
||||||
pub alert_dialog: AlertDialog,
|
pub alert_dialog: AlertDialog,
|
||||||
pub is_reload_request: Rc<Cell<bool>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
@ -38,9 +37,6 @@ impl Widget {
|
|||||||
// Init actions
|
// Init actions
|
||||||
let action = Rc::new(Action::new());
|
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
|
// Init child container
|
||||||
let form = Rc::new(Form::new(profile, action.clone(), auth_url));
|
let form = Rc::new(Form::new(profile, action.clone(), auth_url));
|
||||||
|
|
||||||
@ -71,11 +67,7 @@ impl Widget {
|
|||||||
action.update.connect_activate({
|
action.update.connect_activate({
|
||||||
let form = form.clone();
|
let form = form.clone();
|
||||||
let alert_dialog = alert_dialog.clone();
|
let alert_dialog = alert_dialog.clone();
|
||||||
let is_reload_request = is_reload_request.clone();
|
move || {
|
||||||
move |_is_reload_request| {
|
|
||||||
// Update reload state
|
|
||||||
is_reload_request.replace(_is_reload_request);
|
|
||||||
|
|
||||||
// Update child components
|
// Update child components
|
||||||
form.update();
|
form.update();
|
||||||
|
|
||||||
@ -89,7 +81,6 @@ impl Widget {
|
|||||||
// action,
|
// action,
|
||||||
form,
|
form,
|
||||||
alert_dialog,
|
alert_dialog,
|
||||||
is_reload_request,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,17 +104,14 @@ impl Widget {
|
|||||||
/// Callback wrapper to cancel
|
/// Callback wrapper to cancel
|
||||||
/// [response](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/signal.AlertDialog.response.html)
|
/// [response](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/signal.AlertDialog.response.html)
|
||||||
/// * return require reload state
|
/// * return require reload state
|
||||||
pub fn on_cancel(&self, callback: impl Fn(bool) + 'static) {
|
pub fn on_cancel(&self, callback: impl Fn() + 'static) {
|
||||||
self.alert_dialog
|
self.alert_dialog
|
||||||
.connect_response(Some(RESPONSE_CANCEL.0), {
|
.connect_response(Some(RESPONSE_CANCEL.0), move |this, response| {
|
||||||
let is_reload_request = self.is_reload_request.take();
|
// Prevent double-click action
|
||||||
move |this, response| {
|
this.set_response_enabled(response, false);
|
||||||
// Prevent double-click action
|
|
||||||
this.set_response_enabled(response, false);
|
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
callback(is_reload_request)
|
callback()
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
use gtk::{
|
use gtk::{gio::SimpleAction, glib::uuid_string_random, prelude::ActionExt};
|
||||||
gio::SimpleAction,
|
|
||||||
glib::uuid_string_random,
|
|
||||||
prelude::{ActionExt, StaticVariantType, ToVariant},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Update` action
|
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Update` action
|
||||||
pub struct Update {
|
pub struct Update {
|
||||||
@ -15,7 +11,7 @@ impl Update {
|
|||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
gobject: SimpleAction::new(&uuid_string_random(), Some(&bool::static_variant_type())),
|
gobject: SimpleAction::new(&uuid_string_random(), None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,21 +19,15 @@ impl Update {
|
|||||||
|
|
||||||
/// 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, is_reload_request: bool) {
|
pub fn activate(&self) {
|
||||||
self.gobject.activate(Some(&is_reload_request.to_variant()));
|
self.gobject.activate(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
|
|
||||||
/// 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(bool) + 'static) {
|
pub fn connect_activate(&self, callback: impl Fn() + 'static) {
|
||||||
self.gobject.connect_activate(move |_, this| {
|
self.gobject.connect_activate(move |_, _| callback());
|
||||||
callback(
|
|
||||||
this.expect("Expected `is_reload_request` variant")
|
|
||||||
.get::<bool>()
|
|
||||||
.expect("Parameter type does not match `bool` type"),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ impl File {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
button.set_sensitive(true); // unlock
|
button.set_sensitive(true); // unlock
|
||||||
action_widget.update.activate(false)
|
action_widget.update.activate()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ impl List {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Connect events
|
// Connect events
|
||||||
dropdown.connect_selected_notify(move |_| action_widget.update.activate(false));
|
dropdown.connect_selected_notify(move |_| action_widget.update.activate());
|
||||||
|
|
||||||
// Return activated `Self`
|
// Return activated `Self`
|
||||||
Self {
|
Self {
|
||||||
|
@ -29,7 +29,7 @@ impl Name {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
entry.connect_changed(move |_| action_widget.update.activate(false));
|
entry.connect_changed(move |_| action_widget.update.activate());
|
||||||
|
|
||||||
// Return activated `Self`
|
// Return activated `Self`
|
||||||
Self { entry }
|
Self { entry }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user