2024-10-11 04:37:06 +03:00
|
|
|
use adw::TabView;
|
2024-10-14 05:12:30 +03:00
|
|
|
use gtk::{
|
2024-10-14 05:24:24 +03:00
|
|
|
gio::{Icon, SimpleAction, SimpleActionGroup},
|
2024-10-14 05:12:30 +03:00
|
|
|
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-11-01 03:09:09 +02:00
|
|
|
pub fn new(action_page_new: SimpleAction) -> Self {
|
2024-10-14 05:12:30 +03:00
|
|
|
// Init additional action group
|
|
|
|
let action_group = SimpleActionGroup::new();
|
2024-11-01 03:09:09 +02:00
|
|
|
action_group.add_action(&action_page_new);
|
2024-10-14 05:12:30 +03:00
|
|
|
|
|
|
|
// Init gobject
|
2024-10-14 05:24:24 +03:00
|
|
|
let gobject = TabView::new();
|
2024-10-14 05:12:30 +03:00
|
|
|
|
2024-10-14 05:24:24 +03:00
|
|
|
// Change default icon visible for tabs pinned
|
|
|
|
if let Ok(default_icon) = Icon::for_string("view-pin-symbolic") {
|
|
|
|
gobject.set_default_icon(&default_icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create new group for actions
|
2024-10-14 05:12:30 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|