create local actions group

This commit is contained in:
yggverse 2024-10-14 05:12:30 +03:00
parent 1f44715ed7
commit 28fcf247b2
2 changed files with 27 additions and 7 deletions

View File

@ -9,7 +9,8 @@ use widget::Widget;
use adw::TabView;
use gtk::{
gio::SimpleAction,
glib::{GString, Propagation},
glib::{uuid_string_random, GString, Propagation},
prelude::StaticVariantType,
};
use sqlite::Transaction;
use std::{cell::RefCell, collections::HashMap, sync::Arc};
@ -40,11 +41,17 @@ impl Tab {
action_tab_page_navigation_reload: Arc<SimpleAction>,
action_update: Arc<SimpleAction>,
) -> Arc<Self> {
// Init local actions
let action_tab_open = Arc::new(SimpleAction::new(
&uuid_string_random(),
Some(&String::static_variant_type()),
));
// Init empty HashMap index as no tabs appended yet
let index = Arc::new(RefCell::new(HashMap::new()));
// Init widget
let widget = Arc::new(Widget::new());
let widget = Arc::new(Widget::new(action_tab_open.clone()));
// Init events
widget.gobject().connect_close_page({

View File

@ -1,5 +1,11 @@
use std::sync::Arc;
use adw::TabView;
use gtk::glib::GString;
use gtk::{
gio::{SimpleAction, SimpleActionGroup},
glib::{uuid_string_random, GString},
prelude::{ActionMapExt, WidgetExt},
};
pub struct Widget {
gobject: TabView,
@ -7,10 +13,17 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new() -> Self {
Self {
gobject: TabView::builder().build(),
}
pub fn new(action_tab_append: Arc<SimpleAction>) -> Self {
// Init additional action group
let action_group = SimpleActionGroup::new();
action_group.add_action(action_tab_append.as_ref());
// Init gobject
let gobject = TabView::builder().build();
gobject.insert_action_group(&uuid_string_random(), Some(&action_group));
Self { gobject }
}
// Actions