-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Move file or folder to the trash #3879
Changes from 13 commits
74745d8
62b16cc
99ecee7
2e72e20
e45563b
9897e18
48bcde7
3850c5b
ac4dc54
f9bb682
338c68c
0d3b597
3fa4049
0a02712
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 |
---|---|---|
|
@@ -1299,7 +1299,7 @@ define(function (require, exports, module) { | |
|
||
result.resolve(); | ||
} else { | ||
// Show and error alert | ||
// Show an error alert | ||
Dialogs.showModalDialog( | ||
Dialogs.DIALOG_ID_ERROR, | ||
Strings.ERROR_RENAMING_FILE_TITLE, | ||
|
@@ -1383,6 +1383,62 @@ define(function (require, exports, module) { | |
}); | ||
// No fail handler: silently no-op if file doesn't exist in tree | ||
} | ||
|
||
/** | ||
* Delete file or directore from project | ||
* @param {!Entry} entry FileEntry or DirectoryEntry to delete | ||
*/ | ||
function deleteItem(entry) { | ||
var result = new $.Deferred(); | ||
|
||
entry.remove(function () { | ||
_findTreeNode(entry).done(function ($node) { | ||
_projectTree.one("delete_node.jstree", function () { | ||
// When a node is deleted, the previous node is automatically selected. | ||
// This works fine as long as the previous node is a file, but doesn't | ||
// work so well if the node is a 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. I don't think this behavior is not quite right. Currently, you can only delete file from file tree, and this is done by using the context menu, so by definition, the file is selected (i.e. shown in editor). To determine the file that should become selected, we should first look for Working Files. When deleting the first file in folder list, this is currently working correctly. If there are any other Working Files, then one of them is selected, otherwise nothing is selected. For non-first files in folder list, this currently selects previous file in folder list. It should instead choose from remaining Working Files. If there are no Working Files, then I think nothing should be selected (like File > Close), but I guess this should be discussed with team. 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. Selecting files in the working set after deleting from the file tree didn't feel right. The behavior I wanted was to move the selection to the nearest tree node above the one that was deleted. However, there is a bug in the current implementation (as pointed out by your comment above). The selection should always remain in the file tree after deleting and never get moved to the working set. Try it out with the fixes for |
||
var sel = _projectTree.jstree("get_selected"), | ||
entry = sel ? sel.data("entry") : null; | ||
|
||
if (entry && entry.isDirectory) { | ||
// Make sure it didn't turn into a leaf node. This happens if | ||
// the only file in the directory was deleted | ||
if (sel.hasClass("jstree-leaf")) { | ||
sel.removeClass("jstree-leaf jstree-open"); | ||
sel.addClass("jstree-closed"); | ||
} | ||
} | ||
}); | ||
var oldSuppressToggleOpen = suppressToggleOpen; | ||
suppressToggleOpen = true; | ||
_projectTree.jstree("delete_node", $node); | ||
suppressToggleOpen = oldSuppressToggleOpen; | ||
}); | ||
|
||
// Notify that one of the project files has changed | ||
$(exports).triggerHandler("projectFilesChange"); | ||
|
||
DocumentManager.notifyPathDeleted(entry.fullPath); | ||
|
||
_redraw(true); | ||
result.promise(); | ||
}, function (err) { | ||
// Show an error alert | ||
Dialogs.showModalDialog( | ||
Dialogs.DIALOG_ID_ERROR, | ||
Strings.ERROR_DELETING_FILE_TITLE, | ||
StringUtils.format( | ||
Strings.ERROR_DELETING_FILE, | ||
StringUtils.htmlEscape(entry.fullPath), | ||
FileUtils.getFileErrorString(err) | ||
) | ||
); | ||
|
||
result.reject(err); | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Forces createNewItem() to complete by removing focus from the rename field which causes | ||
|
@@ -1448,6 +1504,7 @@ define(function (require, exports, module) { | |
exports.updateWelcomeProjectPath = updateWelcomeProjectPath; | ||
exports.createNewItem = createNewItem; | ||
exports.renameItemInline = renameItemInline; | ||
exports.deleteItem = deleteItem; | ||
exports.forceFinishRename = forceFinishRename; | ||
exports.showInTree = showInTree; | ||
}); |
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.
skipAutoSelect parameter is unused.
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.
Yep, that should have been passed to
closeFullEditor()
. Fixed.