Spec - how to update a tree list keeping current selection?
I am displaying a tree and I need to add an element, but I want to keep the currently selected item. If I do it like this:
oldSelectedItem := treePresenter selectedItem.
treePresenter
roots: newRootCollection;
selectItem: oldSelectedItem
it will of course work, but there is a problem: the activation event (whenActivatedDo:
) will be triggered and I do not what this!
How can I proceed to avoid it?
Trees and Tree tables in spec implement the API updateRootsKeepingSelection:
to prevent precisely this.
In practice, it makes the same as the code above, but it will not trigger any activation, and no activation transmission.
This code:
treePresenter updateRootsKeepingSelection: newRootCollection
Will have the same effect as the original code, but it will not trigger an activation when executed.
(Of course, to work properly is required that the new collection contains the previously selected elements).