From 355a65d6c946b839338e6410a9709724c7ce219f Mon Sep 17 00:00:00 2001 From: Lost Paul <70213368+LostPaul@users.noreply.github.com> Date: Mon, 20 Mar 2023 22:41:24 +0100 Subject: [PATCH] Delete folder note confirmation modal --- src/commands.ts | 2 +- src/main.ts | 6 +++++- src/modals/deleteConfirmation.ts | 29 +++++++++++++++++++++++------ styles.css | 23 ++++++++++++++++++++++- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index acccb98..3722415 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -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 { diff --git a/src/main.ts b/src/main.ts index 4d445b5..5b28e32 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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() { diff --git a/src/modals/deleteConfirmation.ts b/src/modals/deleteConfirmation.ts index 315b35a..fad9a67 100644 --- a/src/modals/deleteConfirmation.ts +++ b/src/modals/deleteConfirmation.ts @@ -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; diff --git a/styles.css b/styles.css index 4b57c06..257f2a0 100644 --- a/styles.css +++ b/styles.css @@ -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; } \ No newline at end of file