Excercise 6 - Substituting your own Smalltalk code
Here we will make a button that, when pressed, files out your current change set. This is to illustrate the fact that you can always "escape" from the tile-scripting framework to write your own arbitrary Smalltalk code.
- Get a parts bin.
- Drag out an ellipse.
- Drag out a "Text for Editing", and edit its text to say "File Out Changes".
- Place the text over the ellipse, nicely centered (resize the ellipse as needed), then bring up the halo for the text and choose "embed" from its menu, and embed it in the oval
- From the Text's halo menu, choose "lock", so that the label won't go into text-editing mode when the mouse comes down on it - that's not what we want here.
- Next, bring up the ellipse's halo and from the halo tear off a Viewer.
- Name the ellipse "TestButton" (you can edit the name in the halo or at the top of the viewer).
- From the viewer, tear off a "TestButton make sound croak" phrase, and drop it on the world's desktop. A scriptor opens up around it.
- From the scriptor's menu, choose "name and save this script", and give it a name like "doFileout".
- From the scriptor's status menu, change "normal" to "mouseUp". This will allow it to behave like a traditional button.
- Test the button -- when you click on it, you should hear a croak sound.
Now chose "edit script textually" in the scriptor. This will give you a message-editing window in which you can type arbitrary Smalltalk code, and it will be invoked whenever the script is triggered, be it via ticking, mouse actions, or being called from another script.
So now we type in whatever script we want, in plain Smalltalk, and submit it. For the moment, you might edit the method to look like this:
doFileout
Transcript cr; nextPutAll: 'Testing One Two Three...'.
self beep: 'croak'.Now make sure a Transcript is open, and then try the script out. When you click on the button, your message should show up in the Transcript and you should hear the croak.
This shows that the hookup is working. Now all that remains is to edit the method to do something useful; in this case, it will look like this:
doFileout
Smalltalk changes fileOut.
self beep: 'croak'Now, whenever you click on this button, the current change set will be filed out and you will get a frogly confirmation.