mirror of https://github.com/YGGverse/Yoda.git
yggverse
2 months ago
3 changed files with 32 additions and 43 deletions
@ -1,58 +1,52 @@ |
|||||||
use gtk::{glib::GString, prelude::WidgetExt, Box, Notebook}; |
use adw::{TabPage, TabView}; |
||||||
|
use gtk::{glib::GString, Box}; |
||||||
|
|
||||||
pub struct Widget { |
pub struct Widget { |
||||||
gobject: Notebook, |
gobject: TabView, |
||||||
} |
} |
||||||
|
|
||||||
impl Widget { |
impl Widget { |
||||||
// Construct
|
// Construct
|
||||||
pub fn new() -> Self { |
pub fn new() -> Self { |
||||||
Self { |
Self { |
||||||
gobject: Notebook::builder().scrollable(true).build(), |
gobject: TabView::builder().build(), |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
pub fn append(&self, label: &Box, page: &Box, is_current_page: bool) -> u32 { |
pub fn append(&self, page: &Box) -> TabPage { |
||||||
// Append new Notebook page
|
self.gobject.append(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 close(&self) { |
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) { |
pub fn close_all(&self) { |
||||||
// @TODO skip pinned or make confirmation alert (GTK>=4.10)
|
// @TODO skip pinned or make confirmation alert (GTK>=4.10)
|
||||||
while let Some(page_number) = self.gobject.current_page() { |
if let Some(selected_page) = self.gobject.selected_page() { |
||||||
self.gobject.remove_page(Some(page_number)); |
self.gobject.close_other_pages(&selected_page); |
||||||
|
self.close(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn current_name(&self) -> Option<GString> { |
pub fn current_name(&self) -> Option<GString> { |
||||||
let page_number = self.gobject.current_page()?; |
let page = self.gobject.selected_page()?; |
||||||
let nth_page = self.gobject.nth_page(Some(page_number))?; |
|
||||||
|
|
||||||
let widget_name = nth_page.widget_name(); |
/* @TODO
|
||||||
|
let widget_name = page.widget_name(); |
||||||
if !widget_name.is_empty() { |
if !widget_name.is_empty() { |
||||||
Some(widget_name) |
Some(widget_name) |
||||||
} else { |
} else { |
||||||
None |
None |
||||||
} |
} */ |
||||||
|
None |
||||||
} |
} |
||||||
|
|
||||||
pub fn gobject(&self) -> &Notebook { |
pub fn gobject(&self) -> &TabView { |
||||||
&self.gobject |
&self.gobject |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue