Context menu
Well, with our application, we can already navigate through the filesystem and open files, yet one might expect more of a File Explorer. We can add some file-related actions, such as delete and copy/paste. Usually, these tasks are available via the context menu, which gives us a good opportunity to examine how to make it with NW.js
. With the environment integration API, we can create an instance of system menu (http://docs.nwjs.io/en/latest/References/Menu/). Then, we compose objects representing menu items and attach them to the menu instance (http://docs.nwjs.io/en/latest/References/MenuItem/). This menu
can be shown in an arbitrary position:
const menu = new nw.Menu(), menutItem = new nw.MenuItem({ label: "Say hello", click: () => console.log( "hello!" ) }); menu.append( menu ); menu.popup( 10, 10 );
Yet, our task is more specific. We have to display the menu on the right-click in the position of the cursor, that is, we achieve it by...