mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
begin global actions config implementation
This commit is contained in:
parent
f803d89f52
commit
9e481f78ce
9 changed files with 58 additions and 68 deletions
|
|
@ -6,7 +6,6 @@ use debug::Debug;
|
|||
|
||||
use gtk::{
|
||||
gio::SimpleActionGroup,
|
||||
glib::{gformat, uuid_string_random, GString},
|
||||
prelude::{IsA, WidgetExt},
|
||||
Window,
|
||||
};
|
||||
|
|
@ -17,7 +16,6 @@ pub struct Action {
|
|||
debug: Debug,
|
||||
// Group
|
||||
gobject: SimpleActionGroup,
|
||||
name: GString,
|
||||
}
|
||||
|
||||
impl Action {
|
||||
|
|
@ -31,11 +29,10 @@ impl Action {
|
|||
/// * children actions implemented as wrapper also, that extend default [Variant](https://docs.gtk.org/glib/struct.Variant.html) features, etc
|
||||
pub fn new_for(window: &(impl IsA<Window> + WidgetExt)) -> Self {
|
||||
// Init group
|
||||
let name = uuid_string_random();
|
||||
let gobject = SimpleActionGroup::new();
|
||||
|
||||
// Add group to window
|
||||
window.insert_action_group(&name, Some(&gobject));
|
||||
window.insert_action_group(crate::action::APP_BROWSER_WIDGET, Some(&gobject));
|
||||
|
||||
// Init actions
|
||||
let close = Close::new_for(&gobject, window.clone());
|
||||
|
|
@ -45,23 +42,6 @@ impl Action {
|
|||
close,
|
||||
debug,
|
||||
gobject,
|
||||
name,
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn debug(&self) -> GString {
|
||||
self.detailed_name(self.debug.name())
|
||||
}
|
||||
|
||||
pub fn close(&self) -> GString {
|
||||
self.detailed_name(self.close.name())
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
fn detailed_name(&self, action_name: GString) -> GString {
|
||||
gformat!("{}.{}", self.name, action_name)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use gtk::{
|
||||
gio::{SimpleAction, SimpleActionGroup},
|
||||
glib::{uuid_string_random, GString},
|
||||
prelude::{ActionExt, ActionMapExt, GtkWindowExt, IsA},
|
||||
prelude::{ActionMapExt, GtkWindowExt, IsA},
|
||||
Window,
|
||||
};
|
||||
|
||||
|
|
@ -17,8 +16,12 @@ impl Close {
|
|||
/// and [Window](https://docs.gtk.org/gtk4/class.Window.html)
|
||||
/// * this constructor **activate** default feature
|
||||
pub fn new_for(group: &SimpleActionGroup, window: impl IsA<Window>) -> Self {
|
||||
// Get action config
|
||||
let (_group_name, action_name, parameter_type, _accels) =
|
||||
crate::action::APP_BROWSER_WIDGET_CLOSE;
|
||||
|
||||
// Init action GObject
|
||||
let gobject = SimpleAction::new(&uuid_string_random(), None);
|
||||
let gobject = SimpleAction::new(&action_name, parameter_type);
|
||||
|
||||
// Add action to given group
|
||||
group.add_action(&gobject);
|
||||
|
|
@ -31,10 +34,4 @@ impl Close {
|
|||
// Done
|
||||
Self { gobject }
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn name(&self) -> GString {
|
||||
self.gobject.name()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use gtk::{
|
||||
gio::{SimpleAction, SimpleActionGroup},
|
||||
glib::{uuid_string_random, GString},
|
||||
prelude::{ActionExt, ActionMapExt, GtkWindowExt, IsA},
|
||||
prelude::{ActionMapExt, GtkWindowExt, IsA},
|
||||
Window,
|
||||
};
|
||||
|
||||
|
|
@ -17,8 +16,12 @@ impl Debug {
|
|||
/// and [Window](https://docs.gtk.org/gtk4/class.Window.html)
|
||||
/// * this constructor **activate** default feature
|
||||
pub fn new_for(group: &SimpleActionGroup, window: impl IsA<Window>) -> Self {
|
||||
// Get action config
|
||||
let (_group_name, action_name, parameter_type, _accels) =
|
||||
crate::action::APP_BROWSER_WIDGET_DEBUG;
|
||||
|
||||
// Init action GObject
|
||||
let gobject = SimpleAction::new(&uuid_string_random(), None);
|
||||
let gobject = SimpleAction::new(&action_name, parameter_type);
|
||||
|
||||
// Add action to given group
|
||||
group.add_action(&gobject);
|
||||
|
|
@ -31,10 +34,4 @@ impl Debug {
|
|||
// Done
|
||||
Self { gobject }
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn name(&self) -> GString {
|
||||
self.gobject.name()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue