[Cuis-dev] Decentralized menu definition

Hilaire Fernandes hfern at free.fr
Thu Jul 21 08:32:08 PDT 2022


Le 21/07/2022 à 13:31, Gerald Klix via Cuis-dev a écrit :
> Let me point out that Haver already has an
> ActionBuilder package that provides some means
> to define menus and LayoutMorphs with
> buttons -- sort of a toolbar -- in one place.

Thanks for the code example, Gerald, it is helpful.

As a matter of comparison, here is how you will define a menu and sub 
menu spread in several image, possible from different package.

The menu is identified by #exampleMenu used as a pragma tagging the 
relevant methods. Below this #exampleMenu definition is distributed in 
four methods.

*example1_1: menuBuilder*
     <exampleMenu>
     menuBuilder newEntry: #entry1 ::
         label: 'Menu entry 1';
         icon: #worldIcon;
         order: 500.
     menuBuilder newEntry: #entry2 ::
         label: 'Menu entry 2';
         help: 'I can have help too';
         order: 100

*example1_2: menuBuilder*
     <exampleMenu>
     menuBuilder newEntry: #entry3 in: #entry1 ::
         label: 'Menu entry 3';
         order: 1.

*example1_3: menuBuilder*
     <exampleMenu>
     menuBuilder newEntry: #entry4 ::
         label: 'Menu entry 4';
         order: 1.
     menuBuilder newEntry: #'Just a drop place' in: #entry1

*example1_4: menuBuilder*
     <exampleMenu>
     menuBuilder newEntry: #entry5 in: #'Just a drop place'::
         label: 'Menu entry 5'

To get the menu, you just ask for the #exampleMenu:

(MenuBuilder on: #exampleMenu) menu popUpInWorld

Built menus


The menu entries are ordered as specified in the methods. A third party 
package can decide in one of its methods to add menu entries in 
different location of an existing menu hierarchy. To add entries in 
another menu, it should be done in another method with the add-hoc pragma.

Now, if it please you, you can replace menu by command. In the 
implementation of MenuRecord I used a MenuItem instance variable as a 
drop place to put attributes, to avoid adding a third class Command or 
attributes to MenuRecord

It is completely neutral, so we can have:

MenuBuilder -> CommandBuilder

MenuRecord -> CommandRecord

And invoked as:

(CommandBuilder on: #exampleCommand) getMenu popUpInWorld

one may extend it to respond to:

(CommandBuilder on: #exampleCommand) getCircularMorph openInWorld


(CommandBuilder on: #exampleCommand) getToolbar


Ideas borrowed from Pharo, implemented differently and likely less 
capable but easier to understand for me.

Hilaire

-- 
GNU Dr. Geo
http://drgeo.eu
http://blog.drgeo.eu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20220721/20186651/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Capture%20d%E2%80%99%C3%A9cran%20de%202022-07-21%2016-48-17.png
Type: image/png
Size: 10898 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20220721/20186651/attachment-0001.png>


More information about the Cuis-dev mailing list