Book Image

NW.js Essentials

By : Benoit
Book Image

NW.js Essentials

By: Benoit

Overview of this book

If you are an experienced Node.js developer who wants to create amazing desktop applications using NW.js, this is the book for you. Prior knowledge of HTML5, jQuery, and CSS is assumed.
Table of Contents (11 chapters)
10
Index

The Menu API – handling window and context menus

In NW.js, menus can be used in three different contexts:

  • Contextual menus: This is displayed when right-clicking an element inside the application.
  • Window menus: On Microsoft Windows and Linux, you can have one per window; however, in Mac OS X, you can have one, which will be shown on the System taskbar, per application.
  • Tray icon menus: This is displayed when clicking on a tray icon usually on the right side of the OS taskbar.

In this chapter, we're going to deal with the first two contexts. For tray icon menus, the same basic rules apply, but refer to the Tray API section to learn more about it.

The contextual menu

In order to instance a new menu on NW.js, we should proceed as follows:

var gui = require('nw.gui');
var menu = new gui.Menu();

Once the menu has been created, we have to append one or more MenuItem objects to it:

menu.append(new gui.MenuItem({
  label: 'Menu Item'
}));

We have three different types of menu...