2016-08-07 17:53 GMT+02:00 Henrik Nergaard <henrik.nergaard@uia.no>:

ListModel has that: #selectedItemsSorted, but looking at the tree model structure I guess the simplest way is to just traverse the whole structure until the selected nodes are found.

Something like this should do the trick:

��

--------------------------------------------------

TreeModel >> selectionSorted

���������������������������� | ordered lookingFor search |

��

���������������������������� ordered := OrderedCollection new.

��

���������������������������� lookingFor := self selectedItems asIdentitySet.

���������������������������� LookingFor ifEmpty: [ ^ #() ]

���������������������������� search := [ :nodes |

���������������������������������������������������������� nodes do: [ :node |

���������������������������������������������������������������������������������������� (lookingFor includes: node) ifTrue: [

���������������������������������������������������������������������������������������������������������������������� ordered add: node.

���������������������������������������������������������������������������������������������������������������������� lookingFor remove: node.

���������������������������������������������������������������������������������������������������������������������� lookingFor isEmpty ifTrue: [ ^ ordered asArray ]

���������������������������������������������������������������������������������������� ].

���������������������������������������������������������������������������������������� search value:�� node children value����������������������

���������������������������������������������������������� ]��������������������������

���������������������������� ].

��

���������������������������� search value: self roots.

����������������������������

���������������������������� self error: 'should not happen'

��

--------------------------------------


Thanks Peter, Henrik,
yes I was afraid there is no other way.


��

��

Best regards,

Henrik

��

From: Pharo-dev [mailto:pharo-dev-bounces@lists.pharo.org] On Behalf Of Nicolai Hess
Sent: Sunday, August 7, 2016 4:55 PM
To: Pharo Development List <pharo-dev@lists.pharo.org>
Subject: [Pharo-dev] Spec TreeModel get selected items in order

��

Hi,

Is there a way to retrive the selected nodes of a TreeModel in the same order they are

shown in the widget ?

For example, open this tree model, and select item 5/4/3/1
|t|
Transcript clear.
t := TreeModel new.
t beCheckList ;
��autoMultiSelection: true.
t roots:((1 to:10) collect:[:c | TreeNodeModel new content:c;hasContentToShow:true]).
t openWithSpec.
t inspect .

Now, if I try to collect the selected items with

t selectedItems collect:#contents

they appear in the order I selected them, but I would like to get the order
1/2/3/4/5

thanks

Nicolai