Skip to content

Commit

Permalink
Simplify code in WithDefaultListModel
Browse files Browse the repository at this point in the history
  • Loading branch information
saivert committed May 10, 2024
1 parent f4a90bc commit f0863ad
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/ui/withdefaultlistmodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ mod imp {
glib::Object::static_type()
}
fn n_items(&self) -> u32 {
let model = self.flatten_list_model.borrow();
if let Some(model) = model.as_ref() {
if let Some(model) = &*self.flatten_list_model.borrow() {
model.n_items()
} else {
0
}
}
fn item(&self, position: u32) -> Option<glib::Object> {
let model = self.flatten_list_model.borrow();
if let Some(model) = model.as_ref() {
if let Some(model) = &*self.flatten_list_model.borrow() {
model.item(position)
} else {
None
Expand All @@ -64,12 +62,10 @@ mod imp {

impl WithDefaultListModel {
pub fn set_model(&self, new_model: Option<&PwNodeFilterModel>) {
let removed = self.n_items();

let string_list = self.string_list.borrow().clone();
let string_list = &*self.string_list.borrow();

let composite_store = gio::ListStore::new::<gio::ListModel>();
composite_store.append(&string_list);
composite_store.append(string_list);

if let Some(new_model) = new_model {
composite_store.append(new_model);
Expand All @@ -83,10 +79,7 @@ mod imp {
});
flattened_model.connect_closure("items-changed", true, handler);

let added = flattened_model.n_items();
self.flatten_list_model.replace(Some(flattened_model));

self.obj().items_changed(0, removed, added);
}
}
}
Expand Down

0 comments on commit f0863ad

Please sign in to comment.