@@ -91,23 +91,32 @@ define(function (require, exports, module) {
9191
9292
9393 /**
94- * Insertion position constants
95- * Used by addMenu(), addMenuItem(), and addSubMenu() to
96- * specify the relative position of a newly created menu object
97- * @enum {string}
98- */
99- var BEFORE = "before" ;
100- var AFTER = "after" ;
101- var FIRST = "first" ;
102- var LAST = "last" ;
103- var FIRST_IN_SECTION = "firstInSection" ;
104- var LAST_IN_SECTION = "lastInSection" ;
105-
106- /**
107- * Other constants
108- */
109- var DIVIDER = "---" ;
94+ * Insertion position constants
95+ * Used by addMenu(), addMenuItem(), and addSubMenu() to
96+ * specify the relative position of a newly created menu object
97+ * @enum {string}
98+ */
99+ var BEFORE = "before" ,
100+ AFTER = "after" ,
101+ FIRST = "first" ,
102+ LAST = "last" ,
103+ FIRST_IN_SECTION = "firstInSection" ,
104+ LAST_IN_SECTION = "lastInSection" ;
110105
106+ /**
107+ * Other constants
108+ */
109+ var DIVIDER = "---" ;
110+
111+ /**
112+ * Error Codes from Brackets Shell
113+ * @enum {number}
114+ */
115+ var NO_ERROR = 0 ,
116+ ERR_UNKNOWN = 1 ,
117+ ERR_INVALID_PARAMS = 2 ,
118+ ERR_NOT_FOUND = 3 ;
119+
111120 /**
112121 * Maps menuID's to Menu objects
113122 * @type {Object.<string, Menu> }
@@ -462,7 +471,8 @@ define(function (require, exports, module) {
462471 * @return {MenuItem } the newly created MenuItem
463472 */
464473 Menu . prototype . addMenuItem = function ( command , keyBindings , position , relativeID ) {
465- var id ,
474+ var menuID = this . id ,
475+ id ,
466476 $menuItem ,
467477 $link ,
468478 menuItem ,
@@ -547,8 +557,17 @@ define(function (require, exports, module) {
547557 }
548558
549559 brackets . app . addMenuItem ( this . id , name , commandID , bindingStr , displayStr , position , relativeID , function ( err ) {
550- if ( err ) {
551- console . error ( "addMenuItem() -- error: " + err + " when adding command: " + commandID ) ;
560+ switch ( err ) {
561+ case NO_ERROR :
562+ break ;
563+ case ERR_INVALID_PARAMS :
564+ console . error ( "addMenuItem(): Invalid Parameters when adding the command " + commandID ) ;
565+ break ;
566+ case ERR_NOT_FOUND :
567+ console . error ( "_getRelativeMenuItem(): MenuItem with Command id " + relativeID + " not found in the Menu " + menuID ) ;
568+ break ;
569+ default :
570+ console . error ( "addMenuItem(); Unknown Error (" + err + ") when adding the command " + commandID ) ;
552571 }
553572 } ) ;
554573 menuItem . isNative = true ;
@@ -800,15 +819,26 @@ define(function (require, exports, module) {
800819
801820 if ( ! _isHTMLMenu ( id ) ) {
802821 brackets . app . addMenu ( name , id , position , relativeID , function ( err ) {
803- if ( err ) {
804- console . error ( "addMenu() -- error: " + err + " when adding menu with ID: " + id ) ;
805- } else {
822+ switch ( err ) {
823+ case NO_ERROR :
806824 // Make sure name is up to date
807825 brackets . app . setMenuTitle ( id , name , function ( err ) {
808826 if ( err ) {
809827 console . error ( "setMenuTitle() -- error: " + err ) ;
810828 }
811829 } ) ;
830+ break ;
831+ case ERR_UNKNOWN :
832+ console . error ( "addMenu(): Unknown Error when adding the menu " + id ) ;
833+ break ;
834+ case ERR_INVALID_PARAMS :
835+ console . error ( "addMenu(): Invalid Parameters when adding the menu " + id ) ;
836+ break ;
837+ case ERR_NOT_FOUND :
838+ console . error ( "addMenu(): Menu with command " + relativeID + " could not be found when adding the menu " + id ) ;
839+ break ;
840+ default :
841+ console . error ( "addMenu(): Unknown Error (" + err + ") when adding the menu " + id ) ;
812842 }
813843 } ) ;
814844 return menu ;
0 commit comments