Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retain method to ListStore #1133

Merged
merged 1 commit into from
Jul 20, 2023
Merged

Add retain method to ListStore #1133

merged 1 commit into from
Jul 20, 2023

Conversation

ranfdev
Copy link
Member

@ranfdev ranfdev commented Jul 20, 2023

Motivation:
People often endup doing

for item in list_store.iter()
  if item.unwrap().name() == 'Giorgio' {
    list_store.remove(&item)
  }
}

But that unwrap is going to panic, because we added checks to prevent that an iterator over a list is mutated during iteration.

retain is just a nice alternative to provide an easier to use way to remove items while iterating the list.

list_store.retain(|item| item.name() != 'Giorgio')

It will also remove consecutive items with a single splice call, so If the user removes every item, retain doesn't spam items_changed signals

gio/src/list_store.rs Outdated Show resolved Hide resolved
@sdroege sdroege merged commit 80d6fd2 into gtk-rs:master Jul 20, 2023
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants