diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index 84e71047..199ba218 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -152,10 +152,6 @@ export default { 'name': 'Display Lint on File Change Message', 'description': 'Displays a message when `Lint on Focused File Change` occurs', }, - 'timestamp-update-on-file-contents-updated': { - 'name': 'Update YAML Timestamp on File Contents Update', - 'description': 'When the currently active file is modified, `YAML Timestamp` is run on the file. This should update the modified file timestamp if it is more than 5 seconds off from the current value.', - }, 'folders-to-ignore': { 'name': 'Folders to ignore', 'description': 'Folders to ignore when linting all files or linting on save.', @@ -849,6 +845,10 @@ export default { 'name': 'Convert Local Time to UTC', 'description': 'Uses UTC equivalent for saved dates instead of local time', }, + 'update-on-file-contents-updated': { + 'name': 'Update YAML Timestamp on File Contents Update', + 'description': 'When the currently active note is modified, `YAML Timestamp` is run on the note. This should update the modified note timestamp if it is more than 5 seconds off from the current value.', + }, }, // yaml-title-alias.ts 'yaml-title-alias': { diff --git a/src/main.ts b/src/main.ts index 7b920b6e..bbf9861c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -127,8 +127,16 @@ export default class LinterPlugin extends Plugin { setLogLevel(this.settings.logLevel); await this.setOrUpdateMomentInstance(); + let updateMade = false; if (!this.settings.settingsConvertedToConfigKeyValues) { - this.moveConfigValuesToKeyBasedFormat(); + updateMade = await this.moveConfigValuesToKeyBasedFormat(); + } + + if ('lintOnFileContentChangeDelay' in this.settings) { + this.settings.ruleConfigs['yaml-timestamp']['update-on-file-contents-updated'] = this.settings['lintOnFileContentChangeDelay']; + + delete this.settings['lintOnFileContentChangeDelay']; + updateMade = true; } // make sure to load the defaults of any missing rules to make sure they do not cause issues on the settings page @@ -142,10 +150,12 @@ export default class LinterPlugin extends Plugin { const defaults = rule.getDefaultOptions(); if (!('english-symbols-punctuation-before' in this.settings.ruleConfigs[rule.alias])) { this.settings.ruleConfigs[rule.alias]['english-symbols-punctuation-before'] = defaults['english-symbols-punctuation-before']; + updateMade = true; } if (!('english-symbols-punctuation-after' in this.settings.ruleConfigs[rule.alias])) { this.settings.ruleConfigs[rule.alias]['english-symbols-punctuation-after'] = defaults['english-symbols-punctuation-after']; + updateMade = true; } } else if (rule.alias == 'yaml-timestamp') { const defaults = rule.getDefaultOptions(); @@ -158,18 +168,23 @@ export default class LinterPlugin extends Plugin { } } - delete this.settings.ruleConfigs[rule.alias]['force-retention-of-create-value']; + updateMade = true; } if (!('date-modified-source-of-truth' in this.settings.ruleConfigs[rule.alias])) { this.settings.ruleConfigs[rule.alias]['date-modified-source-of-truth'] = defaults['date-modified-source-of-truth']; + updateMade = true; } } } this.updatePasteOverrideStatus(); this.updateHasCustomCommandStatus(); + + if (updateMade) { + await this.saveSettings(); + } } async saveSettings() { @@ -290,7 +305,7 @@ export default class LinterPlugin extends Plugin { this.eventRefs.push(eventRef); eventRef = this.app.workspace.on('editor-change', async (editor: Editor, info: MarkdownView | MarkdownFileInfo) => { - if (this.settings.lintOnFileContentChangeDelay == AfterFileChangeLintTimes.Never) { + if ((this.settings.ruleConfigs['yaml-timestamp']['update-on-file-contents-updated'] ?? AfterFileChangeLintTimes.Never) == AfterFileChangeLintTimes.Never) { return; } @@ -610,7 +625,7 @@ export default class LinterPlugin extends Plugin { private createDebouncedFileUpdate(): Debouncer<[TFile, Editor], Promise> { let delay = 5000; - switch (this.settings.lintOnFileContentChangeDelay) { + switch (this.settings.ruleConfigs['yaml-timestamp']['update-on-file-contents-updated'] ?? AfterFileChangeLintTimes.Never) { case AfterFileChangeLintTimes.After10Seconds: delay = 10000; break; @@ -909,9 +924,10 @@ export default class LinterPlugin extends Plugin { return editor.getLine(selection.anchor.line); } - private moveConfigValuesToKeyBasedFormat() { + private async moveConfigValuesToKeyBasedFormat(): Promise { setLanguage('en'); + let updateMade = false; for (const rule of rules) { const ruleName = getTextInLanguage('rules.' + rule.alias + '.name' as LanguageStringKey); const ruleSettings = this.settings.ruleConfigs[ruleName]; @@ -935,13 +951,17 @@ export default class LinterPlugin extends Plugin { this.settings.ruleConfigs[rule.alias] = newSettingValues; delete this.settings.ruleConfigs[ruleName]; + + updateMade = true; } } this.settings.settingsConvertedToConfigKeyValues = true; - void this.saveSettings(); + await this.saveSettings(); setLanguage(window.localStorage.getItem('language')); + + return updateMade; } private getAllFilesInFolder(startingFolder: TFolder): TFile[] { diff --git a/src/option.ts b/src/option.ts index c7262531..3f762e8f 100644 --- a/src/option.ts +++ b/src/option.ts @@ -1,7 +1,7 @@ import {Setting} from 'obsidian'; import {getTextInLanguage, LanguageStringKey} from './lang/helpers'; import LinterPlugin from './main'; -import {parseTextToHTMLWithoutOuterParagraph} from './ui/helpers'; +import {hideEl, parseTextToHTMLWithoutOuterParagraph, unhideEl} from './ui/helpers'; import {LinterSettings} from './settings-data'; import {AutoCorrectFilesPickerOption} from './ui/linter-components/auto-correct-files-picker-option'; @@ -11,6 +11,7 @@ export type SearchOptionInfo = {name: string, description: string, options?: Dro export abstract class Option { public ruleAlias: string; + protected setting: Setting; /** * Create an option @@ -43,30 +44,47 @@ export abstract class Option { settings.ruleConfigs[this.ruleAlias][this.configKey] = value; } - protected parseNameAndDescriptionAndRemoveSettingBorder(setting: Setting, plugin: LinterPlugin) { - parseTextToHTMLWithoutOuterParagraph(plugin.app, this.getName(), setting.nameEl, plugin.settingsTab.component); - parseTextToHTMLWithoutOuterParagraph(plugin.app, this.getDescription(), setting.descEl, plugin.settingsTab.component); + protected parseNameAndDescriptionAndRemoveSettingBorder(plugin: LinterPlugin) { + parseTextToHTMLWithoutOuterParagraph(plugin.app, this.getName(), this.setting.nameEl, plugin.settingsTab.component); + parseTextToHTMLWithoutOuterParagraph(plugin.app, this.getDescription(), this.setting.descEl, plugin.settingsTab.component); - setting.settingEl.addClass('linter-no-border'); - setting.descEl.addClass('linter-no-padding-top'); + this.setting.settingEl.addClass('linter-no-border'); + this.setting.descEl.addClass('linter-no-padding-top'); + } + + hide() { + hideEl(this.setting.settingEl); + } + + unhide() { + unhideEl(this.setting.settingEl); } } export class BooleanOption extends Option { public defaultValue: boolean; + constructor(configKey: string, nameKey: LanguageStringKey, descriptionKey: LanguageStringKey, defaultValue: any, ruleAlias?: string | null, private onChange?: (value: boolean) => void) { + super(configKey, nameKey, descriptionKey, defaultValue, ruleAlias); + } + public display(containerEl: HTMLElement, settings: LinterSettings, plugin: LinterPlugin): void { - const setting = new Setting(containerEl) + this.setting = new Setting(containerEl) .addToggle((toggle) => { toggle.setValue(settings.ruleConfigs[this.ruleAlias][this.configKey]); toggle.onChange((value) => { this.setOption(value, settings); plugin.settings = settings; + + if (this.onChange) { + this.onChange(value); + } + void plugin.saveSettings(); }); }); - this.parseNameAndDescriptionAndRemoveSettingBorder(setting, plugin); + this.parseNameAndDescriptionAndRemoveSettingBorder(plugin); } } @@ -74,7 +92,7 @@ export class TextOption extends Option { public defaultValue: string; public display(containerEl: HTMLElement, settings: LinterSettings, plugin: LinterPlugin): void { - const setting = new Setting(containerEl) + this.setting = new Setting(containerEl) .addText((textbox) => { textbox.setValue(settings.ruleConfigs[this.ruleAlias][this.configKey]); textbox.onChange((value) => { @@ -84,7 +102,7 @@ export class TextOption extends Option { }); }); - this.parseNameAndDescriptionAndRemoveSettingBorder(setting, plugin); + this.parseNameAndDescriptionAndRemoveSettingBorder(plugin); } } @@ -92,7 +110,7 @@ export class TextAreaOption extends Option { public defaultValue: string; public display(containerEl: HTMLElement, settings: LinterSettings, plugin: LinterPlugin): void { - const setting = new Setting(containerEl) + this.setting = new Setting(containerEl) .addTextArea((textbox) => { textbox.setValue(settings.ruleConfigs[this.ruleAlias][this.configKey]); textbox.onChange((value) => { @@ -102,7 +120,7 @@ export class TextAreaOption extends Option { }); }); - this.parseNameAndDescriptionAndRemoveSettingBorder(setting, plugin); + this.parseNameAndDescriptionAndRemoveSettingBorder(plugin); } } @@ -110,7 +128,7 @@ export class MomentFormatOption extends Option { public defaultValue: boolean; public display(containerEl: HTMLElement, settings: LinterSettings, plugin: LinterPlugin): void { - const setting = new Setting(containerEl) + this.setting = new Setting(containerEl) .addMomentFormat((format) => { format.setValue(settings.ruleConfigs[this.ruleAlias][this.configKey]); format.setPlaceholder('dddd, MMMM Do YYYY, h:mm:ss a'); @@ -121,7 +139,7 @@ export class MomentFormatOption extends Option { }); }); - this.parseNameAndDescriptionAndRemoveSettingBorder(setting, plugin); + this.parseNameAndDescriptionAndRemoveSettingBorder(plugin); } } @@ -153,7 +171,7 @@ export class DropdownOption extends Option { } public display(containerEl: HTMLElement, settings: LinterSettings, plugin: LinterPlugin): void { - const setting = new Setting(containerEl) + this.setting = new Setting(containerEl) .addDropdown((dropdown) => { // First, add all the available options for (const option of this.options) { @@ -170,12 +188,13 @@ export class DropdownOption extends Option { }); }); - this.parseNameAndDescriptionAndRemoveSettingBorder(setting, plugin); + this.parseNameAndDescriptionAndRemoveSettingBorder(plugin); } } export class MdFilePickerOption extends Option { + private settingEl: HTMLDivElement; constructor(configKey: string, nameKey: LanguageStringKey, descriptionKey: LanguageStringKey, ruleAlias?: string | null) { super(configKey, nameKey, descriptionKey, [], ruleAlias); } @@ -183,8 +202,18 @@ export class MdFilePickerOption extends Option { public display(containerEl: HTMLElement, settings: LinterSettings, plugin: LinterPlugin): void { settings.ruleConfigs[this.ruleAlias][this.configKey] = settings.ruleConfigs[this.ruleAlias][this.configKey] ?? []; - new AutoCorrectFilesPickerOption(containerEl, plugin.settingsTab.component, settings.ruleConfigs[this.ruleAlias][this.configKey], plugin.app, () => { + this.settingEl = containerEl.createDiv(); + + new AutoCorrectFilesPickerOption(this.settingEl, plugin.settingsTab.component, settings.ruleConfigs[this.ruleAlias][this.configKey], plugin.app, () => { void plugin.saveSettings(); }, this.nameKey, this.descriptionKey); } + + override hide() { + hideEl(this.settingEl); + } + + override unhide() { + unhideEl(this.settingEl); + } } diff --git a/src/rules.ts b/src/rules.ts index 33b4257d..d4552cd3 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -56,7 +56,17 @@ export class Rule { ) { this.ruleHeading = this.getName().toLowerCase().replaceAll(' ', '-'); - options.unshift(new BooleanOption('enabled', this.descriptionKey, '' as LanguageStringKey, false)); + options.unshift(new BooleanOption('enabled', this.descriptionKey, '' as LanguageStringKey, false, alias, (value: boolean) => { + if (options.length > 1) { + for (let i = 1; i < options.length; i++) { + if (value) { + options[i].unhide(); + } else { + options[i].hide(); + } + } + } + })); for (const option of options) { option.ruleAlias = alias; } diff --git a/src/rules/yaml-timestamp.ts b/src/rules/yaml-timestamp.ts index e250f610..ca84214f 100644 --- a/src/rules/yaml-timestamp.ts +++ b/src/rules/yaml-timestamp.ts @@ -7,6 +7,7 @@ import {escapeDollarSigns} from '../utils/regex'; import {insert} from '../utils/strings'; import parseFormat from 'moment-parseformat'; import {getTextInLanguage} from '../lang/helpers'; +import {AfterFileChangeLintTimes} from '../settings-data'; type DateCreatedSourceOfTruth = 'file system' | 'frontmatter'; type DateModifiedSourceOfTruth = 'file system' | 'user or Linter edits'; @@ -29,6 +30,10 @@ class YamlTimestampOptions implements Options { convertToUTC?: boolean = false; + // This is not used in the rule itself. It is used for running this rule as a standalone when + // editor content is updated. + timestampUpdateOnFileContentUpdated?: AfterFileChangeLintTimes =AfterFileChangeLintTimes.Never; + @RuleBuilder.noSettingControl() fileModifiedTime?: string; @@ -455,6 +460,38 @@ export default class YamlTimestamp extends RuleBuilder { descriptionKey: 'rules.yaml-timestamp.convert-to-utc.description', optionsKey: 'convertToUTC', }), + new DropdownOptionBuilder({ + OptionsClass: YamlTimestampOptions, + nameKey: 'rules.yaml-timestamp.update-on-file-contents-updated.name', + descriptionKey: 'rules.yaml-timestamp.update-on-file-contents-updated.description', + optionsKey: 'timestampUpdateOnFileContentUpdated', + records: [ + { + value: AfterFileChangeLintTimes.Never, + description: AfterFileChangeLintTimes.Never, + }, + { + value: AfterFileChangeLintTimes.After5Seconds, + description: AfterFileChangeLintTimes.After5Seconds, + }, + { + value: AfterFileChangeLintTimes.After10Seconds, + description: AfterFileChangeLintTimes.After10Seconds, + }, + { + value: AfterFileChangeLintTimes.After15Seconds, + description: AfterFileChangeLintTimes.After15Seconds, + }, + { + value: AfterFileChangeLintTimes.After30Seconds, + description: AfterFileChangeLintTimes.After30Seconds, + }, + { + value: AfterFileChangeLintTimes.After1Minute, + description: AfterFileChangeLintTimes.After1Minute, + }, + ], + }), ]; } } diff --git a/src/settings-data.ts b/src/settings-data.ts index eb758aea..2baaa90e 100644 --- a/src/settings-data.ts +++ b/src/settings-data.ts @@ -33,7 +33,6 @@ export interface LinterSettings { recordLintOnSaveLogs: boolean; lintOnFileChange: boolean; displayLintOnFileChangeNotice: boolean; - lintOnFileContentChangeDelay: string; foldersToIgnore: string[]; filesToIgnore: FileToIgnore[]; linterLocale: string; @@ -52,7 +51,6 @@ export const DEFAULT_SETTINGS: Partial = { displayChanged: true, lintOnFileChange: false, displayLintOnFileChangeNotice: false, - lintOnFileContentChangeDelay: AfterFileChangeLintTimes.Never, settingsConvertedToConfigKeyValues: false, foldersToIgnore: [], filesToIgnore: [], diff --git a/src/ui/components/text-box-full.ts b/src/ui/components/text-box-full.ts index eec15874..56057615 100644 --- a/src/ui/components/text-box-full.ts +++ b/src/ui/components/text-box-full.ts @@ -1,7 +1,9 @@ import {Notice, setIcon} from 'obsidian'; import {getTextInLanguage} from 'src/lang/helpers'; +import {hideEl, unhideEl} from '../helpers'; export class TextBoxFull { + settingEl: HTMLDivElement; nameEl: HTMLDivElement; descEl: HTMLDivElement; inputContainerEl: HTMLDivElement; @@ -13,8 +15,8 @@ export class TextBoxFull { } display() { - const settingEl = this.containerEl.createDiv(); - const infoEl = settingEl.createDiv('setting-item-info'); + this.settingEl = this.containerEl.createDiv(); + const infoEl = this.settingEl.createDiv('setting-item-info'); this.nameEl = infoEl.createDiv('setting-item-name'); this.nameEl.setText(this.name); @@ -22,7 +24,7 @@ export class TextBoxFull { this.descEl = infoEl.createDiv('setting-item-description'); this.descEl.setText(this.description); - this.inputContainerEl = settingEl.createDiv('full-width-textbox-input-wrapper'); + this.inputContainerEl = this.settingEl.createDiv('full-width-textbox-input-wrapper'); this.inputContainerEl.onmouseover = () => { if (this.getInput().trim() != '') { this.copyEl.removeClass('linter-visually-hidden'); @@ -57,4 +59,12 @@ export class TextBoxFull { new Notice(`${getTextInLanguage('notice-text.copy-to-clipboard-failed') + reason}`, 0); }); } + + hide() { + hideEl(this.settingEl); + } + + unhide() { + unhideEl(this.settingEl); + } } diff --git a/src/ui/components/toggle-setting.ts b/src/ui/components/toggle-setting.ts index b2736ada..5a3c2598 100644 --- a/src/ui/components/toggle-setting.ts +++ b/src/ui/components/toggle-setting.ts @@ -3,10 +3,11 @@ import LinterPlugin from 'src/main'; import {LinterSettingsKeys} from 'src/settings-data'; import {BaseSetting} from './base-setting'; import {LanguageStringKey} from 'src/lang/helpers'; +import {hideEl, unhideEl} from '../helpers'; export class ToggleSetting extends BaseSetting { setting: Setting; - constructor(containerEl: HTMLDivElement, name: LanguageStringKey, description: LanguageStringKey, keyToUpdate: LinterSettingsKeys, plugin: LinterPlugin) { + constructor(containerEl: HTMLDivElement, name: LanguageStringKey, description: LanguageStringKey, keyToUpdate: LinterSettingsKeys, plugin: LinterPlugin, private onChange?: (value: boolean) => void) { super(containerEl, name, description, keyToUpdate, plugin); this.display(); } @@ -17,10 +18,22 @@ export class ToggleSetting extends BaseSetting { toggle .setValue(this.getBoolean()) .onChange(async (value) => { + if (this.onChange) { + this.onChange(value); + } + void this.saveValue(value); }); }); this.parseNameAndDescription(); } + + hide() { + hideEl(this.setting.settingEl); + } + + unhide() { + unhideEl(this.setting.settingEl); + } } diff --git a/src/ui/linter-components/tab-components/debug-tab.ts b/src/ui/linter-components/tab-components/debug-tab.ts index 390bfde1..ab223d6c 100644 --- a/src/ui/linter-components/tab-components/debug-tab.ts +++ b/src/ui/linter-components/tab-components/debug-tab.ts @@ -36,17 +36,29 @@ export class DebugTab extends Tab { this.addSettingSearchInfo(tempDiv, settingName, settingDesc); + let logDisplay: TextBoxFull = null; tempDiv = this.contentEl.createDiv(); - this.addSettingSearchInfoForGeneralSettings(new ToggleSetting(tempDiv, 'tabs.debug.log-collection.name', 'tabs.debug.log-collection.description', 'recordLintOnSaveLogs', this.plugin)); + const recordLintOnSaveLogsSetting = new ToggleSetting(tempDiv, 'tabs.debug.log-collection.name', 'tabs.debug.log-collection.description', 'recordLintOnSaveLogs', this.plugin, (value: boolean) => { + if (value) { + logDisplay.unhide(); + } else { + logDisplay.hide(); + } + }); + this.addSettingSearchInfoForGeneralSettings(recordLintOnSaveLogsSetting); tempDiv = this.contentEl.createDiv(); settingName = getTextInLanguage('tabs.debug.linter-logs.name'); settingDesc = getTextInLanguage('tabs.debug.linter-logs.description'); - const logDisplay = new TextBoxFull(tempDiv, settingName, ''); + logDisplay = new TextBoxFull(tempDiv, settingName, ''); logDisplay.inputEl.setText(logsFromLastRun.join('\n')); parseTextToHTMLWithoutOuterParagraph(this.plugin.app, settingDesc, logDisplay.descEl, this.plugin.settingsTab.component); + if (!recordLintOnSaveLogsSetting.getBoolean()) { + logDisplay.hide(); + } + this.addSettingSearchInfo(tempDiv, settingName, settingDesc); } } diff --git a/src/ui/linter-components/tab-components/general-tab.ts b/src/ui/linter-components/tab-components/general-tab.ts index dc8bd1ff..7b8b09c6 100644 --- a/src/ui/linter-components/tab-components/general-tab.ts +++ b/src/ui/linter-components/tab-components/general-tab.ts @@ -9,7 +9,6 @@ import {NumberInputSetting} from 'src/ui/components/number-input-setting'; import {ToggleSetting} from 'src/ui/components/toggle-setting'; import {FolderIgnoreOption} from '../folder-ignore-option'; import {FilesToIgnoreOption} from '../files-to-ignore-option'; -import {AfterFileChangeLintTimes} from 'src/settings-data'; export class GeneralTab extends Tab { constructor(navEl: HTMLElement, settingsEl: HTMLElement, isMobile: boolean, plugin: LinterPlugin, private app: App) { @@ -19,32 +18,41 @@ export class GeneralTab extends Tab { display(): void { let tempDiv = this.contentEl.createDiv(); - this.addSettingSearchInfoForGeneralSettings(new ToggleSetting(tempDiv, 'tabs.general.lint-on-save.name', 'tabs.general.lint-on-save.description', 'lintOnSave', this.plugin)); - tempDiv = this.contentEl.createDiv(); - this.addSettingSearchInfoForGeneralSettings(new ToggleSetting(tempDiv, 'tabs.general.display-message.name', 'tabs.general.display-message.description', 'displayChanged', this.plugin)); + let displayCharactersChangedSetting: ToggleSetting = null; + const lintOnSaveSetting = new ToggleSetting(tempDiv, 'tabs.general.lint-on-save.name', 'tabs.general.lint-on-save.description', 'lintOnSave', this.plugin, (value: boolean) => { + if (value) { + displayCharactersChangedSetting.unhide(); + } else { + displayCharactersChangedSetting.hide(); + } + }); + this.addSettingSearchInfoForGeneralSettings(lintOnSaveSetting); tempDiv = this.contentEl.createDiv(); - this.addSettingSearchInfoForGeneralSettings(new ToggleSetting(tempDiv, 'tabs.general.lint-on-file-change.name', 'tabs.general.lint-on-file-change.description', 'lintOnFileChange', this.plugin)); + displayCharactersChangedSetting = new ToggleSetting(tempDiv, 'tabs.general.display-message.name', 'tabs.general.display-message.description', 'displayChanged', this.plugin); + this.addSettingSearchInfoForGeneralSettings(displayCharactersChangedSetting); + if (!lintOnSaveSetting.getBoolean()) { + displayCharactersChangedSetting.hide(); + } + let displayLintOnActiveFileChangeSetting: ToggleSetting = null; tempDiv = this.contentEl.createDiv(); - this.addSettingSearchInfoForGeneralSettings(new ToggleSetting(tempDiv, 'tabs.general.display-lint-on-file-change-message.name', 'tabs.general.display-lint-on-file-change-message.description', 'displayLintOnFileChangeNotice', this.plugin)); - - const yamlTimestampTimeOptions: DropdownRecordInfo = { - isForEnum: true, - values: [ - AfterFileChangeLintTimes.Never, - AfterFileChangeLintTimes.After5Seconds, - AfterFileChangeLintTimes.After10Seconds, - AfterFileChangeLintTimes.After15Seconds, - AfterFileChangeLintTimes.After30Seconds, - AfterFileChangeLintTimes.After1Minute, - ], - descriptions: [], - }; + const lintOnActiveFileChangeSetting = new ToggleSetting(tempDiv, 'tabs.general.lint-on-file-change.name', 'tabs.general.lint-on-file-change.description', 'lintOnFileChange', this.plugin, (value: boolean) => { + if (value) { + displayLintOnActiveFileChangeSetting.unhide(); + } else { + displayLintOnActiveFileChangeSetting.hide(); + } + }); + this.addSettingSearchInfoForGeneralSettings(lintOnActiveFileChangeSetting); tempDiv = this.contentEl.createDiv(); - this.addSettingSearchInfoForGeneralSettings(new DropdownSetting(tempDiv, 'tabs.general.timestamp-update-on-file-contents-updated.name', 'tabs.general.timestamp-update-on-file-contents-updated.description', 'lintOnFileContentChangeDelay', this.plugin, yamlTimestampTimeOptions)); + displayLintOnActiveFileChangeSetting = new ToggleSetting(tempDiv, 'tabs.general.display-lint-on-file-change-message.name', 'tabs.general.display-lint-on-file-change-message.description', 'displayLintOnFileChangeNotice', this.plugin); + this.addSettingSearchInfoForGeneralSettings(displayLintOnActiveFileChangeSetting); + if (!lintOnActiveFileChangeSetting.getBoolean()) { + displayLintOnActiveFileChangeSetting.hide(); + } const sysLocale = navigator.language?.toLowerCase(); const localeValues = ['system-default']; diff --git a/src/ui/linter-components/tab-components/rule-tab.ts b/src/ui/linter-components/tab-components/rule-tab.ts index 76fe4ff2..ebf90ef2 100644 --- a/src/ui/linter-components/tab-components/rule-tab.ts +++ b/src/ui/linter-components/tab-components/rule-tab.ts @@ -1,7 +1,8 @@ import LinterPlugin from 'src/main'; import {Tab} from './tab'; import {Rule} from 'src/rules'; -import {SearchOptionInfo} from 'src/option'; +import {BooleanOption, SearchOptionInfo} from 'src/option'; +import {Setting} from 'obsidian'; export class RuleTab extends Tab { constructor(navEl: HTMLElement, settingsEl: HTMLElement, ruleTypeName: string, private rules: Rule[], isMobile: boolean, plugin: LinterPlugin) { @@ -13,14 +14,24 @@ export class RuleTab extends Tab { for (const rule of this.rules) { const ruleDiv = this.contentEl.createDiv(); ruleDiv.id = rule.alias; - ruleDiv.createEl(this.isMobile ? 'h4' : 'h3', {}, (el) => { - el.innerHTML = `${rule.getName()}`; - }); + + new Setting(ruleDiv).setHeading().settingEl.innerHTML = `${rule.getName()}`; const optionInfo = [] as SearchOptionInfo[]; + let isFirstOption = true; + let hideOnLoad = false; for (const option of rule.options) { option.display(ruleDiv, this.plugin.settings, this.plugin); optionInfo.push(option.getSearchInfo()); + + if (isFirstOption) { + isFirstOption = false; + if (option instanceof BooleanOption) { + hideOnLoad = !this.plugin.settings.ruleConfigs[option.ruleAlias][option.configKey]; + } + } else if (hideOnLoad) { + option.hide(); + } } this.addSettingSearchInfo(ruleDiv, rule.getName().toLowerCase(), rule.getDescription().toLowerCase(), optionInfo, ruleDiv.id); diff --git a/src/ui/linter-components/tab-components/tab.ts b/src/ui/linter-components/tab-components/tab.ts index 7c38c08e..02f1ef8a 100644 --- a/src/ui/linter-components/tab-components/tab.ts +++ b/src/ui/linter-components/tab-components/tab.ts @@ -1,7 +1,7 @@ import {iconInfo} from 'src/ui/icons'; import LinterPlugin from 'src/main'; import {RuleType} from 'src/rules'; -import {setIcon} from 'obsidian'; +import {setIcon, Setting} from 'obsidian'; import {settingSearchInfo} from './tab-searcher'; import {SearchOptionInfo} from 'src/option'; import {hideEl, unhideEl} from 'src/ui/helpers'; @@ -59,7 +59,7 @@ export abstract class Tab { this.contentEl = settingsEl.createDiv('linter-tab-settings'); this.contentEl.id = name.toLowerCase().replace(' ', '-'); - this.headingEl = this.contentEl.createEl('h2', {text: nameInLanguage}); + this.headingEl = new Setting(this.contentEl).setName(nameInLanguage).setHeading().nameEl; hideEl(this.headingEl); }