src/command/Menus.js
function addMenu(name, id, position, relativeID) {
        name = _.escape(name);
        var $menubar = $("#titlebar .nav"),
            menu;

        if (!name || !id) {
            console.error("call to addMenu() is missing required parameters");
            return null;
        }

        // Guard against duplicate menu ids
        if (menuMap[id]) {
            console.log("Menu added with same name and id of existing Menu: " + id);
            return null;
        }

        menu = new Menu(id);
        menuMap[id] = menu;

        if (!_isHTMLMenu(id)) {
            brackets.app.addMenu(name, id, position, relativeID, function (err) {
                switch (err) {
                case NO_ERROR:
                    // Make sure name is up to date
                    brackets.app.setMenuTitle(id, name, function (err) {
                        if (err) {
                            console.error("setMenuTitle() -- error: " + err);
                        }
                    });
                    break;
                case ERR_UNKNOWN:
                    console.error("addMenu(): Unknown Error when adding the menu " + id);
                    break;
                case ERR_INVALID_PARAMS:
                    console.error("addMenu(): Invalid Parameters when adding the menu " + id);
                    break;
                case ERR_NOT_FOUND:
                    console.error("addMenu(): Menu with command " + relativeID + " could not be found when adding the menu " + id);
                    break;
                default:
                    console.error("addMenu(): Unknown Error (" + err + ") when adding the menu " + id);
                }
            });
            return menu;
        }

        var $toggle = $("<a href='#' class='dropdown-toggle' data-toggle='dropdown'>" + name + "</a>"),
            $popUp = $("<ul class='dropdown-menu'></ul>"),
            $newMenu = $("<li class='dropdown' id='" + id + "'></li>").append($toggle).append($popUp);

        // Insert menu
        var $relativeElement = relativeID && $(_getHTMLMenu(relativeID));
        _insertInList($menubar, $newMenu, position, $relativeElement);

        // Install ESC key handling
        PopUpManager.addPopUp($popUp, closeAll, false);

        // todo error handling

        return menu;
    }
function addMenu(name, id, position, relativeID) {
        name = _.escape(name);
        var $menubar = $("#titlebar .nav"),
            menu;

        if (!name || !id) {
            console.error("call to addMenu() is missing required parameters");
            return null;
        }

        // Guard against duplicate menu ids
        if (menuMap[id]) {
            console.log("Menu added with same name and id of existing Menu: " + id);
            return null;
        }

        menu = new Menu(id);
        menuMap[id] = menu;

        if (!_isHTMLMenu(id)) {
            brackets.app.addMenu(name, id, position, relativeID, function (err) {
                switch (err) {
                case NO_ERROR:
                    // Make sure name is up to date
                    brackets.app.setMenuTitle(id, name, function (err) {
                        if (err) {
                            console.error("setMenuTitle() -- error: " + err);
                        }
                    });
                    break;
                case ERR_UNKNOWN:
                    console.error("addMenu(): Unknown Error when adding the menu " + id);
                    break;
                case ERR_INVALID_PARAMS:
                    console.error("addMenu(): Invalid Parameters when adding the menu " + id);
                    break;
                case ERR_NOT_FOUND:
                    console.error("addMenu(): Menu with command " + relativeID + " could not be found when adding the menu " + id);
                    break;
                default:
                    console.error("addMenu(): Unknown Error (" + err + ") when adding the menu " + id);
                }
            });
            return menu;
        }

        var $toggle = $("<a href='#' class='dropdown-toggle' data-toggle='dropdown'>" + name + "</a>"),
            $popUp = $("<ul class='dropdown-menu'></ul>"),
            $newMenu = $("<li class='dropdown' id='" + id + "'></li>").append($toggle).append($popUp);

        // Insert menu
        var $relativeElement = relativeID && $(_getHTMLMenu(relativeID));
        _insertInList($menubar, $newMenu, position, $relativeElement);

        // Install ESC key handling
        PopUpManager.addPopUp($popUp, closeAll, false);

        // todo error handling

        return menu;
    }
function addMenu ( name , id , position , relativeID ) { name = _ . escape ( name ) ; var $menubar = $ ( "#titlebar .nav" ) , menu ; if ( ! name || ! id ) { console . error ( "call to addMenu() is missing required parameters" ) ; return null ; } // Guard against duplicate menu ids if ( menuMap [ id ] ) { console . log ( "Menu added with same name and id of existing Menu: " + id ) ; return null ; } menu = new Menu ( id ) ; menuMap [ id ] = menu ; if ( ! _isHTMLMenu ( id ) ) { brackets . app . addMenu ( name , id , position , relativeID , function ( err ) { switch ( err ) { case NO_ERROR : // Make sure name is up to date brackets . app . setMenuTitle ( id , name , function ( err ) { if ( err ) { console . error ( "setMenuTitle() -- error: " + err ) ; } } ) ; break ; case ERR_UNKNOWN : console . error ( "addMenu(): Unknown Error when adding the menu " + id ) ; break ; case ERR_INVALID_PARAMS : console . error ( "addMenu(): Invalid Parameters when adding the menu " + id ) ; break ; case ERR_NOT_FOUND : console . error ( "addMenu(): Menu with command " + relativeID + " could not be found when adding the menu " + id ) ; break ; default : console . error ( "addMenu(): Unknown Error (" + err + ") when adding the menu " + id ) ; } } ) ; return menu ; } var $toggle = $ ( "<a href='#' class='dropdown-toggle' data-toggle='dropdown'>" + name + "</a>" ) , $popUp = $ ( "<ul class='dropdown-menu'></ul>" ) , $newMenu = $ ( "<li class='dropdown' id='" + id + "'></li>" ) . append ( $toggle ) . append ( $popUp ) ; // Insert menu var $relativeElement = relativeID && $ ( _getHTMLMenu ( relativeID ) ) ; _insertInList ( $menubar , $newMenu , position , $relativeElement ) ; // Install ESC key handling PopUpManager . addPopUp ( $popUp , closeAll , false ) ; // todo error handling return menu ; }
Adds a top-level menu to the application menu bar which may be native or HTML-based.

@param {!string} name - display text for menu
@param {!string} id - unique identifier for a menu.
Core Menus in Brackets use a simple  title as an id, for example "file-menu".
Extensions should use the following format: "author.myextension.mymenuname".
@param {?string} position - constant defining the position of new the Menu relative
to other Menus. Default is LAST (see Insertion position constants).

@param {?string} relativeID - id of Menu the new Menu will be positioned relative to. Required
when position is AFTER or BEFORE, ignored when position is FIRST or LAST

@return {?Menu} the newly created Menu
Adds a top - level menu to the application menu bar which may be native or HTML - based .