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 {
|
2024-10-11 01:38:12 +03:00
|
|
|
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) {
|
2024-10-11 01:38:12 +03:00
|
|
|
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)
|
2024-10-11 01:38:12 +03:00
|
|
|
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> {
|
2024-10-11 01:38:12 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-10-11 01:38:12 +03:00
|
|
|
pub fn gobject(&self) -> &TabView {
|
2024-10-06 16:28:46 +03:00
|
|
|
&self.gobject
|
|
|
|
}
|
|
|
|
}
|