But this is not an operation that he will do nearly as often as adding/deleting names. So, it would be preferable to put this function into a menu.
A menu attaches to the titlebar of the window, and will drop down when the user clicks the mouse on a Menu Heading in the titlebar. (ie, The items for that Menu Heading are displayed). The user can then make selections with the mouse. Alternately, if the items have "mnemonic keys", those keys can be used to open and select menu items. Each menu item can itself have one or more "sub items" extending off of it.
Here is an example of what a menu could look like:
In the above menu, there are 2 headings labeled "File" and "Edit". The "File" heading has been clicked upon so that its items are displayed below. Those items are labeled "Open" and "Save", and the "Open" item itself has two sub-items labeled "All" and "Excerpt" which are shown when "Open" is highlighted.
You can attach one, and only one, menu to a particular window at any given time. But you can change a window's menu to a different menu at any time.
Let's create a menu for our List of Names window. First, flip to the editor window containing ListOfNames.rex.
To create a menu, select the Resources -> Menu menu command. This will pop open an empty window with a title of "(default)". You'll also see a new "Menu" heading appear in the resources, and if you click on it, you'll see that a new menu has been added with a name of "(default)" as so:
Now look at that window titled "(default)". You'll notice that it looks like it has a menu bar, but it is empty except for a dotted box:
This dotted box is showing you where you can add a new item to the menu bar. Let's add a "File" heading. Move the mouse pointer over the box, as shown above, and double-click the left mouse button. This will pop up the "MENU Properties" dialog. It has numerous settings for this new item. Into the box labeled Caption, type File. Now click the OK button and the MENU Properties dialog will disappear.
You should now notice that a "File" heading has been added to the menu. There is now a dotted box next to it, so that you can add a second heading to the menu if desired, just like you added the File heading.
But if you move the mouse pointer over the word "File", and click the left mouse button, you'll notice that the File heading highlights and drops down, and there is another dotted box below, as so:
This other box is showing you where you can add a new item that falls under the File heading. Move the mouse pointer over that box, and doubleclick the left mouse button. This brings up the MENU Properties dialog once again. Into the box labeled Caption, type Open. Now click the OK button and the MENU Properties dialog will disappear.
Once again, move the mouse pointer over the word "File", and click the left mouse button. You'll notice that the File heading highlights and drops down, and there is now an "Open" item under it. The dotted box has moved down to show you where you can add another item under the File menu. Doubleclick on this new box to bring up its menu properties.
Into Caption, type &Save. Also, check the box labeled Pop-up. This means that we intend to add sub-items to this new item. Now click the OK button and the MENU Properties dialog will disappear.
Tip: Placing a & character before some letter in the caption, means that, when the menu is displayed, pressing that letter on the keyboard activates the menu heading\item\subitem associated with that caption. This is a mnemonic.
Once again, move the mouse pointer over the word "File", and click the left mouse button. You'll notice that the File heading highlights and drops down, and there are now "Open" and "Save" items under it. Move the mouse over "Save" and click the left button once. You'll see that the Save item is highlighted and a dotted box appears to the right of it. This is showing you where you can now add a sub-item off of the Save item.
Move the mouse pointer over this box to the right of "Save" and doubleclick on it. Again, the MENU Properties comes up. Into Caption, type All, and then click the OK button.
You'll see that you have now built up a menu that looks like this:
If desired, you can select the Resources -> Quick test command to see how this menu will look and operate when attached to a window. To end the test, simply close the window showing your test menu.
Handling menu selection
Just like with every control in a window, each menu item can have a REXX variable associated with it. For "Pop-up" items, you do not need to associate a variable unless you want to later modify that item.
So too, you can add a subroutine to be called whenever the user selects a particular menu item. (Pop-up items can't be "selected" by the user, so you can't set a handler for them).
Let's associate a variable of "OpenNames" with the "Open" menu item. Double-click on the "Open" item to bring up its MENU Properties dialog. Into the ID box, type OpenNames. Now, click on the Add Event Handler button. A new subroutine is added to the end of our main script as so:
OpenNames: RETURNNext, double-click on the "All" sub-item to the right of "Save". Into the ID box, type SaveNames. Now, click on the Add Event Handler button. A new subroutine named SaveNames is added to the end of our main script.
Note: If you do not first associate a REXX variable with an item, before you click on Add Event Handler, then Programmer Center will create a subroutine name (from the menu captions) that will work with REXX GUI. This is useful to save time (and some memory). But the subroutine name may not be quite as meaningful as picking your own variable name, and depending upon what captions you use, there could be a potential conflict between two items.
Note: You should use unique variables names for each menu item. But it is acceptable to have a control share a variable name with a menu item. A menu item's "variable name" is used only as its handler subroutine name, and therefore never interferes with a control's variable.
We're done creating our menu, so you can now close the (default) menu editor window.
Now let's add an instruction to OpenNames as so:
OpenNames: GuiSay("File -> Open selected") RETURNAnd add this to SaveNames:
SaveNames: GuiSay("File -> Save -> All selected") RETURN
Setting the window to use a menu
We have one final thing to do. We need to set our main window to use this menu. Doubleclick on the (default) "Window" resource to bring up the List of Names window we're designing. Doubleclick on the titlebar to bring up its WINDOW Properties dialog.You'll notice that the Menu field is currently set to "(none)". If you drop down the box, you should see our "(default)" menu item listed. Select it. Now click on the OK button. You have just set the List of Names window to use that menu. You should see the menu appear in the window (although you can't operate it unless you do a quick test, or run the script).
Run the script and select the Open or Save -> All menu items, and you should see the appropriate message box displayed.