From 9a899d2d9f217e627f93bd044f64a4ff72c58930 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Mon, 18 Apr 2022 13:24:43 +0200 Subject: [PATCH] refactor: :recycle: Move Suggestor settings under General Settings dropdown --- main.js | 82 ++++++++++++--------------- src/Settings/BreadcrumbsSettingTab.ts | 43 -------------- src/Settings/GeneralSettings.ts | 43 ++++++++++++++ 3 files changed, 79 insertions(+), 89 deletions(-) diff --git a/main.js b/main.js index c2866798..584fbfbc 100644 --- a/main.js +++ b/main.js @@ -38054,6 +38054,29 @@ function addGeneralSettings(plugin, containerEl) { settings.parseJugglLinksWithoutJuggl = value; await plugin.saveSettings(); })); + new obsidian.Setting(generalDetails) + .setName("Enable Field Suggestor") + .setDesc(fragWithHTML('Alot of Breadcrumbs features require a metadata (or inline Dataview) field to work. For example, `BC-folder-note`.
The Field Suggestor will show an autocomplete menu with all available Breadcrumbs field options when the content you type matches the regex /^BC-.*$/. Basically, just type "BC-" at the start of a line to trigger it.')) + .addToggle((toggle) => toggle.setValue(settings.fieldSuggestor).onChange(async (value) => { + settings.fieldSuggestor = value; + await plugin.saveSettings(); + })); + new obsidian.Setting(generalDetails) + .setName("Enable Relation Suggestor") + .setDesc(fragWithHTML("Enable an editor suggestor which gets triggered by a custom string to show a list of relations from your hierarchies to insert.")) + .addToggle((toggle) => toggle + .setValue(settings.enableRelationSuggestor) + .onChange(async (value) => { + settings.enableRelationSuggestor = value; + await plugin.saveSettings(); + })); + new obsidian.Setting(generalDetails) + .setName("Relation Suggestor Trigger") + .setDesc(fragWithHTML("The string used to trigger the relation suggestor. Default is \\.")) + .addText((text) => text.setValue(settings.relSuggestorTrigger).onChange(async (value) => { + settings.relSuggestorTrigger = value; + await plugin.saveSettings(); + })); if (plugin.app.plugins.plugins.dataview !== undefined) { new obsidian.Setting(generalDetails) .setName("Dataview Wait Time") @@ -38091,28 +38114,19 @@ function addHierarchyNoteSettings(plugin, alternativeHierarchyDetails) { }; }); new obsidian.Setting(hierarchyNoteDetails) - .setName("Hierarchy Note Up Field Name") - .setDesc("Using the breadcrumbs generated by the hierarchy note, which ↑ type should they count as? This has to be one of the ↑ types of one of your existing hierarchies. If you want it to be something else, you can make a new hierarchy just for it.") - .addText((text) => { - let finalValue = settings.HNUpField; - text.setPlaceholder("").setValue(settings.HNUpField); - text.inputEl.onblur = async () => { - finalValue = text.getValue(); - if (finalValue === "") { - settings.HNUpField = finalValue; - await plugin.saveSettings(); - } - else { - const upFields = getFields(settings.userHiers, "up"); - if (upFields.includes(finalValue)) { - settings.HNUpField = finalValue; - await plugin.saveSettings(); - } - else { - new obsidian.Notice("The field name must be one of the exisitng ↓ fields in your hierarchies."); - } - } - }; + .setName("Default Hierarchy Note Field") + .setDesc(fragWithHTML("By default, hierarchy notes use the first up field in your hierarchies. Choose a different one to use by default. If you don't want to choose a default, select the blank option at the bottom of the list.")) + .addDropdown((dd) => { + const upFields = getFields(settings.userHiers, "up"); + dd.setValue(settings.HNUpField || upFields[0]); + const options = {}; + upFields.forEach((field) => (options[field] = field)); + dd.addOptions(options); + dd.onChange(async (field) => { + settings.HNUpField = field; + await plugin.saveSettings(); + await refreshIndex(plugin); + }); }); } @@ -40066,7 +40080,6 @@ class BCSettingTab extends obsidian.PluginSettingTab { } async display() { const { plugin, containerEl } = this; - const { settings } = plugin; containerEl.empty(); containerEl.createEl("h2", { text: "Breadcrumbs Settings" }); containerEl.addClass("BC-settings-tab"); @@ -40079,29 +40092,6 @@ class BCSettingTab extends obsidian.PluginSettingTab { addVisModalSettings(plugin, viewDetails); addTreeViewSettings(plugin, viewDetails); const alternativeHierarchyDetails = details("Alternative Hierarchies", containerEl); - new obsidian.Setting(alternativeHierarchyDetails) - .setName("Enable Field Suggestor") - .setDesc(fragWithHTML('Alot of Breadcrumbs features require a metadata (or inline Dataview) field to work. For example, `BC-folder-note`.
The Field Suggestor will show an autocomplete menu with all available Breadcrumbs field options when the content you type matches the regex /^BC-.*$/. Basically, just type "BC-" at the start of a line to trigger it.')) - .addToggle((toggle) => toggle.setValue(settings.fieldSuggestor).onChange(async (value) => { - settings.fieldSuggestor = value; - await plugin.saveSettings(); - })); - new obsidian.Setting(alternativeHierarchyDetails) - .setName("Enable Relation Suggestor") - .setDesc(fragWithHTML("Enable an editor suggestor which gets triggered by a custom string to show a list of relations from your hierarchies to insert.")) - .addToggle((toggle) => toggle - .setValue(settings.enableRelationSuggestor) - .onChange(async (value) => { - settings.enableRelationSuggestor = value; - await plugin.saveSettings(); - })); - new obsidian.Setting(alternativeHierarchyDetails) - .setName("Relation Suggestor Trigger") - .setDesc(fragWithHTML("The string used to trigger the relation suggestor. Default is \\.")) - .addText((text) => text.setValue(settings.relSuggestorTrigger).onChange(async (value) => { - settings.relSuggestorTrigger = value; - await plugin.saveSettings(); - })); addTagNoteSettings(plugin, alternativeHierarchyDetails); addRegexNoteSettings(plugin, alternativeHierarchyDetails); addNoSystemSettings(plugin, alternativeHierarchyDetails); diff --git a/src/Settings/BreadcrumbsSettingTab.ts b/src/Settings/BreadcrumbsSettingTab.ts index 029fd0a8..3070ebcf 100644 --- a/src/Settings/BreadcrumbsSettingTab.ts +++ b/src/Settings/BreadcrumbsSettingTab.ts @@ -47,7 +47,6 @@ export class BCSettingTab extends PluginSettingTab { async display(): Promise { const { plugin, containerEl } = this; - const { settings } = plugin; containerEl.empty(); containerEl.createEl("h2", { text: "Breadcrumbs Settings" }); @@ -68,48 +67,6 @@ export class BCSettingTab extends PluginSettingTab { containerEl ); - new Setting(alternativeHierarchyDetails) - .setName("Enable Field Suggestor") - .setDesc( - fragWithHTML( - 'Alot of Breadcrumbs features require a metadata (or inline Dataview) field to work. For example, `BC-folder-note`.
The Field Suggestor will show an autocomplete menu with all available Breadcrumbs field options when the content you type matches the regex /^BC-.*$/. Basically, just type "BC-" at the start of a line to trigger it.' - ) - ) - .addToggle((toggle) => - toggle.setValue(settings.fieldSuggestor).onChange(async (value) => { - settings.fieldSuggestor = value; - await plugin.saveSettings(); - }) - ); - new Setting(alternativeHierarchyDetails) - .setName("Enable Relation Suggestor") - .setDesc( - fragWithHTML( - "Enable an editor suggestor which gets triggered by a custom string to show a list of relations from your hierarchies to insert." - ) - ) - .addToggle((toggle) => - toggle - .setValue(settings.enableRelationSuggestor) - .onChange(async (value) => { - settings.enableRelationSuggestor = value; - await plugin.saveSettings(); - }) - ); - new Setting(alternativeHierarchyDetails) - .setName("Relation Suggestor Trigger") - .setDesc( - fragWithHTML( - "The string used to trigger the relation suggestor. Default is \\." - ) - ) - .addText((text) => - text.setValue(settings.relSuggestorTrigger).onChange(async (value) => { - settings.relSuggestorTrigger = value; - await plugin.saveSettings(); - }) - ); - addTagNoteSettings(plugin, alternativeHierarchyDetails); addRegexNoteSettings(plugin, alternativeHierarchyDetails); addNoSystemSettings(plugin, alternativeHierarchyDetails); diff --git a/src/Settings/GeneralSettings.ts b/src/Settings/GeneralSettings.ts index 12a8e25a..821b4897 100644 --- a/src/Settings/GeneralSettings.ts +++ b/src/Settings/GeneralSettings.ts @@ -139,6 +139,49 @@ export function addGeneralSettings(plugin: BCPlugin, containerEl: HTMLElement) { }) ); + + new Setting(generalDetails) + .setName("Enable Field Suggestor") + .setDesc( + fragWithHTML( + 'Alot of Breadcrumbs features require a metadata (or inline Dataview) field to work. For example, `BC-folder-note`.
The Field Suggestor will show an autocomplete menu with all available Breadcrumbs field options when the content you type matches the regex /^BC-.*$/. Basically, just type "BC-" at the start of a line to trigger it.' + ) + ) + .addToggle((toggle) => + toggle.setValue(settings.fieldSuggestor).onChange(async (value) => { + settings.fieldSuggestor = value; + await plugin.saveSettings(); + }) + ); + new Setting(generalDetails) + .setName("Enable Relation Suggestor") + .setDesc( + fragWithHTML( + "Enable an editor suggestor which gets triggered by a custom string to show a list of relations from your hierarchies to insert." + ) + ) + .addToggle((toggle) => + toggle + .setValue(settings.enableRelationSuggestor) + .onChange(async (value) => { + settings.enableRelationSuggestor = value; + await plugin.saveSettings(); + }) + ); + new Setting(generalDetails) + .setName("Relation Suggestor Trigger") + .setDesc( + fragWithHTML( + "The string used to trigger the relation suggestor. Default is \\." + ) + ) + .addText((text) => + text.setValue(settings.relSuggestorTrigger).onChange(async (value) => { + settings.relSuggestorTrigger = value; + await plugin.saveSettings(); + }) + ); + if (plugin.app.plugins.plugins.dataview !== undefined) { new Setting(generalDetails) .setName("Dataview Wait Time")