remove extra actions

This commit is contained in:
yggverse 2024-12-10 22:23:50 +02:00
parent 9b6ee0ab3b
commit 58b685ec1d
4 changed files with 38 additions and 86 deletions

View File

@ -49,7 +49,7 @@ pub fn new(
let cancellable = cancellable.clone();
let progress = progress.clone();
let status = status.clone();
move |_, button| {
move |button| {
// cancel all operations
cancellable.cancel();
// deactivate `spinner`
@ -70,7 +70,7 @@ pub fn new(
let progress = progress.clone();
let status = status.clone();
let on_choose = Rc::new(on_choose);
move |_, button| {
move |button| {
// lock choose button to prevent double click
button.set_sensitive(false);
dialog.save(Window::NONE, Some(&cancellable), {
@ -116,7 +116,7 @@ pub fn new(
let cancellable = cancellable.clone();
let file_launcher = file_launcher.clone();
let status = status.clone();
move |_, button| {
move |button| {
button.set_sensitive(false); // lock
file_launcher.launch(Window::NONE, Some(&cancellable), {
let status = status.clone();

View File

@ -1,9 +1,4 @@
use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, SignalHandlerId},
prelude::ActionExt,
Align, Button,
};
use gtk::{glib::SignalHandlerId, prelude::ButtonExt, Align, Button};
// Defaults
@ -13,7 +8,6 @@ const MARGIN: i32 = 16;
/// Cancel download using shared [Cancellable](https://docs.gtk.org/gio/class.Cancellable.html)
pub struct Cancel {
pub action: SimpleAction,
pub button: Button,
}
@ -22,31 +16,21 @@ impl Cancel {
/// Create new `Self`
pub fn new() -> Self {
let action = SimpleAction::new(&uuid_string_random(), None);
let button = Button::builder()
.action_name(action.name())
.css_classes(CSS_CLASSES)
.halign(Align::Center)
.label(LABEL)
.margin_top(MARGIN)
.visible(false)
.build();
Self { action, button }
Self {
button: Button::builder()
.css_classes(CSS_CLASSES)
.halign(Align::Center)
.label(LABEL)
.margin_top(MARGIN)
.visible(false)
.build(),
}
}
// Actions
/// Formatted action connector for external implementation
pub fn on_activate(
&self,
callback: impl Fn(SimpleAction, Button) + 'static,
) -> SignalHandlerId {
self.action.connect_activate({
let action = self.action.clone();
let button = self.button.clone();
move |_, _| callback(action.clone(), button.clone())
})
pub fn on_activate(&self, callback: impl Fn(&Button) + 'static) -> SignalHandlerId {
self.button.connect_clicked(move |this| callback(this))
}
}

View File

@ -1,9 +1,4 @@
use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, SignalHandlerId},
prelude::ActionExt,
Align, Button,
};
use gtk::{glib::SignalHandlerId, prelude::ButtonExt, Align, Button};
// Defaults
@ -14,7 +9,6 @@ const MARGIN: i32 = 16;
/// Choose destination [File](https://docs.gtk.org/gio/iface.File.html)
/// to write bytes on download
pub struct Choose {
pub action: SimpleAction,
pub button: Button,
}
@ -23,30 +17,20 @@ impl Choose {
/// Create new `Self`
pub fn new() -> Self {
let action = SimpleAction::new(&uuid_string_random(), None);
let button = Button::builder()
.action_name(action.name())
.css_classes(CSS_CLASSES)
.halign(Align::Center)
.label(LABEL)
.margin_top(MARGIN)
.build();
Self { action, button }
Self {
button: Button::builder()
.css_classes(CSS_CLASSES)
.halign(Align::Center)
.label(LABEL)
.margin_top(MARGIN)
.build(),
}
}
// Actions
/// Formatted action connector for external implementation
pub fn on_activate(
&self,
callback: impl Fn(SimpleAction, Button) + 'static,
) -> SignalHandlerId {
self.action.connect_activate({
let action = self.action.clone();
let button = self.button.clone();
move |_, _| callback(action.clone(), button.clone())
})
pub fn on_activate(&self, callback: impl Fn(&Button) + 'static) -> SignalHandlerId {
self.button.connect_clicked(move |this| callback(this))
}
}

View File

@ -1,9 +1,4 @@
use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, SignalHandlerId},
prelude::ActionExt,
Align, Button,
};
use gtk::{glib::SignalHandlerId, prelude::ButtonExt, Align, Button};
// Defaults
@ -13,7 +8,6 @@ const MARGIN: i32 = 16;
/// Open [File](https://docs.gtk.org/gio/iface.File.html) on download complete
pub struct Open {
pub action: SimpleAction,
pub button: Button,
}
@ -22,31 +16,21 @@ impl Open {
/// Create new `Self`
pub fn new() -> Self {
let action = SimpleAction::new(&uuid_string_random(), None);
let button = Button::builder()
.action_name(action.name())
.css_classes(CSS_CLASSES)
.halign(Align::Center)
.label(LABEL)
.margin_top(MARGIN)
.visible(false)
.build();
Self { action, button }
Self {
button: Button::builder()
.css_classes(CSS_CLASSES)
.halign(Align::Center)
.label(LABEL)
.margin_top(MARGIN)
.visible(false)
.build(),
}
}
// Actions
/// Formatted action connector for external implementation
pub fn on_activate(
&self,
callback: impl Fn(SimpleAction, Button) + 'static,
) -> SignalHandlerId {
self.action.connect_activate({
let action = self.action.clone();
let button = self.button.clone();
move |_, _| callback(action.clone(), button.clone())
})
pub fn on_activate(&self, callback: impl Fn(&Button) + 'static) -> SignalHandlerId {
self.button.connect_clicked(move |this| callback(this))
}
}