create tab page on item construct

This commit is contained in:
yggverse 2024-10-11 03:06:48 +03:00
parent 9b94304756
commit 2630fa9283
3 changed files with 40 additions and 8 deletions

View File

@ -79,6 +79,8 @@ impl Tab {
pub fn append(&self) -> Arc<Item> { pub fn append(&self) -> Arc<Item> {
// Init new tab item // Init new tab item
let item = Item::new_arc( let item = Item::new_arc(
self.gobject(),
// Actions
self.action_tab_page_navigation_base.clone(), self.action_tab_page_navigation_base.clone(),
self.action_tab_page_navigation_history_back.clone(), self.action_tab_page_navigation_history_back.clone(),
self.action_tab_page_navigation_history_forward.clone(), self.action_tab_page_navigation_history_forward.clone(),
@ -89,11 +91,7 @@ impl Tab {
// Register dynamically created tab components in the HashMap index // Register dynamically created tab components in the HashMap index
self.index.borrow_mut().insert(item.id(), item.clone()); 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.page_navigation_request_grab_focus(); // @TODO
item item
} }
@ -190,6 +188,7 @@ impl Tab {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Item::restore( match Item::restore(
self.gobject(),
transaction, transaction,
&record.id, &record.id,
self.action_tab_page_navigation_base.clone(), self.action_tab_page_navigation_base.clone(),

View File

@ -1,17 +1,18 @@
mod database; mod database;
mod page; mod page;
mod widget;
use database::Database; use database::Database;
use page::Page; use page::Page;
use widget::Widget;
use sqlite::Transaction; use adw::TabView;
use gtk::{ use gtk::{
gio::SimpleAction, gio::SimpleAction,
glib::{uuid_string_random, GString}, glib::{uuid_string_random, GString},
Box, Box,
}; };
use sqlite::Transaction;
use std::sync::Arc; use std::sync::Arc;
pub struct Item { pub struct Item {
@ -20,11 +21,14 @@ pub struct Item {
id: GString, id: GString,
// Components // Components
page: Arc<Page>, page: Arc<Page>,
widget: Arc<Widget>,
} }
impl Item { impl Item {
// Construct // Construct
pub fn new_arc( pub fn new_arc(
tab_view: &TabView,
// Actions
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>,
action_tab_page_navigation_history_forward: Arc<SimpleAction>, action_tab_page_navigation_history_forward: Arc<SimpleAction>,
@ -44,8 +48,10 @@ impl Item {
action_update.clone(), action_update.clone(),
); );
let widget = Widget::new_arc(tab_view, page.gobject(), Some("New page")); // @TODO
// Return struct // Return struct
Arc::new(Self { id, page }) Arc::new(Self { id, page, widget })
} }
// Actions // Actions
@ -105,6 +111,7 @@ impl Item {
// This method does not contain Self context, // This method does not contain Self context,
// because child items creating in the runtime (by parent component) // because child items creating in the runtime (by parent component)
pub fn restore( pub fn restore(
tab_view: &TabView,
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_id: &i64, app_browser_window_tab_id: &i64,
// Actions // Actions
@ -121,6 +128,7 @@ impl Item {
for record in records { for record in records {
// Construct new item object // Construct new item object
let item = Item::new_arc( let item = Item::new_arc(
tab_view,
action_tab_page_navigation_base.clone(), action_tab_page_navigation_base.clone(),
action_tab_page_navigation_history_back.clone(), action_tab_page_navigation_history_back.clone(),
action_tab_page_navigation_history_forward.clone(), action_tab_page_navigation_history_forward.clone(),

View File

@ -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<Self> {
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
}
}