On Sun, Aug 07, 2016 at 04:55:05PM +0200, Nicolai Hess wrote:
> 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

I vaguely remember that I had this problem long time ago and what I ended up 
doing was to filter against the original collection.
E.g. something like this

t := TreeModel new.
t
        beCheckList;
        autoMultiSelection: true.
d := 1 to: 10.
t roots: d.
t openWithSpec.

sel := (t selectedItems collect: #content).
d select: [ :each | sel includes: each ]

Also looking at the code it seems that TreeModel is really heavily tied to 
Morphic... so maybe not so simple to fix without rewrite.

Peter

Reply via email to