2016-08-10 20:42 GMT+02:00 Nicolai Hess <[email protected]>:
>
>
> 2016-08-10 19:12 GMT+02:00 Nicolai Hess <[email protected]>:
>
>>
>>
>> 2016-08-10 19:05 GMT+02:00 Offray Vladimir Luna Cárdenas <
>> [email protected]>:
>>
>>> Hi,
>>>
>>> I have been fighting with this for several hours until now. I can't
>>> understand how to manage change on selections on TreeModels with Spec,
>>> which is really frustrating....
>>>
>>> Here is what I have:
>>>
>>> GrafoscopioNotebook>>initializePresenter
>>> tree whenSelectedItemChanged: [ :item |
>>> self updateBodyFor: item.
>>> header whenTextChanged: [ :arg |
>>> (tree selectedItem content header) = arg
>>> ifFalse: [
>>> (tree highlightedItem) content header: arg.
>>> tree roots: tree roots]]]
>>>
>>> GrafoscopioNotebook>>updateBodyFor: item
>>> item
>>> ifNotNil: [ self changeBody: item ]
>>> ifNil: [ self inform: 'Nil node' ]
>>>
>>> and #changeBody: deals with putting a textual or code pane according to
>>> some tags on the selected node (and it's working properly).
>>>
>>> The problem seems that when I add/delete nodes to my tree, or while
>>> changing the selection between nodes, the item variable becomes temporarily
>>> nil and I can't update the contents of the body to correspond to the
>>> current selection. I would like to say explicitly that a new tree added
>>> node gets the selection and that the deletion of nodes gives selection to
>>> its siblings or parent (if there are not siblings) and that node body pane
>>> should be updated accordingly.
>>>
>>> Again, any hint would be really valuable... I'll take a break from the
>>> computer to dissipate current frustration... Pharo is generally a happy
>>> productive place... but not today :-/... anyway some hits are part of
>>> learning to play with it.
>>>
>>
>> Hi Offray,
>> I do remember that I tried this as well, I will if I can find out how far
>> I got it to work.
>>
>
> a simiple example:
>
> |t nodeBlock |
> nodeBlock:= [:class | |node|
> node := TreeNodeModel new.
> node hasChildren:[ class subclasses isEmpty not].
> node children: [class subclasses collect:[:subclass | nodeBlock value:
> subclass]].
> node content: class].
> t:=TreeModel new.
> t roots: (Morph subclasses collect:[:class | nodeBlock value:class]).
> t whenBuiltDo:[ t selectedItem:( t roots first selected:true;takeHighlight;
> yourself)].
> t openWithSpec
>
> the important part is the "takeHighlight" and to call it after the widget
> is built
>
>
>
And an awfull example on how to modify selection (only the nodes of the
root, couldn't find out how to do it for arbitrary subnodes)
|t nodeBlock |
nodeBlock:= [:class | |node|
node := TreeNodeModel new.
node hasChildren:[ class subclasses isEmpty not].
node children: [class subclasses collect:[:subclass | nodeBlock value:
subclass]].
node content: class].
t:=TreeModel new.
t autoDeselection:true.
t roots: (Morph subclasses collect:[:class | nodeBlock value:class]).
t menu:[:menu ||group|
group := MenuGroupModel new.
menu addMenuGroup: group.
group addMenuItem:(MenuItemModel new name:'next';action:[
|item|
item := t selectedItem.
item ifNotNil:[|allItems index|
allItems := item container roots.
index := allItems indexOf: item.
(index < allItems size) ifTrue:[item selected:false. item
container selectedItem:((allItems at:(index+1))
selected:true;takeHighlight;yourself)]
]
])].
t whenBuiltDo:[ t selectedItem:( t roots first
selected:true;takeHighlight;yourself)].
t openWithSpec
again, the important part is #selectedItem: and #takeHighlight, otherwise
the model doesn't know about the selection change.
>
>>
>>>
>>> Cheers,
>>>
>>> Offray
>>>
>>>
>>> On 07/08/16 16:11, Offray Vladimir Luna Cárdenas wrote:
>>>
>>>> Hi,
>>>>
>>>> I have a Spec TreeModel to represent the GUI of a grafoscopio notebook.
>>>>
>>>> The message that deletes nodes is something like this:
>>>>
>>>> ============
>>>>
>>>> GrafoscopioNotebook>>removeNode
>>>> | nodeToDelete |
>>>> nodeToDelete := tree selectedItem content.
>>>> nodeToDelete parent removeNode: nodeToDelete.
>>>> tree selectedItem: tree selectedItem parentNode.
>>>> tree needRebuild: true.
>>>> tree roots: tree roots.
>>>> self buildWithSpecLayout: self class defaultSpec.
>>>>
>>>> =============
>>>>
>>>> And its working fine in the sense that it deletes the selected node,
>>>> but after the deletion the contents of the old node are showed no matter if
>>>> I change the node selection on the tree. I would like to manage selections
>>>> in a smart way, so if I add a new node to the notebook, the new node gets
>>>> the selection. If I delete a notebook node, the previous node gets selected
>>>> or the parent if no more siblings are encountered and so on. There is some
>>>> simple example to look for, about managing and updating selections in a
>>>> TreeModel interface?
>>>>
>>>> Thanks,
>>>>
>>>> Offray
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>