Question

I have a ListStore modeling a list of Tags. This list may change apart from the ListStore. What I'd like to do is listen to the TagRemoved event in my TagList class, and remove the Tag from the ListStore when the event is triggered. However, I can't seem to find a way to search a ListStore for the row containing a given Tag, so that I can remove it.

Is there any way to do this?

Was it helpful?

Solution

A GtkListStore implements the GtkTreeModel interface, which contains the tree traversal operations you want. As far as I know, there is no convenience API for searching a list/tree store, so you'll have to roll your own.

Since you're simply iterating over a GtkListStore, you can ignore all of the API dealing with child/parent relations, and simply use gtk_tree_model_iter_first() and gtk_tree_model_iter_next() to traverse the list.

Alternatively, if you already know the index of the removed tag in the store (e.g., from your TagRemoved event), you can turn that into a GtkTreePath and use gtk_tree_model_get_iter() to retrieve the row in question directly without searching.

OTHER TIPS

GtkListStore is internally implemented as a linked list so you should scan the model by yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top