Skip to content

Instantly share code, notes, and snippets.

@tpryan
Created July 11, 2012 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpryan/3087135 to your computer and use it in GitHub Desktop.
Save tpryan/3087135 to your computer and use it in GitHub Desktop.
Sample of Menu removing for Brackets.
define(function (require, exports, module) {
'use strict';
var CommandManager = brackets.getModule("command/CommandManager"),
Menus = brackets.getModule("command/Menus");
// Function to run when the menu item is clicked
function handleHelloWorld() {
menu.removeMenuItem(MY_COMMAND_ID);
window.alert("Hello, world!");
}
// Function to run when the menu item is clicked
function handleHelloWorldContext() {
contextMenu.removeMenuItem(MY_COMMAND_ID_CONTEXT);
window.alert("Hello, world Context!");
}
// First, register a command - a UI-less object associating an id to a handler
var MY_COMMAND_ID = "helloworld.sayhello"; // package-style naming to avoid collisions
CommandManager.register("Hello World", MY_COMMAND_ID, handleHelloWorld);
var MY_COMMAND_ID_CONTEXT = "helloworld.context.sayhello"; // package-style naming to avoid collisions
CommandManager.register("Hello World Context", MY_COMMAND_ID_CONTEXT, handleHelloWorldContext);
// Then create a menu item bound to the command
// The label of the menu item is the name we gave the command (see above)
var menu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU);
var contextMenu = Menus.getContextMenu("project-context-menu");
contextMenu.addMenuItem(MY_COMMAND_ID_CONTEXT);
menu.addMenuItem(MY_COMMAND_ID);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment