How to use a custom icon in a dolphin smalltalk treeview?

165 views Asked by At

In a Dolphin smalltalk treeview I'd like to use a custom icon, depending on the state of the item displayed, (differente state, different icon) How can I do that ?

I cannot really understand how to use a "my" icon. I've create a class "connection", with an instance variable "connected" and two class methods "connectedIcon and unconnectedIcon that returns icon images. Then an instance function "icon" that returns one or the other image based on the connection state.

I can add instances of this class to a tree view and see the name of the connections. But how to show my Icons ?

I tried to sustitute the getImageBlock of my presenter view with the following expression [:obj | obj icon] but it doesn't work. (nothing seems to happen).

this is made in my presenter initialize :

initialize super initialize. treePresenter view getImageBlock: [:obj | obj icon]

what's wrong with it ? best regards Maurizio

3

There are 3 answers

3
James Foster On BEST ANSWER

When you are editing a TreeView, one of the properties is getImageBlock. By default it is not really a block but another object that understands the message #'value:' (the class IconicListAbstract). You can replace this property with a code block (or other object that understands #'value:') and answer the image you want displayed.

0
James Foster On

In Microsoft Windows, icons are typically stored in a DLL. You should be able to use an icon explorer or editing tool to see the icons in a dll. For example, get IconExplorer from http://www.mitec.cz/iconex.html and try opening DolphinDR7.dll. Do the icons and numbers match what you see when you return a number in your application?

To determine (or override) the resource library used, see SessionManager>>#'defaultResLibPath'.

Typically, the getImageBlock is set using the property editor in the GUI editor, but setting it through code can work as well.

0
Maurizio Ferreira On

Wonderful Dolphin Smalltalk!

I had two problems

1) how and where to modify the getImageBlock method of my Treepresenter. 2) where to put the icons ad how to get the imageindex of each icon.

This is the solution :

1) it's not needed. The treeview sends an #iconImageIndex" message to my model this is handled by the default method (in the Object class) that send to my object the message #icon and to the result of this message (an icon) the message #iconIndex. This message is understood from the icon that answers with its own iconIndex.

So the only method I need to impement is #icon in my class Connection that I implemented as follows:

icon opened ifTrue: [^Connection connectedIcon] ifFalse: [^Connection unconnectedIcon]

In the class itself the two icons are imported in the image by evaluating the createIconMethod, as explained in the blog article 'Beauty with less Beast'.

So my problems are solved.

Thanks to all. Maurizio.