mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Auto create folder note when creating note option
This commit is contained in:
parent
abf6336514
commit
be8e17f135
3 changed files with 35 additions and 11 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import { TAbstractFile, TFolder, TFile } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { createFolderNote, getFolder, getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { createFolderNote, getFolder, getFolderNote, turnIntoFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import { removeCSSClassFromEL, addCSSClassToTitleEL } from 'src/functions/styleFunctions';
|
||||
import { removeExtension } from 'src/functions/utils';
|
||||
|
||||
export async function handleCreate(file: TAbstractFile, plugin: FolderNotesPlugin) {
|
||||
if (!plugin.app.workspace.layoutReady) return;
|
||||
|
|
@ -25,15 +26,24 @@ export async function handleCreate(file: TAbstractFile, plugin: FolderNotesPlugi
|
|||
|
||||
async function handleFileCreation(file: TFile, plugin: FolderNotesPlugin) {
|
||||
const folder = getFolder(plugin, file);
|
||||
if (!(folder instanceof TFolder)) { return; }
|
||||
const detachedFolder = await getExcludedFolder(plugin, folder.path, true);
|
||||
if (detachedFolder) { return; }
|
||||
const folderNote = getFolderNote(plugin, folder.path);
|
||||
|
||||
if (folderNote && folderNote.path === file.path) {
|
||||
addCSSClassToTitleEL(folder.path, 'has-folder-note', plugin);
|
||||
addCSSClassToTitleEL(file.path, 'is-folder-note', plugin);
|
||||
return;
|
||||
if (!(folder instanceof TFolder) && plugin.settings.autoCreateForFiles) {
|
||||
if (!file.parent) { return; }
|
||||
const newFolder = await plugin.app.fileManager.createNewFolder(file.parent)
|
||||
turnIntoFolderNote(plugin, file, newFolder);
|
||||
} else if (folder instanceof TFolder) {
|
||||
const detachedFolder = await getExcludedFolder(plugin, folder.path, true);
|
||||
if (detachedFolder) { return; }
|
||||
const folderNote = getFolderNote(plugin, folder.path);
|
||||
|
||||
if (folderNote && folderNote.path === file.path) {
|
||||
addCSSClassToTitleEL(folder.path, 'has-folder-note', plugin);
|
||||
addCSSClassToTitleEL(file.path, 'is-folder-note', plugin);
|
||||
} else {
|
||||
if (!file.parent) { return; }
|
||||
const newFolder = await plugin.app.fileManager.createNewFolder(file.parent)
|
||||
turnIntoFolderNote(plugin, file, newFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ export async function renderGeneral(settingsTab: SettingsTab) {
|
|||
nameSetting.infoEl.appendText('Requires a restart to take effect');
|
||||
nameSetting.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
|
||||
if (settingsTab.plugin.settings.newFolderNoteName !== '{{folder_name}}') {
|
||||
if (settingsTab.plugin.settings.folderNoteName !== '{{folder_name}}') {
|
||||
new Setting(containerEl)
|
||||
.setName('Use folder name instead of folder note name in the tab title')
|
||||
.setDesc('When you\'re using a folder note name like "folder note" and have multiple folder notes open you can\'t separate them anymore by their name. This setting uses the folder name instead and allows you to indentify the different files.')
|
||||
|
|
@ -404,4 +404,17 @@ export async function renderGeneral(settingsTab: SettingsTab) {
|
|||
})
|
||||
);
|
||||
}
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Automatically create folder note when you create a note')
|
||||
.setDesc('Automatically create a folder note when a note is created. It has to be a file type that you selected in the supported file types')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.autoCreateForFiles)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.autoCreateForFiles = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ export interface FolderNotesSettings {
|
|||
autoCreate: boolean;
|
||||
autoCreateForAttachmentFolder: boolean;
|
||||
autoCreateFocusFiles: boolean;
|
||||
autoCreateForFiles: boolean;
|
||||
enableCollapsing: boolean;
|
||||
excludeFolders: (ExcludePattern | ExcludedFolder)[];
|
||||
whitelistFolders: (WhitelistedFolder | WhitelistedPattern)[];
|
||||
|
|
@ -80,6 +81,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
autoCreate: false,
|
||||
autoCreateFocusFiles: true,
|
||||
autoCreateForAttachmentFolder: false,
|
||||
autoCreateForFiles: false,
|
||||
enableCollapsing: false,
|
||||
excludeFolders: [],
|
||||
whitelistFolders: [],
|
||||
|
|
@ -266,7 +268,6 @@ export class SettingsTab extends PluginSettingTab {
|
|||
|
||||
renameFolderNotes() {
|
||||
new Notice('Starting to update folder notes...');
|
||||
console.log('starting to update folder notes 2');
|
||||
const oldTemplate = this.plugin.settings.oldFolderNoteName ?? '{{folder_name}}';
|
||||
|
||||
for (const folder of this.app.vault.getAllLoadedFiles()) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue