use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, SignalHandlerId},
prelude::StaticVariantType,
};
pub struct Open {
pub simple_action: SimpleAction,
}
impl Default for Open {
fn default() -> Self {
Self::new()
}
}
impl Open {
pub fn new() -> Self {
Self {
simple_action: SimpleAction::new(
&uuid_string_random(),
Some(&String::static_variant_type()),
),
}
}
pub fn on_activate(
&self,
callback: impl Fn(&SimpleAction, String) + 'static,
) -> SignalHandlerId {
self.simple_action.connect_activate(move |this, message| {
callback(
this,
message
.expect("Variant required to call this action")
.get::<String>()
.expect("Parameter does not match `String` type"),
)
})
}
}