From 9c669bbd20b608d93274443290781b38882fd0e2 Mon Sep 17 00:00:00 2001 From: Marcus Behrendt Date: Fri, 18 Oct 2024 11:40:39 +0200 Subject: [PATCH 1/4] fix(containers-panel): Use correct initial filter view --- src/view/containers_panel.rs | 153 +++++++++++++++++++---------------- 1 file changed, 83 insertions(+), 70 deletions(-) diff --git a/src/view/containers_panel.rs b/src/view/containers_panel.rs index 8dfc7e9d..9ccbf6c0 100644 --- a/src/view/containers_panel.rs +++ b/src/view/containers_panel.rs @@ -483,9 +483,9 @@ mod imp { self.update_filter(filter_change); } - pub(super) fn set_container_list(&self, value: Option<&model::ContainerList>) { + pub(super) fn set_container_list(&self, value: &model::ContainerList) { let obj = &*self.obj(); - if obj.container_list().as_ref() == value { + if obj.container_list().as_ref() == Some(value) { return; } @@ -493,84 +493,97 @@ mod imp { .iter() .for_each(|action_name| obj.action_set_enabled(action_name, false)); - if let Some(container_list) = value { - container_list.connect_notify_local( - Some("num-selected"), - clone!( - #[weak] - obj, - move |list, _| { - ACTIONS_SELECTION.iter().for_each(|action_name| { - obj.action_set_enabled(action_name, list.num_selected() > 0); - }); - } - ), - ); - - container_list.connect_notify_local( - Some("running"), - clone!( - #[weak] - obj, - move |_, _| obj.imp().update_filter(gtk::FilterChange::Different) - ), - ); - - container_list.connect_container_name_changed(clone!( + value.connect_notify_local( + Some("num-selected"), + clone!( #[weak] obj, - move |_, _| { - obj.imp().update_filter(gtk::FilterChange::Different); - glib::timeout_add_seconds_local_once( - 1, - clone!( - #[weak] - obj, - move || obj.imp().update_sorter() - ), - ); + move |list, _| { + ACTIONS_SELECTION.iter().for_each(|action_name| { + obj.action_set_enabled(action_name, list.num_selected() > 0); + }); } - )); - - let model: gtk::SortListModel = gtk::SortListModel::new( - Some(gtk::FilterListModel::new( - Some(container_list.to_owned()), - self.filter.get().cloned(), - )), - self.sorter.get().cloned(), - ); - - if let Some(view) = &*self.containers_view.borrow() { - view.set_model(Some(model.upcast_ref())); - } + ), + ); - model.connect_items_changed(clone!( + value.connect_notify_local( + Some("running"), + clone!( #[weak] obj, - move |model, _, removed, _| { - obj.imp().filter_stack.set_visible_child_name( - if model.n_items() > 0 - || !obj - .container_list() - .as_ref() - .is_some_and(model::ContainerList::initialized) - { - "containers" - } else { - "empty" - }, - ); + move |_, _| obj.imp().update_filter(gtk::FilterChange::Different) + ), + ); - if removed > 0 { - obj.deselect_hidden_containers(model.upcast_ref()); - } - } - )); + value.connect_container_name_changed(clone!( + #[weak] + obj, + move |_, _| { + obj.imp().update_filter(gtk::FilterChange::Different); + glib::timeout_add_seconds_local_once( + 1, + clone!( + #[weak] + obj, + move || obj.imp().update_sorter() + ), + ); + } + )); - self.model.replace(Some(model.upcast())); + let model = gtk::SortListModel::new( + Some(gtk::FilterListModel::new( + Some(value.to_owned()), + self.filter.get().cloned(), + )), + self.sorter.get().cloned(), + ); + + if let Some(view) = &*self.containers_view.borrow() { + view.set_model(Some(model.upcast_ref())); } - self.container_list.set(value); + self.set_filter_stack_visible_child(value, &model); + model.connect_items_changed(clone!( + #[weak] + obj, + #[weak] + value, + move |model, _, removed, _| { + obj.imp().set_filter_stack_visible_child(&value, model); + + if removed > 0 { + obj.deselect_hidden_containers(model.upcast_ref()); + } + } + )); + value.connect_initialized_notify(clone!( + #[weak] + obj, + #[weak] + model, + move |container_list| obj + .imp() + .set_filter_stack_visible_child(container_list, &model) + )); + + self.model.replace(Some(model.upcast())); + + self.container_list.set(Some(value)); + } + + fn set_filter_stack_visible_child( + &self, + container_list: &model::ContainerList, + model: &impl IsA, + ) { + self.filter_stack.set_visible_child_name( + if model.n_items() > 0 || !container_list.initialized() { + "containers" + } else { + "empty" + }, + ); } fn update_filter(&self, filter_change: gtk::FilterChange) { From 6c33b8ae473877299b47f1bae3f9775d2c68b910 Mon Sep 17 00:00:00 2001 From: Marcus Behrendt Date: Fri, 18 Oct 2024 11:40:49 +0200 Subject: [PATCH 2/4] fix(pods-panel): Use correct initial filter view --- src/view/pods_panel.rs | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/view/pods_panel.rs b/src/view/pods_panel.rs index e8302099..62127d91 100644 --- a/src/view/pods_panel.rs +++ b/src/view/pods_panel.rs @@ -391,28 +391,27 @@ mod imp { view::PodRow::from(item.downcast_ref().unwrap()).upcast() }); + self.set_filter_stack_visible_child(value, &model); model.connect_items_changed(clone!( #[weak] obj, + #[weak] + value, move |model, _, removed, _| { - obj.imp().filter_stack.set_visible_child_name( - if model.n_items() > 0 - || !obj - .pod_list() - .as_ref() - .is_some_and(model::PodList::initialized) - { - "list" - } else { - "empty" - }, - ); + obj.imp().set_filter_stack_visible_child(&value, model); if removed > 0 { obj.deselect_hidden_pods(model.upcast_ref()); } } )); + value.connect_initialized_notify(clone!( + #[weak] + obj, + #[weak] + model, + move |value| obj.imp().set_filter_stack_visible_child(value, &model) + )); ACTIONS_SELECTION .iter() @@ -433,6 +432,20 @@ mod imp { self.pod_list.set(Some(value)); } + fn set_filter_stack_visible_child( + &self, + pod_list: &model::PodList, + model: &impl IsA, + ) { + self.filter_stack.set_visible_child_name( + if model.n_items() > 0 || !pod_list.initialized() { + "list" + } else { + "empty" + }, + ); + } + fn update_filter(&self, filter_change: gtk::FilterChange) { if let Some(filter) = self.filter.get() { filter.changed(filter_change); From 32ed1eb6420cfc3d939a3c8accbf39abda59c586 Mon Sep 17 00:00:00 2001 From: Marcus Behrendt Date: Fri, 18 Oct 2024 11:40:57 +0200 Subject: [PATCH 3/4] fix(images-panel): Use correct initial filter view --- src/view/images_panel.rs | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/view/images_panel.rs b/src/view/images_panel.rs index 7227461e..267a8a03 100644 --- a/src/view/images_panel.rs +++ b/src/view/images_panel.rs @@ -387,28 +387,27 @@ mod imp { view::ImageRow::from(item.downcast_ref().unwrap()).upcast() }); + self.set_filter_stack_visible_child(value, &model); model.connect_items_changed(clone!( #[weak] obj, + #[weak] + value, move |model, _, removed, _| { - obj.imp().filter_stack.set_visible_child_name( - if model.n_items() > 0 - || !obj - .image_list() - .as_ref() - .is_some_and(model::ImageList::initialized) - { - "list" - } else { - "empty" - }, - ); + obj.imp().set_filter_stack_visible_child(&value, model); if removed > 0 { obj.deselect_hidden_images(model.upcast_ref()); } } )); + value.connect_initialized_notify(clone!( + #[weak] + obj, + #[weak] + model, + move |value| obj.imp().set_filter_stack_visible_child(value, &model) + )); obj.action_set_enabled(ACTION_DELETE_SELECTION, false); value.connect_notify_local( @@ -425,6 +424,20 @@ mod imp { self.image_list.set(Some(value)); } + fn set_filter_stack_visible_child( + &self, + image_list: &model::ImageList, + model: &impl IsA, + ) { + self.filter_stack.set_visible_child_name( + if model.n_items() > 0 || !image_list.initialized() { + "list" + } else { + "empty" + }, + ); + } + fn update_filter(&self, filter_change: gtk::FilterChange) { if let Some(filter) = self.filter.get() { filter.changed(filter_change); From e85e595b8ea94d154664e1b93571c7c6d526f7ec Mon Sep 17 00:00:00 2001 From: Marcus Behrendt Date: Fri, 18 Oct 2024 11:41:09 +0200 Subject: [PATCH 4/4] fix(volumes-panel): Use correct initial filter view --- src/view/volumes_panel.rs | 132 ++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 61 deletions(-) diff --git a/src/view/volumes_panel.rs b/src/view/volumes_panel.rs index 5076088f..238d2e9f 100644 --- a/src/view/volumes_panel.rs +++ b/src/view/volumes_panel.rs @@ -40,7 +40,7 @@ mod imp { pub(super) filter: OnceCell, pub(super) sorter: OnceCell, pub(super) search_term: RefCell, - #[property(get, set = Self::set_volume_list, explicit_notify, nullable)] + #[property(get, set = Self::set_volume_list)] pub(super) volume_list: glib::WeakRef, #[property(get, set)] pub(super) collapsed: Cell, @@ -333,77 +333,87 @@ mod imp { self.update_filter(filter_change); } - pub(super) fn set_volume_list(&self, value: Option<&model::VolumeList>) { + pub(super) fn set_volume_list(&self, value: &model::VolumeList) { let obj = &*self.obj(); - if obj.volume_list().as_ref() == value { + if obj.volume_list().as_ref() == Some(value) { return; } obj.action_set_enabled(ACTION_DELETE_SELECTION, false); - if let Some(volume_list) = value { - volume_list.connect_notify_local( - Some("num-selected"), - clone!( - #[weak] - obj, - move |list, _| { - obj.action_set_enabled( - ACTION_DELETE_SELECTION, - list.num_selected() > 0, - ); - } - ), - ); - - volume_list.connect_notify_local( - Some("used"), - clone!( - #[weak] - obj, - move |_, _| { - obj.imp().update_filter(gtk::FilterChange::Different); - } - ), - ); - - let model = gtk::SortListModel::new( - Some(gtk::FilterListModel::new( - Some(volume_list.to_owned()), - self.filter.get().cloned(), - )), - self.sorter.get().cloned(), - ); - - self.list_box.bind_model(Some(&model), |item| { - view::VolumeRow::from(item.downcast_ref().unwrap()).upcast() - }); - - model.connect_items_changed(clone!( + value.connect_notify_local( + Some("num-selected"), + clone!( #[weak] obj, - move |model, _, removed, _| { - obj.imp().filter_stack.set_visible_child_name( - if model.n_items() > 0 || { - !obj.volume_list() - .as_ref() - .is_some_and(model::VolumeList::initialized) - } { - "list" - } else { - "empty" - }, - ); + move |list, _| { + obj.action_set_enabled(ACTION_DELETE_SELECTION, list.num_selected() > 0); + } + ), + ); - if removed > 0 { - obj.deselect_hidden_volumes(model.upcast_ref()); - } + value.connect_notify_local( + Some("used"), + clone!( + #[weak] + obj, + move |_, _| { + obj.imp().update_filter(gtk::FilterChange::Different); } - )); - } + ), + ); + + let model = gtk::SortListModel::new( + Some(gtk::FilterListModel::new( + Some(value.to_owned()), + self.filter.get().cloned(), + )), + self.sorter.get().cloned(), + ); + + self.list_box.bind_model(Some(&model), |item| { + view::VolumeRow::from(item.downcast_ref().unwrap()).upcast() + }); + + self.set_filter_stack_visible_child(value, &model); + model.connect_items_changed(clone!( + #[weak] + obj, + #[weak] + value, + move |model, _, removed, _| { + obj.imp().set_filter_stack_visible_child(&value, model); + + if removed > 0 { + obj.deselect_hidden_volumes(model.upcast_ref()); + } + } + )); + value.connect_initialized_notify(clone!( + #[weak] + obj, + #[weak] + model, + move |volume_list| obj + .imp() + .set_filter_stack_visible_child(volume_list, &model) + )); + + self.volume_list.set(Some(value)); + } - self.volume_list.set(value); - obj.notify("volume-list"); + fn set_filter_stack_visible_child( + &self, + volume_list: &model::VolumeList, + model: &impl IsA, + ) { + self.filter_stack.set_visible_child_name( + if model.n_items() > 0 || !volume_list.initialized() { + "list" + } else { + "empty" + }, + ); } fn update_filter(&self, filter_change: gtk::FilterChange) {