@@ -31,9 +31,9 @@ define(function (require, exports, module) {
3131 workingSetListCmenu = Menus . getContextMenu ( Menus . ContextMenuIds . WORKING_SET_CONTEXT_MENU ) ;
3232
3333 // Constants
34- var closeOthers = "file.close_others " ,
35- closeAbove = "file.close_above " ,
36- closeBelow = "file.close_below " ;
34+ const closeAbove = "file.close_above " ,
35+ closeBelow = "file.close_below " ,
36+ closeAll = "file.close_all_in_pane " ;
3737
3838 // Global vars and preferences
3939 var prefs = PreferencesManager . getExtensionPrefs ( "closeOthers" ) ,
@@ -42,16 +42,13 @@ define(function (require, exports, module) {
4242 prefs . definePreference ( "below" , "boolean" , true , {
4343 description : Strings . DESCRIPTION_CLOSE_OTHERS_BELOW
4444 } ) ;
45- prefs . definePreference ( "others" , "boolean" , true , {
46- description : Strings . DESCRIPTION_CLOSE_OTHERS
47- } ) ;
4845 prefs . definePreference ( "above" , "boolean" , true , {
4946 description : Strings . DESCRIPTION_CLOSE_OTHERS_ABOVE
5047 } ) ;
5148
5249
5350 /**
54- * Handle the different Close Other commands
51+ * Handle the different Close commands
5552 * @param {string } mode
5653 */
5754 function handleClose ( mode ) {
@@ -63,23 +60,30 @@ define(function (require, exports, module) {
6360 i ;
6461
6562 for ( i = start ; i < end ; i ++ ) {
66- if ( ( mode === closeOthers && i !== targetIndex ) || ( mode !== closeOthers ) ) {
67- files . push ( workingSetList [ i ] ) ;
68- }
63+ files . push ( workingSetList [ i ] ) ;
6964 }
7065
7166 CommandManager . execute ( Commands . FILE_CLOSE_LIST , { fileList : files } ) ;
7267 }
7368
69+ /**
70+ * Handle Close All - closes all files in the active pane
71+ */
72+ function handleCloseAll ( ) {
73+ let workingSetList = MainViewManager . getWorkingSet ( MainViewManager . ACTIVE_PANE ) ;
74+ CommandManager . execute ( Commands . FILE_CLOSE_LIST , { fileList : workingSetList } ) ;
75+ }
76+
7477 /**
7578 * Enable/Disable the menu items depending on which document is selected in the working set
7679 */
7780 function contextMenuOpenHandler ( ) {
7881 var file = MainViewManager . getCurrentlyViewedFile ( MainViewManager . ACTIVE_PANE ) ;
7982
80- // reset these labels for Working Set context (because tabBar may have changed them to "Left/Right" )
83+ // reset these labels for Working Set context (because tabBar may have changed them)
8184 CommandManager . get ( closeAbove ) . setName ( Strings . CMD_FILE_CLOSE_ABOVE ) ;
8285 CommandManager . get ( closeBelow ) . setName ( Strings . CMD_FILE_CLOSE_BELOW ) ;
86+ CommandManager . get ( closeAll ) . setName ( Strings . CMD_FILE_CLOSE_ALL ) ;
8387
8488 if ( file ) {
8589 var targetIndex = MainViewManager . findInWorkingSet ( MainViewManager . ACTIVE_PANE , file . fullPath ) ,
@@ -91,12 +95,6 @@ define(function (require, exports, module) {
9195 CommandManager . get ( closeBelow ) . setEnabled ( true ) ;
9296 }
9397
94- if ( workingSetListSize === 1 ) { // hide "Close Others" if there is only one file in Working Files
95- CommandManager . get ( closeOthers ) . setEnabled ( false ) ;
96- } else {
97- CommandManager . get ( closeOthers ) . setEnabled ( true ) ;
98- }
99-
10098 if ( targetIndex === 0 ) { // hide "Close Others Above" if the first file in Working Files is selected
10199 CommandManager . get ( closeAbove ) . setEnabled ( false ) ;
102100 } else {
@@ -108,14 +106,13 @@ define(function (require, exports, module) {
108106
109107 /**
110108 * Returns the preferences used to add/remove the menu items
111- * @return {{closeBelow: boolean, closeOthers: boolean, closeAbove: boolean} }
109+ * @return {{closeBelow: boolean, closeAbove: boolean} }
112110 */
113111 function getPreferences ( ) {
114112 // It's senseless to look prefs up for the current file, instead look them up for
115113 // the current project (or globally)
116114 return {
117115 closeBelow : prefs . get ( "below" , PreferencesManager . CURRENT_PROJECT ) ,
118- closeOthers : prefs . get ( "others" , PreferencesManager . CURRENT_PROJECT ) ,
119116 closeAbove : prefs . get ( "above" , PreferencesManager . CURRENT_PROJECT )
120117 } ;
121118 }
@@ -126,22 +123,6 @@ define(function (require, exports, module) {
126123 function prefChangeHandler ( ) {
127124 var prefs = getPreferences ( ) ;
128125
129- if ( prefs . closeBelow !== menuEntriesShown . closeBelow ) {
130- if ( prefs . closeBelow ) {
131- workingSetListCmenu . addMenuItem ( closeBelow , "" , Menus . AFTER , Commands . FILE_CLOSE ) ;
132- } else {
133- workingSetListCmenu . removeMenuItem ( closeBelow ) ;
134- }
135- }
136-
137- if ( prefs . closeOthers !== menuEntriesShown . closeOthers ) {
138- if ( prefs . closeOthers ) {
139- workingSetListCmenu . addMenuItem ( closeOthers , "" , Menus . AFTER , Commands . FILE_CLOSE ) ;
140- } else {
141- workingSetListCmenu . removeMenuItem ( closeOthers ) ;
142- }
143- }
144-
145126 if ( prefs . closeAbove !== menuEntriesShown . closeAbove ) {
146127 if ( prefs . closeAbove ) {
147128 workingSetListCmenu . addMenuItem ( closeAbove , "" , Menus . AFTER , Commands . FILE_CLOSE ) ;
@@ -150,6 +131,14 @@ define(function (require, exports, module) {
150131 }
151132 }
152133
134+ if ( prefs . closeBelow !== menuEntriesShown . closeBelow ) {
135+ if ( prefs . closeBelow ) {
136+ workingSetListCmenu . addMenuItem ( closeBelow , "" , Menus . AFTER , closeAbove ) ;
137+ } else {
138+ workingSetListCmenu . removeMenuItem ( closeBelow ) ;
139+ }
140+ }
141+
153142 menuEntriesShown = prefs ;
154143 }
155144
@@ -162,22 +151,20 @@ define(function (require, exports, module) {
162151 CommandManager . register ( Strings . CMD_FILE_CLOSE_BELOW , closeBelow , function ( ) {
163152 handleClose ( closeBelow ) ;
164153 } ) ;
165- CommandManager . register ( Strings . CMD_FILE_CLOSE_OTHERS , closeOthers , function ( ) {
166- handleClose ( closeOthers ) ;
167- } ) ;
168154 CommandManager . register ( Strings . CMD_FILE_CLOSE_ABOVE , closeAbove , function ( ) {
169155 handleClose ( closeAbove ) ;
170156 } ) ;
157+ CommandManager . register ( Strings . CMD_FILE_CLOSE_ALL , closeAll , handleCloseAll ) ;
171158
172- if ( prefs . closeBelow ) {
173- workingSetListCmenu . addMenuItem ( closeBelow , "" , Menus . AFTER , Commands . FILE_CLOSE ) ;
174- }
175- if ( prefs . closeOthers ) {
176- workingSetListCmenu . addMenuItem ( closeOthers , "" , Menus . AFTER , Commands . FILE_CLOSE ) ;
177- }
159+ // Menu order: Close, Close Others Above, Close Others Below, Close All
178160 if ( prefs . closeAbove ) {
179161 workingSetListCmenu . addMenuItem ( closeAbove , "" , Menus . AFTER , Commands . FILE_CLOSE ) ;
180162 }
163+ if ( prefs . closeBelow ) {
164+ workingSetListCmenu . addMenuItem ( closeBelow , "" , Menus . AFTER , closeAbove ) ;
165+ }
166+ workingSetListCmenu . addMenuItem ( closeAll , "" , Menus . AFTER , closeBelow ) ;
167+
181168 menuEntriesShown = prefs ;
182169 }
183170
0 commit comments