Browse Source

implement tabs id features

master
yggverse 2 months ago
parent
commit
06cfd72c62
  1. 43
      src/app/browser/window/tab.rs
  2. 2
      src/app/browser/window/tab/item.rs
  3. 3
      src/app/browser/window/tab/item/widget.rs
  4. 13
      src/app/browser/window/tab/widget.rs

43
src/app/browser/window/tab.rs

@ -23,7 +23,7 @@ pub struct Tab {
action_tab_page_navigation_reload: Arc<SimpleAction>, action_tab_page_navigation_reload: Arc<SimpleAction>,
action_update: Arc<SimpleAction>, action_update: Arc<SimpleAction>,
// Dynamically allocated reference index // Dynamically allocated reference index
index: RefCell<HashMap<GString, Arc<Item>>>, index: Arc<RefCell<HashMap<GString, Arc<Item>>>>,
// GTK // GTK
widget: Arc<Widget>, widget: Arc<Widget>,
} }
@ -39,24 +39,29 @@ impl Tab {
action_update: Arc<SimpleAction>, action_update: Arc<SimpleAction>,
) -> Arc<Self> { ) -> Arc<Self> {
// Init empty HashMap index as no tabs appended yet // Init empty HashMap index as no tabs appended yet
let index = RefCell::new(HashMap::new()); let index = Arc::new(RefCell::new(HashMap::new()));
// Init widget // Init widget
let widget = Arc::new(Widget::new()); let widget = Arc::new(Widget::new());
// Init events // Init events
widget.gobject().connect_close_page(move |_, _| { widget.gobject().connect_close_page({
/* @TODO let index = index.clone();
// Cleanup HashMap index move |_, item| {
let id = tab_page.widget_name(); // Get index ID by keyword saved
match item.keyword() {
// Check for required value as raw access to gobject @TODO Some(id) => {
if id.is_empty() { if id.is_empty() {
panic!("Undefined tab index!") panic!("Tab index can not be empty!")
} }
// Cleanup HashMap index
index.borrow_mut().remove(&id);
}
None => panic!("Undefined tab index!"),
}
tab.index.borrow_mut().remove(&id); */ Propagation::Proceed
Propagation::Proceed }
}); });
// Return activated struct // Return activated struct
@ -108,7 +113,7 @@ impl Tab {
// Toggle pin status for active tab // Toggle pin status for active tab
pub fn pin(&self) { pub fn pin(&self) {
if let Some(id) = self.widget.current_name() { if let Some(id) = self.widget.current_page_keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.pin(); // toggle item.pin(); // toggle
} }
@ -116,7 +121,7 @@ impl Tab {
} }
pub fn page_navigation_base(&self) { pub fn page_navigation_base(&self) {
if let Some(id) = self.widget.current_name() { if let Some(id) = self.widget.current_page_keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.page_navigation_base(); item.page_navigation_base();
} }
@ -124,7 +129,7 @@ impl Tab {
} }
pub fn page_navigation_history_back(&self) { pub fn page_navigation_history_back(&self) {
if let Some(id) = self.widget.current_name() { if let Some(id) = self.widget.current_page_keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.page_navigation_history_back(); item.page_navigation_history_back();
} }
@ -132,7 +137,7 @@ impl Tab {
} }
pub fn page_navigation_history_forward(&self) { pub fn page_navigation_history_forward(&self) {
if let Some(id) = self.widget.current_name() { if let Some(id) = self.widget.current_page_keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.page_navigation_history_forward(); item.page_navigation_history_forward();
} }
@ -140,7 +145,7 @@ impl Tab {
} }
pub fn page_navigation_reload(&self) { pub fn page_navigation_reload(&self) {
if let Some(id) = self.widget.current_name() { if let Some(id) = self.widget.current_page_keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.page_navigation_reload(); item.page_navigation_reload();
} }
@ -148,7 +153,7 @@ impl Tab {
} }
pub fn update(&self) { pub fn update(&self) {
if let Some(id) = self.widget.current_name() { if let Some(id) = self.widget.current_page_keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.update(); item.update();
} }

2
src/app/browser/window/tab/item.rs

@ -49,7 +49,7 @@ impl Item {
action_update.clone(), action_update.clone(),
); );
let widget = Widget::new_arc(tab_view, page.gobject(), None, is_selected); // @TODO let widget = Widget::new_arc(id.as_str(), tab_view, page.gobject(), None, is_selected); // @TODO
// Return struct // Return struct
Arc::new(Self { id, page, widget }) Arc::new(Self { id, page, widget })

3
src/app/browser/window/tab/item/widget.rs

@ -11,6 +11,7 @@ pub struct Widget {
impl Widget { impl Widget {
// Construct // Construct
pub fn new_arc( pub fn new_arc(
keyword: &str, // ID
tab_view: &TabView, tab_view: &TabView,
page: &Box, page: &Box,
title: Option<&str>, title: Option<&str>,
@ -18,6 +19,8 @@ impl Widget {
) -> Arc<Self> { ) -> Arc<Self> {
let gobject = tab_view.append(page); let gobject = tab_view.append(page);
gobject.set_keyword(keyword);
gobject.set_title(match title { gobject.set_title(match title {
Some(value) => value, Some(value) => value,
None => DEFAULT_TITLE, None => DEFAULT_TITLE,

13
src/app/browser/window/tab/widget.rs

@ -29,17 +29,10 @@ impl Widget {
} }
// Getters // Getters
pub fn current_name(&self) -> Option<GString> { pub fn current_page_keyword(&self) -> Option<GString> {
let page = self.gobject.selected_page()?; let page = self.gobject.selected_page()?;
let id = page.keyword()?;
/* @TODO Some(id)
let widget_name = page.widget_name();
if !widget_name.is_empty() {
Some(widget_name)
} else {
None
} */
None
} }
pub fn gobject(&self) -> &TabView { pub fn gobject(&self) -> &TabView {

Loading…
Cancel
Save