-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add "New Folder" and "Rename" features #1719
Conversation
@@ -979,6 +1020,97 @@ define(function (require, exports, module) { | |||
} | |||
|
|||
/** | |||
* Rename the selected item in the project tree | |||
*/ | |||
function renameSelectedItem() { |
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.
Drive-by comment: is it worth factoring this so the rename functionality is programmatically accessible? People can't really call the raw fs.rename() directly since it doesn't send out notifications or update any of the UI.
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 call. Done.
Oh, one other comment actually -- the inline editor UI shows the filename in two places, so it needs to listen for the notification to. (Or maybe its TextRanges do, and then the inline editor UI listens to something they dispatch in turn). The Find in Files panel could be another one, but I think since we don't keep it up to date in other cases (e.g. the text content changing causing line numbers to shift) we could safely ignore it for now. |
For the inline editor, we actually get lucky. Only the filename is shown. If the file is renamed, it is selected before it is renamed, so the inline editor is closed. If a folder containing the file is renamed, no UI needs to change and the functionality works since the underlying document path is changed. Find in Files has been fixed. |
On Windows, when you use New Folder, the initial folder named "Untitled" is not sorted correctly. It's listed with the files (at the bottom) and not with the folders (at the top). Even after changing the name, it's still sorted with the files. |
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Initial review complete |
Thanks for reviewing! All comments have been addressed and changes pushed. |
I notice another bug that the "New File" recognizes when a file named Untitled.js already exists, and then generates a unique name (e.g. Untitled-1.js), but "New Folder" does not generate a unique name. |
UTR BUG: I keep hitting the case where "New File" and "New Folder" stop working, but I can't nail down a reproducible recipe. Anyway, something to be on the lookout for. |
I fixed the "New Folder" untitled naming problem. I haven't seen cases where "New File" or "New Folder" break. Are you seeing this on Mac or PC? |
I've seen the failing "New File" in master, so it's not related to Glenn's changes. There seems to be some case where it throws an exception when trying to scroll the new file into view in the project panel. I'll try to find repro steps and file a bug. |
The selection is now done after sorting. Hopefully this resolves the last issue. |
Yes, this fixes the selection issue. This pull request is now ready to merge as soon as the necessary brackets-shell pull request gets merged. |
Merging |
Add "New Folder" and "Rename" features
This pull request adds two new features: New Folder, and Rename file/folder.
IMPORTANT: This pull request requires adobe/brackets-shell#120
USAGE
The New Folder command is added to the File menu and the project context menu. When selected, a new folder is created at the same level as the current selection in the project tree. If nothing in the project tree is selected (for example, if a file in the working set is selected), the folder is created at the root of the project folder.
The Rename command is added to the project context menu. It will rename the selected file or folder. Note that the Rename command will only work on project tree items. You cannot rename a file in the working set.
API NOTES
DocumentManager
dispatches a newfileNameChange
event whenever the name of a file or folder has changed.DirectoryEntry.getDirectory()
is now implemented. This will return a reference to an existing directory or create a new directory if needed.UNIT TESTS
Unit tests are added for rename(), but not directory creation. We need an API to remove a directory before we can add unit tests that create a directory.