18 - Modified settings to use new SettingGroup API.

This commit is contained in:
Caleb Campbell
2026-02-10 10:32:39 +11:00
parent 889732b301
commit 95149fb9c3
7 changed files with 423 additions and 327 deletions

View File

@@ -4,7 +4,7 @@ import { QuoteReferencePosition } from 'src/settings';
export const SETTINGS_LABELS: SettingsLabels = {
required: {
name: 'Erforderliche Einstellungen',
name: 'Erforderlich',
controls: {
biblesPath: {
name: 'Bibeldateien',
@@ -15,7 +15,7 @@ export const SETTINGS_LABELS: SettingsLabels = {
},
optional: {
name: 'Optionale Einstellungen',
name: 'Optional',
controls: {
defaultVersion: {
name: 'Standardversion',
@@ -48,8 +48,7 @@ export const SETTINGS_LABELS: SettingsLabels = {
},
quoteFormat: {
name: 'Einstellungen für das Angebotsformat',
description: 'Einstellungen für das Zitatpassageformat.',
name: 'Angebotsformat',
controls: {
includeReference: {
name: 'Referenz angeben',
@@ -73,8 +72,7 @@ export const SETTINGS_LABELS: SettingsLabels = {
},
calloutFormat: {
name: 'Einstellungen für das Callout-Format',
description: 'Einstellungen für das Format des Callout-Passages.',
name: 'Callout-Format',
controls: {
calloutType: {
name: 'Callout-Typ',

View File

@@ -4,7 +4,7 @@ import { QuoteReferencePosition } from 'src/settings';
export const SETTINGS_LABELS: SettingsLabels = {
required: {
name: 'Required Settings',
name: 'Required',
controls: {
biblesPath: {
name: 'Bibles path',
@@ -15,7 +15,7 @@ export const SETTINGS_LABELS: SettingsLabels = {
},
optional: {
name: 'Optional Settings',
name: 'Optional',
controls: {
defaultVersion: {
name: 'Default version',
@@ -47,8 +47,7 @@ export const SETTINGS_LABELS: SettingsLabels = {
},
quoteFormat: {
name: 'Quote Format Settings',
description: 'Settings for the quote passage format.',
name: 'Quote format',
controls: {
includeReference: {
name: 'Include reference',
@@ -72,8 +71,7 @@ export const SETTINGS_LABELS: SettingsLabels = {
},
calloutFormat: {
name: 'Callout Format Settings',
description: 'Settings for the callout passage format.',
name: 'Callout format',
controls: {
calloutType: {
name: 'Callout type',

View File

@@ -4,7 +4,7 @@ import { QuoteReferencePosition } from 'src/settings';
export const SETTINGS_LABELS: SettingsLabels = {
required: {
name: '필수 설정',
name: '필수',
controls: {
biblesPath: {
name: '성경의 길',
@@ -15,7 +15,7 @@ export const SETTINGS_LABELS: SettingsLabels = {
},
optional: {
name: '선택적 설정',
name: '선택 과목',
controls: {
defaultVersion: {
name: '기본 버전',
@@ -46,8 +46,7 @@ export const SETTINGS_LABELS: SettingsLabels = {
},
quoteFormat: {
name: '견적 형식 설정',
description: '인용구 형식 설정입니다.',
name: '견적 형식',
controls: {
includeReference: {
name: '참조 포함',
@@ -69,8 +68,7 @@ export const SETTINGS_LABELS: SettingsLabels = {
},
calloutFormat: {
name: '콜아웃 형식 설정',
description: '설명문 형식 설정입니다.',
name: '콜아웃 형식',
controls: {
calloutType: {
name: '콜아웃 유형',

View File

@@ -39,7 +39,6 @@ export interface SettingsLabels {
quoteFormat: {
name: string;
description: string;
controls: {
includeReference: Control;
referencePosition: Control & {
@@ -54,7 +53,6 @@ export interface SettingsLabels {
calloutFormat: {
name: string;
description: string;
controls: {
calloutType: Control;
linkToPassage: Control;

View File

@@ -6,6 +6,7 @@ import {
Notice,
PluginSettingTab,
Setting,
SettingGroup,
TextComponent,
} from 'obsidian';
import { PassageFormat } from './passage-reference';
@@ -16,7 +17,7 @@ import { SettingsLabels } from './i18n/models';
import { I18N } from './i18n';
export default class LocalBibleRefSettingTab extends PluginSettingTab {
private readonly hiddenClass = 'local-bible-ref-hidden';
private readonly settingClass = 'local-bible-ref-setting';
private plugin: LocalBibleRefPlugin;
private folderDoesNotExistText = '';
@@ -49,240 +50,265 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
this.settingsLabels;
containerEl.empty();
new Setting(containerEl).setName(required.name).setHeading();
// required settings ---
let biblesPathTimeout: number;
new Setting(containerEl)
.setName(required.controls.biblesPath.name)
.setDesc(required.controls.biblesPath.description)
.addText((text) => {
text
.setPlaceholder(required.controls.biblesPath.placeholder)
.setValue(this.plugin.settings.biblesPath)
.onChange(async (value) => {
// toggle visibility of default version setting
if (value) {
defaultVersionSetting.settingEl.removeClass(this.hiddenClass);
} else {
defaultVersionSetting.settingEl.addClass(this.hiddenClass);
(
defaultVersionSetting.components[0] as TextComponent
).inputEl.value = '';
this.plugin.settings.defaultVersionShorthand = '';
}
new SettingGroup(containerEl)
.setHeading(required.name)
.addSetting((setting) =>
setting
.setName(required.controls.biblesPath.name)
.setDesc(required.controls.biblesPath.description)
.setClass(this.settingClass)
.addText((text) => {
text
.setPlaceholder(required.controls.biblesPath.placeholder)
.setValue(this.plugin.settings.biblesPath)
.onChange(async (value) => {
// toggle editability of default version setting
if (value) {
defaultVersionSetting.setDisabled(false);
} else {
defaultVersionSetting.setDisabled(true);
const textComponent = defaultVersionSetting
.components[0] as TextComponent;
textComponent.inputEl.value = '';
this.plugin.settings.defaultVersionShorthand = '';
}
const path = value ? normalizePath(value) : '';
this.plugin.settings.biblesPath = path;
await this.plugin.saveSettings();
const path = value ? normalizePath(value) : '';
this.plugin.settings.biblesPath = path;
await this.plugin.saveSettings();
clearTimeout(biblesPathTimeout);
biblesPathTimeout = window.setTimeout(async () => {
if (!path) return;
const exists = this.app.vault.getFolderByPath(path);
if (!exists)
new Notice(`${this.folderDoesNotExistText} ${path}.`);
}, 1000);
});
new PathSuggest(this.app, text.inputEl);
});
clearTimeout(biblesPathTimeout);
biblesPathTimeout = window.setTimeout(async () => {
if (!path) return;
const exists = this.app.vault.getFolderByPath(path);
if (!exists)
new Notice(`${this.folderDoesNotExistText} ${path}.`);
}, 1000);
});
new PathSuggest(this.app, text.inputEl);
})
);
// optional settings ---
new Setting(containerEl).setName(optional.name).setHeading();
let defaultVersionTimeout: number;
const defaultVersionSetting = new Setting(containerEl)
.setName(optional.controls.defaultVersion.name)
.setDesc(optional.controls.defaultVersion.description)
.addText((text) => {
text
.setPlaceholder(optional.controls.defaultVersion.placeholder)
.setValue(this.plugin.settings.defaultVersionShorthand)
.onChange(async (value) => {
this.plugin.settings.defaultVersionShorthand = value;
await this.plugin.saveSettings();
let defaultVersionSetting = {} as Setting;
new SettingGroup(containerEl)
.setHeading(optional.name)
.addSetting((setting) => {
setting
.setName(optional.controls.defaultVersion.name)
.setDesc(optional.controls.defaultVersion.description)
.setClass(this.settingClass)
.addText((text) => {
text
.setPlaceholder(optional.controls.defaultVersion.placeholder)
.setValue(this.plugin.settings.defaultVersionShorthand)
.onChange(async (value) => {
this.plugin.settings.defaultVersionShorthand = value;
await this.plugin.saveSettings();
clearTimeout(defaultVersionTimeout);
defaultVersionTimeout = window.setTimeout(async () => {
const path = `${this.plugin.settings.biblesPath}/${value}`;
const exists = this.app.vault.getFolderByPath(
normalizePath(path)
);
if (!exists)
new Notice(`${this.folderDoesNotExistText} ${path}.`);
}, 1000);
clearTimeout(defaultVersionTimeout);
defaultVersionTimeout = window.setTimeout(async () => {
const path = `${this.plugin.settings.biblesPath}/${value}`;
const exists = this.app.vault.getFolderByPath(
normalizePath(path)
);
if (!exists)
new Notice(`${this.folderDoesNotExistText} ${path}.`);
}, 1000);
});
new VersionSuggest(this.app, text.inputEl, this.plugin.settings);
});
new VersionSuggest(this.app, text.inputEl, this.plugin.settings);
});
if (this.plugin.settings.biblesPath) {
defaultVersionSetting.settingEl.removeClass(this.hiddenClass);
} else {
defaultVersionSetting.settingEl.addClass(this.hiddenClass);
}
new Setting(containerEl)
.setName(optional.controls.defaultPassageFormat.name)
.setDesc(optional.controls.defaultPassageFormat.description)
.addDropdown((dropdown) =>
dropdown
.addOptions(optional.controls.defaultPassageFormat.options)
.setValue(this.plugin.settings.defaultPassageFormat)
.onChange(async (value) => {
this.plugin.settings.defaultPassageFormat = value as PassageFormat;
await this.plugin.saveSettings();
})
if (this.plugin.settings.biblesPath) setting.setDisabled(false);
else setting.setDisabled(true);
defaultVersionSetting = setting;
})
.addSetting((setting) =>
setting
.setName(optional.controls.defaultPassageFormat.name)
.setDesc(optional.controls.defaultPassageFormat.description)
.setClass(this.settingClass)
.addDropdown((dropdown) =>
dropdown
.addOptions(optional.controls.defaultPassageFormat.options)
.setValue(this.plugin.settings.defaultPassageFormat)
.onChange(async (value) => {
this.plugin.settings.defaultPassageFormat =
value as PassageFormat;
await this.plugin.saveSettings();
})
)
)
.addSetting((setting) =>
setting
.setName(optional.controls.bibleFormat.name)
.setDesc(optional.controls.bibleFormat.description)
.setClass(this.settingClass)
.addDropdown((dropdown) =>
dropdown
.addOptions({
[BibleFormat.LocalBibleRef]: 'Local Bible Ref',
[BibleFormat.BibleLinker]: 'Bible Linker',
})
.setValue(this.plugin.settings.bibleFormat)
.onChange(async (value) => {
this.plugin.settings.bibleFormat = value as BibleFormat;
await this.plugin.saveSettings();
})
)
)
.addSetting((setting) =>
setting
.setName(optional.controls.fullPreview.name)
.setDesc(optional.controls.fullPreview.description)
.setClass(this.settingClass)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.fullPreview)
.onChange(async (value) => {
this.plugin.settings.fullPreview = value;
await this.plugin.saveSettings();
})
)
);
new Setting(containerEl)
.setName(optional.controls.bibleFormat.name)
.setDesc(optional.controls.bibleFormat.description)
.addDropdown((dropdown) =>
dropdown
.addOptions({
[BibleFormat.LocalBibleRef]: 'Local Bible Ref',
[BibleFormat.BibleLinker]: 'Bible Linker',
})
.setValue(this.plugin.settings.bibleFormat)
.onChange(async (value) => {
this.plugin.settings.bibleFormat = value as BibleFormat;
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName(optional.controls.fullPreview.name)
.setDesc(optional.controls.fullPreview.description)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.fullPreview)
.onChange(async (value) => {
this.plugin.settings.fullPreview = value;
await this.plugin.saveSettings();
})
);
// quote format settings ---
new Setting(containerEl)
.setName(quoteFormat.name)
.setDesc(quoteFormat.description)
.setHeading();
let quoteRefPositionSetting = {} as Setting;
let quoteRefLinkSetting = {} as Setting;
new SettingGroup(containerEl)
.setHeading(quoteFormat.name)
.addSetting((setting) =>
setting
.setName(quoteFormat.controls.includeReference.name)
.setDesc(quoteFormat.controls.includeReference.description)
.setClass(this.settingClass)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.quote.includeReference)
.onChange(async (value) => {
// toggle editability of other paragraph reference settings
if (value) {
quoteRefPositionSetting.setDisabled(false);
quoteRefLinkSetting.setDisabled(false);
} else {
quoteRefPositionSetting.setDisabled(true);
quoteRefLinkSetting.setDisabled(true);
}
new Setting(containerEl)
.setName(quoteFormat.controls.includeReference.name)
.setDesc(quoteFormat.controls.includeReference.description)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.quote.includeReference)
.onChange(async (value) => {
// toggle visibility of other paragraph reference settings
if (value) {
quoteRefPositionSetting.settingEl.removeClass(this.hiddenClass);
quoteRefLinkSetting.settingEl.removeClass(this.hiddenClass);
} else {
quoteRefPositionSetting.settingEl.addClass(this.hiddenClass);
quoteRefLinkSetting.settingEl.addClass(this.hiddenClass);
}
this.plugin.settings.quote.includeReference = value;
await this.plugin.saveSettings();
})
)
)
.addSetting((setting) => {
setting
.setName(quoteFormat.controls.referencePosition.name)
.setDesc(quoteFormat.controls.referencePosition.description)
.setClass(this.settingClass)
.addDropdown((dropdown) =>
dropdown
.addOptions(quoteFormat.controls.referencePosition.options)
.setValue(this.plugin.settings.quote.referencePosition)
.onChange(async (value) => {
this.plugin.settings.quote.referencePosition =
value as QuoteReferencePosition;
await this.plugin.saveSettings();
})
);
this.plugin.settings.quote.includeReference = value;
await this.plugin.saveSettings();
})
);
const quoteRefPositionSetting = new Setting(containerEl)
.setName(quoteFormat.controls.referencePosition.name)
.setDesc(quoteFormat.controls.referencePosition.description)
.addDropdown((dropdown) =>
dropdown
.addOptions(quoteFormat.controls.referencePosition.options)
.setValue(this.plugin.settings.quote.referencePosition)
.onChange(async (value) => {
this.plugin.settings.quote.referencePosition =
value as QuoteReferencePosition;
await this.plugin.saveSettings();
})
);
const quoteRefLinkSetting = new Setting(containerEl)
.setName(quoteFormat.controls.linkToPassage.name)
.setDesc(quoteFormat.controls.linkToPassage.description)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.quote.linkToPassage)
.onChange(async (value) => {
this.plugin.settings.quote.linkToPassage = value;
await this.plugin.saveSettings();
})
);
if (this.plugin.settings.quote.includeReference) {
quoteRefPositionSetting.settingEl.removeClass(this.hiddenClass);
quoteRefLinkSetting.settingEl.removeClass(this.hiddenClass);
} else {
quoteRefPositionSetting.settingEl.addClass(this.hiddenClass);
quoteRefLinkSetting.settingEl.addClass(this.hiddenClass);
}
const includeRef = this.plugin.settings.quote.includeReference;
if (includeRef) setting.setDisabled(false);
else setting.setDisabled(true);
quoteRefPositionSetting = setting;
})
.addSetting((setting) => {
setting
.setName(quoteFormat.controls.linkToPassage.name)
.setDesc(quoteFormat.controls.linkToPassage.description)
.setClass(this.settingClass)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.quote.linkToPassage)
.onChange(async (value) => {
this.plugin.settings.quote.linkToPassage = value;
await this.plugin.saveSettings();
})
);
const includeRef = this.plugin.settings.quote.includeReference;
if (includeRef) setting.setDisabled(false);
else setting.setDisabled(true);
quoteRefLinkSetting = setting;
});
// callout format settings ---
new Setting(containerEl)
.setName(calloutFormat.name)
.setDesc(calloutFormat.description)
.setHeading();
new Setting(containerEl)
.setName(calloutFormat.controls.calloutType.name)
.setDesc(calloutFormat.controls.calloutType.description)
.addDropdown((dropdown) =>
dropdown
.addOptions({
note: 'Note',
abstract: 'Abstract',
info: 'Info',
todo: 'Todo',
tip: 'Tip',
success: 'Success',
question: 'Question',
warning: 'Warning',
failure: 'Failure',
danger: 'Danger',
bug: 'Bug',
example: 'Example',
quote: 'Quote',
})
.setValue(this.plugin.settings.callout.type)
.onChange(async (value) => {
this.plugin.settings.callout.type = value as CalloutType;
await this.plugin.saveSettings();
})
new SettingGroup(containerEl)
.setHeading(calloutFormat.name)
.addSetting((setting) =>
setting
.setName(calloutFormat.controls.calloutType.name)
.setDesc(calloutFormat.controls.calloutType.description)
.setClass(this.settingClass)
.addDropdown((dropdown) =>
dropdown
.addOptions({
note: 'Note',
abstract: 'Abstract',
info: 'Info',
todo: 'Todo',
tip: 'Tip',
success: 'Success',
question: 'Question',
warning: 'Warning',
failure: 'Failure',
danger: 'Danger',
bug: 'Bug',
example: 'Example',
quote: 'Quote',
})
.setValue(this.plugin.settings.callout.type)
.onChange(async (value) => {
this.plugin.settings.callout.type = value as CalloutType;
await this.plugin.saveSettings();
})
)
)
.addSetting((setting) =>
setting
.setName(calloutFormat.controls.linkToPassage.name)
.setDesc(calloutFormat.controls.linkToPassage.description)
.setClass(this.settingClass)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.callout.linkToPassage)
.onChange(async (value) => {
this.plugin.settings.callout.linkToPassage = value;
await this.plugin.saveSettings();
})
)
)
.addSetting((setting) =>
setting
.setName(calloutFormat.controls.collapsible.name)
.setDesc(calloutFormat.controls.collapsible.description)
.setClass(this.settingClass)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.callout.collapsible)
.onChange(async (value) => {
this.plugin.settings.callout.collapsible = value;
await this.plugin.saveSettings();
})
)
);
new Setting(containerEl)
.setName(calloutFormat.controls.linkToPassage.name)
.setDesc(calloutFormat.controls.linkToPassage.description)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.callout.linkToPassage)
.onChange(async (value) => {
this.plugin.settings.callout.linkToPassage = value;
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName(calloutFormat.controls.collapsible.name)
.setDesc(calloutFormat.controls.collapsible.description)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.callout.collapsible)
.onChange(async (value) => {
this.plugin.settings.callout.collapsible = value;
await this.plugin.saveSettings();
})
);
// just acts as a spacer for the issues link
new Setting(containerEl).setHeading();
const issuesLink = document.createElement('a');
issuesLink.href = 'https://github.com/camelChief/local-bible-ref/issues';