|
|
|
@ -4,22 +4,31 @@ mod page;
@@ -4,22 +4,31 @@ mod page;
|
|
|
|
|
use label::Label; |
|
|
|
|
use page::Page; |
|
|
|
|
|
|
|
|
|
use gtk::{prelude::WidgetExt, GestureClick, Notebook}; |
|
|
|
|
use gtk::{ |
|
|
|
|
glib::{uuid_string_random, GString}, |
|
|
|
|
prelude::WidgetExt, |
|
|
|
|
GestureClick, Notebook, Widget, |
|
|
|
|
}; |
|
|
|
|
use std::{cell::RefCell, collections::HashMap, sync::Arc}; |
|
|
|
|
|
|
|
|
|
pub struct Tab { |
|
|
|
|
widget: Notebook, |
|
|
|
|
// Dynamically allocated reference index
|
|
|
|
|
labels: RefCell<HashMap<u32, Arc<Label>>>, |
|
|
|
|
pages: RefCell<HashMap<u32, Arc<Page>>>, |
|
|
|
|
labels: RefCell<HashMap<GString, Arc<Label>>>, |
|
|
|
|
pages: RefCell<HashMap<GString, Arc<Page>>>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Tab { |
|
|
|
|
// Construct
|
|
|
|
|
pub fn new() -> Tab { |
|
|
|
|
// Init widget
|
|
|
|
|
let widget = Notebook::builder().scrollable(true).build(); |
|
|
|
|
|
|
|
|
|
// Connect actions
|
|
|
|
|
widget.connect_page_reordered(|this: &Notebook, widget: &Widget, page_number: u32| todo!()); |
|
|
|
|
|
|
|
|
|
Self { |
|
|
|
|
// Init widget
|
|
|
|
|
widget: Notebook::builder().scrollable(true).build(), |
|
|
|
|
widget, |
|
|
|
|
// Init empty hashmap as no tabs yet
|
|
|
|
|
labels: RefCell::new(HashMap::new()), |
|
|
|
|
pages: RefCell::new(HashMap::new()), |
|
|
|
@ -28,9 +37,17 @@ impl Tab {
@@ -28,9 +37,17 @@ impl Tab {
|
|
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
pub fn append(&self, is_current_page: bool) -> u32 { |
|
|
|
|
// Generate unique ID for new page components
|
|
|
|
|
let id = uuid_string_random(); |
|
|
|
|
|
|
|
|
|
// Init new tab components
|
|
|
|
|
let label = Arc::new(Label::new(false)); |
|
|
|
|
let page = Arc::new(Page::new()); |
|
|
|
|
let label = Arc::new(Label::new(id.clone(), false)); |
|
|
|
|
let page = Arc::new(Page::new(id.clone())); |
|
|
|
|
|
|
|
|
|
// Register dynamically created tab components in the HashMap index
|
|
|
|
|
// @TODO cleanup on tab remove
|
|
|
|
|
self.labels.borrow_mut().insert(id.clone(), label.clone()); |
|
|
|
|
self.pages.borrow_mut().insert(id.clone(), page.clone()); |
|
|
|
|
|
|
|
|
|
// Init additional label actions
|
|
|
|
|
let controller = GestureClick::new(); |
|
|
|
@ -57,17 +74,6 @@ impl Tab {
@@ -57,17 +74,6 @@ impl Tab {
|
|
|
|
|
self.widget.set_current_page(Some(page_number)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Register dynamically created tab components in the HashMap index
|
|
|
|
|
// @TODO static key on tab reorder
|
|
|
|
|
// @TODO cleanup on tab remove
|
|
|
|
|
self.labels |
|
|
|
|
.borrow_mut() |
|
|
|
|
.insert(page_number.try_into().unwrap(), label); |
|
|
|
|
|
|
|
|
|
self.pages |
|
|
|
|
.borrow_mut() |
|
|
|
|
.insert(page_number.try_into().unwrap(), page); |
|
|
|
|
|
|
|
|
|
// Result
|
|
|
|
|
page_number |
|
|
|
|
} |
|
|
|
@ -87,12 +93,15 @@ impl Tab {
@@ -87,12 +93,15 @@ impl Tab {
|
|
|
|
|
|
|
|
|
|
// Toggle pin status for active tab
|
|
|
|
|
pub fn pin(&self) { |
|
|
|
|
// Get current page
|
|
|
|
|
if let Some(page_number) = self.widget.current_page() { |
|
|
|
|
let label = self.labels.borrow(); |
|
|
|
|
label |
|
|
|
|
.get(&page_number) |
|
|
|
|
.unwrap() |
|
|
|
|
.pin(!label.get(&page_number).unwrap().is_pinned()); // toggle
|
|
|
|
|
// Get default widget to extract it name as the ID for childs
|
|
|
|
|
if let Some(widget) = self.widget.nth_page(Some(page_number)) { |
|
|
|
|
// Get label by ID
|
|
|
|
|
if let Some(label) = self.labels.borrow().get(&widget.widget_name()) { |
|
|
|
|
label.pin(!label.is_pinned()); // toggle
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|