-
-
Notifications
You must be signed in to change notification settings - Fork 24
Working with context menu
Eugen Kremer edited this page Jan 5, 2017
·
2 revisions
Working with context menu means the way how javascript plugin developers can override default context menu of Notepad++ and improve so the user experience enormously.
Following steps are necessary:
- Create own instance of context menu.
- Add code filling new context menu.
- Add code deciding if own or default context menu should be shown.
- Add code disabling some menu items dependend on current context.
- Add own context menu handler.
(function(){
var ctxMenu = Editor.createContextMenu({oninitpopup:function(){
// disable item if nothing selected
selectionItem.disabled = currentView.selection == "";
}});
var selectionItem = ctxMenu.addItem({text:"Show selection", cmd:function(m){
alert("Selection: " + currentView.selection);
}})
var showAlertItem = ctxMenu.addItem({text:"Show alert", cmd:function(m){
alert("Always available menu item clicked");
}})
OnContextMenu = function(){
// Show new context menu only for JavaScript files
if (Editor.langs[currentView.lang] != "JS")
return false;
ctxMenu.show();
return true;
}
GlobalListener.addListener({
CONTEXTMENU: OnContextMenu
})
})()
Use snippet above to realize context menus in your own plugins. Take a look into API for more.