Skip to content

Instantly share code, notes, and snippets.

@philippeback
Created September 1, 2014 19:18
Show Gist options
  • Save philippeback/b7ac873f8b05a7cb2333 to your computer and use it in GitHub Desktop.
Save philippeback/b7ac873f8b05a7cb2333 to your computer and use it in GitHub Desktop.
Spec Tutorial in a Worskspace
ComposableModel subclass: #MyModelList
instanceVariableNames: 'list'
classVariableNames: ''
category: 'Spec-Tutorial'.
MyModelList compile: 'initializeWidgets
list := self newList.
list items: (AbstractWidgetModel allSubclasses
sorted: [:a :b | a name < b name ]).
self focusOrder add: list' classified: #initialization.
MyModelList class compile: 'defaultSpec
<spec: #default>
^ SpecLayout composed
add: #list;
yourself'.
MyModelList compile: 'list
^ list'
classified: #accessing.
MyModelList compile: 'title
^ ''Widgets''' classified: #protocol.
MyModelList compile: 'whenSelectedItemChanged: aBlock
list whenSelectedItemChanged: aBlock
' classified: #'protocol-events'.
ComposableModel subclass: #MyProtocolList
instanceVariableNames: 'label protocols'
classVariableNames: ''
category: 'Spec-Tutorial'.
MyProtocolList compile: 'initializeWidgets
protocols := self newList.
label := self newLabel.
label text: ''Protocol''.
protocols displayBlock: [ :m | m selector ].
self focusOrder add: protocols' classified: #initializing.
MyProtocolList class compile: 'defaultSpec
<spec: #default>
^ SpecLayout composed
newColumn: [ :column |
column
add: #label
height: self toolbarHeight; "This one is in ComposableModel"
add: #protocols ];
yourself'.
MyProtocolList
compile: 'label
^ label' classified: #accessing;
compile: 'protocols
^ protocols' classified: #accessing;
compile: 'items: aCollection
protocols items: aCollection' classified: #protocol;
compile: 'label: aText
label text: aText' classified: #protocol;
compile: 'resetSelection
protocols resetSelection' classified: #protocol;
compile: 'title
^ ''Protocol widget''' classified: #protocol;
compile: 'whenSelectedItemChanged: aBlock
protocols whenSelectedItemChanged: aBlock' classified: #'protocol-events'.
(MyProtocolList new items: Collection allSubclasses; yourself) openWithSpec.
ComposableModel subclass: #MyProtocolViewer
instanceVariableNames: 'models protocols events'
classVariableNames: ''
category: 'Spec-Tutorial'.
MyProtocolViewer compile: '
initializeWidgets
models := self instantiate: ModelList.
protocols := self instantiate: MyProtocolList.
events := self instantiate: MyProtocolList.
protocols label: ''protocol''.
events label: ''protocol-events''.
self focusOrder
add: models;
add: protocols;
add: events' classified: #initalization.
MyProtocolViewer class compile: 'defaultSpec
<spec: #default>
^ SpecLayout composed
newColumn: [ :column |
column
add: #models;
add: #protocols;
add: #events ];
yourself'.
MyProtocolViewer compile: 'initializePresenter
models whenSelectedItemChanged: [ :class |
self resetProtocolSelection.
self resetEventSelection.
class
ifNil: [
protocols items: #().
events items: #() ]
ifNotNil: [
protocols items: (self methodsIn: class for: ''protocol'').
events items: (self methodsIn: class for: ''protocol-events'') ] ].
protocols whenSelectedItemChanged: [ :method | method ifNotNil: [ self resetEventSelection ] ].
events whenSelectedItemChanged: [ :method | method ifNotNil: [ self resetProtocolSelection ] ].'.
"Now, I got fed up with the compile:classified: which would be nicer the other way around for a tutorial. Let's fix this".
TClassDescription compile: '
classified: heading compile: code
self compile: code classified: heading' classified: #compiling.
MyProtocolViewer
classified: #accessing
compile:'events
^ events';
classified: #accessing
compile: 'models
^ models';
classified: #accessing
compile: 'protocols
^ protocols';
classified: #private
compile: 'methodsIn: class for: protocol
^ (class methodsInProtocol: protocol)
sorted: [ :a :b | a selector < b selector ]';
classified: #protocol
compile: 'resetEventSelection
events resetSelection';
classified: #protocol
compile: 'resetProtocolSelection
protocols resetSelection';
classified: #protocol
compile: 'title
^ ''Protocol viewer''';
classified: #'protocol-events'
compile: 'whenClassChanged: aBlock
models whenSelectedItemChanged: aBlock';
classified: #'protocol-events'
compile: 'whenEventChangedDo: aBlock
events whenSelectedItemChanged: aBlock';
classified: #'protocol-events'
compile: 'whenProtocolChangedDo: aBlock
protocols whenSelectedItemChanged: aBlock'.
MyProtocolViewer new openWithSpec.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment