The model for building menus is based on the hierarchy and containership of menu objects, not the kind of menu. You don’t explicitly define menu bars, pulldown menus, or submenus. Instead, you build a hierarchy of menu objects, where each menu object contains another menu object or executes an action.

Just as a form contains controls, menus objects contain other menu objects. dBASE Plus automatically determines where menus appear based on their level in the hierarchy.

The code below is the source for the menu file described in the previous topic, and illustrates how dBASE Plus interprets and implements a menu structure.

(To view the source for any other menu file, choose a .MNU or .POP file on the Navigator’s forms page, then choose Open In Source Editor from the file’s context menu. Or you can type modi comm <filename.ext> in the Command window, where filename.ext is the .MNU or .POP file you want to examine.)

** END HEADER -- do not remove this line

//

// Generated on 10/24/97

//

parameter formObj

new mtestMENU(formObj, "root")

class mtestMENU(formObj, name) of MENUBAR(formObj, name)

this.MENU2 = new MENU(this) 

with (this.MENU2) 

text = "&File" 

endwith 

this.MENU2.MENU3 = new MENU(this.MENU2) 

with (this.MENU2.MENU3) 

text = "&Form" 

endwith 

this.MENU2.MENU3.MENU7 = new MENU(this.MENU2.MENU3) 

with (this.MENU2.MENU3.MENU7) 

onClick = {;form.close( )} 

text = "&Close" 

endwith 

this.MENU12 = new MENU(this) 

with (this.MENU12) 

text = "&Edit" 

endwith 

this.MENU12.UNDO = new MENU(this.MENU12) 

with (this.MENU12.UNDO) 

text = "&Undo" 

shortCut = "Ctrl+Z" 

endwith 

this.MENU12.CUT = new MENU(this.MENU12) 

with (this.MENU12.CUT) 

text = "Cu&t" 

shortCut = "Ctrl+X" 

endwith 

this.MENU12.COPY = new MENU(this.MENU12) 

with (this.MENU12.COPY) 

text = "&Copy" 

shortCut = "Ctrl+C" 

endwith 

this.MENU12.PASTE = new MENU(this.MENU12) 

with (this.MENU12.PASTE) 

text = "&Paste" 

shortCut = "Ctrl+V" 

endwith 

this.MENU17 = new MENU(this) 

with (this.MENU17) 

text = "&Window" 

endwith 

this.MENU11 = new MENU(this) 

with (this.MENU11) 

text = "" 

endwith 

this.windowMenu = this.menu17 

this.editCutMenu = this.menu12.cut 

this.editCopyMenu = this.menu12.copy 

this.editPasteMenu = this.menu12.paste 

this.editUndoMenu = this.menu12.undo 

endclass

In the code above, after the menus are defined, certain key menus are assigned to menubar properties which automatically give the menus their required functionality. For example, when this.menu12.copy is assigned to the menubar’s editCopyMenu property, the copy menu takes on the following characteristics:

The Copy item remains dimmed unless there is highlighted text in an appropriate object on the form, such as an Entryfield or Editor object.

When text is highlighted, the Copy item is enabled.

When the Copy item is selected, the highlighted text is copied to the Windows clipboard.

The remaining Editmenu properties function in a similar fashion.

You can modify the preset Edit menu by adding, inserting, or changing item characteristics from the pulldown Menu designer properties sheet.

The windowMenu property is useful only with top-level menus on MDI forms. The menu assigned to windowMenu will automatically have a menu added to it for each open child window (such as all other active dBASE Plus windows). This feature provides a means for the user to easily switch windows.

Another important menubar feature is the onInitMenu event, which is fired when the menu system is opened. You can use this event to check for certain conditions and then modify your menus accordingly.

If, for example, you offer a Clear All item on your Edit menu, you can set an onInitMenu( ) event to disable the item if no tables are open when your form opens. To do that, you could add a pointer to the top of your menu file:

NEW MTESTMENU(FormObj,"Root")

CLASS MTESTMENU(FormObj,Name) OF MENUBAR(FormObj,Name)

this.onInitMenu = class::chkClearAll

And then create a method to handle the event:

function chkClearAll

 if alias( ) == ""

  this.edit.clear_all.enabled = false

 endif

return