Skip to content

Commit 0feccb0

Browse files
committed
feat: show/hide pin unpin option based on the current tab status
1 parent 7c20d27 commit 0feccb0

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/extensionsIntegrated/TabBar/more-options.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ define(function (require, exports, module) {
2626
const CommandManager = require("command/CommandManager");
2727
const Commands = require("command/Commands");
2828
const FileSystem = require("filesystem/FileSystem");
29+
const MainViewManager = require("view/MainViewManager");
2930
const Menus = require("command/Menus");
3031
const Strings = require("strings");
3132

@@ -43,6 +44,22 @@ define(function (require, exports, module) {
4344
// this is set inside the showMoreOptionsContextMenu. read that func for more details
4445
let _currentTabContext = { filePath: null, paneId: null };
4546

47+
/**
48+
* this function is called before the context menu is shown
49+
* it updates the menu items based on the current tab context
50+
* so we only show the relevant options
51+
*/
52+
function _updateMenuItems() {
53+
// PIN/UNPIN logic
54+
const isPinned = MainViewManager.isPathPinned(
55+
_currentTabContext.paneId,
56+
_currentTabContext.filePath
57+
);
58+
59+
CommandManager.get(Commands.FILE_PIN).setEnabled(!isPinned);
60+
CommandManager.get(Commands.FILE_UNPIN).setEnabled(isPinned);
61+
}
62+
4663
// gets the working set (list of open files) for the given pane
4764
function _getWorkingSet(paneId) {
4865
return paneId === "first-pane" ? Global.firstPaneWorkingSet : Global.secondPaneWorkingSet;
@@ -151,14 +168,18 @@ define(function (require, exports, module) {
151168
menu.addMenuItem(TABBAR_CLOSE_SAVED_TABS);
152169
menu.addMenuItem(TABBAR_CLOSE_ALL);
153170
menu.addMenuDivider();
154-
menu.addMenuItem(Commands.FILE_PIN);
155-
menu.addMenuItem(Commands.FILE_UNPIN);
171+
menu.addMenuItem(Commands.FILE_PIN, null, null, null, { hideWhenCommandDisabled: true });
172+
menu.addMenuItem(Commands.FILE_UNPIN, null, null, null, { hideWhenCommandDisabled: true });
156173
menu.addMenuDivider();
157174
menu.addMenuItem(Commands.FILE_RENAME);
158175
menu.addMenuItem(Commands.FILE_DELETE);
159176
menu.addMenuItem(Commands.NAVIGATE_SHOW_IN_FILE_TREE);
160177
menu.addMenuDivider();
161178
menu.addMenuItem(Commands.FILE_REOPEN_CLOSED);
179+
180+
// _updateMenuItems function disables the button which are not needed for the current tab
181+
// and those items are then hidden by the menu system automatically because of the hideWhenCommandDisabled flag
182+
menu.on("beforeContextMenuOpen", _updateMenuItems);
162183
}
163184

164185
module.exports = {

0 commit comments

Comments
 (0)