Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Disabled context menu items for unsaved files #12806

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,27 @@ define(function (require, exports, module) {
var AppInit = require("utils/AppInit"),
Commands = require("command/Commands"),
Menus = require("command/Menus"),
Strings = require("strings");
Strings = require("strings"),
MainViewManager = require("view/MainViewManager"),
CommandManager = require("command/CommandManager");

function _setContextMenuItemsVisible(enabled, items) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs JSDoc

items.forEach(function (item) {
CommandManager.get(item).setEnabled(enabled);
});
}

function _setMenuItemsVisible() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs JSDoc

var file = MainViewManager.getCurrentlyViewedFile(MainViewManager.ACTIVE_PANE);
if (file) {
file.exists(function (err, isPresent) {
if (err) {
return err;
}
_setContextMenuItemsVisible(isPresent, [Commands.FILE_RENAME, Commands.NAVIGATE_SHOW_IN_FILE_TREE, Commands.NAVIGATE_SHOW_IN_OS]);
});
}
}

AppInit.htmlReady(function () {
/*
Expand Down Expand Up @@ -340,5 +360,9 @@ define(function (require, exports, module) {
$(this).addClass("open");
}
});
// Check the visibility of context menu items before opening the context menu.
// 'Rename', 'Show in file tree' and 'Show in explorer' items will be disabled for files that have not yet been saved to disk.
Menus.getContextMenu(Menus.ContextMenuIds.WORKING_SET_CONTEXT_MENU).on("beforeContextMenuOpen", _setMenuItemsVisible);
Menus.getContextMenu(Menus.ContextMenuIds.PROJECT_MENU).on("beforeContextMenuOpen", _setMenuItemsVisible);
});
});