diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form.rs index 1b66e38b..fbe1de8f 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form.rs @@ -31,11 +31,11 @@ impl Form { /// Create new `Self` pub fn new(profile: Rc, action: Rc) -> Self { // Init components - let drop = Rc::new(Drop::new(profile.clone(), action.clone())); let file = Rc::new(File::new(action.clone())); let list = Rc::new(List::new()); let name = Rc::new(Name::new(action.clone())); - let save = Rc::new(Save::new(profile)); + let save = Rc::new(Save::new(profile.clone())); + let drop = Rc::new(Drop::new(profile.clone(), action.clone(), list.clone())); // Init main container let gobject = Box::builder().orientation(Orientation::Vertical).build(); diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/drop.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/drop.rs index 1413d24f..75d749e6 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/drop.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/drop.rs @@ -1,4 +1,5 @@ use super::Action; +use super::List; use crate::profile::Profile; use adw::{ prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, @@ -30,7 +31,7 @@ impl Drop { // Constructors /// Create new `Self` - pub fn new(profile: Rc, action: Rc) -> Self { + pub fn new(profile: Rc, action: Rc, list: Rc) -> Self { // Init selected option holder let profile_identity_gemini_id = Rc::new(RefCell::new(None::)); @@ -76,14 +77,21 @@ impl Drop { // Connect confirmation event dialog.connect_response(Some(RESPONSE_CONFIRM.0), { let action = action.clone(); - let profile = profile.clone(); let gobject = gobject.clone(); + let list = list.clone(); + let profile = profile.clone(); let profile_identity_gemini_id = profile_identity_gemini_id.clone(); move |_, _| { match profile.identity.gemini.delete(profile_identity_gemini_id) { Ok(_) => { - gobject.set_css_classes(&["success"]); - gobject.set_label("Identity successfully deleted") + if list.remove(profile_identity_gemini_id).is_some() { + gobject.set_css_classes(&["success"]); + gobject.set_label("Identity successfully deleted") + } else { + gobject.set_css_classes(&["error"]); + gobject.set_label("List item not found") + // @TODO unexpected + } } Err(e) => { gobject.set_css_classes(&["error"]); diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs index 14235b88..0ff6b7c1 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs @@ -88,6 +88,25 @@ impl List { self.model.append(&Item::new(value, title, subtitle)); } + /// Find list item by `Value` + /// * return list item `position` found + pub fn find(&self, value: i64) -> Option { + self.model + .find_with_equal_func(|this| value == this.clone().downcast::().unwrap().value()) + } + + /// Remove list item by `Value` + /// * return `position` of removed list item + pub fn remove(&self, value: i64) -> Option { + match self.find(value) { + Some(position) => { + self.model.remove(position); + Some(position) + } + None => None, + } + } + // Events /// Run callback function on `connect_selected_notify` event