Login  Register

Re: Spec: Binding widgets how to

Posted by Nicolai Hess-3-2 on Nov 29, 2015; 6:38pm
URL: https://forum.world.st/Spec-Binding-widgets-how-to-tp4863742p4864181.html



2015-11-26 19:36 GMT+01:00 Offray Vladimir Luna Cárdenas <[hidden email]>:
Hi,

I had tried that before and didn't work. Passing information between widgets and back in this spec interface seems my stop point now... If someone could help me with some kind of minimalist example that uses treeModel, that would be greatly appreciated.

Find attached a minimal example. (I use Morph and its subclasses for generating some tree data, these are just names, renaming a node does not rename the class :))

You can listen on tree node selection by registering with #whenSelectedChanged, on the TreeNode(!)

"create the node"
t :=  TreeNodeModel new
        content: aClass name;
        hasChildren: [ aClass subclasses notEmpty ];
        children: [ subItems ifNil:[subItems:=aClass subclasses collect: [ :s | self buildNodeFor: s ] ]];
        yourself.

"listen on selection"
t whenSelectedChanged: [ :bool | bool ifTrue:[self field text: t content] ].

this will change the text field content with the content of the node (the default label).

Changing the label node *Morph* on accepting the text field text is somehow impossible or difficult.
I would have expected that Spec would create a MorphicTreeNodeAdapter that represents some Morph, for which the adapter would update/change the state, if you change
the TreeNodeModel content.
Instead, it creates some strange SpecTreeNodeModel. And the only way to update the NodeLabel and make this change visible is to
rebuild the whole tree:

tree roots: tree roots.

Yes, I did not find another way.

Luckily MorphTreeMorph is smart enough to remember the selection and path expansion state, so this works quite well.

 

Cheers,

Offray


On 26/11/15 12:47, webwarrior wrote:
Try #whenHighlightedItemChanged: method.

I remember that distinction between selection/highlight is not very clear in
TreeModel.



--
View this message in context: http://forum.world.st/Spec-Binding-widgets-how-to-tp4863742p4863757.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.






Tree-TextField-Demo-NicolaiHess.2.mcz (2K) Download Attachment