Recipe: Creating a 'jump-to-project' button
Last updated at 8:56 am UTC on 3 April 2019
On way to use Squeak/Morphic as a presentation system is to use each project as a slide. The slides may contain active content or just static text, pictures and sound buttons. See examples on Bob's SuperSwiki.
An important ingredient for this is a 'jump-to-project' button. Of course there is a 'jump-to-project' menu item, but for an info kiosk, for example, this is too clumsy. Two or three simple buttons like 'Previous', 'Home' and 'Next' will do the job.
Let's say we want to create a button which opens the project named 'Slide08'. This assumes that you have named each project after you have created it.
Make sure you are in a Morphic project.
Open a Workspace and paste in the following code:
b := SimpleButtonMorph new.
b target: (Project named: 'Slide08').
b actionSelector: #enter.
b position: (Project current world bounds bottomRight - (40 @ 40)).
b label: 'Next'.
Select the code and evaluate it.
(Squeak 4.1 OK)
Close the Workspace and discard the content.
Another solution is to put the following code into a workspace and select it.
(Project named: 'Slide08') enter
Then choose 'button for it' from the menu.
The expression (Project named: 'Slide08') gives access to the Project object with the name 'Slide08'. When you send it the message 'enter' the project is opened.
All projects are kept in the class variable 'AllProject' of the class 'Project'. A Project object has an instance variable 'nextProject'. There is no setter in Squeak 3.1-4173 for this variable. Of course you can add one and make use of this and make the 'next project' button of the golden ProjectNavigation Morph functional by adding some code. But perhaps you dont want to use the ProjectNavigation Morph (Preferences 'showProjectNavigator') and implement two simple 'previous' and 'next' buttons. For this case this recipe has been written.
This works for Squeak versions 2.8 and later.
To facilitate the task you may write a utility method which takes the names of the previous, the home and the next project as arguments and creates the buttons.
Also see Project and look at the class side of Project for additional interesting information.