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

119 lines
4.3 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(
2021-07-08 20:20:38 +00:00
"Reload Required for change to take effect. Turn on to start collecting daily statistics of your writing. Stored in the .vault-stats file in the root of your vault. This is required for counts of the day."
2021-07-07 12:34:39 +00:00
)
.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 17:29:16 +00:00
new Setting(containerEl)
2021-07-08 20:20:38 +00:00
.setName("Don't Count Comments")
.setDesc("Turn on if you don't want markdown comments to be counted.")
2021-07-07 17:29:16 +00:00
.addToggle((cb: ToggleComponent) => {
cb.setValue(this.plugin.settings.countComments);
cb.onChange(async (value: boolean) => {
this.plugin.settings.countComments = 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);
2021-07-08 20:20:38 +00:00
cb.onChange((value: string) => {
let newPreset = PRESETS.find((preset) => preset.name === "custom");
this.plugin.settings.preset = newPreset;
this.plugin.settings.statusBarQuery = value;
this.plugin.saveSettings();
});
2021-07-07 12:34:39 +00:00
});
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) => {
2021-07-08 20:20:38 +00:00
let newPreset = PRESETS.find((preset) => preset.name === "custom");
this.plugin.settings.preset = newPreset;
2021-07-07 17:00:11 +00:00
this.plugin.settings.statusBarAltQuery = value;
this.plugin.saveSettings();
});
2021-07-07 12:34:39 +00:00
});
2021-07-08 20:42:07 +00:00
this.containerEl.createEl("p", {
text:
"Syntax for the status bars works like this: \n" +
"- To get a stat input the name of the stat in between `{}` eg. `{word_count}`.\n" +
"- All other words remain.\n\n" +
"Available Stats:\n" +
"- word_count\n" +
"- character_count\n" +
"- sentence_count\n" +
"- total_word_count\n" +
"- total_character_count\n" +
"- total_sentence_count\n" +
"- file_count\n" +
"- words_today\n" +
"- characters_today\n" +
"- sentences_today\n",
});
}
}