From 28fcf247b222d410508831a1049e244baa55392e Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 14 Oct 2024 05:12:30 +0300 Subject: [PATCH] create local actions group --- src/app/browser/window/tab.rs | 11 +++++++++-- src/app/browser/window/tab/widget.rs | 23 ++++++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 9206c5c7..49b98b74 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -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, action_update: Arc, ) -> Arc { + // 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({ diff --git a/src/app/browser/window/tab/widget.rs b/src/app/browser/window/tab/widget.rs index 1fed0cbe..73da3ba1 100644 --- a/src/app/browser/window/tab/widget.rs +++ b/src/app/browser/window/tab/widget.rs @@ -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) -> 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