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

Commit

Permalink
Fix Issue 14346 - Disable commands on File Change (#14352)
Browse files Browse the repository at this point in the history
* Disable menu items on file change

* Refactor the enable/disable logic
  • Loading branch information
boopeshmahendran authored and swmitra committed May 23, 2018
1 parent 0d42474 commit 37793e7
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/extensions/default/RemoteFileAdapter/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ define(function (require, exports, module) {
Commands = brackets.getModule("command/Commands"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
WorkingSetView = brackets.getModule("project/WorkingSetView"),
MainViewManager = brackets.getModule("view/MainViewManager"),
Menus = brackets.getModule("command/Menus"),
RemoteFile = require("RemoteFile");

Expand All @@ -56,22 +57,20 @@ define(function (require, exports, module) {
* Disable context menus which are not useful for remote file
*/
function _setMenuItemsVisible() {
var file = WorkingSetView.getContext(),
cMenuItems = [Commands.FILE_SAVE, Commands.FILE_RENAME, Commands.NAVIGATE_SHOW_IN_FILE_TREE, Commands.NAVIGATE_SHOW_IN_OS];
var file = MainViewManager.getCurrentlyViewedFile(MainViewManager.ACTIVE_PANE),
cMenuItems = [Commands.FILE_SAVE, Commands.FILE_RENAME, Commands.NAVIGATE_SHOW_IN_FILE_TREE, Commands.NAVIGATE_SHOW_IN_OS],
enable = (file.constructor.name !== "RemoteFile");

if (file.constructor.name === "RemoteFile") {
// Enable or disable commands based on whether the file is a remoteFile or not.
cMenuItems.forEach(function (item) {
CommandManager.get(item).setEnabled(false);
CommandManager.get(item).setEnabled(enable);
});
} else {
//Explicitly enabling save, other commands are handled by DefaultMenus.js
CommandManager.get(Commands.FILE_SAVE).setEnabled(true);
}
}

AppInit.htmlReady(function () {

Menus.getContextMenu(Menus.ContextMenuIds.WORKING_SET_CONTEXT_MENU).on("beforeContextMenuOpen", _setMenuItemsVisible);
MainViewManager.on("currentFileChange", _setMenuItemsVisible);

var protocolAdapter = {
priority: 0, // Default priority
Expand Down

0 comments on commit 37793e7

Please sign in to comment.