DOCS

Menus

A web application starts with an empty Menu Bar. Using wa we can create menus and register callbacks for the menu events.

Define a menu

Use wa.window.createMenu(menu) to create and add the menu to the menu bar. The parameter menu is a plain object with the structure of your menu.

  var menu ={
	  "label": "File",
	  "tag": "fileMenu",
	  "menu": "menubar",
	  "submenus": [
		{
		  "label": "Open",
		  "tag": "dothis",
		  "shortcut": "Cmd-O"
		}
	  ]
  };

  wa.window.createMenu( menu );

The menu object requires the following keys:

tag key is a unique string to identify your menu. We use this tag to identify the menu when handling a menu event. REQUIRED

A tag
label key is the actual caption that will be displayed on the menu. REQUIRED
menu key tells Deskframe where to insert this menu. Specify a menu using it's tag value or use the special tag "menubar" to add the menu to your applications menu bar. REQUIRED
submenus key is an array of child menus. Each entry in this array follow the same structure as the menu object. OPTIONAL
shortcut key specifies the keyboard shortcut of a menu. This entry only applies to sub-menus. OPTIONAL
Non-printable keys are represented with the following:
"Cmd" which will use the command key on Mac or the control key on Windows.
"Ctrl", "Shift", "Enter", "Space", "Del", "Bksp",
"Return", "Esc", "Clear", "PageUp", "PageDown", "Tab"
"Left", "Right", "Up", "Down", "Help", and "Ins" (Insert).
Use a dash to combine keys like "Cmd-Shift-M".

Handle menu actions

The easiest way to handle a menu action is to set the callback property when you define your menu and submenus with wa.window.createMenu().

Another route is to add an event listener for the event menuAction.

window.addEventListener("menuAction", function(o){
  wa.log("got menuAction for [" + o.tag + "]" );
  if(o.tag == "dothis"){
	wa.log("menu dothis");
  }
});


Fork me on GitHub