2014-12-20 5:49 GMT+01:00 Daniel Lyons <fusion@storytotell.org>:
Supposing I have a domain model, Activity, which looks like this:
Object subclass: #Activity instanceVariableNames: 'title cost' classVariableNames: '' category: 'PERT'
Then I have the expected accessors for title and cost.
I make a Polymorph dialog for editing one of these things like so:
PolymorphEditActivity>>edit: anActivity | builder content dialog | activity := anActivity. builder := Smalltalk ui theme builder.
content := builder newLabelGroup: { 'Title' -> (builder newTextEntryFor: self activity getText: #title setText: #title: help: 'The title of the activity'). 'Cost' -> (builder newTextEntryFor: self activity getText: #cost setText: #cost: help: 'The cost of the activity') }. dialog := builder newPluggableDialogWindow: 'Edit activity' for: content. ^ builder openModal: dialog.
*First question*: how do I return a value from the dialog?
You don't need the return something, you don't even need to use a separate instvar in the PolymorphEditActivity. If "anActivity" is a Activity with the accessor #title / #title: #cost/#cost:, the PluggableDialogWindow will change this attributes only if the dialog is closed with "OK" | anActivity builder content dialog | anActivity := Activity new. anActivity title: 'what'. anActivity cost: '100'. builder := Smalltalk ui theme builder. content := builder newLabelGroup: {('Title' -> (builder newTextEntryFor: anActivity getText: #title setText: #title: help: 'The title of the activity')). ('Cost' -> (builder newTextEntryFor: anActivity getText: #cost setText: #cost: help: 'The cost of the activity'))}. dialog := builder newPluggableDialogWindow: 'Edit activity' for: content. builder openModal: dialog. anActivity inspect