- if (was_selected)
- gtk_tree_selection_unselect_iter(selection, iter);
- else
- gtk_tree_selection_select_iter(selection, iter);
+
+ /* if the parent is expanded, just (un)select the children and we'll
+ track their selection status in the callback
+ otherwise just change the selection status directly without
+ bothering gtk */
+ if (expanded) {
+ if (was_selected)
+ gtk_tree_selection_unselect_iter(selection, iter);
+ else
+ gtk_tree_selection_select_iter(selection, iter);
+ } else {
+ int idx;
+ gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, -1);
+ if (was_selected)
+ track_unselect(idx);
+ else
+ track_select(idx);
+ }