Skip to content

Commit 6ab40f5

Browse files
committed
chore: move to trash error dialogs and status bars
1 parent 1bfd750 commit 6ab40f5

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/document/DocumentCommandHandlers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ define(function (require, exports, module) {
18931893
.done(function (id) {
18941894
if (id === Dialogs.DIALOG_BTN_OK) {
18951895
if(Phoenix.isNativeApp && canMoveToTrash) {
1896-
Phoenix.app.moveToTrash(entry.fullPath);
1896+
ProjectManager.moveToTrash(entry);
18971897
return;
18981898
}
18991899
ProjectManager.deleteItem(entry);

src/nls/root/strings.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ define({
3131
"MOVING": "Moving {0}",
3232
"COPYING": "Copying {0}",
3333
"DELETING": "Deleting {0}",
34+
"DELETE_TO_TRASH": "Moving {0} to Trash",
35+
"DELETE_TO_RECYCLE_BIN": "Moving {0} to Recycle Bin",
3436
"RENAMING": "Renaming",
3537
"STORED_IN_YOUR_BROWSER": "Stored in Your Browser",
3638
"SUPPORT_US_OPEN_COLLECTIVE": "Support us on GitHub Sponsors",

src/project/ProjectManager.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,35 @@ define(function (require, exports, module) {
13581358
return actionCreator.startCreating(baseDir, initialName, isFolder);
13591359
}
13601360

1361+
function moveToTrash(entry) {
1362+
const result = new $.Deferred();
1363+
const canMoveToTrash = Phoenix.app.canMoveToTrash(entry.fullPath);
1364+
if(!canMoveToTrash){
1365+
console.error("Only tauri paths can be moved to trash, but got", entry.fullPath);
1366+
result.reject(FileSystemError.NOT_SUPPORTED);
1367+
return result.promise();
1368+
}
1369+
let name = _getProjectDisplayNameOrPath(entry.fullPath);
1370+
const messageTemplate = Phoenix.platform === "win" ?
1371+
Strings.DELETE_TO_RECYCLE_BIN : Strings.DELETE_TO_TRASH;
1372+
let message = StringUtils.format(messageTemplate, name);
1373+
setProjectBusy(true, message);
1374+
Phoenix.app.moveToTrash(entry.fullPath)
1375+
.then(()=>{
1376+
DocumentManager.notifyPathDeleted(entry.fullPath);
1377+
let parent = window.path.dirname(entry.fullPath);
1378+
_updateModelWithChange(parent);
1379+
result.resolve();
1380+
}).catch(err=>{
1381+
_showErrorDialog(ERR_TYPE_DELETE, entry.isDirectory, FileUtils.getFileErrorString(err), entry.fullPath);
1382+
result.reject(err);
1383+
}).finally(()=>{
1384+
setProjectBusy(false, message);
1385+
});
1386+
1387+
return result.promise();
1388+
}
1389+
13611390
/**
13621391
* Delete file or directore from project
13631392
* @param {!(File|Directory)} entry File or Directory to delete
@@ -2165,6 +2194,7 @@ define(function (require, exports, module) {
21652194
exports.createNewItem = createNewItem;
21662195
exports.renameItemInline = renameItemInline;
21672196
exports.deleteItem = deleteItem;
2197+
exports.moveToTrash = moveToTrash;
21682198
exports.forceFinishRename = forceFinishRename;
21692199
exports.showInTree = showInTree;
21702200
exports.shouldShowFileNameInTree = ProjectModel._shouldShowName;

0 commit comments

Comments
 (0)