Skip to content

Commit

Permalink
refactor: ♻️ Move Suggestor settings under General Settings dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Apr 18, 2022
1 parent 464bf46 commit 9a899d2
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 89 deletions.
82 changes: 36 additions & 46 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`.</br>The Field Suggestor will show an autocomplete menu with all available Breadcrumbs field options when the content you type matches the regex <code>/^BC-.*$/</code>. 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 <code>\\</code>."))
.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")
Expand Down Expand Up @@ -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 <code>up</code> 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);
});
});
}

Expand Down Expand Up @@ -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");
Expand All @@ -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`.</br>The Field Suggestor will show an autocomplete menu with all available Breadcrumbs field options when the content you type matches the regex <code>/^BC-.*$/</code>. 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 <code>\\</code>."))
.addText((text) => text.setValue(settings.relSuggestorTrigger).onChange(async (value) => {
settings.relSuggestorTrigger = value;
await plugin.saveSettings();
}));
addTagNoteSettings(plugin, alternativeHierarchyDetails);
addRegexNoteSettings(plugin, alternativeHierarchyDetails);
addNoSystemSettings(plugin, alternativeHierarchyDetails);
Expand Down
43 changes: 0 additions & 43 deletions src/Settings/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class BCSettingTab extends PluginSettingTab {

async display(): Promise<void> {
const { plugin, containerEl } = this;
const { settings } = plugin;

containerEl.empty();
containerEl.createEl("h2", { text: "Breadcrumbs Settings" });
Expand All @@ -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`.</br>The Field Suggestor will show an autocomplete menu with all available Breadcrumbs field options when the content you type matches the regex <code>/^BC-.*$/</code>. 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 <code>\\</code>."
)
)
.addText((text) =>
text.setValue(settings.relSuggestorTrigger).onChange(async (value) => {
settings.relSuggestorTrigger = value;
await plugin.saveSettings();
})
);

addTagNoteSettings(plugin, alternativeHierarchyDetails);
addRegexNoteSettings(plugin, alternativeHierarchyDetails);
addNoSystemSettings(plugin, alternativeHierarchyDetails);
Expand Down
43 changes: 43 additions & 0 deletions src/Settings/GeneralSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.</br>The Field Suggestor will show an autocomplete menu with all available Breadcrumbs field options when the content you type matches the regex <code>/^BC-.*$/</code>. 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 <code>\\</code>."
)
)
.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")
Expand Down

0 comments on commit 9a899d2

Please sign in to comment.