-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add "New Folder" and "Rename" features #1719
Changes from 5 commits
a582f8b
36ca3dd
2e38d6d
7d97275
3291e05
5db70c8
cd0199c
c16e87c
edda6b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,8 @@ | |
* 2nd arg to the listener is the removed FileEntry. | ||
* - workingSetRemoveList -- When a list of files is to be removed from the working set (e.g. project close). | ||
* The 2nd arg to the listener is the array of removed FileEntry objects. | ||
* - fileNameChange -- When the name of a file or folder has changed. The 2nd arg is the old name. | ||
* The 3rd arg is the new name. | ||
* | ||
* These are jQuery events, so to listen for them you do something like this: | ||
* $(DocumentManager).on("eventname", handler); | ||
|
@@ -1061,7 +1063,49 @@ define(function (require, exports, module) { | |
} | ||
} | ||
|
||
|
||
/** | ||
* Called after a file or folder name has changed. This function is responsible | ||
* for updating underlying model data and notifying all views of the change. | ||
* | ||
* @param {string} oldName The old name of the file/folder | ||
* @param {string} newName The new name of the file/folder | ||
*/ | ||
function notifyFileNameChanged(oldName, newName) { | ||
var i, path; | ||
|
||
// Update currentDocument | ||
FileUtils.updateFileEntryPath(_currentDocument.file, oldName, newName); | ||
|
||
// Update open documents | ||
var keysToDelete = []; | ||
for (path in _openDocuments) { | ||
if (_openDocuments.hasOwnProperty(path)) { | ||
if (path.indexOf(oldName) === 0) { | ||
// Copy value to new key | ||
var newKey = path.replace(oldName, newName); | ||
|
||
_openDocuments[newKey] = _openDocuments[path]; | ||
keysToDelete.push(path); | ||
|
||
// Update document file | ||
FileUtils.updateFileEntryPath(_openDocuments[newKey].file, oldName, newName); | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case of a file (as opposed to a folder), we can exit this loop after we find the first item because we know there will be at most 1. So, it might be worth adding an isFolder parameter to this function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
// Delete the old keys | ||
for (i = 0; i < keysToDelete.length; i++) { | ||
delete _openDocuments[keysToDelete[i]]; | ||
} | ||
|
||
// Update working set | ||
for (i = 0; i < _workingSet.length; i++) { | ||
FileUtils.updateFileEntryPath(_workingSet[i], oldName, newName); | ||
} | ||
|
||
// Send a "fileNameChanged" event. This will trigger the views to update. | ||
$(exports).triggerHandler("fileNameChange", [oldName, newName]); | ||
} | ||
|
||
// Define public API | ||
exports.Document = Document; | ||
exports.getCurrentDocument = getCurrentDocument; | ||
|
@@ -1080,10 +1124,11 @@ define(function (require, exports, module) { | |
exports.closeFullEditor = closeFullEditor; | ||
exports.closeAll = closeAll; | ||
exports.notifyFileDeleted = notifyFileDeleted; | ||
exports.notifyFileNameChanged = notifyFileNameChanged; | ||
|
||
// Setup preferences | ||
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); | ||
$(exports).bind("currentDocumentChange workingSetAdd workingSetAddList workingSetRemove workingSetRemoveList", _savePreferences); | ||
$(exports).bind("currentDocumentChange workingSetAdd workingSetAddList workingSetRemove workingSetRemoveList fileNameChange", _savePreferences); | ||
|
||
// Performance measurements | ||
PerfUtils.createPerfMeasurement("DOCUMENT_MANAGER_GET_DOCUMENT_FOR_PATH", "DocumentManager.getDocumentForPath()"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ define({ | |
"NOT_READABLE_ERR" : "The file could not be read.", | ||
"NO_MODIFICATION_ALLOWED_ERR" : "The target directory cannot be modified.", | ||
"NO_MODIFICATION_ALLOWED_ERR_FILE" : "The permissions do not allow you to make modifications.", | ||
"FILE_EXISTS_ERR" : "The file already exists.", | ||
|
||
// Project error strings | ||
"ERROR_LOADING_PROJECT" : "Error loading project", | ||
|
@@ -49,6 +50,8 @@ define({ | |
"ERROR_RELOADING_FILE" : "An error occurred when trying to reload the file <span class='dialog-filename'>{0}</span>. {1}", | ||
"ERROR_SAVING_FILE_TITLE" : "Error saving file", | ||
"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 file", | ||
"ERROR_RENAMING_FILE" : "An error occurred when trying to rename the file <span class='dialog-filename'>{0}</span>. {1}", | ||
"INVALID_FILENAME_TITLE" : "Invalid file name", | ||
"INVALID_FILENAME_MESSAGE" : "Filenames cannot contain the following characters: /?*:;{}<>\\|", | ||
"FILE_ALREADY_EXISTS" : "The file <span class='dialog-filename'>{0}</span> already exists.", | ||
|
@@ -140,6 +143,7 @@ define({ | |
// File menu commands | ||
"FILE_MENU" : "File", | ||
"CMD_FILE_NEW" : "New", | ||
"CMD_FILE_NEW_FOLDER" : "New Folder", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we have "New Folder", I think "New" should be changed to "New File". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
"CMD_FILE_OPEN" : "Open\u2026", | ||
"CMD_ADD_TO_WORKING_SET" : "Add To Working Set", | ||
"CMD_OPEN_FOLDER" : "Open Folder\u2026", | ||
|
@@ -148,6 +152,7 @@ define({ | |
"CMD_FILE_SAVE" : "Save", | ||
"CMD_FILE_SAVE_ALL" : "Save All", | ||
"CMD_LIVE_FILE_PREVIEW" : "Live Preview", | ||
"CMD_FILE_RENAME" : "Rename\u2026", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think "Rename..." should have ellipses, since it uses inline editing (i.e. it does not invoke a modal dialog). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we used ellipses when we require more input. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I always thought the distinction was to use ellipses if you're invoking a modal dialog. I don't see ellipses after Rename anywhere else (including Windows File Explorer, DW, VS, Xcode). Also, "New" and "New Folder" require the same additional input as "Rename", and I don't think that we want to add ellipses to those. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, since we don't have ellipses for "New File" or "New Folder", we should probably leave it off "Rename" too. Done. |
||
"CMD_QUIT" : "Quit", | ||
|
||
// Edit menu commands | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"reset" sounds like it's being changed back to a previous state. How about updateDocumentTitle() or changeDocumentTitle() ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion. Done.