diff --git a/js/common/dialogs.js b/js/common/dialogs.js index 9634676..a443720 100644 --- a/js/common/dialogs.js +++ b/js/common/dialogs.js @@ -81,9 +81,9 @@ class GenericModal { element.innerHTML = value; } - async _showMessage(message) { + async _showMessage(message, options) { const messageDialog = new MessageModal("message"); - return await messageDialog.open(message); + return await messageDialog.open(message, options); } _addModalLayer(modal) { @@ -232,11 +232,16 @@ class GenericModal { } class MessageModal extends GenericModal { - async open(message) { + async open(message, {plainText = false} = {}) { let p = super.open(); const okButton = this._currentModal.querySelector("button.ok-button"); this._addDialogElement('okButton', okButton, 'click', this._closeModal); - this._currentModal.querySelector("#message").innerHTML = message; + const messageElement = this._currentModal.querySelector("#message"); + if (plainText) { + messageElement.textContent = message; + } else { + messageElement.innerHTML = message; + } return p; } diff --git a/js/common/file_dialog.js b/js/common/file_dialog.js index b96b609..203cc61 100644 --- a/js/common/file_dialog.js +++ b/js/common/file_dialog.js @@ -623,11 +623,11 @@ class FileDialog extends GenericModal { async _handleMoveButton() { // Get the new path const newFolderDialog = new FileDialog("folder-select", this._showBusy); - let hidePaths = new Set(); - hidePaths.add(this._getSelectedFilePath()); + const hidePaths = new Set(this._getSelectedFilePath()); hidePaths.add(this._currentPath); let newFolder = await newFolderDialog.open(this._fileHelper, FILE_DIALOG_MOVE, hidePaths, false); let errors = false; + let movedAny = false; if (newFolder) { const files = this._getSelectedFilesInfo(); for (let file of files) { @@ -635,17 +635,29 @@ class FileDialog extends GenericModal { const filetype = file.filetype == "folder" ? "folder" : "file"; const oldPath = this._currentPath + filename; const newPath = newFolder + filename; - if (await this._showBusy(this._fileHelper.fileExists(newPath))) { - this._showMessage(`Error moving ${oldPath}. Another ${filetype} with the same name already exists at ${newPath}.`); - errors = true; - } else if (!(await this._showBusy(this._fileHelper.move(oldPath, newPath)))) { - this._showMessage(`Error moving ${oldPath} to ${newPath}. Make sure the file you are moving exists.`); + let errorMessage; + try { + if (await this._showBusy(this._fileHelper.fileExists(newPath))) { + errorMessage = `Error moving ${oldPath}. Another ${filetype} with the same name already exists at ${newPath}.`; + } else if (await this._showBusy(this._fileHelper.move(oldPath, newPath))) { + movedAny = true; + } else { + errorMessage = `Error moving ${oldPath} to ${newPath}. Make sure the file you are moving exists.`; + } + } catch (error) { + errorMessage = `Error moving ${oldPath} to ${newPath}: ${error?.message ?? String(error)}`; + } + if (errorMessage) { errors = true; + await this._showMessage(errorMessage, {plainText: true}); } } if (!errors) { // Go to the new location await this._openFolder(newFolder); + } else if (movedAny) { + // Update the source list after a partially successful move + await this._openFolder(); } } } @@ -773,7 +785,7 @@ class FileDialog extends GenericModal { paths.push(this._currentPath); } } else { - paths.push(this._currentPath + filename); + paths.push(this._currentPath + file.filename); } }