From c893b812e382b0b761df0040f83b46e49d74c2c4 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sun, 2 Jan 2022 10:06:08 +0200 Subject: [PATCH] feat(Threading): :sparkles: Option for customisable template for new note --- src/BreadcrumbsSettingTab.ts | 24 ++++++++++++++++++++++++ src/constants.ts | 1 + src/interfaces.ts | 1 + src/main.ts | 14 ++++++++++++-- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index 79be3383..f48a412b 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -945,6 +945,30 @@ export class BCSettingTab extends PluginSettingTab { }) ); + new Setting(threadingDetails) + .setName("New Note Name Template") + .setDesc( + fragWithHTML( + `When threading into a new note, choose the template for the new note name.
+ The default is {{field}} of {{current}}.
+ Options include:
+ + ` + ) + ) + .addText((text) => { + text.setValue(settings.threadingTemplate); + text.inputEl.onblur = async () => { + settings.threadingTemplate = text.getValue(); + await plugin.saveSettings(); + }; + }); + const debugDetails = details("Debugging"); new Setting(debugDetails) diff --git a/src/constants.ts b/src/constants.ts index 57bc0028..7cc64cdb 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -183,6 +183,7 @@ export const DEFAULT_SETTINGS: BCSettings = { showAll: false, noPathMessage: `This note has no real or implied parents`, threadIntoNewPane: false, + threadingTemplate: "{{field}} of {{current}}", trailSeperator: "→", treatCurrNodeAsImpliedSibling: false, trimDendronNotes: false, diff --git a/src/interfaces.ts b/src/interfaces.ts index 8ef7aa49..648ba633 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -58,6 +58,7 @@ export interface BCSettings { showTrail: boolean; squareDirectionsOrder: (0 | 1 | 2 | 3 | 4)[]; threadIntoNewPane: boolean; + threadingTemplate: string; trailSeperator: string; treatCurrNodeAsImpliedSibling: boolean; trimDendronNotes: boolean; diff --git a/src/main.ts b/src/main.ts index ba5c1fe8..74038dde 100644 --- a/src/main.ts +++ b/src/main.ts @@ -434,9 +434,19 @@ export default class BCPlugin extends Plugin { const newFileParent = app.fileManager.getNewFileParent(currFile.path); + const dir = getFieldInfo(userHiers, field).fieldDir; const oppField = - getOppFields(userHiers, field)[0] ?? - fallbackOppField(field, getFieldInfo(userHiers, field).fieldDir); + getOppFields(userHiers, field)[0] ?? fallbackOppField(field, dir); + + let newBasename = settings.threadingTemplate + .replace("{{current}}", currFile.basename) + .replace("{{field}}", field) + .replace("{{dir}}", dir) + .replace( + "{{date}}", + new Date().toLocaleDateString().replaceAll(/[/\\]/g, "") + ); + const newFile = await app.vault.create( normalizePath(