mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
create parental app mod
This commit is contained in:
parent
2461f2a0fb
commit
b2aa3af46a
37 changed files with 176 additions and 111 deletions
42
src/app/action.rs
Normal file
42
src/app/action.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// 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 std::sync::Arc;
|
||||
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{gformat, uuid_string_random, GString},
|
||||
prelude::ActionExt,
|
||||
};
|
||||
|
||||
pub struct Action {
|
||||
group: GString,
|
||||
simple: Arc<SimpleAction>,
|
||||
}
|
||||
|
||||
impl Action {
|
||||
// Construct
|
||||
pub fn new(group: &str, is_enabled: bool) -> Self {
|
||||
// Create random action name as no static values should be in use
|
||||
let simple = Arc::new(SimpleAction::new(&uuid_string_random(), None));
|
||||
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) -> Arc<SimpleAction> {
|
||||
self.simple.clone()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue