From 32cc7e73446cfccd5c3899b9564d8bfe76180220 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 15 Dec 2021 14:03:23 -0500 Subject: [PATCH] add open app listto dock --- examples/dock/main.rs | 2 +- examples/dock/style.css | 10 +++--- examples/dock/window/imp.rs | 7 ++-- examples/dock/window/mod.rs | 62 +++++++++++++++++++--------------- examples/dock/window/window.ui | 12 +++++-- 5 files changed, 54 insertions(+), 39 deletions(-) diff --git a/examples/dock/main.rs b/examples/dock/main.rs index 2eb4d630..060b771e 100644 --- a/examples/dock/main.rs +++ b/examples/dock/main.rs @@ -120,7 +120,7 @@ fn main() { Event::Response(event) => { if let pop_launcher::Response::Update(results) = event { - let model = window.model(); + let model = window.saved_app_model(); let model_len = model.n_items(); dbg!(&results); let new_results: Vec = results diff --git a/examples/dock/style.css b/examples/dock/style.css index a04559df..4e838ccf 100644 --- a/examples/dock/style.css +++ b/examples/dock/style.css @@ -1,21 +1,21 @@ row:hover { transition: 100ms; background: #888888; - border-radius: 10px; + border-radius: 12px; } row { background: #333333; - border-radius: 10px; + border-radius: 12px; } listview { - border-radius: 10px; + border-radius: 12px; background: #333333; } window { background: rgba(50,50,50,0.0); } box#dock-container { - padding-right: 10px; - border-radius: 10px; + padding-right: 12px; + border-radius: 12px; background: #333333; } diff --git a/examples/dock/window/imp.rs b/examples/dock/window/imp.rs index 87ecf178..037e17c2 100644 --- a/examples/dock/window/imp.rs +++ b/examples/dock/window/imp.rs @@ -15,14 +15,17 @@ use once_cell::sync::OnceCell; #[template(file = "window.ui")] pub struct Window { #[template_child] - pub list_view: TemplateChild, + pub saved_app_list_view: TemplateChild, + #[template_child] + pub unsaved_open_app_list_view: TemplateChild, #[template_child] pub revealer: TemplateChild, #[template_child] pub cursor_enter_handle: TemplateChild, #[template_child] pub cursor_leave_handle: TemplateChild, - pub model: OnceCell, + pub saved_app_model: OnceCell, + pub unsaved_open_app_model: OnceCell, pub enter_event_controller: OnceCell, pub leave_event_controller: OnceCell, } diff --git a/examples/dock/window/mod.rs b/examples/dock/window/mod.rs index 277a2955..5865ec51 100644 --- a/examples/dock/window/mod.rs +++ b/examples/dock/window/mod.rs @@ -33,23 +33,25 @@ impl Window { self_ } - pub fn model(&self) -> &gio::ListStore { + pub fn saved_app_model(&self) -> &gio::ListStore { // Get state let imp = imp::Window::from_instance(self); - imp.model.get().expect("Could not get model") + imp.saved_app_model + .get() + .expect("Could not get saved_app_model") } fn setup_model(&self) { // Get state and set model let imp = imp::Window::from_instance(self); - let model = gio::ListStore::new(DesktopAppInfo::static_type()); + let saved_app_model = gio::ListStore::new(DesktopAppInfo::static_type()); let selection_model = gtk::SingleSelection::builder() .autoselect(false) .can_unselect(true) .selected(gtk4::INVALID_LIST_POSITION) - .model(&model) + .model(&saved_app_model) .build(); xdg::BaseDirectories::new() .expect("could not access XDG Base directory") @@ -69,7 +71,7 @@ impl Window { && defaults.contains(&app_info.name().as_str()) { dbg!(app_info.name()); - model.append(&app_info) + saved_app_model.append(&app_info) } else { // println!("Ignoring {}", path); } @@ -83,42 +85,46 @@ impl Window { } }); - imp.model.set(model).expect("Could not set model"); + imp.saved_app_model + .set(saved_app_model) + .expect("Could not set model"); // Wrap model with selection and pass it to the list view - imp.list_view.set_model(Some(&selection_model)); + imp.saved_app_list_view.set_model(Some(&selection_model)); } fn setup_callbacks(&self) { // Get state let imp = imp::Window::from_instance(self); let window = self.clone().upcast::(); - let list_view = &imp.list_view; + let saved_app_list_view = &imp.saved_app_list_view; - let app_selection_model = list_view + let saved_app_selection_model = saved_app_list_view .model() .expect("List view missing selection model") .downcast::() .expect("could not downcast listview model to single selection model"); - app_selection_model.connect_selected_notify(glib::clone!(@weak window => move |model| { - let position = model.selected(); - println!("selected app {}", position); - // Launch the application when an item of the list is activated - if let Some(item) = model.item(position) { - let app_info = item.downcast::().unwrap(); - let context = window.display().app_launch_context(); - if let Err(err) = app_info.launch(&[], Some(&context)) { - gtk::MessageDialog::builder() - .text(&format!("Failed to start {}", app_info.name())) - .secondary_text(&err.to_string()) - .message_type(gtk::MessageType::Error) - .modal(true) - .transient_for(&window) - .build() - .show(); + saved_app_selection_model.connect_selected_notify( + glib::clone!(@weak window => move |model| { + let position = model.selected(); + println!("selected app {}", position); + // Launch the application when an item of the list is activated + if let Some(item) = model.item(position) { + let app_info = item.downcast::().unwrap(); + let context = window.display().app_launch_context(); + if let Err(err) = app_info.launch(&[], Some(&context)) { + gtk::MessageDialog::builder() + .text(&format!("Failed to start {}", app_info.name())) + .secondary_text(&err.to_string()) + .message_type(gtk::MessageType::Error) + .modal(true) + .transient_for(&window) + .build() + .show(); + } } - } - })); + }), + ); let enter_event_controller = &imp.enter_event_controller.get().unwrap(); let leave_event_controller = &imp.leave_event_controller.get().unwrap(); @@ -242,6 +248,6 @@ impl Window { }); // Set the factory of the list view let imp = imp::Window::from_instance(self); - imp.list_view.set_factory(Some(&factory)); + imp.saved_app_list_view.set_factory(Some(&factory)); } } diff --git a/examples/dock/window/window.ui b/examples/dock/window/window.ui index 5e8c2223..f4cd9b58 100644 --- a/examples/dock/window/window.ui +++ b/examples/dock/window/window.ui @@ -1,7 +1,7 @@