Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions js/common/dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
28 changes: 20 additions & 8 deletions js/common/file_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,29 +623,41 @@ 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) {
const filename = file.filename;
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();
}
}
}
Expand Down Expand Up @@ -773,7 +785,7 @@ class FileDialog extends GenericModal {
paths.push(this._currentPath);
}
} else {
paths.push(this._currentPath + filename);
paths.push(this._currentPath + file.filename);
}
}

Expand Down