From 2630fa9283b6b3565bc8da96131c13f7d2f57888 Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 11 Oct 2024 03:06:48 +0300 Subject: [PATCH] create tab page on item construct --- src/app/browser/window/tab.rs | 7 +++---- src/app/browser/window/tab/item.rs | 16 +++++++++++---- src/app/browser/window/tab/item/widget.rs | 25 +++++++++++++++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 src/app/browser/window/tab/item/widget.rs diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index a20a7d0a..189c4308 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -79,6 +79,8 @@ impl Tab { pub fn append(&self) -> Arc { // Init new tab item let item = Item::new_arc( + self.gobject(), + // Actions self.action_tab_page_navigation_base.clone(), self.action_tab_page_navigation_history_back.clone(), self.action_tab_page_navigation_history_forward.clone(), @@ -89,11 +91,7 @@ impl Tab { // Register dynamically created tab components in the HashMap index self.index.borrow_mut().insert(item.id(), item.clone()); - // Append new page - self.widget.append(item.gobject()); - item.page_navigation_request_grab_focus(); // @TODO - item } @@ -190,6 +188,7 @@ impl Tab { Ok(records) => { for record in records { match Item::restore( + self.gobject(), transaction, &record.id, self.action_tab_page_navigation_base.clone(), diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index 7a77621f..2fc9d9b5 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -1,17 +1,18 @@ mod database; mod page; +mod widget; use database::Database; use page::Page; +use widget::Widget; -use sqlite::Transaction; - +use adw::TabView; use gtk::{ gio::SimpleAction, glib::{uuid_string_random, GString}, Box, }; - +use sqlite::Transaction; use std::sync::Arc; pub struct Item { @@ -20,11 +21,14 @@ pub struct Item { id: GString, // Components page: Arc, + widget: Arc, } impl Item { // Construct pub fn new_arc( + tab_view: &TabView, + // Actions action_tab_page_navigation_base: Arc, action_tab_page_navigation_history_back: Arc, action_tab_page_navigation_history_forward: Arc, @@ -44,8 +48,10 @@ impl Item { action_update.clone(), ); + let widget = Widget::new_arc(tab_view, page.gobject(), Some("New page")); // @TODO + // Return struct - Arc::new(Self { id, page }) + Arc::new(Self { id, page, widget }) } // Actions @@ -105,6 +111,7 @@ impl Item { // This method does not contain Self context, // because child items creating in the runtime (by parent component) pub fn restore( + tab_view: &TabView, transaction: &Transaction, app_browser_window_tab_id: &i64, // Actions @@ -121,6 +128,7 @@ impl Item { for record in records { // Construct new item object let item = Item::new_arc( + tab_view, action_tab_page_navigation_base.clone(), action_tab_page_navigation_history_back.clone(), action_tab_page_navigation_history_forward.clone(), diff --git a/src/app/browser/window/tab/item/widget.rs b/src/app/browser/window/tab/item/widget.rs new file mode 100644 index 00000000..ca415206 --- /dev/null +++ b/src/app/browser/window/tab/item/widget.rs @@ -0,0 +1,25 @@ +use adw::{TabPage, TabView}; +use gtk::Box; +use std::sync::Arc; + +pub struct Widget { + gobject: TabPage, +} + +impl Widget { + // Construct + pub fn new_arc(tab_view: &TabView, page: &Box, title: Option<&str>) -> Arc { + let gobject = tab_view.append(page); + + if let Some(value) = title { + gobject.set_title(value); + } + + Arc::new(Self { gobject }) + } + + // Getters + pub fn gobject(&self) -> &TabPage { + &self.gobject + } +}