libcosmic/examples/app_library/window/imp.rs

45 lines
1.2 KiB
Rust
Raw Normal View History

2021-12-06 10:56:45 -05:00
use glib::signal::Inhibit;
2022-01-14 17:53:11 -05:00
use gtk4::glib;
2021-12-30 16:54:35 -05:00
use gtk4::subclass::prelude::*;
2022-01-14 17:53:11 -05:00
use gtk4::SearchEntry;
use once_cell::sync::OnceCell;
2022-01-14 17:53:11 -05:00
use crate::app_grid::AppGrid;
use crate::group_grid::GroupGrid;
2021-12-06 10:56:45 -05:00
// Object holding the state
#[derive(Default)]
2022-01-14 17:53:11 -05:00
pub struct AppLibraryWindow {
pub entry: OnceCell<SearchEntry>,
2022-01-14 17:53:11 -05:00
pub app_grid: OnceCell<AppGrid>,
pub group_grid: OnceCell<GroupGrid>,
}
// The central trait for subclassing a GObject
#[glib::object_subclass]
2022-01-14 17:53:11 -05:00
impl ObjectSubclass for AppLibraryWindow {
// `NAME` needs to match `class` attribute of template
2022-01-14 17:53:11 -05:00
const NAME: &'static str = "AppLibraryWindow";
type Type = super::AppLibraryWindow;
2021-12-30 16:54:35 -05:00
type ParentType = gtk4::ApplicationWindow;
}
// Trait shared by all GObjects
2022-01-14 17:53:11 -05:00
impl ObjectImpl for AppLibraryWindow {}
// Trait shared by all widgets
2022-01-14 17:53:11 -05:00
impl WidgetImpl for AppLibraryWindow {}
// Trait shared by all windows
2022-01-14 17:53:11 -05:00
impl WindowImpl for AppLibraryWindow {
2021-12-06 10:56:45 -05:00
fn close_request(&self, window: &Self::Type) -> Inhibit {
2022-01-14 17:53:11 -05:00
let imp = AppLibraryWindow::from_instance(window);
imp.group_grid.get().unwrap().store_data();
2021-12-06 10:56:45 -05:00
// Pass close request on to the parent
self.parent_close_request(window)
}
}
// Trait shared by all application
2022-01-14 17:53:11 -05:00
impl ApplicationWindowImpl for AppLibraryWindow {}