The test #testPickedChangesAfterSelect selects an item which is not in the 
browser, so I would consider that a bug.

Adding the item to the browser before selecting it should be correct and make 
the test work.

ChangesBrowserTest >> testPickedChangesAfterSelect
               | item |
               Item := RBAddClassChange.
               Item definition: ‘test’ controller: nil.
               Browser changes: {item}.
               Self assert: …..
               ….

Best regards,
Henrik

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



2016-08-07 18:23 GMT+02:00 Nicolai Hess 
<nicolaih...@gmail.com<mailto:nicolaih...@gmail.com>>:


2016-08-07 17:53 GMT+02:00 Henrik Nergaard 
<henrik.nerga...@uia.no<mailto:henrik.nerga...@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.


I tried to fix this, but there is a test case for the ChangesBrowser that tests 
the selection.
The problem is, that the test case selects an item by calling #selectedItem: 
and the behavior is different for when this is called by the view.
The test case just selects the "change", whereas when this is called by the 
view, the selected item is TreeNodeModel (with #contents).
And I can not fix #pickedChanges without breaking this test.
Any Idea ?




Best regards,
Henrik

From: Pharo-dev 
[mailto:pharo-dev-boun...@lists.pharo.org<mailto:pharo-dev-boun...@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<mailto: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


Reply via email to