Squeak
  links to this page:    
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
How to study a menu
Last updated at 5:46 am UTC on 26 May 2007
From ye juan January 18, 2004 How to study a menu
I want to do something about "save a project on local file". In the world menu, the selector is #saveOnFile, however, I can not get anything useful from it.

How to save a part bin How to fish for it
If you open the World menu, then get a halo on the "save project on file" menu item [meta click once to get the halo on the menu, then again to get the menu on the specific item], you can then inspect the item. If you then look at the MenuItemMorph's instance variables, you will see that:
And then we look at implementors of doMenuItem:with: and we see that TheWorldMenu defines this as:
doMenuItem: aCollection with: event
	| realTarget selector nArgs |
	selector _ aCollection second.
	nArgs _ selector numArgs.
	realTarget _ aCollection first.
	realTarget == #myWorld ifTrue: [realTarget _ myWorld].
	realTarget == #myHand ifTrue: [realTarget _ myHand].
	realTarget == #myProject ifTrue: [realTarget _ self projectForMyWorld].
	^nArgs = 0 
		ifTrue:[realTarget perform: selector]
		ifFalse:[realTarget perform: selector with: event].
So now we know that when this item is selected, this is the equivalent of what happens:
“menu myWorld saveOnFile�. Which is the same as: “ActiveWorld saveOnFile� since ActiveWorld will be set to the world in which the menu is raised. So now we can do this from a program.

Going a bit further, we see that PasteUpMorph>>saveOnFile (for a World) actually does "self project saveAs", which does this:
	self forgetExistingURL.
	self storeOnServer.
So you could get the same effect for the current Project by just doing this:
     Project current saveAs.
By following the definitions of Project>>storeOnServer further, you will see how it works.

Also see How to study a menu
for a step by step example of getting secrets out of the menu code.