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

Commit 2ee5a98

Browse files
committed
Merge pull request #8008 from SAPlayer/issue-8003
Use correct error message when renaming/deleting folder
2 parents 6030d23 + a74e70a commit 2ee5a98

2 files changed

Lines changed: 113 additions & 102 deletions

File tree

src/nls/root/strings.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ define({
4040
"UNSUPPORTED_ENCODING_ERR" : "{APP_NAME} currently only supports UTF-8 encoded text files.",
4141
"FILE_EXISTS_ERR" : "The file or directory already exists.",
4242
"FILE" : "file",
43+
"FILE_TITLE" : "File",
4344
"DIRECTORY" : "directory",
45+
"DIRECTORY_TITLE" : "Directory",
4446
"DIRECTORY_NAMES_LEDE" : "Directory names",
4547
"FILENAMES_LEDE" : "Filenames",
46-
"FILENAME" : "filename",
47-
"DIRECTORY_NAME" : "directory name",
48+
"FILENAME" : "Filename",
49+
"DIRECTORY_NAME" : "Directory Name",
4850

4951

5052
// Project error strings
51-
"ERROR_LOADING_PROJECT" : "Error loading project",
53+
"ERROR_LOADING_PROJECT" : "Error Loading Project",
5254
"OPEN_DIALOG_ERROR" : "An error occurred when showing the open file dialog. (error {0})",
5355
"REQUEST_NATIVE_FILE_SYSTEM_ERROR" : "An error occurred when trying to load the directory <span class='dialog-filename'>{0}</span>. (error {1})",
5456
"READ_DIRECTORY_ENTRIES_ERROR" : "An error occurred when reading the contents of the directory <span class='dialog-filename'>{0}</span>. (error {1})",
@@ -61,10 +63,10 @@ define({
6163
"ERROR_RELOADING_FILE" : "An error occurred when trying to reload the file <span class='dialog-filename'>{0}</span>. {1}",
6264
"ERROR_SAVING_FILE_TITLE" : "Error Saving File",
6365
"ERROR_SAVING_FILE" : "An error occurred when trying to save the file <span class='dialog-filename'>{0}</span>. {1}",
64-
"ERROR_RENAMING_FILE_TITLE" : "Error Renaming File",
65-
"ERROR_RENAMING_FILE" : "An error occurred when trying to rename the file <span class='dialog-filename'>{0}</span>. {1}",
66-
"ERROR_DELETING_FILE_TITLE" : "Error Deleting File",
67-
"ERROR_DELETING_FILE" : "An error occurred when trying to delete the file <span class='dialog-filename'>{0}</span>. {1}",
66+
"ERROR_RENAMING_FILE_TITLE" : "Error Renaming {0}",
67+
"ERROR_RENAMING_FILE" : "An error occurred when trying to rename the {2} <span class='dialog-filename'>{0}</span>. {1}",
68+
"ERROR_DELETING_FILE_TITLE" : "Error Deleting {0}",
69+
"ERROR_DELETING_FILE" : "An error occurred when trying to delete the {2} <span class='dialog-filename'>{0}</span>. {1}",
6870
"INVALID_FILENAME_TITLE" : "Invalid {0}",
6971
"INVALID_FILENAME_MESSAGE" : "{0} cannot use any system reserved words, end with dots (.) or use any of the following characters: <code class='emphasized'>{1}</code>",
7072
"ENTRY_WITH_SAME_NAME_EXISTS" : "A file or directory with the name <span class='dialog-filename'>{0}</span> already exists.",
@@ -183,7 +185,7 @@ define({
183185
"REPLACE_IN_FILES_ERRORS_TITLE" : "Replace Errors",
184186
"REPLACE_IN_FILES_ERRORS" : "The following files weren't modified because they changed after the search or couldn't be written.",
185187

186-
"ERROR_FETCHING_UPDATE_INFO_TITLE" : "Error getting update info",
188+
"ERROR_FETCHING_UPDATE_INFO_TITLE" : "Error Getting Update Info",
187189
"ERROR_FETCHING_UPDATE_INFO_MSG" : "There was a problem getting the latest update information from the server. Please make sure you are connected to the internet and try again.",
188190

189191
// File exclusion filters

src/project/ProjectManager.js

Lines changed: 103 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ define(function (require, exports, module) {
115115
*/
116116
var SETTINGS_FILENAME = "." + PreferencesManager.SETTINGS_FILENAME;
117117

118+
/**
119+
* @const
120+
* @private
121+
* Error context to show the correct error message
122+
* @type {int}
123+
*/
124+
var ERR_TYPE_CREATE = 1,
125+
ERR_TYPE_CREATE_EXISTS = 2,
126+
ERR_TYPE_RENAME = 3,
127+
ERR_TYPE_DELETE = 4,
128+
ERR_TYPE_LOADING_PROJECT = 5,
129+
ERR_TYPE_LOADING_PROJECT_NATIVE = 6,
130+
ERR_TYPE_MAX_FILES = 7,
131+
ERR_TYPE_OPEN_DIALOG = 8,
132+
ERR_TYPE_INVALID_FILENAME = 9;
133+
118134
/**
119135
* @private
120136
* Reference to the tree control container div. Initialized by
@@ -764,6 +780,62 @@ define(function (require, exports, module) {
764780
return Async.withTimeout(result.promise(), 1000);
765781
}
766782

783+
function _showErrorDialog(errType, isFolder, error, path) {
784+
var titleType = isFolder ? Strings.DIRECTORY_TITLE : Strings.FILE_TITLE,
785+
entryType = isFolder ? Strings.DIRECTORY : Strings.FILE,
786+
title,
787+
message;
788+
path = StringUtils.breakableUrl(path);
789+
790+
switch (errType) {
791+
case ERR_TYPE_CREATE:
792+
title = StringUtils.format(Strings.ERROR_CREATING_FILE_TITLE, titleType);
793+
message = StringUtils.format(Strings.ERROR_CREATING_FILE, entryType, path, error);
794+
break;
795+
case ERR_TYPE_CREATE_EXISTS:
796+
title = StringUtils.format(Strings.INVALID_FILENAME_TITLE, titleType);
797+
message = StringUtils.format(Strings.ENTRY_WITH_SAME_NAME_EXISTS, path);
798+
break;
799+
case ERR_TYPE_RENAME:
800+
title = StringUtils.format(Strings.ERROR_RENAMING_FILE_TITLE, titleType);
801+
message = StringUtils.format(Strings.ERROR_RENAMING_FILE, path, error, entryType);
802+
break;
803+
case ERR_TYPE_DELETE:
804+
title = StringUtils.format(Strings.ERROR_DELETING_FILE_TITLE, titleType);
805+
message = StringUtils.format(Strings.ERROR_DELETING_FILE, path, error, entryType);
806+
break;
807+
case ERR_TYPE_LOADING_PROJECT:
808+
title = Strings.ERROR_LOADING_PROJECT;
809+
message = StringUtils.format(Strings.READ_DIRECTORY_ENTRIES_ERROR, path, error);
810+
break;
811+
case ERR_TYPE_LOADING_PROJECT_NATIVE:
812+
title = Strings.ERROR_LOADING_PROJECT;
813+
message = StringUtils.format(Strings.REQUEST_NATIVE_FILE_SYSTEM_ERROR, path, error);
814+
break;
815+
case ERR_TYPE_MAX_FILES:
816+
title = Strings.ERROR_MAX_FILES_TITLE;
817+
message = Strings.ERROR_MAX_FILES;
818+
break;
819+
case ERR_TYPE_OPEN_DIALOG:
820+
title = Strings.ERROR_LOADING_PROJECT;
821+
message = StringUtils.format(Strings.OPEN_DIALOG_ERROR, error);
822+
break;
823+
case ERR_TYPE_INVALID_FILENAME:
824+
title = StringUtils.format(Strings.INVALID_FILENAME_TITLE, isFolder ? Strings.DIRECTORY_NAME : Strings.FILENAME);
825+
message = StringUtils.format(Strings.INVALID_FILENAME_MESSAGE, isFolder ? Strings.DIRECTORY_NAMES_LEDE : Strings.FILENAMES_LEDE, error);
826+
break;
827+
}
828+
829+
if (title && message) {
830+
return Dialogs.showModalDialog(
831+
DefaultDialogs.DIALOG_ID_ERROR,
832+
title,
833+
message
834+
);
835+
}
836+
return null;
837+
}
838+
767839
/**
768840
* @private
769841
* See shouldShow
@@ -945,15 +1017,7 @@ define(function (require, exports, module) {
9451017
// Fetch dirEntry's contents
9461018
dirEntry.getContents(function (err, contents, stats, statsErrs) {
9471019
if (err) {
948-
Dialogs.showModalDialog(
949-
DefaultDialogs.DIALOG_ID_ERROR,
950-
Strings.ERROR_LOADING_PROJECT,
951-
StringUtils.format(
952-
Strings.READ_DIRECTORY_ENTRIES_ERROR,
953-
StringUtils.breakableUrl(dirEntry.fullPath),
954-
err
955-
)
956-
);
1020+
_showErrorDialog(ERR_TYPE_LOADING_PROJECT, null, err, dirEntry.fullPath);
9571021
// Reject the render promise so we can move on.
9581022
deferred.reject();
9591023
} else {
@@ -1049,25 +1113,13 @@ define(function (require, exports, module) {
10491113
return updateWelcomeProjectPath(PreferencesManager.getViewState("projectPath"));
10501114
}
10511115

1052-
/**
1053-
* Error dialog when max files in index is hit
1054-
* @return {Dialog}
1055-
*/
1056-
function _showMaxFilesDialog() {
1057-
return Dialogs.showModalDialog(
1058-
DefaultDialogs.DIALOG_ID_ERROR,
1059-
Strings.ERROR_MAX_FILES_TITLE,
1060-
Strings.ERROR_MAX_FILES
1061-
);
1062-
}
1063-
10641116
function _watchProjectRoot(rootPath) {
10651117
FileSystem.on("change", _fileSystemChange);
10661118
FileSystem.on("rename", _fileSystemRename);
10671119

10681120
FileSystem.watch(FileSystem.getDirectoryForPath(rootPath), _shouldShowName, function (err) {
10691121
if (err === FileSystemError.TOO_MANY_ENTRIES) {
1070-
_showMaxFilesDialog();
1122+
_showErrorDialog(ERR_TYPE_MAX_FILES);
10711123
} else if (err) {
10721124
console.error("Error watching project root: ", rootPath, err);
10731125
}
@@ -1200,7 +1252,6 @@ define(function (require, exports, module) {
12001252
if (exists) {
12011253
var projectRootChanged = (!_projectRoot || !rootEntry) ||
12021254
_projectRoot.fullPath !== rootEntry.fullPath;
1203-
var i;
12041255

12051256
// Success!
12061257
var perfTimerName = PerfUtils.markStart("Load Project: " + rootPath);
@@ -1246,31 +1297,24 @@ define(function (require, exports, module) {
12461297
PerfUtils.addMeasurement(perfTimerName);
12471298
});
12481299
} else {
1249-
Dialogs.showModalDialog(
1250-
DefaultDialogs.DIALOG_ID_ERROR,
1251-
Strings.ERROR_LOADING_PROJECT,
1252-
StringUtils.format(
1253-
Strings.REQUEST_NATIVE_FILE_SYSTEM_ERROR,
1254-
StringUtils.breakableUrl(rootPath),
1255-
err || FileSystemError.NOT_FOUND
1256-
)
1257-
).done(function () {
1258-
// Reset _projectRoot to null so that the following _loadProject call won't
1259-
// run the 'beforeProjectClose' event a second time on the original project,
1260-
// which is now partially torn down (see #6574).
1261-
_projectRoot = null;
1262-
1263-
// The project folder stored in preference doesn't exist, so load the default
1264-
// project directory.
1265-
// TODO (issue #267): When Brackets supports having no project directory
1266-
// defined this code will need to change
1267-
_loadProject(_getWelcomeProjectPath()).always(function () {
1268-
// Make sure not to reject the original deferred until the fallback
1269-
// project is loaded, so we don't violate expectations that there is always
1270-
// a current project before continuing after _loadProject().
1271-
result.reject();
1300+
_showErrorDialog(ERR_TYPE_LOADING_PROJECT_NATIVE, null, rootPath, err || FileSystemError.NOT_FOUND)
1301+
.done(function () {
1302+
// Reset _projectRoot to null so that the following _loadProject call won't
1303+
// run the 'beforeProjectClose' event a second time on the original project,
1304+
// which is now partially torn down (see #6574).
1305+
_projectRoot = null;
1306+
1307+
// The project folder stored in preference doesn't exist, so load the default
1308+
// project directory.
1309+
// TODO (issue #267): When Brackets supports having no project directory
1310+
// defined this code will need to change
1311+
_loadProject(_getWelcomeProjectPath()).always(function () {
1312+
// Make sure not to reject the original deferred until the fallback
1313+
// project is loaded, so we don't violate expectations that there is always
1314+
// a current project before continuing after _loadProject().
1315+
result.reject();
1316+
});
12721317
});
1273-
});
12741318
}
12751319
});
12761320
}
@@ -1522,11 +1566,7 @@ define(function (require, exports, module) {
15221566
result.reject();
15231567
}
15241568
} else {
1525-
Dialogs.showModalDialog(
1526-
DefaultDialogs.DIALOG_ID_ERROR,
1527-
Strings.ERROR_LOADING_PROJECT,
1528-
StringUtils.format(Strings.OPEN_DIALOG_ERROR, err)
1529-
);
1569+
_showErrorDialog(ERR_TYPE_OPEN_DIALOG, null, err);
15301570
result.reject();
15311571
}
15321572
});
@@ -1565,11 +1605,7 @@ define(function (require, exports, module) {
15651605
// See http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
15661606
if ((filename.search(new RegExp("[" + _invalidChars + "]+")) !== -1) ||
15671607
filename.match(_illegalFilenamesRegEx)) {
1568-
Dialogs.showModalDialog(
1569-
DefaultDialogs.DIALOG_ID_ERROR,
1570-
StringUtils.format(Strings.INVALID_FILENAME_TITLE, isFolder ? Strings.DIRECTORY_NAME : Strings.FILENAME),
1571-
StringUtils.format(Strings.INVALID_FILENAME_MESSAGE, isFolder ? Strings.DIRECTORY_NAMES_LEDE : Strings.FILENAMES_LEDE, _invalidChars)
1572-
);
1608+
_showErrorDialog(ERR_TYPE_INVALID_FILENAME, isFolder, _invalidChars);
15731609
return false;
15741610
}
15751611
return true;
@@ -1694,38 +1730,26 @@ define(function (require, exports, module) {
16941730
_createNode($baseDirNode, null, _entryToJSON(entry), true, true);
16951731
};
16961732

1697-
var errorCallback = function (error, entry) {
1698-
var titleType = isFolder ? Strings.DIRECTORY_NAME : Strings.FILENAME,
1699-
entryType = isFolder ? Strings.DIRECTORY : Strings.FILE;
1733+
var errorCallback = function (error) {
17001734
if (error === FileSystemError.ALREADY_EXISTS) {
1701-
Dialogs.showModalDialog(
1702-
DefaultDialogs.DIALOG_ID_ERROR,
1703-
StringUtils.format(Strings.INVALID_FILENAME_TITLE, titleType),
1704-
StringUtils.format(Strings.ENTRY_WITH_SAME_NAME_EXISTS,
1705-
StringUtils.breakableUrl(data.rslt.name))
1706-
);
1735+
_showErrorDialog(ERR_TYPE_CREATE_EXISTS, isFolder, null, data.rslt.name);
17071736
} else {
17081737
var errString = error === FileSystemError.NOT_WRITABLE ?
17091738
Strings.NO_MODIFICATION_ALLOWED_ERR :
17101739
StringUtils.format(Strings.GENERIC_ERROR, error);
17111740

1712-
Dialogs.showModalDialog(
1713-
DefaultDialogs.DIALOG_ID_ERROR,
1714-
StringUtils.format(Strings.ERROR_CREATING_FILE_TITLE, entryType),
1715-
StringUtils.format(Strings.ERROR_CREATING_FILE, entryType,
1716-
StringUtils.breakableUrl(data.rslt.name), errString)
1717-
);
1741+
_showErrorDialog(ERR_TYPE_CREATE, isFolder, errString, data.rslt.name);
17181742
}
17191743

17201744
errorCleanup();
17211745
};
17221746

17231747
var newItemPath = baseDirEntry.fullPath + data.rslt.name;
17241748

1725-
FileSystem.resolve(newItemPath, function (err, item) {
1749+
FileSystem.resolve(newItemPath, function (err) {
17261750
if (!err) {
17271751
// Item already exists, fail with error
1728-
errorCallback(FileSystemError.ALREADY_EXISTS, item);
1752+
errorCallback(FileSystemError.ALREADY_EXISTS);
17291753
} else {
17301754
if (isFolder) {
17311755
var directory = FileSystem.getDirectoryForPath(newItemPath);
@@ -1820,17 +1844,11 @@ define(function (require, exports, module) {
18201844
result.resolve();
18211845
} else {
18221846
// Show an error alert
1823-
Dialogs.showModalDialog(
1824-
DefaultDialogs.DIALOG_ID_ERROR,
1825-
Strings.ERROR_RENAMING_FILE_TITLE,
1826-
StringUtils.format(
1827-
Strings.ERROR_RENAMING_FILE,
1828-
StringUtils.breakableUrl(newName),
1829-
err === FileSystemError.ALREADY_EXISTS ?
1847+
var errString = err === FileSystemError.ALREADY_EXISTS ?
18301848
Strings.FILE_EXISTS_ERR :
1831-
FileUtils.getFileErrorString(err)
1832-
)
1833-
);
1849+
FileUtils.getFileErrorString(err);
1850+
1851+
_showErrorDialog(ERR_TYPE_RENAME, isFolder, errString, newName);
18341852
result.reject(err);
18351853
}
18361854
});
@@ -2005,16 +2023,7 @@ define(function (require, exports, module) {
20052023
_deleteTreeNode(entry);
20062024
result.resolve();
20072025
} else {
2008-
// Show an error alert
2009-
Dialogs.showModalDialog(
2010-
Dialogs.DIALOG_ID_ERROR,
2011-
Strings.ERROR_DELETING_FILE_TITLE,
2012-
StringUtils.format(
2013-
Strings.ERROR_DELETING_FILE,
2014-
_.escape(entry.fullPath),
2015-
FileUtils.getFileErrorString(err)
2016-
)
2017-
);
2026+
_showErrorDialog(ERR_TYPE_DELETE, entry.isDirectory, FileUtils.getFileErrorString(err), entry.fullPath);
20182027

20192028
result.reject(err);
20202029
}

0 commit comments

Comments
 (0)