View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Right Click Context Menus

In this case, I will walk you through a small tutorial that will explain how to put right click context menus onto your widgets. Right click menus are definitely a great way to spice up your UI and to allow users to interact with the model on a much easier scale.

First lets create a new package called "RightClickExample". I will define the namespace for the classes to be in the RightClick space. The first class I create will be called Example. Then we will create a simple window spec under the Class objects. This spec contains a list, a text box, and a text editor. From there we can either a) click the visual tab, click edit, select the widget and: under the details tab of the GUI Painter Tool enter the name of a menu or b) under the source we can set the menu through a line of code that looks like #menu: #ListRightClick (where ListRightClick is the menu resource). Make sure if you choose to do the code that you insert the menu under the appropriate item.

Now lets create the menu to link into the UI. I first create a new protocol called resources (if this doesn't already exist). Copy and paste the following code into a new method under the resources protocol:

ListRightClick
	"Tools.MenuEditor new openOnClass: self andSelector: #ListRightClick"

	
	^#(#{UI.Menu} #(
			#(#{UI.MenuItem} 
				#rawLabel: 'This is a list' ) 
			#(#{UI.MenuItem} 
				#rawLabel: 'Item 1' ) 
			#(#{UI.MenuItem} 
				#rawLabel: 'Item 2' ) ) #(2 1 ) nil ) decodeAsLiteralArray



From here, you can change the menu using strictly code, or we can click on the visual tab and hit edit.




The filed out .st package can be found here: RightClickExample.st

To run the test, type "RightClick.Example open" into a blank workspace and press ctrl+d or "do-it".

















This page was created by Brian O'Connor

Links to this Page