Browse Source

implement activate action

master
yggverse 2 months ago
parent
commit
bdad712690
  1. 8
      src/browser/main/mod.rs
  2. 32
      src/browser/main/tab/mod.rs

8
src/browser/main/mod.rs

@ -1,11 +1,13 @@ @@ -1,11 +1,13 @@
mod tab;
use std::sync::Arc;
use tab::Tab;
use gtk::{glib::GString, prelude::BoxExt, Box, Orientation};
pub struct Main {
tab: Tab,
tab: Arc<Tab>,
widget: Box,
}
@ -13,7 +15,9 @@ impl Main { @@ -13,7 +15,9 @@ impl Main {
// Construct
pub fn new() -> Main {
// Init components
let tab = Tab::new();
let tab = Arc::new(Tab::new());
tab.activate(tab.clone());
// Extras
let widget = Box::builder().orientation(Orientation::Vertical).build();

32
src/browser/main/tab/mod.rs

@ -14,7 +14,7 @@ use std::{cell::RefCell, collections::HashMap, sync::Arc}; @@ -14,7 +14,7 @@ use std::{cell::RefCell, collections::HashMap, sync::Arc};
pub struct Tab {
// GTK
widget: Arc<Notebook>,
widget: Notebook,
// Dynamically allocated reference index
labels: RefCell<HashMap<GString, Arc<Label>>>,
pages: RefCell<HashMap<GString, Arc<Page>>>,
@ -22,37 +22,27 @@ pub struct Tab { @@ -22,37 +22,27 @@ pub struct Tab {
impl Tab {
// Construct
pub fn new() -> Tab {
// Init GTK component
let notebook = Arc::new(Notebook::builder().scrollable(true).build());
// Init new Tab struct
let tab = Self {
// Reference wanted for async events, create new smart pointer
widget: notebook.clone(),
pub fn new() -> Self {
Self {
widget: Notebook::builder().scrollable(true).build(),
// Init empty HashMap index as no tabs appended yet
labels: RefCell::new(HashMap::new()),
pages: RefCell::new(HashMap::new()),
};
// Connect events
/* @TODO move outside
notebook.connect_page_removed({
// Make new local ref
let tab = tab.clone();
// Begin async action
}
}
// Actions
pub fn activate(&self, tab: Arc<Self>) {
self.widget.connect_page_removed({
move |_, widget: &Widget, _| {
// Cleanup HashMap index
let id = &widget.widget_name();
tab.labels.borrow_mut().remove(id);
tab.pages.borrow_mut().remove(id);
}
});*/
tab // return Arc pointer to the new Tab constructed
});
}
// Actions
pub fn append(&self, is_current_page: bool) -> u32 {
// Generate unique ID for new page components
let id = uuid_string_random();

Loading…
Cancel
Save