Skip to content

Commit b18d00f

Browse files
committed
feat: allow disable commands handling by taking the pinned tabs into account
1 parent 5034fc9 commit b18d00f

2 files changed

Lines changed: 31 additions & 20 deletions

File tree

src/extensions/default/CloseOthers/main.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,22 @@ define(function (require, exports, module) {
9292
CommandManager.get(closeAll).setName(Strings.CMD_FILE_CLOSE_ALL);
9393

9494
if (file) {
95-
var targetIndex = MainViewManager.findInWorkingSet(MainViewManager.ACTIVE_PANE, file.fullPath),
96-
workingSetListSize = MainViewManager.getWorkingSetSize(MainViewManager.ACTIVE_PANE);
97-
98-
if (targetIndex === workingSetListSize - 1) { // hide "Close Others Below" if the last file in Working Files is selected
99-
CommandManager.get(closeBelow).setEnabled(false);
100-
} else {
101-
CommandManager.get(closeBelow).setEnabled(true);
102-
}
103-
104-
if (targetIndex === 0) { // hide "Close Others Above" if the first file in Working Files is selected
105-
CommandManager.get(closeAbove).setEnabled(false);
106-
} else {
107-
CommandManager.get(closeAbove).setEnabled(true);
108-
}
95+
let workingSetList = MainViewManager.getWorkingSet(MainViewManager.ACTIVE_PANE),
96+
targetIndex = MainViewManager.findInWorkingSet(MainViewManager.ACTIVE_PANE, file.fullPath),
97+
lastIndex = workingSetList.length - 1;
98+
99+
// we disable the bulk closing menu items if there are no files to close
100+
// so for "Close Above", if the first file is selected or all files above are pinned
101+
// for "Close Below", if the last file is selected or all files below are pinned
102+
// for "Close All", if all files are pinned
103+
let isPrevFilePinned = targetIndex > 0 &&
104+
MainViewManager.isPathPinned(MainViewManager.ACTIVE_PANE, workingSetList[targetIndex - 1].fullPath);
105+
let isLastFilePinned = lastIndex >= 0 &&
106+
MainViewManager.isPathPinned(MainViewManager.ACTIVE_PANE, workingSetList[lastIndex].fullPath);
107+
108+
CommandManager.get(closeAbove).setEnabled(targetIndex > 0 && !isPrevFilePinned);
109+
CommandManager.get(closeBelow).setEnabled(targetIndex < lastIndex && !isLastFilePinned);
110+
CommandManager.get(closeAll).setEnabled(!isLastFilePinned);
109111
}
110112
}
111113

src/extensionsIntegrated/TabBar/more-options.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,26 @@ define(function (require, exports, module) {
6464
closeBelowCmd.setName(Strings.CLOSE_TABS_TO_THE_RIGHT);
6565
closeAllCmd.setName(Strings.CLOSE_ALL_TABS);
6666

67-
// Enable/disable Close Left/Right based on tab position
67+
// Enable/disable Close Left/Right/All based on tab position and pinned files
68+
const workingSetList = MainViewManager.getWorkingSet(_currentTabContext.paneId);
6869
const targetIndex = MainViewManager.findInWorkingSet(
6970
_currentTabContext.paneId,
7071
_currentTabContext.filePath
7172
);
72-
const workingSetListSize = MainViewManager.getWorkingSetSize(_currentTabContext.paneId);
73+
const lastIndex = workingSetList.length - 1;
7374

74-
// disable "Close Tabs to the Left" if this is the first tab
75-
closeAboveCmd.setEnabled(targetIndex > 0);
76-
// disable "Close Tabs to the Right" if this is the last tab
77-
closeBelowCmd.setEnabled(targetIndex < workingSetListSize - 1);
75+
// we disable the bulk closing menu items if there are no files to close
76+
// for 'Close Tabs to the Left', if the first tab is selected or all tabs to the left are pinned
77+
// for 'Close Tabs to the Right', if the last tab is selected or all tabs to the right are pinned
78+
// for 'Close All Tabs', if all tabs are pinned
79+
const isPrevTabPinned = targetIndex > 0 &&
80+
MainViewManager.isPathPinned(_currentTabContext.paneId, workingSetList[targetIndex - 1].fullPath);
81+
const isLastTabPinned = lastIndex >= 0 &&
82+
MainViewManager.isPathPinned(_currentTabContext.paneId, workingSetList[lastIndex].fullPath);
83+
84+
closeAboveCmd.setEnabled(targetIndex > 0 && !isPrevTabPinned);
85+
closeBelowCmd.setEnabled(targetIndex < lastIndex && !isLastTabPinned);
86+
closeAllCmd.setEnabled(!isLastTabPinned);
7887
}
7988

8089
/**

0 commit comments

Comments
 (0)