mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
create tab page on item construct
This commit is contained in:
parent
9b94304756
commit
2630fa9283
@ -79,6 +79,8 @@ impl Tab {
|
||||
pub fn append(&self) -> Arc<Item> {
|
||||
// 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(),
|
||||
|
@ -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<Page>,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Item {
|
||||
// Construct
|
||||
pub fn new_arc(
|
||||
tab_view: &TabView,
|
||||
// Actions
|
||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||
@ -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(),
|
||||
|
25
src/app/browser/window/tab/item/widget.rs
Normal file
25
src/app/browser/window/tab/item/widget.rs
Normal 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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user