Delete folder note confirmation modal

This commit is contained in:
Lost Paul 2023-03-20 22:41:24 +01:00
parent bb5a8ae797
commit 355a65d6c9
4 changed files with 51 additions and 9 deletions

View file

@ -1,4 +1,4 @@
import { App, TFolder, Menu, TAbstractFile, Notice, Platform, TFile } from 'obsidian';
import { App, TFolder, Menu, TAbstractFile, Notice, TFile } from 'obsidian';
import FolderNotesPlugin from './main';
import { ExcludedFolder } from './settings';
export class Commands {

View file

@ -211,7 +211,11 @@ export default class FolderNotesPlugin extends Plugin {
}
async deleteFolderNote(file: TFile) {
new DeleteConfirmationModal(this.app, this, file).open();
if (this.settings.showDeleteConfirmation) {
new DeleteConfirmationModal(this.app, this, file).open();
} else {
await this.app.vault.delete(file);
}
}
onunload() {

View file

@ -8,27 +8,44 @@ export default class DeleteConfirmationModal extends Modal {
super(app);
this.plugin = plugin;
this.app = app;
this.file = file;
this.file = file;
}
onOpen() {
const { contentEl } = this;
contentEl.createEl('h2', { text: 'Delete folder note' });
const setting = new Setting(contentEl);
setting.infoEl.createEl('p', { text: `Are you sure you want to delete the folder note "${this.file.name}" ?` });
setting.infoEl.createEl('p', { text: 'lt will be moved to your system trash.' });
setting.infoEl.createEl('p', { text: `Are you sure you want to delete the folder note "${this.file.name}" ?` });
setting.infoEl.createEl('p', { text: 'It will be moved to your system trash.' });
setting.infoEl.parentElement?.classList.add('fn-delete-confirmation-modal');
const button = setting.infoEl.createEl('button', { text: 'Delete' });
// Create a container for the buttons and the checkbox
const buttonContainer = setting.infoEl.createEl('div', { cls: 'fn-delete-confirmation-modal-buttons' });
const checkbox = buttonContainer.createEl('input', { type: 'checkbox' });
checkbox.addEventListener('change', (e) => {
const target = e.target as HTMLInputElement;
if (target.checked) {
this.plugin.settings.showDeleteConfirmation = false;
} else {
this.plugin.settings.showDeleteConfirmation = true;
}
});
const checkBoxText = buttonContainer.createEl('span', { text: 'Don\'t ask again' });
checkBoxText.addEventListener('click', () => {
checkbox.click();
});
const button = buttonContainer.createEl('button', { text: 'Delete' });
button.classList.add('mod-warning', 'fn-confirmation-modal-button');
button.addEventListener('click', async () => {
this.close();
this.app.vault.delete(this.file);
this.app.vault.delete(this.file);
});
button.focus();
const cancelButton = setting.infoEl.createEl('button', { text: 'Cancel' });
const cancelButton = buttonContainer.createEl('button', { text: 'Cancel' });
cancelButton.addEventListener('click', async () => {
this.close();
});
}
onClose() {
const { contentEl } = this;

View file

@ -3,6 +3,7 @@
padding-bottom: 4px;
padding-top: 4px;
}
.nav-folder-title {
padding-bottom: 0;
padding-top: 0;
@ -35,7 +36,7 @@
display: flex;
}
.fn-exclude-folder-list-item > *.last-child {
.fn-exclude-folder-list-item>*.last-child {
margin-right: 0;
}
@ -45,4 +46,24 @@
.fn-confirmation-modal-button {
margin-right: 0.7rem;
}
.fn-delete-confirmation-modal-buttons {
display: flex;
align-items: center;
margin-top: 10px;
}
.fn-delete-confirmation-modal-buttons span:hover,
.fn-delete-confirmation-modal-buttons input:hover {
cursor: pointer;
}
.fn-delete-confirmation-modal-buttons .fn-confirmation-modal-button {
margin-left: auto;
}
.fn-delete-confirmation-modal-buttons input[type="checkbox"] {
margin-right: 5px;
}