use shared pointer for page id string

This commit is contained in:
yggverse 2024-10-15 08:18:16 +03:00
parent 96d06c1ffb
commit e41216ab75
3 changed files with 7 additions and 5 deletions

View File

@ -26,7 +26,7 @@ pub struct Tab {
action_tab_page_navigation_reload: Arc<SimpleAction>, action_tab_page_navigation_reload: Arc<SimpleAction>,
action_update: Arc<SimpleAction>, action_update: Arc<SimpleAction>,
// Dynamically allocated reference index // Dynamically allocated reference index
index: Arc<RefCell<HashMap<GString, Arc<Item>>>>, index: Arc<RefCell<HashMap<Arc<GString>, Arc<Item>>>>,
// GTK // GTK
widget: Arc<Widget>, widget: Arc<Widget>,
} }

View File

@ -17,7 +17,7 @@ use std::sync::Arc;
pub struct Item { pub struct Item {
// Auto-generated unique item ID // Auto-generated unique item ID
// useful as widget name in GTK actions callback // useful as widget name in GTK actions callback
id: GString, id: Arc<GString>,
// Components // Components
page: Arc<Page>, page: Arc<Page>,
widget: Arc<Widget>, widget: Arc<Widget>,
@ -39,7 +39,7 @@ impl Item {
is_selected: bool, is_selected: bool,
) -> Arc<Self> { ) -> Arc<Self> {
// Generate unique ID for new page components // Generate unique ID for new page components
let id = uuid_string_random(); let id = Arc::new(uuid_string_random());
// Init components // Init components
let page = Page::new_arc( let page = Page::new_arc(
@ -201,7 +201,7 @@ impl Item {
} }
// Getters // Getters
pub fn id(&self) -> GString { pub fn id(&self) -> Arc<GString> {
self.id.clone() self.id.clone()
} }

View File

@ -27,6 +27,7 @@ use sqlite::Transaction;
use std::{cell::RefCell, path::Path, sync::Arc}; use std::{cell::RefCell, path::Path, sync::Arc};
pub struct Page { pub struct Page {
id: Arc<GString>,
// Actions // Actions
action_page_open: Arc<SimpleAction>, action_page_open: Arc<SimpleAction>,
action_tab_page_navigation_reload: Arc<SimpleAction>, action_tab_page_navigation_reload: Arc<SimpleAction>,
@ -43,7 +44,7 @@ pub struct Page {
impl Page { impl Page {
// Construct // Construct
pub fn new_arc( pub fn new_arc(
id: GString, id: Arc<GString>,
action_tab_open: Arc<SimpleAction>, action_tab_open: Arc<SimpleAction>,
action_tab_page_navigation_base: Arc<SimpleAction>, action_tab_page_navigation_base: Arc<SimpleAction>,
action_tab_page_navigation_history_back: Arc<SimpleAction>, action_tab_page_navigation_history_back: Arc<SimpleAction>,
@ -102,6 +103,7 @@ impl Page {
// Return activated structure // Return activated structure
Arc::new(Self { Arc::new(Self {
id,
// Actions // Actions
action_page_open, action_page_open,
action_tab_page_navigation_reload, action_tab_page_navigation_reload,