branch: store the selection and expanded state
We were currently saving the tree state as a sparse dict that can be
used to restore the collapsed/expanded state of tree items.
Extend this data structure to also include the selection state.
The data structure currently stores the expanded state implicitly;
existence of the dict means that the item is expanded.
The expanded state will now store the expanded state alongside other
data. Use separate dict entries for the expanded state, the selected
state and the children dict.
Update def _toggled_expanded() to only expand items and item when
that item has children. This avoid additional refreshes of the UI
because Qt will no longer re-layout the widgets below the clicked
widget.
The net result is that the selection state is restored across refreshes.
No longer do we lose the user's selection in response to actions, and
the UI no longer redraws itself as items are clicked.
Closes #1221
Reported-by: Jakub Klos <jakub@icewarp.com>
Signed-off-by: David Aguilar <davvid@gmail.com>