mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Option to delete folder note permanently, move to trash, ...
Now you can choose if you want to delete the folder note permanently or just want to move it the system/obsidian trash like it's possible for normal files This also fixes #142 & #120
This commit is contained in:
parent
945c25f97e
commit
7e26d0e246
6 changed files with 90 additions and 47 deletions
|
|
@ -90,7 +90,7 @@ export class Commands {
|
|||
if (!(folder instanceof TFolder)) return;
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
if (!(folderNote instanceof TFile)) return;
|
||||
deleteFolderNote(this.plugin, folderNote);
|
||||
deleteFolderNote(this.plugin, folderNote, true);
|
||||
}
|
||||
});
|
||||
this.plugin.addCommand({
|
||||
|
|
@ -298,7 +298,7 @@ export class Commands {
|
|||
item.setTitle('Delete folder note')
|
||||
.setIcon('trash')
|
||||
.onClick(() => {
|
||||
deleteFolderNote(this.plugin, folderNote);
|
||||
deleteFolderNote(this.plugin, folderNote, true);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { TAbstractFile, TFolder, TFile } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { getFolderNote, getFolder } from 'src/functions/folderNoteFunctions';
|
||||
import { getFolderNote, getFolder, deleteFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { removeCSSClassFromEL, addCSSClassToTitleEL } from 'src/functions/styleFunctions';
|
||||
import { getFolderPathFromString } from 'src/functions/utils';
|
||||
|
||||
|
|
@ -28,5 +28,5 @@ export function handleDelete(file: TAbstractFile, plugin: FolderNotesPlugin) {
|
|||
if (!folderNote) { return; }
|
||||
removeCSSClassFromEL(folderNote.path, 'is-folder-note');
|
||||
if (!plugin.settings.syncDelete) { return; }
|
||||
plugin.app.vault.delete(folderNote);
|
||||
deleteFolderNote(plugin, folderNote, false);
|
||||
}
|
||||
|
|
@ -179,14 +179,25 @@ export async function openFolderNote(plugin: FolderNotesPlugin, file: TAbstractF
|
|||
}
|
||||
}
|
||||
|
||||
export async function deleteFolderNote(plugin: FolderNotesPlugin, file: TFile) {
|
||||
if (plugin.settings.showDeleteConfirmation) {
|
||||
export async function deleteFolderNote(plugin: FolderNotesPlugin, file: TFile, displayModal: boolean) {
|
||||
if (plugin.settings.showDeleteConfirmation && displayModal) {
|
||||
return new DeleteConfirmationModal(plugin.app, plugin, file).open();
|
||||
}
|
||||
const folder = getFolder(plugin, file);
|
||||
if (!folder) return;
|
||||
removeCSSClassFromEL(folder.path, 'has-folder-note');
|
||||
await plugin.app.vault.delete(file);
|
||||
switch (plugin.settings.deleteFilesAction) {
|
||||
case 'trash':
|
||||
await plugin.app.vault.trash(file, true);
|
||||
break;
|
||||
case 'obsidianTrash':
|
||||
console.log('obsidianTrash');
|
||||
await plugin.app.vault.trash(file, false);
|
||||
break;
|
||||
case 'delete':
|
||||
await plugin.app.vault.delete(file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
export function extractFolderName(template: string, changedFileName: string) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { App, Modal, Setting, TFile, Platform } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { getFolder } from 'src/functions/folderNoteFunctions';
|
||||
import { deleteFolderNote, getFolder } from 'src/functions/folderNoteFunctions';
|
||||
import { removeCSSClassFromEL } from 'src/functions/styleFunctions';
|
||||
export default class DeleteConfirmationModal extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
|
|
@ -13,59 +13,60 @@ export default class DeleteConfirmationModal extends Modal {
|
|||
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: 'It will be moved to your system trash.' });
|
||||
const { contentEl, plugin } = this;
|
||||
const modalTitle = contentEl.createDiv({ cls: 'fn-modal-title' });
|
||||
const modalContent = contentEl.createDiv({ cls: 'fn-modal-content' });
|
||||
modalTitle.createEl('h2', { text: 'Delete folder note' });
|
||||
modalContent.createEl('p', { text: `Are you sure you want to delete the folder note "${this.file.name}" ?` });
|
||||
switch (plugin.settings.deleteFilesAction) {
|
||||
case 'trash':
|
||||
modalContent.createEl('p', { text: 'It will be moved to your system trash.' });
|
||||
break;
|
||||
case 'obsidianTrash':
|
||||
modalContent.createEl('p', { text: 'It will be moved to your Obsidian trash, which is located in the ".trash" hidden folder in your vault.' });
|
||||
break;
|
||||
case 'delete':
|
||||
modalContent.createEl('p', { text: 'It will be permanently deleted.' }).setCssStyles({ color: 'red' });
|
||||
break;
|
||||
}
|
||||
|
||||
setting.infoEl.parentElement?.classList.add('fn-delete-confirmation-modal');
|
||||
const buttonContainer = contentEl.createEl('div', { cls: 'modal-button-container' });
|
||||
|
||||
// Create a container for the buttons and the checkbox
|
||||
const buttonContainer = setting.infoEl.createEl('div', { cls: 'fn-delete-confirmation-modal-buttons' });
|
||||
if (Platform.isMobileApp) {
|
||||
const confirmButton = buttonContainer.createEl('button', { text: 'Delete and don\'t ask again' });
|
||||
confirmButton.classList.add('mod-warning', 'fn-confirmation-modal-button');
|
||||
confirmButton.addEventListener('click', async () => {
|
||||
this.plugin.settings.showDeleteConfirmation = false;
|
||||
this.plugin.saveSettings();
|
||||
this.close();
|
||||
const folder = getFolder(this.plugin, this.file);
|
||||
if (!folder) return;
|
||||
removeCSSClassFromEL(folder?.path, 'has-folder-note');
|
||||
this.app.vault.delete(this.file);
|
||||
});
|
||||
} else {
|
||||
const checkbox = buttonContainer.createEl('input', { type: 'checkbox' });
|
||||
checkbox.addEventListener('change', (e) => {
|
||||
if (!Platform.isMobile) {
|
||||
const checkbox = buttonContainer.createEl('label', { cls: 'mod-checkbox' })
|
||||
checkbox.tabIndex = -1
|
||||
const input = checkbox.createEl('input', { type: 'checkbox' });
|
||||
checkbox.appendText('Don\'t ask again')
|
||||
input.addEventListener('change', (e) => {
|
||||
const target = e.target as HTMLInputElement;
|
||||
if (target.checked) {
|
||||
this.plugin.settings.showDeleteConfirmation = false;
|
||||
plugin.settings.showDeleteConfirmation = false;
|
||||
} else {
|
||||
this.plugin.settings.showDeleteConfirmation = true;
|
||||
plugin.settings.showDeleteConfirmation = true;
|
||||
}
|
||||
this.plugin.saveSettings();
|
||||
plugin.saveSettings();
|
||||
});
|
||||
const checkBoxText = buttonContainer.createEl('span', { text: 'Don\'t ask again' });
|
||||
checkBoxText.addEventListener('click', () => {
|
||||
checkbox.click();
|
||||
} else {
|
||||
const confirmButton = buttonContainer.createEl('button', { text: 'Delete and don\'t ask again', cls: 'mod-destructive' });
|
||||
confirmButton.addEventListener('click', async () => {
|
||||
plugin.settings.showDeleteConfirmation = false;
|
||||
plugin.saveSettings();
|
||||
this.close();
|
||||
deleteFolderNote(plugin, this.file, false);
|
||||
});
|
||||
}
|
||||
const button = buttonContainer.createEl('button', { text: 'Delete' });
|
||||
button.classList.add('mod-warning', 'fn-confirmation-modal-button');
|
||||
button.addEventListener('click', async () => {
|
||||
|
||||
const deleteButton = buttonContainer.createEl('button', { text: 'Delete', cls: 'mod-warning' });
|
||||
deleteButton.addEventListener('click', async () => {
|
||||
this.close();
|
||||
const folder = getFolder(this.plugin, this.file);
|
||||
if (!folder) return;
|
||||
removeCSSClassFromEL(folder.path, 'has-folder-note');
|
||||
this.app.vault.delete(this.file);
|
||||
deleteFolderNote(plugin, this.file, false);
|
||||
});
|
||||
button.focus();
|
||||
const cancelButton = buttonContainer.createEl('button', { text: 'Cancel' });
|
||||
deleteButton.focus();
|
||||
|
||||
const cancelButton = buttonContainer.createEl('button', { text: 'Cancel', cls: 'mod-cancel' });
|
||||
cancelButton.addEventListener('click', async () => {
|
||||
this.close();
|
||||
});
|
||||
|
||||
}
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
|
|
|
|||
|
|
@ -278,6 +278,35 @@ export async function renderGeneral(settingsTab: SettingsTab) {
|
|||
settingsTab.display();
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Confirm folder note deletion')
|
||||
.setDesc('Ask for confirmation before deleting a folder note')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.showDeleteConfirmation)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.showDeleteConfirmation = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Deleted folder notes')
|
||||
.setDesc('What happens to the folder note after you delete it')
|
||||
.addDropdown((dropdown) => {
|
||||
dropdown.addOption('trash', 'Move to system trash');
|
||||
dropdown.addOption('obsidianTrash', 'Move to Obsidian trash (.trash folder)');
|
||||
dropdown.addOption('delete', 'Delete permanently');
|
||||
dropdown.setValue(settingsTab.plugin.settings.deleteFilesAction);
|
||||
dropdown.onChange(async (value: 'trash' | 'delete' | 'obsidianTrash') => {
|
||||
settingsTab.plugin.settings.deleteFilesAction = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
});
|
||||
});
|
||||
|
||||
if (Platform.isDesktop) {
|
||||
const setting3 = new Setting(containerEl);
|
||||
setting3.setName('Open folder note in a new tab by default');
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ export interface FolderNotesSettings {
|
|||
hideCollapsingIcon: boolean;
|
||||
ignoreAttachmentFolder: boolean;
|
||||
tabManagerEnabled: boolean;
|
||||
deleteFilesAction: 'delete' | 'trash' | 'obsidianTrash';
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
||||
|
|
@ -147,6 +148,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
hideCollapsingIcon: false,
|
||||
tabManagerEnabled: true,
|
||||
ignoreAttachmentFolder: true,
|
||||
deleteFilesAction: 'trash',
|
||||
};
|
||||
|
||||
export class SettingsTab extends PluginSettingTab {
|
||||
|
|
|
|||
Loading…
Reference in a new issue