Custom list/tree items in Spec
Hi, if it possible to design custom item model for list or tree item in Spec? I know that there is an option to add icon and so on, but can I design my own model? For example make it a two line item with 2 radio buttons⦠Cheers Uko
2014-09-24 10:42 GMT+02:00 Yuriy Tymchuk <yuriy.tymchuk@me.com>:
Hi,
if it possible to design custom item model for list or tree item in Spec? I know that there is an option to add icon and so on, but can I design my own model? For example make it a two line item with 2 radio buttonsâ¦
Cheers Uko
You can do funny/ugly things in spec, don't know if this is supposed to work that way, but it does. (The magic lies in the displayBlock... buildWithSpec) | nodeCreator ui layout | "helper block for creating a dynamicmodel based on a FileReference item" nodeCreator := [ :item | | uii layouti | uii := DynamicComposableModel new. uii instantiateModels: #(#text LabelModel #button1 #CheckBoxModel #button2 #CheckBoxModel). layouti := SpecLayout composed newColumn: [ :col | col add: #text; newRow:[:row| row add: #button1; add: #button2 ] ] yourself. uii button1 label: 'writeable'. uii button2 label: 'readable'. uii text text:item pathString. uii button1 state: item isWritable. uii button2 state: item isReadable. uii button2 whenChangedDo:[: s | s inform:'me changed']. uii layout:layouti. uii ]. "this is the main widget " ui := DynamicComposableModel new. ui instantiateModels: #(#tree #TreeModel). ui tree roots: {(FileLocator desktop)}. ui tree childrenBlock: [ :it | it isDirectory ifTrue: [ it children collect: [ :item | |icon| icon := item isDirectory ifTrue: [ Smalltalk ui icons smallOpenIcon ] ifFalse: [ Smalltalk ui icons smallLeftFlushIcon ]. TreeNodeModel new content: item; icon: icon .] ] ifFalse: [ {} ] ]. ui tree rootNodeHolder: [ :item | | icon | icon := item isDirectory ifTrue: [ Smalltalk ui icons smallOpenIcon ] ifFalse: [ Smalltalk ui icons smallLeftFlushIcon ]. TreeNodeModel new content: item; icon: icon ]. "dynamically build treenode*morph* by calling the spec interpreter with our nodecreator block" ui tree displayBlock: [ :item |self haltOnce. (nodeCreator value: item) buildWithSpec]. layout := SpecLayout composed newColumn: [ :c | c add: #tree ]; yourself. ^ ui openWithSpecLayout: layout
participants (2)
-
Nicolai Hess -
Yuriy Tymchuk