-
-
Notifications
You must be signed in to change notification settings - Fork 356
Expand file tree
/
Copy pathSettingsTab.ts
More file actions
704 lines (623 loc) · 31.1 KB
/
SettingsTab.ts
File metadata and controls
704 lines (623 loc) · 31.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
import { Notice, PluginSettingTab, Setting, debounce } from 'obsidian';
import { StatusConfiguration, StatusType } from '../StatusConfiguration';
import type TasksPlugin from '../main';
import { StatusRegistry } from '../StatusRegistry';
import { Status } from '../Status';
import type { StatusCollection } from '../StatusCollection';
import * as Themes from './Themes';
import { type HeadingState, TASK_FORMATS } from './Settings';
import { getSettings, isFeatureEnabled, updateGeneralSetting, updateSettings } from './Settings';
import { GlobalFilter } from './GlobalFilter';
import { StatusSettings } from './StatusSettings';
import settingsJson from './settingsConfiguration.json';
import { CustomStatusModal } from './CustomStatusModal';
export class SettingsTab extends PluginSettingTab {
// If the UI needs a more complex setting you can create a
// custom function and specify it from the json file. It will
// then be rendered instead of a normal checkbox or text box.
customFunctions: { [K: string]: Function } = {
insertTaskCoreStatusSettings: this.insertTaskCoreStatusSettings.bind(this),
insertCustomTaskStatusSettings: this.insertCustomTaskStatusSettings.bind(this),
};
private readonly plugin: TasksPlugin;
constructor({ plugin }: { plugin: TasksPlugin }) {
super(plugin.app, plugin);
this.plugin = plugin;
}
private static createFragmentWithHTML = (html: string) =>
createFragment((documentFragment) => (documentFragment.createDiv().innerHTML = html));
public async saveSettings(update?: boolean): Promise<void> {
await this.plugin.saveSettings();
if (update) {
this.display();
}
}
public display(): void {
const { containerEl } = this;
containerEl.empty();
this.containerEl.addClass('tasks-settings');
// For reasons I don't understand, 'h2' is tiny in Settings,
// so I have used 'h3' as the largest heading.
containerEl.createEl('h3', { text: 'Tasks Settings' });
containerEl.createEl('p', {
cls: 'tasks-setting-important',
text: 'Changing any settings requires a restart of obsidian.',
});
// ---------------------------------------------------------------------------
containerEl.createEl('h4', { text: 'Task Format Settings' });
// ---------------------------------------------------------------------------
new Setting(containerEl)
.setName('Task Format')
.setDesc(
SettingsTab.createFragmentWithHTML(
'<p>The format that Tasks uses to read and write tasks.</p>' +
'<p><b>Important:</b> Tasks currently only supports one format at a time. Selecting Dataview will currently <b>stop Tasks reading its own emoji signifiers</b>.</p>' +
'<p>See the <a href="https://publish.obsidian.md/tasks/Reference/Task+Formats/About+Task+Formats">documentation</a>.</p>',
),
)
.addDropdown((dropdown) => {
for (const key of Object.keys(TASK_FORMATS) as (keyof TASK_FORMATS)[]) {
dropdown.addOption(key, TASK_FORMATS[key].displayName);
}
dropdown.setValue(getSettings().taskFormat).onChange(async (value) => {
updateSettings({ taskFormat: value as keyof TASK_FORMATS });
await this.plugin.saveSettings();
});
});
// ---------------------------------------------------------------------------
containerEl.createEl('h4', { text: 'Global filter Settings' });
// ---------------------------------------------------------------------------
new Setting(containerEl)
.setName('Global task filter')
.setDesc(
SettingsTab.createFragmentWithHTML(
'<p><b>Recommended: Leave empty if you want all checklist items in your vault to be tasks managed by this plugin.</b></p>' +
'<p>Use a global filter if you want Tasks to only act on a subset of your "<code>- [ ]</code>" checklist items, so that ' +
'a checklist item must include the specified string in its description in order to be considered a task.<p>' +
'<p>For example, if you set the global filter to <code>#task</code>, the Tasks plugin will only handle checklist items tagged with <code>#task</code>.</br>' +
'Other checklist items will remain normal checklist items and not appear in queries or get a done date set.</p>' +
'<p>See the <a href="https://publish.obsidian.md/tasks/Getting+Started/Global+Filter">documentation</a>.</p>',
),
)
.addText((text) => {
// I wanted to make this say 'for example, #task or TODO'
// but wasn't able to figure out how to make the text box
// wide enough for the whole string to be visible.
text.setPlaceholder('e.g. #task or TODO')
.setValue(GlobalFilter.get())
.onChange(async (value) => {
GlobalFilter.set(value);
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('"Tasks: Toggle task done" command inserts global task filter')
.setDesc(
SettingsTab.createFragmentWithHTML(
'Enabling this causes "Tasks: Toggle task done" command to insert the global task filter when creating a new checkbox',
),
)
.addToggle((toggle) => {
const settings = getSettings();
toggle.setValue(settings.autoInsertGlobalFilter).onChange(async (value) => {
updateSettings({ autoInsertGlobalFilter: value });
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Remove global filter from description')
.setDesc(
'Enabling this removes the string that you set as global filter from the task description when displaying a task.',
)
.addToggle((toggle) => {
const settings = getSettings();
toggle.setValue(settings.removeGlobalFilter).onChange(async (value) => {
updateSettings({ removeGlobalFilter: value });
await this.plugin.saveSettings();
});
});
// ---------------------------------------------------------------------------
containerEl.createEl('h4', { text: 'Global Query' });
// ---------------------------------------------------------------------------
makeMultilineTextSetting(
new Setting(containerEl)
.setDesc(
SettingsTab.createFragmentWithHTML(
'<p>A query that is automatically included at the start of every Tasks block in the vault.' +
' Useful for adding default filters, or layout options.</p>' +
'<p>See the <a href="https://publish.obsidian.md/tasks/Queries/Global+Query">documentation</a>.</p>',
),
)
.addTextArea((text) => {
const settings = getSettings();
text.inputEl.rows = 4;
text.setPlaceholder('# For example...\npath does not include _templates/\nlimit 300\nshow urgency')
.setValue(settings.globalQuery)
.onChange(async (value) => {
updateSettings({ globalQuery: value });
await this.plugin.saveSettings();
});
}),
);
// ---------------------------------------------------------------------------
containerEl.createEl('h4', { text: 'Task Statuses' });
// ---------------------------------------------------------------------------
const { headingOpened } = getSettings();
settingsJson.forEach((heading) => {
this.addOneSettingsBlock(containerEl, heading, headingOpened);
});
// ---------------------------------------------------------------------------
containerEl.createEl('h4', { text: 'Date Settings' });
// ---------------------------------------------------------------------------
new Setting(containerEl)
.setName('Set created date on every added task')
.setDesc(
SettingsTab.createFragmentWithHTML(
"Enabling this will add a timestamp ➕ YYYY-MM-DD before other date values, when a task is created with 'Create or edit task', or by completing a recurring task.</br>" +
'<p>See the <a href="https://publish.obsidian.md/tasks/Getting+Started/Dates#Created+date">documentation</a>.</p>',
),
)
.addToggle((toggle) => {
const settings = getSettings();
toggle.setValue(settings.setCreatedDate).onChange(async (value) => {
updateSettings({ setCreatedDate: value });
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Set done date on every completed task')
.setDesc(
SettingsTab.createFragmentWithHTML(
'Enabling this will add a timestamp ✅ YYYY-MM-DD at the end when a task is toggled to done.</br>' +
'<p>See the <a href="https://publish.obsidian.md/tasks/Getting+Started/Dates#Done+date">documentation</a>.</p>',
),
)
.addToggle((toggle) => {
const settings = getSettings();
toggle.setValue(settings.setDoneDate).onChange(async (value) => {
updateSettings({ setDoneDate: value });
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Use filename as Scheduled date for undated tasks')
.setDesc(
SettingsTab.createFragmentWithHTML(
'Save time entering Scheduled (⏳) dates.</br>' +
'If this option is enabled, any undated tasks will be given a default Scheduled date extracted from their file name.</br>' +
'The date in the file name must be in one of <code>YYYY-MM-DD</code> or <code>YYYYMMDD</code> formats.</br>' +
'Undated tasks have none of Due (📅 ), Scheduled (⏳) and Start (🛫) dates.</br>' +
'<p>See the <a href="https://publish.obsidian.md/tasks/Getting+Started/Use+Filename+as+Default+Date">documentation</a>.</p>',
),
)
.addToggle((toggle) => {
const settings = getSettings();
toggle.setValue(settings.useFilenameAsScheduledDate).onChange(async (value) => {
updateSettings({ useFilenameAsScheduledDate: value });
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Folders with default Scheduled dates')
.setDesc(
'Leave empty if you want to use default Scheduled dates everywhere, or enter a comma-separated list of folders.',
)
.addText(async (input) => {
const settings = getSettings();
await this.plugin.saveSettings();
input
.setValue(SettingsTab.renderFolderArray(settings.filenameAsDateFolders))
.onChange(async (value) => {
const folders = SettingsTab.parseCommaSeparatedFolders(value);
updateSettings({ filenameAsDateFolders: folders });
await this.plugin.saveSettings();
});
});
// ---------------------------------------------------------------------------
containerEl.createEl('h4', { text: 'Recurring task Settings' });
// ---------------------------------------------------------------------------
new Setting(containerEl)
.setName('Next recurrence appears on the line below')
.setDesc(
SettingsTab.createFragmentWithHTML(
'Enabling this will make the next recurrence of a task appear on the line below the completed task. Otherwise the next recurrence will appear before the completed one.</br>' +
'<p>See the <a href="https://publish.obsidian.md/tasks/Getting+Started/Recurring+Tasks">documentation</a>.</p>',
),
)
.addToggle((toggle) => {
const { recurrenceOnNextLine: recurrenceOnNextLine } = getSettings();
toggle.setValue(recurrenceOnNextLine).onChange(async (value) => {
updateSettings({ recurrenceOnNextLine: value });
await this.plugin.saveSettings();
});
});
// ---------------------------------------------------------------------------
containerEl.createEl('h4', { text: 'Auto-suggest Settings' });
// ---------------------------------------------------------------------------
new Setting(containerEl)
.setName('Auto-suggest task content')
.setDesc(
SettingsTab.createFragmentWithHTML(
'Enabling this will open an intelligent suggest menu while typing inside a recognized task line.</br>' +
'<p>See the <a href="https://publish.obsidian.md/tasks/Getting+Started/Auto-Suggest">documentation</a>.</p>',
),
)
.addToggle((toggle) => {
const settings = getSettings();
toggle.setValue(settings.autoSuggestInEditor).onChange(async (value) => {
updateSettings({ autoSuggestInEditor: value });
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Minimum match length for auto-suggest')
.setDesc(
'If higher than 0, auto-suggest will be triggered only when the beginning of any supported keywords is recognized.',
)
.addSlider((slider) => {
const settings = getSettings();
slider
.setLimits(0, 3, 1)
.setValue(settings.autoSuggestMinMatch)
.setDynamicTooltip()
.onChange(async (value) => {
updateSettings({ autoSuggestMinMatch: value });
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Maximum number of auto-suggestions to show')
.setDesc(
'How many suggestions should be shown when an auto-suggest menu pops up (including the "⏎" option).',
)
.addSlider((slider) => {
const settings = getSettings();
slider
.setLimits(3, 12, 1)
.setValue(settings.autoSuggestMaxItems)
.setDynamicTooltip()
.onChange(async (value) => {
updateSettings({ autoSuggestMaxItems: value });
await this.plugin.saveSettings();
});
});
// ---------------------------------------------------------------------------
containerEl.createEl('h4', { text: 'Dialog Settings' });
// ---------------------------------------------------------------------------
new Setting(containerEl)
.setName('Provide access keys in dialogs')
.setDesc(
SettingsTab.createFragmentWithHTML(
'If the access keys (keyboard shortcuts) for various controls' +
' in dialog boxes conflict with system keyboard shortcuts' +
' or assistive technology functionality that is important for you,' +
' you may want to deactivate them here.</br>' +
'<p>See the <a href="https://publish.obsidian.md/tasks/Getting+Started/Create+or+edit+Task#Keyboard+shortcuts">documentation</a>.</p>',
),
)
.addToggle((toggle) => {
const settings = getSettings();
toggle.setValue(settings.provideAccessKeys).onChange(async (value) => {
updateSettings({ provideAccessKeys: value });
await this.plugin.saveSettings();
});
});
}
private addOneSettingsBlock(containerEl: HTMLElement, heading: any, headingOpened: HeadingState) {
const detailsContainer = containerEl.createEl('details', {
cls: 'tasks-nested-settings',
attr: {
...(heading.open || headingOpened[heading.text] ? { open: true } : {}),
},
});
detailsContainer.empty();
detailsContainer.ontoggle = () => {
headingOpened[heading.text] = detailsContainer.open;
updateSettings({ headingOpened: headingOpened });
this.plugin.saveSettings();
};
const summary = detailsContainer.createEl('summary');
new Setting(summary).setHeading().setName(heading.text);
summary.createDiv('collapser').createDiv('handle');
// detailsContainer.createEl(heading.level as keyof HTMLElementTagNameMap, { text: heading.text });
if (heading.notice !== null) {
const notice = detailsContainer.createEl('div', {
cls: heading.notice.class,
text: heading.notice.text,
});
if (heading.notice.html !== null) {
notice.insertAdjacentHTML('beforeend', heading.notice.html);
}
}
// This will process all the settings from settingsConfiguration.json and render
// them out reducing the duplication of the code in this file. This will become
// more important as features are being added over time.
heading.settings.forEach((setting: any) => {
if (setting.featureFlag !== '' && !isFeatureEnabled(setting.featureFlag)) {
// The settings configuration has a featureFlag set and the user has not
// enabled it. Skip adding the settings option.
return;
}
if (setting.type === 'checkbox') {
new Setting(detailsContainer)
.setName(setting.name)
.setDesc(setting.description)
.addToggle((toggle) => {
const settings = getSettings();
if (!settings.generalSettings[setting.settingName]) {
updateGeneralSetting(setting.settingName, setting.initialValue);
}
toggle
.setValue(<boolean>settings.generalSettings[setting.settingName])
.onChange(async (value) => {
updateGeneralSetting(setting.settingName, value);
await this.plugin.saveSettings();
});
});
} else if (setting.type === 'text') {
new Setting(detailsContainer)
.setName(setting.name)
.setDesc(setting.description)
.addText((text) => {
const settings = getSettings();
if (!settings.generalSettings[setting.settingName]) {
updateGeneralSetting(setting.settingName, setting.initialValue);
}
const onChange = async (value: string) => {
updateGeneralSetting(setting.settingName, value);
await this.plugin.saveSettings();
};
text.setPlaceholder(setting.placeholder.toString())
.setValue(settings.generalSettings[setting.settingName].toString())
.onChange(debounce(onChange, 500, true));
});
} else if (setting.type === 'textarea') {
new Setting(detailsContainer)
.setName(setting.name)
.setDesc(setting.description)
.addTextArea((text) => {
const settings = getSettings();
if (!settings.generalSettings[setting.settingName]) {
updateGeneralSetting(setting.settingName, setting.initialValue);
}
const onChange = async (value: string) => {
updateGeneralSetting(setting.settingName, value);
await this.plugin.saveSettings();
};
text.setPlaceholder(setting.placeholder.toString())
.setValue(settings.generalSettings[setting.settingName].toString())
.onChange(debounce(onChange, 500, true));
text.inputEl.rows = 8;
text.inputEl.cols = 40;
});
} else if (setting.type === 'function') {
this.customFunctions[setting.settingName](detailsContainer, this);
}
if (setting.notice !== null) {
const notice = detailsContainer.createEl('p', {
cls: setting.notice.class,
text: setting.notice.text,
});
if (setting.notice.html !== null) {
notice.insertAdjacentHTML('beforeend', setting.notice.html);
}
}
});
}
private static parseCommaSeparatedFolders(input: string): string[] {
return (
input
// a limitation is that folder names may not contain commas
.split(',')
.map((folder) => folder.trim())
// remove leading and trailing slashes
.map((folder) => folder.replace(/^\/|\/$/g, ''))
.filter((folder) => folder !== '')
);
}
private static renderFolderArray(folders: string[]): string {
return folders.join(',');
}
/**
* Settings for Core Task Status
* These are built-in statuses that can have minimal edits made,
* but are not allowed to be deleted or added to.
*
* @param {HTMLElement} containerEl
* @param {SettingsTab} settings
* @memberof SettingsTab
*/
insertTaskCoreStatusSettings(containerEl: HTMLElement, settings: SettingsTab) {
const { statusSettings } = getSettings();
/* -------------------- One row per core status in the settings -------------------- */
statusSettings.coreStatuses.forEach((status_type) => {
createRowForTaskStatus(
containerEl,
status_type,
statusSettings.coreStatuses,
statusSettings,
settings,
settings.plugin,
true, // isCoreStatus
);
});
}
/**
* Settings for Custom Task Status
*
* @param {HTMLElement} containerEl
* @param {SettingsTab} settings
* @memberof SettingsTab
*/
insertCustomTaskStatusSettings(containerEl: HTMLElement, settings: SettingsTab) {
const { statusSettings } = getSettings();
/* -------------------- One row per custom status in the settings -------------------- */
statusSettings.customStatuses.forEach((status_type) => {
createRowForTaskStatus(
containerEl,
status_type,
statusSettings.customStatuses,
statusSettings,
settings,
settings.plugin,
false, // isCoreStatus
);
});
containerEl.createEl('div');
/* -------------------- 'Add New Task Status' button -------------------- */
const setting = new Setting(containerEl).addButton((button) => {
button
.setButtonText('Add New Task Status')
.setCta()
.onClick(async () => {
StatusSettings.addStatus(
statusSettings.customStatuses,
new StatusConfiguration('', '', '', false, StatusType.TODO),
);
await updateAndSaveStatusSettings(statusSettings, settings);
});
});
setting.infoEl.remove();
/* -------------------- Add all Status types supported by ... buttons -------------------- */
type NamedTheme = [string, StatusCollection];
const themes: NamedTheme[] = [
// Light and Dark themes - alphabetical order
['AnuPpuccin Theme', Themes.anuppuccinSupportedStatuses()],
['Aura Theme', Themes.auraSupportedStatuses()],
['Ebullientworks Theme', Themes.ebullientworksSupportedStatuses()],
['ITS Theme & SlRvb Checkboxes', Themes.itsSupportedStatuses()],
['Minimal Theme', Themes.minimalSupportedStatuses()],
['Things Theme', Themes.thingsSupportedStatuses()],
// Dark only themes - alphabetical order
['LYT Mode Theme (Dark mode only)', Themes.lytModeSupportedStatuses()],
];
for (const [name, collection] of themes) {
const addStatusesSupportedByThisTheme = new Setting(containerEl).addButton((button) => {
const label = `${name}: Add ${collection.length} supported Statuses`;
button.setButtonText(label).onClick(async () => {
await addCustomStatesToSettings(collection, statusSettings, settings);
});
});
addStatusesSupportedByThisTheme.infoEl.remove();
}
/* -------------------- 'Add All Unknown Status Types' button -------------------- */
const addAllUnknownStatuses = new Setting(containerEl).addButton((button) => {
button
.setButtonText('Add All Unknown Status Types')
.setCta()
.onClick(async () => {
const tasks = this.plugin.getTasks();
const allStatuses = tasks!.map((task) => {
return task.status;
});
const unknownStatuses = StatusRegistry.getInstance().findUnknownStatuses(allStatuses);
if (unknownStatuses.length === 0) {
return;
}
unknownStatuses.forEach((s) => {
StatusSettings.addStatus(statusSettings.customStatuses, s);
});
await updateAndSaveStatusSettings(statusSettings, settings);
});
});
addAllUnknownStatuses.infoEl.remove();
/* -------------------- 'Reset Custom Status Types to Defaults' button -------------------- */
const clearCustomStatuses = new Setting(containerEl).addButton((button) => {
button
.setButtonText('Reset Custom Status Types to Defaults')
.setWarning()
.onClick(async () => {
StatusSettings.resetAllCustomStatuses(statusSettings);
await updateAndSaveStatusSettings(statusSettings, settings);
});
});
clearCustomStatuses.infoEl.remove();
}
}
/**
* Create the row to see and modify settings for a single task status type.
* @param containerEl
* @param statusType - The status type to be edited.
* @param statuses - The list of statuses that statusType is stored in.
* @param statusSettings - All the status types already in the user's settings, EXCEPT the standard ones.
* @param settings
* @param plugin
* @param isCoreStatus - whether the status is a core status
*/
function createRowForTaskStatus(
containerEl: HTMLElement,
statusType: StatusConfiguration,
statuses: StatusConfiguration[],
statusSettings: StatusSettings,
settings: SettingsTab,
plugin: TasksPlugin,
isCoreStatus: boolean,
) {
//const taskStatusDiv = containerEl.createEl('div');
const taskStatusPreview = containerEl.createEl('pre');
taskStatusPreview.addClass('row-for-status');
taskStatusPreview.textContent = new Status(statusType).previewText();
const setting = new Setting(containerEl);
setting.infoEl.replaceWith(taskStatusPreview);
if (!isCoreStatus) {
setting.addExtraButton((extra) => {
extra
.setIcon('cross')
.setTooltip('Delete')
.onClick(async () => {
if (StatusSettings.deleteStatus(statuses, statusType)) {
await updateAndSaveStatusSettings(statusSettings, settings);
}
});
});
}
setting.addExtraButton((extra) => {
extra
.setIcon('pencil')
.setTooltip('Edit')
.onClick(async () => {
const modal = new CustomStatusModal(plugin, statusType, isCoreStatus);
modal.onClose = async () => {
if (modal.saved) {
if (StatusSettings.replaceStatus(statuses, statusType, modal.statusConfiguration())) {
await updateAndSaveStatusSettings(statusSettings, settings);
}
}
};
modal.open();
});
});
setting.infoEl.remove();
}
async function addCustomStatesToSettings(
supportedStatuses: StatusCollection,
statusSettings: StatusSettings,
settings: SettingsTab,
) {
const notices = StatusSettings.bulkAddStatusCollection(statusSettings, supportedStatuses);
notices.forEach((notice) => {
new Notice(notice);
});
await updateAndSaveStatusSettings(statusSettings, settings);
}
async function updateAndSaveStatusSettings(statusTypes: StatusSettings, settings: SettingsTab) {
updateSettings({
statusSettings: statusTypes,
});
// Update the active statuses.
// This saves the user from having to restart Obsidian in order to apply the changed status(es).
StatusSettings.applyToStatusRegistry(statusTypes, StatusRegistry.getInstance());
await settings.saveSettings(true);
}
function makeMultilineTextSetting(setting: Setting) {
const { settingEl, infoEl, controlEl } = setting;
const textEl: HTMLElement | null = controlEl.querySelector('textarea');
console.log({ settingEl, infoEl, controlEl, textEl });
// Not a setting with a text field
if (textEl === null) {
return;
}
settingEl.style.display = 'block';
infoEl.style.marginRight = '0px';
textEl.style.minWidth = '-webkit-fill-available';
}