11import { Setting } from 'obsidian' ;
22import { getTextInLanguage , LanguageStringKey } from './lang/helpers' ;
33import LinterPlugin from './main' ;
4- import { parseTextToHTMLWithoutOuterParagraph } from './ui/helpers' ;
4+ import { hideEl , parseTextToHTMLWithoutOuterParagraph , unhideEl } from './ui/helpers' ;
55import { LinterSettings } from './settings-data' ;
66import { AutoCorrectFilesPickerOption } from './ui/linter-components/auto-correct-files-picker-option' ;
77
@@ -11,6 +11,7 @@ export type SearchOptionInfo = {name: string, description: string, options?: Dro
1111
1212export abstract class Option {
1313 public ruleAlias : string ;
14+ protected setting : Setting ;
1415
1516 /**
1617 * Create an option
@@ -43,38 +44,55 @@ export abstract class Option {
4344 settings . ruleConfigs [ this . ruleAlias ] [ this . configKey ] = value ;
4445 }
4546
46- protected parseNameAndDescriptionAndRemoveSettingBorder ( setting : Setting , plugin : LinterPlugin ) {
47- parseTextToHTMLWithoutOuterParagraph ( plugin . app , this . getName ( ) , setting . nameEl , plugin . settingsTab . component ) ;
48- parseTextToHTMLWithoutOuterParagraph ( plugin . app , this . getDescription ( ) , setting . descEl , plugin . settingsTab . component ) ;
47+ protected parseNameAndDescriptionAndRemoveSettingBorder ( plugin : LinterPlugin ) {
48+ parseTextToHTMLWithoutOuterParagraph ( plugin . app , this . getName ( ) , this . setting . nameEl , plugin . settingsTab . component ) ;
49+ parseTextToHTMLWithoutOuterParagraph ( plugin . app , this . getDescription ( ) , this . setting . descEl , plugin . settingsTab . component ) ;
4950
50- setting . settingEl . addClass ( 'linter-no-border' ) ;
51- setting . descEl . addClass ( 'linter-no-padding-top' ) ;
51+ this . setting . settingEl . addClass ( 'linter-no-border' ) ;
52+ this . setting . descEl . addClass ( 'linter-no-padding-top' ) ;
53+ }
54+
55+ hide ( ) {
56+ hideEl ( this . setting . settingEl ) ;
57+ }
58+
59+ unhide ( ) {
60+ unhideEl ( this . setting . settingEl ) ;
5261 }
5362}
5463
5564export class BooleanOption extends Option {
5665 public defaultValue : boolean ;
5766
67+ constructor ( configKey : string , nameKey : LanguageStringKey , descriptionKey : LanguageStringKey , defaultValue : any , ruleAlias ?: string | null , private onChange ?: ( value : boolean ) => void ) {
68+ super ( configKey , nameKey , descriptionKey , defaultValue , ruleAlias ) ;
69+ }
70+
5871 public display ( containerEl : HTMLElement , settings : LinterSettings , plugin : LinterPlugin ) : void {
59- const setting = new Setting ( containerEl )
72+ this . setting = new Setting ( containerEl )
6073 . addToggle ( ( toggle ) => {
6174 toggle . setValue ( settings . ruleConfigs [ this . ruleAlias ] [ this . configKey ] ) ;
6275 toggle . onChange ( ( value ) => {
6376 this . setOption ( value , settings ) ;
6477 plugin . settings = settings ;
78+
79+ if ( this . onChange ) {
80+ this . onChange ( value ) ;
81+ }
82+
6583 void plugin . saveSettings ( ) ;
6684 } ) ;
6785 } ) ;
6886
69- this . parseNameAndDescriptionAndRemoveSettingBorder ( setting , plugin ) ;
87+ this . parseNameAndDescriptionAndRemoveSettingBorder ( plugin ) ;
7088 }
7189}
7290
7391export class TextOption extends Option {
7492 public defaultValue : string ;
7593
7694 public display ( containerEl : HTMLElement , settings : LinterSettings , plugin : LinterPlugin ) : void {
77- const setting = new Setting ( containerEl )
95+ this . setting = new Setting ( containerEl )
7896 . addText ( ( textbox ) => {
7997 textbox . setValue ( settings . ruleConfigs [ this . ruleAlias ] [ this . configKey ] ) ;
8098 textbox . onChange ( ( value ) => {
@@ -84,15 +102,15 @@ export class TextOption extends Option {
84102 } ) ;
85103 } ) ;
86104
87- this . parseNameAndDescriptionAndRemoveSettingBorder ( setting , plugin ) ;
105+ this . parseNameAndDescriptionAndRemoveSettingBorder ( plugin ) ;
88106 }
89107}
90108
91109export class TextAreaOption extends Option {
92110 public defaultValue : string ;
93111
94112 public display ( containerEl : HTMLElement , settings : LinterSettings , plugin : LinterPlugin ) : void {
95- const setting = new Setting ( containerEl )
113+ this . setting = new Setting ( containerEl )
96114 . addTextArea ( ( textbox ) => {
97115 textbox . setValue ( settings . ruleConfigs [ this . ruleAlias ] [ this . configKey ] ) ;
98116 textbox . onChange ( ( value ) => {
@@ -102,15 +120,15 @@ export class TextAreaOption extends Option {
102120 } ) ;
103121 } ) ;
104122
105- this . parseNameAndDescriptionAndRemoveSettingBorder ( setting , plugin ) ;
123+ this . parseNameAndDescriptionAndRemoveSettingBorder ( plugin ) ;
106124 }
107125}
108126
109127export class MomentFormatOption extends Option {
110128 public defaultValue : boolean ;
111129
112130 public display ( containerEl : HTMLElement , settings : LinterSettings , plugin : LinterPlugin ) : void {
113- const setting = new Setting ( containerEl )
131+ this . setting = new Setting ( containerEl )
114132 . addMomentFormat ( ( format ) => {
115133 format . setValue ( settings . ruleConfigs [ this . ruleAlias ] [ this . configKey ] ) ;
116134 format . setPlaceholder ( 'dddd, MMMM Do YYYY, h:mm:ss a' ) ;
@@ -121,7 +139,7 @@ export class MomentFormatOption extends Option {
121139 } ) ;
122140 } ) ;
123141
124- this . parseNameAndDescriptionAndRemoveSettingBorder ( setting , plugin ) ;
142+ this . parseNameAndDescriptionAndRemoveSettingBorder ( plugin ) ;
125143 }
126144}
127145
@@ -153,7 +171,7 @@ export class DropdownOption extends Option {
153171 }
154172
155173 public display ( containerEl : HTMLElement , settings : LinterSettings , plugin : LinterPlugin ) : void {
156- const setting = new Setting ( containerEl )
174+ this . setting = new Setting ( containerEl )
157175 . addDropdown ( ( dropdown ) => {
158176 // First, add all the available options
159177 for ( const option of this . options ) {
@@ -170,21 +188,32 @@ export class DropdownOption extends Option {
170188 } ) ;
171189 } ) ;
172190
173- this . parseNameAndDescriptionAndRemoveSettingBorder ( setting , plugin ) ;
191+ this . parseNameAndDescriptionAndRemoveSettingBorder ( plugin ) ;
174192 }
175193}
176194
177195
178196export class MdFilePickerOption extends Option {
197+ private settingEl : HTMLDivElement ;
179198 constructor ( configKey : string , nameKey : LanguageStringKey , descriptionKey : LanguageStringKey , ruleAlias ?: string | null ) {
180199 super ( configKey , nameKey , descriptionKey , [ ] , ruleAlias ) ;
181200 }
182201
183202 public display ( containerEl : HTMLElement , settings : LinterSettings , plugin : LinterPlugin ) : void {
184203 settings . ruleConfigs [ this . ruleAlias ] [ this . configKey ] = settings . ruleConfigs [ this . ruleAlias ] [ this . configKey ] ?? [ ] ;
185204
186- new AutoCorrectFilesPickerOption ( containerEl , plugin . settingsTab . component , settings . ruleConfigs [ this . ruleAlias ] [ this . configKey ] , plugin . app , ( ) => {
205+ this . settingEl = containerEl . createDiv ( ) ;
206+
207+ new AutoCorrectFilesPickerOption ( this . settingEl , plugin . settingsTab . component , settings . ruleConfigs [ this . ruleAlias ] [ this . configKey ] , plugin . app , ( ) => {
187208 void plugin . saveSettings ( ) ;
188209 } , this . nameKey , this . descriptionKey ) ;
189210 }
211+
212+ override hide ( ) {
213+ hideEl ( this . settingEl ) ;
214+ }
215+
216+ override unhide ( ) {
217+ unhideEl ( this . settingEl ) ;
218+ }
190219}
0 commit comments