[enh] factored HandMorph openMenu

Stephan B. Wessels stephan.wessels at sdrc.com
Tue Mar 7 21:52:23 UTC 2000


Have you ever had a situation where multiple change sets you've written all make
extensions or modifications to the #openMenu method in HandMorph?  It's pretty
easy to get a collision where you edit the method but forget to file out all of
the change sets that have conflicting interests.  Later when you load them back
in to a "virgin" image, the last change set loaded "wins" with it's version of
the open menu.

Or how about when someone adds some really cool new tool you just have to
install, but then notice that your own menu items were replaced?

This change set addresses the issue of individuals wanting to add their own
extensions to the open menu method in HandMorph without colliding and
overwriting.  It uses the same technique used in the latest Preferences code in
V2.8a.  I've extended the open menu, appearance menu and changes menu to use
this technique.  I've also added a hook to the file list menu that gets modified
pretty often in File List too.

For the HandMorph open menu here's the procedure you use to add in your own open
menu items:

1. Create a new method to add your menu item in the HandMorph category 'user
defined open menu items'.  For example the menu item should look like this...
(note the argument <menu> is passed along)

    openDualFileListMenuItem: menu

     | morphItemAbove item |
     morphItemAbove _ menu lastItemWithSelector: #openFileDirectly.
     morphItemAbove isNil ifTrue: [^nil].
     item _ MenuItemMorph new
          contents: 'dual file list';
          target: menu defaultTarget;
          selector: #openDualFileList;
          arguments: EmptyArray.
     item setBalloonText: 'Open up a dual file list.'.
     menu addMorph: item behind: morphItemAbove.

The above example adds a menu item named 'dual file list' with the selector
#openDualFileList that gets inserted directly underneath the existing menu item
that uses the selector #openFileDirectly.

To add a menu line do something like this inside the method:

     menu addMorph: MenuLineMorph new behind: aPreviousMenuItemMorph.

You can also just add new menu items easily to the end of the open menu by
writing a method using the standard add:action: type selectors.

The beauty of this approach to extending the open menu is that you keep the
parts that are pertinent to the change set you are writing with the change set
and you leave the open menu code alone.  (After this extension gets installed of
course).

I encourage that we adopt this technique for menus that have level of sharing.
About the only likely collisions now would be common method names.

Hope someone likes this...

  - Steve

-------------- next part --------------
A non-text attachment was scrubbed...
Name: refactor-menus.06Mar1632.cs
Type: application/x-unknown-content-type-cs_auto_file
Size: 18413 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20000307/aae6bcc0/refactor-menus.06Mar1632.bin


More information about the Squeak-dev mailing list