FAQ: Finding Code in an Image
Last updated at 3:08 am UTC on 12 May 2018
How do I find the code that does X in Squeak? For example, how do I find the code that handles the "save and quit" menu item?
On the menus there are a couple of possibilities. Let's, for example, try to find out how the "help..." item in the World menu works:
- Open a Method Finder and in the top pane type help or world or menu. Hit return and in the pane below will be a list of symbols continaing that string. Any one of these would contain something of interest: buildWorldMenu or helpDo, in this case. Note that most menus are dynamically constructed when needed, so all you need to do is modify the method that builds the menu and save the image to make the change permanent.
- An alternative approach is to search for the text contained in the menu. Type help... in a Workspace, select it and press cmd-shift-e (which is "method strings with it" in the pop-up menu). Up pops a browser listing the three methods that reference a string containing the characters typed. Again, change the appropriate method and you're in business.
Regarding the windows present in the Squeak distributed image, some (the Play with me's) are projects. Click in one of these windows and pick "enter" from the menu that appears. Once in the project, all morphs can be manipulated (inspected, moved, trashed, etc) by cmd-clicking on the morph and clicking on the appropriate halo. The other windows are simple workspaces with text typed in them. BobArning
A really fun way to do this is to interrogate the menu itself, which is easy in Morphic.
- Show the menu (can help to pin it down first),
- Blue button click on the save-and-quit menu item. This brings a halo on the menu.
- Blue button click again on the save-and-quit menu item. Now the halo is on the menu item itself.
- Red button click the red menu halo to show the menu.
- Choose debug and then explore morph.
- Expand the root:morph and look at the possibilities. In particular there is one called selector that says #doMenuItem:with:. That selector isn't the one we want here, but it's second argument (left click the triangle to expand the arguments) is #saveAndQuit. David Mitchell