Skip to content

Commit c3cbeaa

Browse files
authored
Merge pull request #599 from makermelissa-ai-assistant/fix/issue-553-move-errors
Show file move failures in the dialog
2 parents 79dd781 + 9121248 commit c3cbeaa

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

‎js/common/dialogs.js‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ class GenericModal {
8181
element.innerHTML = value;
8282
}
8383

84-
async _showMessage(message) {
84+
async _showMessage(message, options) {
8585
const messageDialog = new MessageModal("message");
86-
return await messageDialog.open(message);
86+
return await messageDialog.open(message, options);
8787
}
8888

8989
_addModalLayer(modal) {
@@ -232,11 +232,16 @@ class GenericModal {
232232
}
233233

234234
class MessageModal extends GenericModal {
235-
async open(message) {
235+
async open(message, {plainText = false} = {}) {
236236
let p = super.open();
237237
const okButton = this._currentModal.querySelector("button.ok-button");
238238
this._addDialogElement('okButton', okButton, 'click', this._closeModal);
239-
this._currentModal.querySelector("#message").innerHTML = message;
239+
const messageElement = this._currentModal.querySelector("#message");
240+
if (plainText) {
241+
messageElement.textContent = message;
242+
} else {
243+
messageElement.innerHTML = message;
244+
}
240245

241246
return p;
242247
}

‎js/common/file_dialog.js‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -623,29 +623,41 @@ class FileDialog extends GenericModal {
623623
async _handleMoveButton() {
624624
// Get the new path
625625
const newFolderDialog = new FileDialog("folder-select", this._showBusy);
626-
let hidePaths = new Set();
627-
hidePaths.add(this._getSelectedFilePath());
626+
const hidePaths = new Set(this._getSelectedFilePath());
628627
hidePaths.add(this._currentPath);
629628
let newFolder = await newFolderDialog.open(this._fileHelper, FILE_DIALOG_MOVE, hidePaths, false);
630629
let errors = false;
630+
let movedAny = false;
631631
if (newFolder) {
632632
const files = this._getSelectedFilesInfo();
633633
for (let file of files) {
634634
const filename = file.filename;
635635
const filetype = file.filetype == "folder" ? "folder" : "file";
636636
const oldPath = this._currentPath + filename;
637637
const newPath = newFolder + filename;
638-
if (await this._showBusy(this._fileHelper.fileExists(newPath))) {
639-
this._showMessage(`Error moving ${oldPath}. Another ${filetype} with the same name already exists at ${newPath}.`);
640-
errors = true;
641-
} else if (!(await this._showBusy(this._fileHelper.move(oldPath, newPath)))) {
642-
this._showMessage(`Error moving ${oldPath} to ${newPath}. Make sure the file you are moving exists.`);
638+
let errorMessage;
639+
try {
640+
if (await this._showBusy(this._fileHelper.fileExists(newPath))) {
641+
errorMessage = `Error moving ${oldPath}. Another ${filetype} with the same name already exists at ${newPath}.`;
642+
} else if (await this._showBusy(this._fileHelper.move(oldPath, newPath))) {
643+
movedAny = true;
644+
} else {
645+
errorMessage = `Error moving ${oldPath} to ${newPath}. Make sure the file you are moving exists.`;
646+
}
647+
} catch (error) {
648+
errorMessage = `Error moving ${oldPath} to ${newPath}: ${error?.message ?? String(error)}`;
649+
}
650+
if (errorMessage) {
643651
errors = true;
652+
await this._showMessage(errorMessage, {plainText: true});
644653
}
645654
}
646655
if (!errors) {
647656
// Go to the new location
648657
await this._openFolder(newFolder);
658+
} else if (movedAny) {
659+
// Update the source list after a partially successful move
660+
await this._openFolder();
649661
}
650662
}
651663
}
@@ -773,7 +785,7 @@ class FileDialog extends GenericModal {
773785
paths.push(this._currentPath);
774786
}
775787
} else {
776-
paths.push(this._currentPath + filename);
788+
paths.push(this._currentPath + file.filename);
777789
}
778790
}
779791

0 commit comments

Comments
 (0)