...
This commit is contained in:
2
collections/documents/images/new-file.md
Normal file
2
collections/documents/images/new-file.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# New File
|
||||||
|
|
||||||
@@ -33,42 +33,45 @@ class FileTreeActions {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
newFile: async function(path, isDir) {
|
'new-file': async function(path, isDir) {
|
||||||
if (!isDir) return;
|
if (!isDir) return;
|
||||||
|
|
||||||
const filename = await this.showInputDialog('Enter filename:', 'new-file.md');
|
await this.showInputDialog('Enter filename:', 'new-file.md', async (filename) => {
|
||||||
if (filename) {
|
if (filename) {
|
||||||
const fullPath = `${path}/${filename}`.replace(/\/+/g, '/');
|
const fullPath = `${path}/${filename}`.replace(/\/+/g, '/');
|
||||||
await this.webdavClient.put(fullPath, '# New File\n\n');
|
await this.webdavClient.put(fullPath, '# New File\n\n');
|
||||||
await this.fileTree.load();
|
await this.fileTree.load();
|
||||||
showNotification(`Created ${filename}`, 'success');
|
showNotification(`Created ${filename}`, 'success');
|
||||||
}
|
await this.editor.loadFile(fullPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
newFolder: async function(path, isDir) {
|
'new-folder': async function(path, isDir) {
|
||||||
if (!isDir) return;
|
if (!isDir) return;
|
||||||
|
|
||||||
const foldername = await this.showInputDialog('Enter folder name:', 'new-folder');
|
await this.showInputDialog('Enter folder name:', 'new-folder', async (foldername) => {
|
||||||
if (foldername) {
|
if (foldername) {
|
||||||
const fullPath = `${path}/${foldername}`.replace(/\/+/g, '/');
|
const fullPath = `${path}/${foldername}`.replace(/\/+/g, '/');
|
||||||
await this.webdavClient.mkcol(fullPath);
|
await this.webdavClient.mkcol(fullPath);
|
||||||
await this.fileTree.load();
|
await this.fileTree.load();
|
||||||
showNotification(`Created folder ${foldername}`, 'success');
|
showNotification(`Created folder ${foldername}`, 'success');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
rename: async function(path, isDir) {
|
rename: async function(path, isDir) {
|
||||||
const oldName = path.split('/').pop();
|
const oldName = path.split('/').pop();
|
||||||
const newName = await this.showInputDialog('Rename to:', oldName);
|
await this.showInputDialog('Rename to:', oldName, async (newName) => {
|
||||||
|
if (newName && newName !== oldName) {
|
||||||
if (newName && newName !== oldName) {
|
const parentPath = path.substring(0, path.lastIndexOf('/'));
|
||||||
const parentPath = path.substring(0, path.lastIndexOf('/'));
|
|
||||||
const newPath = parentPath ? `${parentPath}/${newName}` : newName;
|
const newPath = parentPath ? `${parentPath}/${newName}` : newName;
|
||||||
|
|
||||||
await this.webdavClient.move(path, newPath);
|
await this.webdavClient.move(path, newPath);
|
||||||
await this.fileTree.load();
|
await this.fileTree.load();
|
||||||
showNotification('Renamed', 'success');
|
showNotification('Renamed', 'success');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
copy: async function(path, isDir) {
|
copy: async function(path, isDir) {
|
||||||
@@ -143,34 +146,47 @@ class FileTreeActions {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Modern dialog implementations
|
// Modern dialog implementations
|
||||||
async showInputDialog(title, placeholder = '') {
|
async showInputDialog(title, placeholder = '', onConfirm) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const dialog = this.createInputDialog(title, placeholder);
|
const dialog = this.createInputDialog(title, placeholder);
|
||||||
const input = dialog.querySelector('input');
|
const input = dialog.querySelector('input');
|
||||||
const confirmBtn = dialog.querySelector('.btn-primary');
|
const confirmBtn = dialog.querySelector('.btn-primary');
|
||||||
const cancelBtn = dialog.querySelector('.btn-secondary');
|
const cancelBtn = dialog.querySelector('.btn-secondary');
|
||||||
|
const closeBtn = dialog.querySelector('.btn-close');
|
||||||
|
|
||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
dialog.remove();
|
dialog.remove();
|
||||||
document.querySelector('.modal-backdrop').remove();
|
const backdrop = document.querySelector('.modal-backdrop');
|
||||||
|
if (backdrop) {
|
||||||
|
backdrop.remove();
|
||||||
|
}
|
||||||
document.body.classList.remove('modal-open');
|
document.body.classList.remove('modal-open');
|
||||||
|
resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
confirmBtn.onclick = () => {
|
confirmBtn.onclick = async () => {
|
||||||
resolve(input.value.trim());
|
await onConfirm(input.value.trim());
|
||||||
cleanup();
|
cleanup();
|
||||||
};
|
};
|
||||||
|
|
||||||
cancelBtn.onclick = () => {
|
cancelBtn.onclick = () => {
|
||||||
resolve(null);
|
|
||||||
cleanup();
|
cleanup();
|
||||||
};
|
};
|
||||||
|
|
||||||
input.onkeypress = (e) => {
|
closeBtn.onclick = () => {
|
||||||
if (e.key === 'Enter') confirmBtn.click();
|
cleanup();
|
||||||
if (e.key === 'Escape') cancelBtn.click();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
input.onkeypress = (e) => {
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
e.preventDefault();
|
||||||
|
confirmBtn.click();
|
||||||
|
}
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
cancelBtn.click();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
document.body.appendChild(dialog);
|
document.body.appendChild(dialog);
|
||||||
document.body.classList.add('modal-open');
|
document.body.classList.add('modal-open');
|
||||||
input.focus();
|
input.focus();
|
||||||
@@ -183,6 +199,7 @@ class FileTreeActions {
|
|||||||
const dialog = this.createConfirmDialog(title, message);
|
const dialog = this.createConfirmDialog(title, message);
|
||||||
const confirmBtn = dialog.querySelector('.btn-danger');
|
const confirmBtn = dialog.querySelector('.btn-danger');
|
||||||
const cancelBtn = dialog.querySelector('.btn-secondary');
|
const cancelBtn = dialog.querySelector('.btn-secondary');
|
||||||
|
const closeBtn = dialog.querySelector('.btn-close');
|
||||||
|
|
||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
dialog.remove();
|
dialog.remove();
|
||||||
@@ -199,6 +216,11 @@ class FileTreeActions {
|
|||||||
resolve(false);
|
resolve(false);
|
||||||
cleanup();
|
cleanup();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
closeBtn.onclick = () => {
|
||||||
|
resolve(false);
|
||||||
|
cleanup();
|
||||||
|
};
|
||||||
|
|
||||||
document.body.appendChild(dialog);
|
document.body.appendChild(dialog);
|
||||||
document.body.classList.add('modal-open');
|
document.body.classList.add('modal-open');
|
||||||
|
|||||||
Reference in New Issue
Block a user