@@ -10,6 +10,8 @@ define(function (require, exports, module) {
1010 const Commands = require ( "command/Commands" ) ;
1111 const DocumentManager = require ( "document/DocumentManager" ) ;
1212 const WorkspaceManager = require ( "view/WorkspaceManager" ) ;
13+ const Menus = require ( "command/Menus" ) ;
14+ const Strings = require ( "strings" ) ;
1315
1416 const Global = require ( "./global" ) ;
1517 const Helper = require ( "./helper" ) ;
@@ -458,24 +460,50 @@ define(function (require, exports, module) {
458460
459461
460462 /**
461- * This is called when the tab bar preference is changed
463+ * This is called when the tab bar preference is changed either,
464+ * from the preferences file or the menu bar
462465 * It takes care of creating or cleaning up the tab bar
463466 */
464467 function preferenceChanged ( ) {
465- Preference . tabBarEnabled = PreferencesManager . get ( Preference . PREFERENCES_TAB_BAR ) . showTabBar ;
466- Preference . tabBarNumberOfTabs = PreferencesManager . get ( Preference . PREFERENCES_TAB_BAR ) . numberOfTabs ;
468+ const prefs = PreferencesManager . get ( Preference . PREFERENCES_TAB_BAR ) ;
469+ Preference . tabBarEnabled = prefs . showTabBar ;
470+ Preference . tabBarNumberOfTabs = prefs . numberOfTabs ;
471+
472+ // Update menu checkmark
473+ CommandManager . get ( Commands . TOGGLE_TABBAR ) . setChecked ( prefs . showTabBar ) ;
467474
468- // preference should be enabled and number of tabs should be greater than 0
469475 if ( Preference . tabBarEnabled && Preference . tabBarNumberOfTabs !== 0 ) {
470476 createTabBar ( ) ;
471477 } else {
472478 cleanupTabBar ( ) ;
473479 }
474480 }
475481
482+ /**
483+ * Registers the commands,
484+ * for toggling the tab bar from the menu bar
485+ */
486+ function _registerCommands ( ) {
487+ CommandManager . register (
488+ Strings . CMD_TOGGLE_TABBAR ,
489+ Commands . TOGGLE_TABBAR ,
490+ ( ) => {
491+ const currentPref = PreferencesManager . get ( Preference . PREFERENCES_TAB_BAR ) ;
492+ PreferencesManager . set ( Preference . PREFERENCES_TAB_BAR , {
493+ ...currentPref ,
494+ showTabBar : ! currentPref . showTabBar
495+ } ) ;
496+ }
497+ ) ;
498+ }
476499
477500
478501 AppInit . appReady ( function ( ) {
502+ _registerCommands ( ) ;
503+
504+ // add the toggle tab bar command to the view menu
505+ const viewMenu = Menus . getMenu ( Menus . AppMenuBar . VIEW_MENU ) ;
506+ viewMenu . addMenuItem ( Commands . TOGGLE_TABBAR , "" , Menus . AFTER , Commands . VIEW_HIDE_SIDEBAR ) ;
479507
480508 PreferencesManager . on ( "change" , Preference . PREFERENCES_TAB_BAR , preferenceChanged ) ;
481509 // calling preference changed here itself to check if the tab bar is enabled,
0 commit comments