nandhini
nandhini

Reputation: 21

Enable options like cut,copy,paste when i right click the mouse in node web-kit window

I want to enable the right click options in node web-kit window.I mean cut,copy,paste options should be enabled when i right click the mouse in node web-kit window.

please send me the code for enabling the options in node web-kit window using javascript.

Upvotes: 2

Views: 952

Answers (1)

sampathsris
sampathsris

Reputation: 22290

You can use https://github.com/b1rdex/nw-contextmenu

Just copy this code (MIT Licensed) and you'll have your context menu.

$(function() {
  function Menu(cutLabel, copyLabel, pasteLabel) {
    var gui = require('nw.gui')
      , menu = new gui.Menu()

      , cut = new gui.MenuItem({
        label: cutLabel || "Cut"
        , click: function() {
          document.execCommand("cut");
          console.log('Menu:', 'cutted to clipboard');
        }
      })

      , copy = new gui.MenuItem({
        label: copyLabel || "Copy"
        , click: function() {
          document.execCommand("copy");
          console.log('Menu:', 'copied to clipboard');
        }
      })

      , paste = new gui.MenuItem({
        label: pasteLabel || "Paste"
        , click: function() {
          document.execCommand("paste");
          console.log('Menu:', 'pasted to textarea');
        }
      })
    ;

    menu.append(cut);
    menu.append(copy);
    menu.append(paste);

    return menu;
  }

  var menu = new Menu(/* pass cut, copy, paste labels if you need i18n*/);
  $(document).on("contextmenu", function(e) {
    e.preventDefault();
    menu.popup(e.originalEvent.x, e.originalEvent.y);
  });
});

Upvotes: 2

Related Questions