Browse Source

begin gtk notebook to adwaita tab page features replacement

master
yggverse 2 months ago
parent
commit
ef5eb9b317
  1. 27
      src/app/browser/window/tab.rs
  2. 42
      src/app/browser/window/tab/widget.rs
  3. 6
      src/app/browser/window/widget.rs

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

@ -4,16 +4,15 @@ mod widget; @@ -4,16 +4,15 @@ mod widget;
use database::Database;
use item::Item;
use sqlite::Transaction;
use widget::Widget;
use adw::TabView;
use gtk::{
gio::SimpleAction,
glib::GString,
glib::{GString, Propagation},
prelude::{ActionExt, WidgetExt},
Notebook,
};
use sqlite::Transaction;
use std::{cell::RefCell, collections::HashMap, sync::Arc};
// Main
@ -65,23 +64,18 @@ impl Tab { @@ -65,23 +64,18 @@ impl Tab {
pub fn activate(&self, tab: Arc<Self>) {
self.widget
.gobject()
.connect_page_removed(move |_, widget, _| {
.connect_close_page(move |_, tab_page| {
/* @TODO
// Cleanup HashMap index
let id = widget.widget_name();
let id = tab_page.widget_name();
// Check for required value as raw access to gobject @TODO
if id.is_empty() {
panic!("Undefined tab index!")
}
tab.index.borrow_mut().remove(&id);
});
// Switch page post-event (`connect_switch_page` activates before `page_number` get updated)
self.widget.gobject().connect_page_notify({
let action_update = self.action_update.clone();
// Update window header with current page title
move |_| action_update.activate(None)
tab.index.borrow_mut().remove(&id); */
Propagation::Proceed
});
}
@ -253,6 +247,7 @@ impl Tab { @@ -253,6 +247,7 @@ impl Tab {
let id = Database::last_insert_id(transaction);
// At least one active page wanted to continue
/* @TODO
if let Some(current_page) = self.widget.gobject().current_page() {
// Read collected HashMap index
for (_, item) in self.index.borrow().iter() {
@ -269,7 +264,7 @@ impl Tab { @@ -269,7 +264,7 @@ impl Tab {
None => panic!(), // page number expected at this point @TODO Err?
}
}
};
}; */
}
Err(e) => return Err(e.to_string()),
}
@ -278,7 +273,7 @@ impl Tab { @@ -278,7 +273,7 @@ impl Tab {
}
// Getters
pub fn gobject(&self) -> &Notebook {
pub fn gobject(&self) -> &TabView {
self.widget.gobject()
}

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

@ -1,58 +1,52 @@ @@ -1,58 +1,52 @@
use gtk::{glib::GString, prelude::WidgetExt, Box, Notebook};
use adw::{TabPage, TabView};
use gtk::{glib::GString, Box};
pub struct Widget {
gobject: Notebook,
gobject: TabView,
}
impl Widget {
// Construct
pub fn new() -> Self {
Self {
gobject: Notebook::builder().scrollable(true).build(),
gobject: TabView::builder().build(),
}
}
// Actions
pub fn append(&self, label: &Box, page: &Box, is_current_page: bool) -> u32 {
// Append new Notebook page
let page_number = self.gobject.append_page(page, Some(label));
// Additional setup for Notebook tab created
self.gobject.set_tab_reorderable(page, true);
if is_current_page {
self.gobject.set_current_page(Some(page_number));
}
// Result
page_number
pub fn append(&self, page: &Box) -> TabPage {
self.gobject.append(page)
}
pub fn close(&self) {
self.gobject.remove_page(self.gobject().current_page());
if let Some(selected_page) = self.gobject.selected_page() {
self.gobject.close_page(&selected_page);
}
}
pub fn close_all(&self) {
// @TODO skip pinned or make confirmation alert (GTK>=4.10)
while let Some(page_number) = self.gobject.current_page() {
self.gobject.remove_page(Some(page_number));
if let Some(selected_page) = self.gobject.selected_page() {
self.gobject.close_other_pages(&selected_page);
self.close();
}
}
// Getters
pub fn current_name(&self) -> Option<GString> {
let page_number = self.gobject.current_page()?;
let nth_page = self.gobject.nth_page(Some(page_number))?;
let page = self.gobject.selected_page()?;
let widget_name = nth_page.widget_name();
/* @TODO
let widget_name = page.widget_name();
if !widget_name.is_empty() {
Some(widget_name)
} else {
None
}
} */
None
}
pub fn gobject(&self) -> &Notebook {
pub fn gobject(&self) -> &TabView {
&self.gobject
}
}

6
src/app/browser/window/widget.rs

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
use adw::ToolbarView;
use gtk::{prelude::BoxExt, Box, Notebook, Orientation};
use adw::{TabView, ToolbarView};
use gtk::{prelude::BoxExt, Box, Orientation};
pub struct Widget {
gobject: Box,
@ -7,7 +7,7 @@ pub struct Widget { @@ -7,7 +7,7 @@ pub struct Widget {
impl Widget {
// Construct
pub fn new(header: &ToolbarView, tab: &Notebook) -> Self {
pub fn new(header: &ToolbarView, tab: &TabView) -> Self {
let gobject = Box::builder().orientation(Orientation::Vertical).build();
gobject.append(header);
gobject.append(tab);

Loading…
Cancel
Save