Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Simple "Hello World" extension

peterflynn edited this page Jun 7, 2012 · 25 revisions
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window */

/** Simple extension that adds a "File > Hello World" menu item */
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() {
        window.alert("Hello, world!");
    }
    
    
    // First, register a command - a UI-less object associating an id to a handler
    var MY_COMMAND_ID = "helloworld.sayhello";
    CommandManager.register("Hello World", MY_COMMAND_ID, handleHelloWorld);

    // 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);
    menu.addMenuItem("menu-helloworld-sayhello", MY_COMMAND_ID);
    
    // We could also add a key binding at the same time:
    //menu.addMenuItem("menu-helloworld-sayhello", MY_COMMAND_ID, "Ctrl-Alt-H");
    // Note: on a Mac, Brackets will automatically change "Ctrl" to "Cmd".

    // For dynamic menu item labels, you can change the command name like this:
    //CommandManager.get(MY_COMMAND_ID).setName("Goodbye!");    
    
});
Clone this wiki locally