13.2 Menu Editor
The easiest way to equip your program with a menu (→ Figure 13.2.4) is to use the menu editor. It is a good plan if you record this structure - especially with a complex menu structure - and then map it in a table:
| Name | Level | Group | Caption | Action | Day | Shortcut | V | E | T | C |
|---|---|---|---|---|---|---|---|---|---|---|
| mnu1Menu | 0 | ~ | Picturefile | ~ | ~ | CTRL+W | + | + | ~ | ~ |
| mnu11Open | 1 | ~ | Open… | OpenImage | CTRL+O | + | + | ~ | ~ | |
| mnu12New | 1 | ~ | New | ~ | ~ | CTRL+N | + | + | ~ | ~ |
| mnu13Space | 1 | ~ | ~ | ~ | ~ | ~ | + | + | ~ | ~ |
| mnu14Print | 1 | ~ | ~ | ~ | CTRL+P | + | ~ | ~ | ~ | |
| mnu15Close | 1 | ~ | Exit | FormClose | ~ | CTRL+Q | + | + | ~ | ~ |
| mnu2Menu | 0 | ~ | Extras | ~ | ~ | ~ | + | + | ~ | ~ |
| mnu21Options | 1 | ~ | Options | ~ | ~ | ~ | + | + | ~ | ~ |
| mnu22SelectColor | 1 | ~ | Select color | ~ | ~ | ~ | + | + | ~ | ~ |
| mnu221Palette1 | 2 | ~ | Colourchart1 | ~ | ~ | ~ | + | + | ~ | ~ |
| mnu222Space | 2 | ~ | ~ | ~ | ~ | ~ | + | + | ~ | ~ |
| mnu223Palette2 | 2 | ~ | Colourchart2 | ~ | ~ | ~ | + | + | ~ | ~ |
| mnu23PreView | 1 | ~ | Preview | ~ | ~ | ~ | + | + | ~ | ~ |
| mnu3Menu | 0 | ~ | Help | ~ | ~ | ~ | + | + | ~ | ~ |
| mnu31Help | 1 | ~ | Help | HelpMe | ~ | F1 | + | + | ~ | ~ |
| mnu32Web | 1 | ~ | Onlinehelp | ~ | ~ | ~ | + | + | ~ | ~ |
Table 13.2.1: Menu structure (V=Visible, E=Enabled, T=Toogle and C=Checked)
- by clicking on the Menu Editor button in the menu bar (above the form),
- with the key combination CTRL+E or
- after clicking the right mouse button on the form in which you activate the menu editor entry from the context menu that opens.
Figure 13.2.1: (partial) view of the menu editor
When you create a menu structure, the following steps have been tried and tested:
- A click on the Insert button in the menu editor creates a new menu entry.Enter the information from your table in the upper and lower part of the menu editor for each menu item → figure 13.2.1 and → figure 13.2.2.You can correct (change or delete) your entries at any time.
- If you leave the text field blank at Caption, a dividing line between two menu entries is automatically created in the menu at runtime. The name of the menu item only appears in the menu editor in light grey.
- Change the level of a menu item by selecting the menu item and then increasing or decreasing the level using the two indent and move buttons. The small dots in front of the menu item indicate the current level. In the menu editor, you can recognize a menu item of level zero by its font style bold.
- You can move a menu item with the two buttons' Move up' and' Move down' in the menu structure. Please make sure that you adjust the names of the menu entries if this name indicates a ranking and sequence.
- Assign a suitable icon from the collection of gambas to the individual menu entries if you want to follow the usual practice with menu entries.
- Check all entries in the menu editor carefully before closing the menu editor.
Figure 13.2.2: (Part) view2 of the menu editor
Confirm all entries or changes in the menu editor with OK. When you close the menu editor although you have made changes, the system asks whether you want to save the changes:
Entries in the menu editor for Action are only necessary if, for example, you want to use the Action class for synchronization between the menu and an inserted toolbar. The chapter' 13.5 Menu and Toolbar' explains how to implement this synchronization.
Figure 13.2.4: Select 'Exit' menu item
To do this, click on the entry you want to add code as an event handling procedure in the form menu; for example, for the mnu15Close_Click() event:
Public Sub mnu15Close_Click() FHelp.Close FMain.Close End ' mnu15Close_Click()
Further procedures (selection):
Public Sub mnu11Open_Click() ImageOpen() mnu14Print.Enabled = True End ' mnu11Open_Click() Public Sub mnu15Close_Click() FHelp.Close FMain.Close End ' mnu15Close_Click() Public Sub mnu23PreView_Click() If mnu23PreView.Checked = True Then Message.Info("Show preview or" & gb.NewLine & "Generate preview image or...") Endif ' Checked = True End ' mnu23PreView_Click() Public Sub mnu31Help_Click() FHelp.Show End ' mnu31Help_Click() Public Sub mnu32Web_Click() Desktop.Open("http://www.gambas-buch.de/dw/doku.php?id=k13:start") End ' mnu32Web_Click()
Note that you cannot assign procedures to all menu entries. This applies, for example, to all entries of level 0 as well as to entries that contain further entries as (sub-)menus as in mnu22SelectColor.
Whether you make entries in the Tag text field (data type Variant) depends on whether you later evaluate this entry in the program and react depending on the evaluation result.
In the example FNotepad 3.0.0 in the Gambas examples it is demonstrated that you can also select a menu at runtime of the program via ALT+underlined_letters, if you prefix the selected letter with a & sign in front of the entry' Caption'. For example, the combination ALT+a calls the save dialog:



