Callback called twice in TreeViewItem::setSelected



I fixed a small issue in TreeViewItem:
When calling TreeViewItem::setSelected(true, true) on an item that is already selected, the itemSelectionChanged() callback is called a first time with isNowSelected = false and then a second time with isNowSelected = true, whereas nothing changed. The first callback call comes from the deselectOtherItemsFirst option.

In order to fix this issue, I modified TreeViewItem::setSelection by replacing the call to deselectAllRecursively() by a call to a new function deselectAllRecursivelyExcept():

void TreeViewItem::deselectAllRecursivelyExcept(TreeViewItem* item)
  if (this != item)
    setSelected(false, false);
  for (int i = 0; i < subItems.size(); ++i)

This way, the current item is not unselected if it is not necessary to unselect it.

I hope this may help,



Thanks, that seems to make sense, and I should probably make it work like that.

My only worry is that people might be relying on that deselect-reselect behaviour in their treeviews. I often get annoyed with things like XCode, where you click on a file in the treeview to try to open it, but if it’s already selected, nothing happens, and you have to select something else and go back…