remove extra wrapper

This commit is contained in:
yggverse 2024-11-05 18:48:00 +02:00
parent d7c0577052
commit 7079cc7230
2 changed files with 55 additions and 100 deletions

View file

@ -1,60 +0,0 @@
// This helper created as the attempt to drop static names usage
// and replace them with objects (to follow encapsulation for children mods)
// @TODO find alternative implementation, if exist for GTK 4
use gtk::{
gio::SimpleAction,
glib::{gformat, uuid_string_random, GString, Variant, VariantTy},
prelude::ActionExt,
};
pub struct Action {
group: GString,
simple: SimpleAction,
}
impl Action {
// Construct
pub fn new(group: &str, is_enabled: bool, parameter_type: Option<&VariantTy>) -> Self {
// Create random action name as no static values should be in use
let simple = SimpleAction::new(&uuid_string_random(), parameter_type);
simple.set_enabled(is_enabled);
// Assign action to the group
let group = GString::from(group);
// Return new Action
Self { group, simple }
}
/// Stateful constructors useful for actions that require custom values
/// but could not receive it directly with action argument
/// e.g. [MenuModel](https://docs.gtk.org/gio/class.MenuModel.html)
pub fn new_stateful(
group: &str,
is_enabled: bool,
parameter_type: Option<&VariantTy>,
state: &Variant,
) -> Self {
// Create random action name as no static values should be in use
let simple = SimpleAction::new_stateful(&uuid_string_random(), parameter_type, state);
simple.set_enabled(is_enabled);
// Assign action to the group
let group = GString::from(group);
// Return new Action
Self { group, simple }
}
// Getters
pub fn detailed_name(&self) -> GString {
gformat!("{}.{}", self.group, self.simple.name()) // @TODO find the way to ident parent group
// from SimpleAction object
}
// App mods work with simple and system-wide data types, let them take it
pub fn simple(&self) -> SimpleAction {
self.simple.clone()
}
}