mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Fix #95
Also added a setting to allow the automatic creation of folder notes for the attachment folder
This commit is contained in:
parent
c72697b81b
commit
e8e80f6ddb
3 changed files with 43 additions and 13 deletions
|
|
@ -33,12 +33,24 @@ export function handleCreate(file: TAbstractFile, plugin: FolderNotesPlugin) {
|
|||
if (!(file instanceof TFolder)) return;
|
||||
|
||||
if (!plugin.settings.autoCreate) return;
|
||||
let openFile = true;
|
||||
|
||||
const attachmentFolderPath = plugin.app.vault.getConfig('attachmentFolderPath') as string;
|
||||
const cleanAttachmentFolderPath = attachmentFolderPath?.replace('./', '') || '';
|
||||
const attachmentsAreInRootFolder = attachmentFolderPath === './' || attachmentFolderPath === '';
|
||||
|
||||
if (!plugin.settings.autoCreateForAttachmentFolder) {
|
||||
if (!attachmentsAreInRootFolder && cleanAttachmentFolderPath === file.name) return;
|
||||
} else {
|
||||
openFile = false;
|
||||
}
|
||||
|
||||
const excludedFolder = getExcludedFolder(plugin, file.path);
|
||||
if (excludedFolder?.disableAutoCreate) return;
|
||||
|
||||
const folderNote = getFolderNote(plugin, file.path);
|
||||
if (folderNote) return;
|
||||
|
||||
createFolderNote(plugin, file.path, true, undefined, true);
|
||||
createFolderNote(plugin, file.path, openFile, undefined, true);
|
||||
addCSSClassToTitleEL(file.path, 'has-folder-note');
|
||||
}
|
||||
|
|
@ -294,18 +294,6 @@ export async function renderGeneral(settingsTab: SettingsTab) {
|
|||
setting3.infoEl.appendText('Requires a restart to take effect');
|
||||
setting3.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
}
|
||||
new Setting(containerEl)
|
||||
.setName('Automatically create folder notes')
|
||||
.setDesc('Automatically create a folder note when a new folder is created')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.autoCreate)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.autoCreate = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Enable front matter title plugin integration')
|
||||
|
|
@ -342,4 +330,32 @@ export async function renderGeneral(settingsTab: SettingsTab) {
|
|||
new ConfirmationModal(settingsTab.app, settingsTab.plugin).open();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Automatically create folder notes')
|
||||
.setDesc('Automatically create a folder note when a new folder is created')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.autoCreate)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.autoCreate = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
})
|
||||
);
|
||||
|
||||
if (settingsTab.plugin.settings.autoCreate) {
|
||||
new Setting(containerEl)
|
||||
.setName('Auto create folder note for attachment folder')
|
||||
.setDesc('Automatically create a folder note for the attachment folder when you attach a file to a note and the attachment folder gets created')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.autoCreateForAttachmentFolder)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.autoCreateForAttachmentFolder = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ export interface FolderNotesSettings {
|
|||
hideFolderNote: boolean;
|
||||
templatePath: string;
|
||||
autoCreate: boolean;
|
||||
autoCreateForAttachmentFolder: boolean;
|
||||
enableCollapsing: boolean;
|
||||
excludeFolders: (ExcludePattern | ExcludedFolder)[];
|
||||
whitelistFolders: (WhitelistedFolder | WhitelistedPattern)[];
|
||||
|
|
@ -72,6 +73,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
hideFolderNote: true,
|
||||
templatePath: '',
|
||||
autoCreate: false,
|
||||
autoCreateForAttachmentFolder: false,
|
||||
enableCollapsing: false,
|
||||
excludeFolders: [],
|
||||
whitelistFolders: [],
|
||||
|
|
|
|||
Loading…
Reference in a new issue