From bc4e44d9c86302e12a3a75937f749421e53ed84f Mon Sep 17 00:00:00 2001 From: william Date: Mon, 18 Sep 2023 22:00:40 -0400 Subject: [PATCH] Start remove app --- Cargo.lock | 5 +++-- Cargo.toml | 1 + src/ui/appview/imp.rs | 10 +++++++++- src/ui/window/mod.rs | 15 +++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2fa8139..f46a635 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,6 +66,7 @@ name = "config-manager-client" version = "0.1.0" dependencies = [ "f-uuid", + "gio", "glib-build-tools", "gtk4", "libadwaita", @@ -239,9 +240,9 @@ dependencies = [ [[package]] name = "gio" -version = "0.18.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7884cba6b1c5db1607d970cadf44b14a43913d42bc68766eea6a5e2fe0891524" +checksum = "57052f84e8e5999b258e8adf8f5f2af0ac69033864936b8b6838321db2f759b1" dependencies = [ "futures-channel", "futures-core", diff --git a/Cargo.toml b/Cargo.toml index 41d7438..6ac7f61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] adw = { version = "0.5.2", package = "libadwaita", features = ["v1_3"] } f-uuid = { version = "1.0.0", registry = "gitea" } +gio = { version = "0.18.2", features = ["v2_74"] } gtk = { version = "0.7.1", package = "gtk4", features = ["v4_10"] } log = { version = "0.4", features = ["max_level_debug", "release_max_level_info"] } simplelog = "^0.12.0" diff --git a/src/ui/appview/imp.rs b/src/ui/appview/imp.rs index 4a8b247..6da11dd 100644 --- a/src/ui/appview/imp.rs +++ b/src/ui/appview/imp.rs @@ -1,7 +1,7 @@ use std::cell::RefCell; use adw::glib; use glib::subclass::InitializingObject; -use gtk::{Button, CompositeTemplate}; +use gtk::{Button, CompositeTemplate, template_callbacks}; use gtk::prelude::*; use gtk::subclass::prelude::*; use crate::ui::objects::app::AppObject; @@ -15,6 +15,14 @@ pub struct AppView { pub application: RefCell> } +#[template_callbacks] +impl AppView { + #[template_callback] + fn handle_remove_button_clicked(&self, button: &Button) { + println!("Clicked!"); + } +} + #[glib::object_subclass] impl ObjectSubclass for AppView { const NAME: &'static str = "CmAppView"; diff --git a/src/ui/window/mod.rs b/src/ui/window/mod.rs index 9d74a96..3d0310f 100644 --- a/src/ui/window/mod.rs +++ b/src/ui/window/mod.rs @@ -124,6 +124,21 @@ impl Window { dialog.present(); } + fn remove_application(&self, id: &str) { + let apps = self.imp().apps.get().unwrap(); + let index = apps.find_with_equal_func(|obj| -> bool { + let id_prop = obj + .downcast_ref::() + .expect("The object should be of type 'AppObject'") + .property_value("id"); + + let app_id = id_prop.get::().expect("AppObject 'id' property should be a string"); + app_id == id + }); + + dbg!(index); + } + fn restore_data(&self) { let data = vec!( AppData {