mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
move tab open action to separated mod
This commit is contained in:
parent
9ff32a3419
commit
38f945105c
13 changed files with 252 additions and 75 deletions
76
src/app/browser/window/tab/action.rs
Normal file
76
src/app/browser/window/tab/action.rs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
mod append;
|
||||
mod open;
|
||||
|
||||
use append::Append;
|
||||
use open::Open;
|
||||
|
||||
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 {
|
||||
// Actions
|
||||
append: Rc<Append>,
|
||||
open: Rc<Open>,
|
||||
// Group
|
||||
id: GString,
|
||||
gobject: SimpleActionGroup,
|
||||
}
|
||||
|
||||
impl Action {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
// Init actions
|
||||
let append = Rc::new(Append::new());
|
||||
let open = Rc::new(Open::new());
|
||||
|
||||
// Generate unique group ID
|
||||
let id = uuid_string_random();
|
||||
|
||||
// Init group
|
||||
let gobject = SimpleActionGroup::new();
|
||||
|
||||
// Add action to given group
|
||||
gobject.add_action(append.gobject());
|
||||
gobject.add_action(open.gobject());
|
||||
|
||||
// Done
|
||||
Self {
|
||||
append,
|
||||
open,
|
||||
id,
|
||||
gobject,
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
/// Get reference `Append` action
|
||||
pub fn append(&self) -> &Rc<Append> {
|
||||
&self.append
|
||||
}
|
||||
|
||||
/// Get reference `Open` action
|
||||
pub fn open(&self) -> &Rc<Open> {
|
||||
&self.open
|
||||
}
|
||||
|
||||
/// 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