-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Add drag and drop to move items in FileTreeView #13546
Changes from 1 commit
5f3c992
88e18f9
b856622
a98af02
dc98af6
113d25f
4c5bfc2
b0f99b4
4699ebf
4d187dc
9430b1b
9ab2c4a
8651108
0954350
4146637
5f9ebe4
b7df261
b0eee1b
d148980
5f8f7e7
b1f00df
45305cd
be7a935
0ca8bdf
09efcdb
e56830b
f416c65
ed84e49
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 |
|---|---|---|
|
|
@@ -116,7 +116,8 @@ define(function (require, exports, module) { | |
| ERR_TYPE_LOADING_PROJECT_NATIVE = 6, | ||
| ERR_TYPE_MAX_FILES = 7, | ||
| ERR_TYPE_OPEN_DIALOG = 8, | ||
| ERR_TYPE_INVALID_FILENAME = 9; | ||
| ERR_TYPE_INVALID_FILENAME = 9, | ||
| ERR_TYPE_MOVE = 10; | ||
|
|
||
| /** | ||
| * @private | ||
|
|
@@ -293,6 +294,13 @@ define(function (require, exports, module) { | |
| this.model.restoreContext(); | ||
| }; | ||
|
|
||
| /** | ||
| * See `ProjectModel.setDraggedOver` | ||
| */ | ||
| ActionCreator.prototype.setDraggedOver = function (path) { | ||
| this.model.setDraggedOver(path); | ||
| }; | ||
|
|
||
| /** | ||
| * See `ProjectModel.startRename` | ||
| */ | ||
|
|
@@ -368,6 +376,34 @@ define(function (require, exports, module) { | |
| _saveTreeState(); | ||
| }; | ||
|
|
||
| /** | ||
| * Moves the item in the oldPath to the newDirectory directory | ||
| * | ||
| * See `ProjectModel.moveItem` | ||
| */ | ||
| ActionCreator.prototype.moveItem = function(oldPath, newDirectory) { | ||
| var self = this; | ||
|
|
||
| // Remove selected marker | ||
| self.setSelected(null); | ||
|
Contributor
Author
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. As of now, I just remove the selected flag if any of the items are moved. Need feedback on the correct way to handle it. |
||
|
|
||
| this.model.moveItem(oldPath, newDirectory) | ||
| .fail(function(errorInfo) { | ||
| // Need to do display the error message on the next event loop turn | ||
| // because some errors can come up synchronously and then the dialog | ||
| // is not displayed. | ||
| window.setTimeout(function () { | ||
| switch (errorInfo.type) { | ||
| // TODO: handle Errors | ||
| default: | ||
| console.log(errorInfo.type); | ||
| _showErrorDialog(ERR_TYPE_MOVE, errorInfo.isFolder, Strings.FILE_EXISTS_ERR, errorInfo.fullPath); | ||
| break; | ||
| } | ||
| }, 10); | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * See `ProjectModel.refresh` | ||
| */ | ||
|
|
@@ -604,6 +640,11 @@ define(function (require, exports, module) { | |
| title = StringUtils.format(Strings.INVALID_FILENAME_TITLE, isFolder ? Strings.DIRECTORY_NAME : Strings.FILENAME); | ||
| message = StringUtils.format(Strings.INVALID_FILENAME_MESSAGE, isFolder ? Strings.DIRECTORY_NAMES_LEDE : Strings.FILENAMES_LEDE, error); | ||
| break; | ||
| case ERR_TYPE_MOVE: | ||
| // TODO: Change it to handle move errors | ||
| title = StringUtils.format(Strings.GENERIC_ERROR, titleType); | ||
| message = StringUtils.format(Strings.GENERIC_ERROR, path); | ||
| break; | ||
| } | ||
|
|
||
| if (title && message) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -714,6 +714,20 @@ define(function (require, exports, module) { | |
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Moves the draggedOver flag | ||
| * | ||
| * @param {string} path full path to the folder over which dragging is done | ||
| */ | ||
| ProjectModel.prototype.setDraggedOver = function(path) { | ||
| var oldDraggedOverPath = this.makeProjectRelativeIfPossible(this._selections.draggedOver), | ||
| newDraggedOverPath = this.makeProjectRelativeIfPossible(path); | ||
|
|
||
| this._selections.draggedOver = path; | ||
|
|
||
| this._viewModel.moveMarker("draggedOver", oldDraggedOverPath, newDraggedOverPath); | ||
| }; | ||
|
|
||
| /** | ||
| * Gets the currently selected file or directory. | ||
| * | ||
|
|
@@ -1239,6 +1253,50 @@ define(function (require, exports, module) { | |
| this._viewModel.closeSubtree(this.makeProjectRelativeIfPossible(path)); | ||
| }; | ||
|
|
||
| /** | ||
| * Moves the item in oldPath to the newDirectory directory | ||
| * @param {string} oldPath old path of the item | ||
| * @param {string} newDirectory path of the directory to move the item | ||
| * @return {$.Promise} promise resolved when the item is moved | ||
| */ | ||
| ProjectModel.prototype.moveItem = function(oldPath, newDirectory) { | ||
| var self = this, | ||
| d = new $.Deferred(), | ||
| fileName = FileUtils.getBaseName(oldPath), | ||
| fullNewPath = newDirectory + fileName; | ||
|
|
||
| // Add trailing slash if directory is moved | ||
| if (!_pathIsFile(oldPath)) { | ||
| fullNewPath = _ensureTrailingSlash(fullNewPath); | ||
| } | ||
|
|
||
| // Reusing the _renameItem for moving item | ||
| this._renameItem(oldPath, fullNewPath, fileName, !_pathIsFile(fullNewPath)).then(function () { | ||
| var newDirectoryRelative = self.makeProjectRelativeIfPossible(newDirectory), | ||
| needsLoading = !self._viewModel.isPathLoaded(newDirectoryRelative); | ||
|
Collaborator
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. Nit: some extra spaces after
Collaborator
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. Maybe save the reference to |
||
|
|
||
| // If directory view not loaded, load it and then update the view | ||
| if (needsLoading) { | ||
| self._getDirectoryContents(newDirectory).then(function(contents) { | ||
| self._viewModel.setDirectoryContents(newDirectoryRelative, contents); | ||
| self._viewModel.moveItem(self.makeProjectRelativeIfPossible(oldPath), self.makeProjectRelativeIfPossible(fullNewPath)); | ||
|
Collaborator
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. Maybe make these variables too |
||
| }); | ||
| } else { | ||
| self._viewModel.moveItem(self.makeProjectRelativeIfPossible(oldPath), self.makeProjectRelativeIfPossible(fullNewPath)); | ||
| } | ||
| d.resolve(); | ||
| }).fail(function (errorType) { | ||
| var errorInfo = { | ||
| type: errorType, | ||
| isFolder: !_pathIsFile(fullNewPath), | ||
| fullPath: fullNewPath | ||
| }; | ||
| d.reject(errorInfo); | ||
| }); | ||
|
|
||
| return d.promise(); | ||
| }; | ||
|
|
||
| /** | ||
| * Toggle the open state of subdirectories. | ||
| * @param {!string} path parent directory | ||
|
|
||
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.
No need to set
thisto variable here (for now at least)