mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
begin local actions implementation
This commit is contained in:
parent
9398a835cd
commit
9ff32a3419
19 changed files with 402 additions and 226 deletions
|
|
@ -1,45 +1,109 @@
|
|||
use gtk::{gio::SimpleAction, glib::uuid_string_random, prelude::StaticVariantType};
|
||||
mod about;
|
||||
mod close;
|
||||
mod debug;
|
||||
mod profile;
|
||||
mod update;
|
||||
|
||||
use about::About;
|
||||
use close::Close;
|
||||
use debug::Debug;
|
||||
use profile::Profile;
|
||||
use update::Update;
|
||||
|
||||
use gtk::{
|
||||
gio::SimpleActionGroup,
|
||||
glib::{uuid_string_random, GString},
|
||||
prelude::ActionMapExt,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
/// [SimpleActionGroup](https://docs.gtk.org/gio/class.SimpleActionGroup.html) wrapper for `Browser` actions
|
||||
pub struct Action {
|
||||
about: SimpleAction,
|
||||
debug: SimpleAction,
|
||||
profile: SimpleAction,
|
||||
quit: SimpleAction,
|
||||
update: SimpleAction,
|
||||
// Actions
|
||||
about: Rc<About>,
|
||||
close: Rc<Close>,
|
||||
debug: Rc<Debug>,
|
||||
profile: Rc<Profile>,
|
||||
update: Rc<Update>,
|
||||
// Group
|
||||
id: GString,
|
||||
gobject: SimpleActionGroup,
|
||||
}
|
||||
|
||||
impl Action {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
// Init actions
|
||||
let about = Rc::new(About::new());
|
||||
let close = Rc::new(Close::new());
|
||||
let debug = Rc::new(Debug::new());
|
||||
let profile = Rc::new(Profile::new());
|
||||
let update = Rc::new(Update::new());
|
||||
|
||||
// Generate unique group ID
|
||||
let id = uuid_string_random();
|
||||
|
||||
// Init group
|
||||
let gobject = SimpleActionGroup::new();
|
||||
|
||||
// Add action to given group
|
||||
gobject.add_action(about.gobject());
|
||||
gobject.add_action(close.gobject());
|
||||
gobject.add_action(debug.gobject());
|
||||
gobject.add_action(profile.gobject());
|
||||
gobject.add_action(update.gobject());
|
||||
|
||||
// Done
|
||||
Self {
|
||||
about: SimpleAction::new(&uuid_string_random(), None),
|
||||
debug: SimpleAction::new(&uuid_string_random(), None),
|
||||
profile: SimpleAction::new(&uuid_string_random(), None),
|
||||
quit: SimpleAction::new(&uuid_string_random(), None),
|
||||
update: SimpleAction::new(&uuid_string_random(), Some(&String::static_variant_type())),
|
||||
about,
|
||||
close,
|
||||
debug,
|
||||
profile,
|
||||
update,
|
||||
id,
|
||||
gobject,
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn about(&self) -> &SimpleAction {
|
||||
/// Get reference `About` action
|
||||
pub fn about(&self) -> &Rc<About> {
|
||||
&self.about
|
||||
}
|
||||
|
||||
pub fn debug(&self) -> &SimpleAction {
|
||||
/// Get reference `Close` action
|
||||
pub fn close(&self) -> &Rc<Close> {
|
||||
&self.close
|
||||
}
|
||||
|
||||
/// Get reference `Debug` action
|
||||
pub fn debug(&self) -> &Rc<Debug> {
|
||||
&self.debug
|
||||
}
|
||||
|
||||
pub fn profile(&self) -> &SimpleAction {
|
||||
/// Get reference `Profile` action
|
||||
pub fn profile(&self) -> &Rc<Profile> {
|
||||
&self.profile
|
||||
}
|
||||
|
||||
pub fn quit(&self) -> &SimpleAction {
|
||||
&self.quit
|
||||
}
|
||||
|
||||
pub fn update(&self) -> &SimpleAction {
|
||||
/// Get reference `Update` action
|
||||
pub fn update(&self) -> &Rc<Update> {
|
||||
&self.update
|
||||
}
|
||||
|
||||
/// Get auto-generated name for action group
|
||||
/// * useful for manual relationship with GObjects or as the `detailed_name`
|
||||
/// for [Accels](https://docs.gtk.org/gtk4/method.Application.set_accels_for_action.html) or
|
||||
/// [Menu](https://docs.gtk.org/gio/class.Menu.html) builder
|
||||
pub fn id(&self) -> &GString {
|
||||
&self.id
|
||||
}
|
||||
|
||||
/// Get reference to [SimpleActionGroup](https://docs.gtk.org/gio/class.SimpleActionGroup.html) GObject
|
||||
pub fn gobject(&self) -> &SimpleActionGroup {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue