better-word-count/src/settings/settings-tab.ts

83 lines
2.8 KiB
TypeScript
Raw Normal View History

2021-07-07 12:34:39 +00:00
import {
App,
DropdownComponent,
PluginSettingTab,
Setting,
TextAreaComponent,
ToggleComponent,
} from "obsidian";
import type BetterWordCount from "src/main";
2021-07-07 12:34:39 +00:00
import { PRESETS, PresetOption } from "../settings/settings";
export class BetterWordCountSettingsTab extends PluginSettingTab {
2021-07-07 12:34:39 +00:00
private disableTextAreas: boolean;
constructor(app: App, private plugin: BetterWordCount) {
super(app, plugin);
2021-07-07 12:34:39 +00:00
this.disableTextAreas =
this.plugin.settings.preset.name === "custom" ? false : true;
}
display(): void {
let { containerEl } = this;
containerEl.empty();
containerEl.createEl("h2", { text: "Better Word Count Settings" });
2021-07-07 12:34:39 +00:00
// General Settings
containerEl.createEl("h3", { text: "General Settings" });
new Setting(containerEl)
2021-07-07 12:34:39 +00:00
.setName("Collect Statistics")
.setDesc(
"Turn on to start collecting daily statistics of your writing. Stored in the .vault-stats file in the root of your vault."
)
.addToggle((cb: ToggleComponent) => {
cb.setValue(this.plugin.settings.collectStats);
cb.onChange(async (value: boolean) => {
this.plugin.settings.collectStats = value;
await this.plugin.saveSettings();
});
});
2021-07-07 12:34:39 +00:00
// Status Bar Settings
containerEl.createEl("h3", { text: "Status Bar Settings" });
new Setting(containerEl)
2021-07-07 12:34:39 +00:00
.setName("Select a Preset")
.setDesc(
"Presets are premade status bar expressions. Overides status bar settings."
)
.addDropdown((cb: DropdownComponent) => {
PRESETS.forEach((preset: PresetOption) => {
cb.addOption(preset.name, preset.name);
});
cb.setValue(this.plugin.settings.preset.name);
2021-07-07 12:34:39 +00:00
cb.onChange(async (value: string) => {
let newPreset = PRESETS.find((preset) => preset.name === value);
this.plugin.settings.preset = newPreset;
this.plugin.settings.statusBarQuery = newPreset.statusBarQuery;
this.plugin.settings.statusBarAltQuery = newPreset.statusBarAltQuery;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
2021-07-07 12:34:39 +00:00
.setName("Status Bar Text")
.setDesc("Customize the Status Bar text with this.")
.addTextArea((cb: TextAreaComponent) => {
cb.setPlaceholder("Enter an expression...");
cb.setValue(this.plugin.settings.statusBarQuery);
});
new Setting(containerEl)
2021-07-07 12:34:39 +00:00
.setName("Alternative Status Bar Text")
.setDesc("Customize the Alternative Status Bar text with this.")
.addTextArea((cb: TextAreaComponent) => {
cb.setPlaceholder("Enter an expression...");
cb.setValue(this.plugin.settings.statusBarAltQuery);
2021-07-07 17:00:11 +00:00
cb.onChange((value: string) => {
this.plugin.settings.statusBarAltQuery = value;
this.plugin.saveSettings();
});
2021-07-07 12:34:39 +00:00
});
}
}