Hi Nicolai and Doru and community, This is working like a charm. I can add an remove nodes to selected nodes on any place of the tree, as you can see in this screenshot: http://www.enlightenment.org/ss/e-53eff22637d2c7.34692752.jpg I have some questions: - I have an issue still and is that once I have deleted a particular node, its parent should be now the selected node. If this doesn't happen, deleting and adding nodes with nothing selected becomes problematic. How can I reassign the selection to a node's parent? - This is more like a curiosity on good practices. The more I write on UbakyeBrowser>>buildBrowser, the more a lateral panel becomes red. I imagine that this is related with the extension of the code and some kind of reminder for modularization. Being the tree and its behaviour the more complex part of the interface I think that is the first candidate for this to happen. There is any reading I can see for advice on this? Following the advice of Doru, here is a way to see the code and launching the last version in a default Moose: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Gofer new smalltalkhubUser: 'Offray' project: 'Ubakye'; package: 'Ubakye'; load. UbakyeBrowser open. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Some time ago I said that I was approaching to the fun part of the Smalltalk joyride, and now if feels even closer! :-) https://twitter.com/offrayLC/status/493979407011561473/photo/1 Thanks, Offray On 08/14/2014 12:11 AM, Tudor Girba wrote:
Hi,
The important visual objects, such as the selection, are reflected on the ports of the pane containing the presentation.
The tree has two ports that are relevant for selection: - #selection will give you the selected node - #selectionPath will give you the path from the selected node to the root
You can do like this: a tree act: [:treePresentation | treePresentation selection inspect ] entitled: 'Inspect selection'; act: [:treePresentation | treePresentation selectionPath inspect ] entitled: 'Inspect selection path'
Cheers, Doru
On Thu, Aug 14, 2014 at 1:32 AM, Nicolai Hess <nicolaihess@web.de <mailto:nicolaihess@web.de>> wrote:
Hi Offray,
some notes about your code:
browser act: [:newNode | newNode := UbakyeNode header: 'nuevoNodo' body: ''. mainTree addNode: newNode.]
this would change the block parameter "newNode", but the block parameter is supposed to deliver the object you'll act on, the browser for example. I think you wanted to write this code:
browser act: [ :b | |newNode|
newNode := UbakyeNode header: 'nuevoNodo' body: ''. b entity addNode: newNode .
if you call "b update" like you did in the "remove action" your browse tree update will work.
changing OrderedCollection to GLMAnnouncingCollection should work, but you'll have to define the appropiate announcer source #children instead of #yourself. #yourself gives the mainTree, and that does not work as your mainTree is not a GLMAnnouncingCollection.
updateOn: GLMItemAdded from: #children
There are two things I don't understand
1. setting updateOn: on the browser does not work:
browser updateOn: GLMItemAdded from: #children.
but setting it on the tree
(browser transmit) to: #preview; andShow: [ :a | a tree "-->" updateOn: GLMItemAdded from: #children;
title: mainTree header; children: [:eachNode | eachNode children ];
format: [:eachNode | eachNode header ]. a text title: 'Text'].
updates the tree when adding an element by the + button
2. is there a way to get the currently selected tree node? Otherwise all new nodes only added to the first node.
There are plenty of examples, but no one with add/remove or selection on trees.
Nicolai
2014-08-13 21:37 GMT+02:00 Offray Vladimir Luna Cárdenas <offray@riseup.net <mailto:offray@riseup.net>>:
Hi Usman,
On 08/13/2014 02:16 AM, Usman Bhatti wrote:
Hi Offray,
As Doru mentioned, without a complete example it is difficult to reproduce and analyze your problem.
My main issue is that I don't know how to share a complete example except by sharing this url:
http://smalltalkhub.com/#!/~__Offray/Ubakye/ <http://smalltalkhub.com/#!/~Offray/Ubakye/>
and advising to upload the code and run "UbakyeBrowser open". In file based frameworks I can point to a specific file which contains the model of my defined objects, but I don't know how to share my own defined objects/messages in Smalltalk except by this or by manually cutting and pasting to email (it should be a better way).
Anyway this is the part where I define a UbakyeNode:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-__=-=-=-=-=- Object subclass: #UbakyeNode instanceVariableNames: 'header headers key icon body children parent node' classVariableNames: '' category: 'Ubakye-Model' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-__=-=-=-=-=-
and the children method is the one which uses a colection:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-__=-=-=-=-=- UbakyeNode>>children "Returns the receivers list of children"
^ children ifNil: [children := OrderedCollection new] =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-__=-=-=-=-=-
For the tree to get updated on node addition or removal, you need to use GLMAnnouncingCollection to group your nodes. Hence, when you add a new node in your announcing collection object, this code comes into effect:
updateOn: GLMItemAdded from: #yourself;
So, make sure you are using appropriate collection object.
I tried changing OrderedCollection in the children message by GLMAnnouncingCollection, but the header message started to fail. Can I pass my children collection to a GLMAnnouncingCollection just in the interface or need I to change the object definition for the UbakyeNode, and if this is the case, how can I access the header of a UbakyeNode stored in this kind of collection? I know is kind of dumb to ask without proper context, but I hope that the SmalltalkHub repository (or other method) can be used to share my own defined object to make better questions.
usman
Cheers,
Offray
-- www.tudorgirba.com <http://www.tudorgirba.com>
"Every thing has its own flow"