55 lines
1.3 KiB
Rust
Raw Normal View History

2024-10-14 05:12:30 +03:00
use std::sync::Arc;
2024-10-11 04:37:06 +03:00
use adw::TabView;
2024-10-14 05:12:30 +03:00
use gtk::{
gio::{SimpleAction, SimpleActionGroup},
glib::{uuid_string_random, GString},
prelude::{ActionMapExt, WidgetExt},
};
2024-10-06 16:28:46 +03:00
pub struct Widget {
gobject: TabView,
2024-10-06 16:28:46 +03:00
}
impl Widget {
// Construct
2024-10-14 05:12:30 +03:00
pub fn new(action_tab_append: Arc<SimpleAction>) -> Self {
// Init additional action group
let action_group = SimpleActionGroup::new();
action_group.add_action(action_tab_append.as_ref());
// Init gobject
let gobject = TabView::builder().build();
gobject.insert_action_group(&uuid_string_random(), Some(&action_group));
Self { gobject }
2024-10-06 16:28:46 +03:00
}
2024-10-06 17:12:08 +03:00
// Actions
pub fn close(&self) {
if let Some(selected_page) = self.gobject.selected_page() {
self.gobject.close_page(&selected_page);
}
2024-10-06 17:12:08 +03:00
}
pub fn close_all(&self) {
// @TODO skip pinned or make confirmation alert (GTK>=4.10)
if let Some(selected_page) = self.gobject.selected_page() {
self.gobject.close_other_pages(&selected_page);
self.close();
2024-10-06 17:12:08 +03:00
}
}
2024-10-06 16:28:46 +03:00
// Getters
2024-10-11 05:01:42 +03:00
pub fn current_page_keyword(&self) -> Option<GString> {
let page = self.gobject.selected_page()?;
2024-10-11 05:01:42 +03:00
let id = page.keyword()?;
Some(id)
2024-10-06 17:12:08 +03:00
}
pub fn gobject(&self) -> &TabView {
2024-10-06 16:28:46 +03:00
&self.gobject
}
}