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

Commit

Permalink
Merge pull request #12234 from adobe/marcel/rename-outside-project-fail
Browse files Browse the repository at this point in the history
Show an error message when trying to rename a file outside of the project
  • Loading branch information
abose committed Mar 31, 2016
2 parents f393bfe + 18c2e0b commit b05d263
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ define({
"ERROR_SAVING_FILE" : "An error occurred when trying to save the file <span class='dialog-filename'>{0}</span>. {1}",
"ERROR_RENAMING_FILE_TITLE" : "Error Renaming {0}",
"ERROR_RENAMING_FILE" : "An error occurred when trying to rename the {2} <span class='dialog-filename'>{0}</span>. {1}",
"ERROR_RENAMING_NOT_IN_PROJECT" : "The file or directory is not part of the currently opened project. Unfortunately, only project files can be renamed at this point.",
"ERROR_DELETING_FILE_TITLE" : "Error Deleting {0}",
"ERROR_DELETING_FILE" : "An error occurred when trying to delete the {2} <span class='dialog-filename'>{0}</span>. {1}",
"INVALID_FILENAME_TITLE" : "Invalid {0}",
Expand Down
18 changes: 11 additions & 7 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,14 +1320,18 @@ define(function (require, exports, module) {
// because some errors can come up synchronously and then the dialog
// is not displayed.
window.setTimeout(function () {
if (errorInfo.type === ProjectModel.ERROR_INVALID_FILENAME) {
switch (errorInfo.type) {
case ProjectModel.ERROR_INVALID_FILENAME:
_showErrorDialog(ERR_TYPE_INVALID_FILENAME, errorInfo.isFolder, ProjectModel._invalidChars);
} else {
var errString = errorInfo.type === FileSystemError.ALREADY_EXISTS ?
Strings.FILE_EXISTS_ERR :
FileUtils.getFileErrorString(errorInfo.type);

_showErrorDialog(ERR_TYPE_RENAME, errorInfo.isFolder, errString, errorInfo.fullPath);
break;
case FileSystemError.ALREADY_EXISTS:
_showErrorDialog(ERR_TYPE_RENAME, errorInfo.isFolder, Strings.FILE_EXISTS_ERR, errorInfo.fullPath);
break;
case ProjectModel.ERROR_NOT_IN_PROJECT:
_showErrorDialog(ERR_TYPE_RENAME, errorInfo.isFolder, Strings.ERROR_RENAMING_NOT_IN_PROJECT, errorInfo.fullPath);
break;
default:
_showErrorDialog(ERR_TYPE_RENAME, errorInfo.isFolder, FileUtils.getFileErrorString(errorInfo.type), errorInfo.fullPath);
}
}, 10);
d.reject(errorInfo);
Expand Down
16 changes: 13 additions & 3 deletions src/project/ProjectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ define(function (require, exports, module) {
EVENT_SHOULD_SELECT = "select",
EVENT_SHOULD_FOCUS = "focus",
ERROR_CREATION = "creationError",
ERROR_INVALID_FILENAME = "invalidFilename";
ERROR_INVALID_FILENAME = "invalidFilename",
ERROR_NOT_IN_PROJECT = "notInProject";

/**
* @private
Expand Down Expand Up @@ -799,18 +800,27 @@ define(function (require, exports, module) {
* @return {$.Promise} resolved when the operation is complete.
*/
ProjectModel.prototype.startRename = function (path) {
var d = new $.Deferred();
path = _getPathFromFSObject(path);
if (!path) {
path = this._selections.context;
if (!path) {
return new $.Deferred().resolve().promise();
return d.resolve().promise();
}
}

if (this._selections.rename && this._selections.rename.path === path) {
return;
}

if (!this.isWithinProject(path)) {
return d.reject({
type: ERROR_NOT_IN_PROJECT,
isFolder: !_pathIsFile(path),
fullPath: path
}).promise();
}

var projectRelativePath = this.makeProjectRelativeIfPossible(path);

if (!this._viewModel.isFilePathVisible(projectRelativePath)) {
Expand All @@ -825,7 +835,6 @@ define(function (require, exports, module) {

this._viewModel.moveMarker("rename", null,
projectRelativePath);
var d = new $.Deferred();
this._selections.rename = {
deferred: d,
type: FILE_RENAMING,
Expand Down Expand Up @@ -1346,6 +1355,7 @@ define(function (require, exports, module) {
exports.EVENT_SHOULD_FOCUS = EVENT_SHOULD_FOCUS;
exports.ERROR_CREATION = ERROR_CREATION;
exports.ERROR_INVALID_FILENAME = ERROR_INVALID_FILENAME;
exports.ERROR_NOT_IN_PROJECT = ERROR_NOT_IN_PROJECT;
exports.FILE_RENAMING = FILE_RENAMING;
exports.FILE_CREATING = FILE_CREATING;
exports.RENAME_CANCELLED = RENAME_CANCELLED;
Expand Down

0 comments on commit b05d263

Please sign in to comment.