2024-11-10 07:09:55 +02:00
|
|
|
mod about;
|
|
|
|
mod close;
|
|
|
|
mod debug;
|
|
|
|
mod profile;
|
|
|
|
mod update;
|
2024-11-08 06:47:58 +02:00
|
|
|
|
2024-11-10 07:09:55 +02:00
|
|
|
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
|
2024-11-08 09:19:16 +02:00
|
|
|
pub struct Action {
|
2024-11-10 07:09:55 +02:00
|
|
|
// Actions
|
|
|
|
about: Rc<About>,
|
|
|
|
close: Rc<Close>,
|
|
|
|
debug: Rc<Debug>,
|
|
|
|
profile: Rc<Profile>,
|
|
|
|
update: Rc<Update>,
|
|
|
|
// Group
|
|
|
|
id: GString,
|
|
|
|
gobject: SimpleActionGroup,
|
2024-11-08 06:47:58 +02:00
|
|
|
}
|
|
|
|
|
2024-11-08 09:19:16 +02:00
|
|
|
impl Action {
|
2024-11-08 06:47:58 +02:00
|
|
|
// Constructors
|
|
|
|
|
2024-11-10 07:09:55 +02:00
|
|
|
/// Create new `Self`
|
2024-11-08 06:47:58 +02:00
|
|
|
pub fn new() -> Self {
|
2024-11-10 07:09:55 +02:00
|
|
|
// 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
|
2024-11-08 06:47:58 +02:00
|
|
|
Self {
|
2024-11-10 07:09:55 +02:00
|
|
|
about,
|
|
|
|
close,
|
|
|
|
debug,
|
|
|
|
profile,
|
|
|
|
update,
|
|
|
|
id,
|
|
|
|
gobject,
|
2024-11-08 06:47:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getters
|
|
|
|
|
2024-11-12 18:02:35 +02:00
|
|
|
/// Get reference to `About` action
|
2024-11-10 07:09:55 +02:00
|
|
|
pub fn about(&self) -> &Rc<About> {
|
2024-11-08 06:47:58 +02:00
|
|
|
&self.about
|
|
|
|
}
|
|
|
|
|
2024-11-12 18:02:35 +02:00
|
|
|
/// Get reference to `Close` action
|
2024-11-10 07:09:55 +02:00
|
|
|
pub fn close(&self) -> &Rc<Close> {
|
|
|
|
&self.close
|
|
|
|
}
|
|
|
|
|
2024-11-12 18:02:35 +02:00
|
|
|
/// Get reference to `Debug` action
|
2024-11-10 07:09:55 +02:00
|
|
|
pub fn debug(&self) -> &Rc<Debug> {
|
2024-11-08 06:47:58 +02:00
|
|
|
&self.debug
|
|
|
|
}
|
|
|
|
|
2024-11-12 18:02:35 +02:00
|
|
|
/// Get reference to `Profile` action
|
2024-11-10 07:09:55 +02:00
|
|
|
pub fn profile(&self) -> &Rc<Profile> {
|
2024-11-08 06:47:58 +02:00
|
|
|
&self.profile
|
|
|
|
}
|
|
|
|
|
2024-11-12 18:02:35 +02:00
|
|
|
/// Get reference to `Update` action
|
2024-11-10 07:09:55 +02:00
|
|
|
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
|
2024-11-08 06:47:58 +02:00
|
|
|
}
|
|
|
|
|
2024-11-10 07:09:55 +02:00
|
|
|
/// Get reference to [SimpleActionGroup](https://docs.gtk.org/gio/class.SimpleActionGroup.html) GObject
|
|
|
|
pub fn gobject(&self) -> &SimpleActionGroup {
|
|
|
|
&self.gobject
|
2024-11-08 06:47:58 +02:00
|
|
|
}
|
|
|
|
}
|