mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
update list model on item delete
This commit is contained in:
parent
29083f50d9
commit
6ed544ca62
@ -31,11 +31,11 @@ impl Form {
|
||||
/// Create new `Self`
|
||||
pub fn new(profile: Rc<Profile>, action: Rc<Action>) -> 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();
|
||||
|
@ -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<Profile>, action: Rc<Action>) -> Self {
|
||||
pub fn new(profile: Rc<Profile>, action: Rc<Action>, list: Rc<List>) -> Self {
|
||||
// Init selected option holder
|
||||
let profile_identity_gemini_id = Rc::new(RefCell::new(None::<i64>));
|
||||
|
||||
@ -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"]);
|
||||
|
@ -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<u32> {
|
||||
self.model
|
||||
.find_with_equal_func(|this| value == this.clone().downcast::<Item>().unwrap().value())
|
||||
}
|
||||
|
||||
/// Remove list item by `Value`
|
||||
/// * return `position` of removed list item
|
||||
pub fn remove(&self, value: i64) -> Option<u32> {
|
||||
match self.find(value) {
|
||||
Some(position) => {
|
||||
self.model.remove(position);
|
||||
Some(position)
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
// Events
|
||||
|
||||
/// Run callback function on `connect_selected_notify` event
|
||||
|
Loading…
x
Reference in New Issue
Block a user