Extra practice
Changing the window's title
To add a statement to your openFile script that changes the window title, use the Subpart Features Syntax tool, Subpart Features Syntax icon.
To set the title to the file name that the user selected, add the following statement to the end of your script:
(self subpartNamed: 'Window') title: file.
Connections to connections
Because connections are also VA Smalltalk parts, you can add event-to-script connections to a connection. Add the following new script to the fileSelection category and make it run when the result event occurs:
beep
"beeps just to try out event-to-script connections"
CgDisplay default bell: 20.
Create the connection by clicking mouse button 2 (mouse button 3 on UNIX systems) on the event-to-script connection line that you already created, and then select Connect > normalResult. Click mouse button 1 on the free-form surface. Select Event to Script from the pop-up menu. Select beep from the method list and then select OK.
If you have made the connection properly, you should see a new connection line from the middle of your first connection to an icon representing the beep script. When you test your view, you should hear a beep when the file is opened.
Tip icon
Timing considerations must be taken into account when establishing your connections or accessing parts through scripts.
When creating an "attribute changed" event-to-script connection, do not try to use an attribute-to-attribute connection to the changing attribute to pass a parameter on the event-to-script connection. The attribute might not actually be changed yet. Use the value that is passed as a parameter on the event notification instead.
Changing categories
Try moving the beep script created above to a new category. Select the beep script and then select Categorize > Change Categories from the method list pop-up menu. Select <new category> in the Selection Required window and then select OK. In the prompter window, type in aNewCategory and select OK. Now, test your window again. VA Smalltalk maintains all connections when a script is moved.
Try moving the beep script back to the fileSelection category. VA Smalltalk shows you that the category aNewCategory is now empty.
Last modified date: 05/14/2020