| Search Locate Previous Next | Contents |
In Causeway, you define menus as simple text variables. This is partly to make them easy to edit, and also to allow the possibility of saving several alternative menus on file if you need to make your system language-independent. The basic format of a Causeway menu is:
[Root] &File>file &Help>help [file] &New : NEWFILE ª file'(untitled)' ª inx1 : file,inx &Save : SAVEFILE file ------------- E&xit:Post 'SC' [help] &About:#.Win.Msg 'My Program' 'Keep off'
Each menu or submenu is entered in a section, with its name in [brackets] like this. Note that these names are case-sensitive! The menu items start with a caption, and are then followed either by a > symbol (which points to a sub-menu section) or a colon and the APL code to execute when the user selects this menu item. Optionally, you may add another colon and a list of names to holler (separated by commas as for the event table).
To try this out, make a vector of text (mm'[Root]' '') and edit it to look like the example above.
Then call up your form and set the menu name as the Menu property on the main form. You might also like to set the Titlebar property to an expression such as:
file,' - Contacts'
... with a dependency on file. Note that the form must update the titlebar when the filename changes that is why you hollered it in the menu-item action.
Now when you CPro.Call the form you will have a working menu, and you can check out File,New and File,Exit. This uses another of the Causeway utilities CPro.Post to send an event to another object in this case it sends a System Close to itself (as far as Causeway is concerned, a menu is just a property of the form, so this closes the form). We could equally well have chosen to:
CPro.Return 'All done' ... or ¸ CPro.Do 'Close'
... but note that this last example gives no possible opportunity for your application to intervene with an Are you sure? it just closes.
Adding Hints and Shortcut Keys
If you start any standard Microsoft application, you will see that as you run the mouse down the menu you get an expanded description of the caption in the status bar at the foot of the form. It has also become the norm to allow Ctrl+N as a shortcut for File,New and Ctrl+S to serve as File,Save. To specify these in the menu definition requires a little overloading of the caption:
[file] &New=Ctrl+N;Clears a new contacts file: NEWFILE &Save=Ctrl+S;Saves your work to the current file: ... ... and so on
To set the shortcut key, use any combination of Alt+Shift+Ctrl+A Z or the same combinations +F1 F12, Home, End, PgUp, PgDn, Enter, Esc. Note that the longer text is a very good source of documentation for the maintenance programmer, as APL allows you to double-click anywhere in a text vector to edit the name at the cursor. Even if you dont need these hints for the user, add them for yourself, or whoever comes after you, as executable documentation.
Here is the menu I made for the contacts application:
menu_main [Root] &File>file &View>view &Help>help [file] &New=Ctrl+N;Clear all data : NEWFILE ª ... &Open=Ctrl+O;Open an existing file : OPENFILE ... &Save=Ctrl+S;Save your work : SAVEFILE ... Save&As;Save with a new name : SAVEFILE ... ------------- E&xit:Post 'SC' [view] &Options:#.Win.Msg 'Preferences' [help] &About:#.Win.Msg 'My Program' 'Keep off'
Just as with dialogue boxes, it is a good idea to invent a convention for menu names and stay with it. I normally use menu.xx as the menu that associates with dbx.xx, but you might want to keep all your menus and dialogues together in the same namespace.
Including the Same Options on a Toolbar
In Causeway, you treat toolbars just like any other kind of form you can even run them stand-alone to test out the actions. You then make them as part of the Create action on the main form and they duly attach themselves to the appropriate edge of their parent. Long thin toolbars stretch themselves out along the top edge and tall ones snap to the left edge. At the moment Causeway does not support drag-off floating toolbars in true Microsoft style sorry.
For a horizontal toolbar, the depth of the bar is set by the vertical dimension of the form this is a change from Causeway shareware when the designed shape of the toolbar was completely ignored. To get a toolbar nicely resized, use the Causeway utility #.Class.MakeBar, which checks the bounding box of the tools that you define and makes the tool bar deep enough to enclose all of them, leaving a symmetrical margin top and bottom (or side-to-side for a tall toolbar).
To design our new toolbar we specify a particular form class as the left argument to Dbx:
'tb' Dbx 'dbx.tb' dbx.tb#.Class.MakeBar dbx.tb © Tidy up the form shape
... I have added a tool button and set its caption to the special value *New which will invoke Dyalogs built-in bitmap for this operation. The Designer does not show captions on tool buttons instead you see the caption as a pop-up tip when the mouse is over the button.
Check out the Cue-card on the right-mouse menu for tool buttons to see what other built-in bitmaps are available, and note that you can set your own tips and bitmaps. For the moment, just add tool buttons to duplicate File,Open and File,Save, and possibly a Close button anchored right. The finished dialogue box could look a little like:
Disp dbx.tb[;1 2 5]ÚÎÎÂÎÎÎÎÎÎÎÎÎÎÂÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÌ
ÛTBÛ(untitled)ÛÚÎÎÎÎÂÎÎÎÎÌ Û
Û Û ÛÛ Û Û Û
Û Û ÛÀÎÎÎÎÁÎÎÎÎÙ Û
ÃÎÎÏÎÎÎÎÎÎÎÎÎÎÏÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÝ
ÛTLÛ*New ÛÚÎÎÎÎÎÎÎÎÎÂÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÌÛ
Û Û ÛÛBehaviourÛÚÎÎÂÂÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÂÎÎÎÎÎÎÎÎÎÎÎÌÛÛ
Û Û ÛÛ ÛÛSLÛÛNEWFILE ª file(un... Û{fileÛinx}ÛÛÛ
Û Û ÛÛ ÛÀÎÎÁÁÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÁÎÎÎÎÎÎÎÎÎÎÎÙÛÛ
Û Û ÛÀÎÎÎÎÎÎÎÎÎÁÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÙÛ
ÃÎÎÏÎÎÎÎÎÎÎÎÎÎÏÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÝ
ÛTLÛ*Open ÛÚÎÎÎÎÎÎÎÎÎÂÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÌÛ
Û Û ÛÛBehaviourÛÚÎÎÂÂÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÂÎÎÎÎÎÎÎÎÎÎÎÌÛÛ
Û Û ÛÛ ÛÛSLÛÛOPENFILE file#.Win... Û{fileÛinx}ÛÛÛ
Û Û ÛÛ ÛÀÎÎÁÁÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÁÎÎÎÎÎÎÎÎÎÎÎÙÛÛ
Û Û ÛÀÎÎÎÎÎÎÎÎÎÁÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÙÛ
ÃÎÎÏÎÎÎÎÎÎÎÎÎÎÏÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÝ
ÛTLÛ*Save ÛÚÎÎÎÎÎÎÎÎÎÂÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÌ Û
Û Û ÛÛBehaviourÛÚÎÎÂÂÎÎÎÎÎÎÎÎÎÎÎÎÎÎÂÎÎÌÛ Û
Û Û ÛÛ ÛÛSLÛÛSAVEFILE fileÛ{}ÛÛ Û
Û Û ÛÛ ÛÀÎÎÁÁÎÎÎÎÎÎÎÎÎÎÎÎÎÎÁÎÎÙÛ Û
Û Û ÛÀÎÎÎÎÎÎÎÎÎÁÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÙ Û
ÀÎÎÁÎÎÎÎÎÎÎÎÎÎÁÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÙ
Now all we need to do is to add it to the event-action table of the main form, and the application begins to look quite professional!
Disp ((1 5),(1 2))dbx.mfÚÎÎÂÂÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÂÎÎÌ
ÛCRÛÛ¸ Do SetIcon cau... Û{}Û
ÃÎÎÏÏÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÏÎÎÝ
ÛCRÛÛinx1 Û{}Û
ÃÎÎÏÏÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÏÎÎÝ
ÛPCÛÛMake dbx.tb Û{}Û
ÀÎÎÁÁÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÁÎÎÙ
Bug Alert! This example drew the toolbar correctly, because it was made on a Post-Create (PC) event, rather than on Create! Post-Create is a kludge it runs after the first refresh of the object, so in this case it occurs after the menu has been added to the form. If you put the CPro.Make dbx.tb on the Create, the top line of the toolbar is not drawn properly, as Dyalog adds the menu over the top (by about 1 pixel) of the toolbar.