Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Changes from all commits
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
36 changes: 35 additions & 1 deletion src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,37 @@ 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");

/**
* Disables menu items present in items if enabled is true.
* enabled is true if file is saved and present on user system.
* @param {boolean} enabled
* @param {array} items
*/
function _setContextMenuItemsVisible(enabled, items) {
Copy link
Copy Markdown
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);
});
}

/**
* Checks if file saved and present on system and
* disables menu items accordingly
*/
function _setMenuItemsVisible() {
Copy link
Copy Markdown
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 +370,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);
});
});