2021-07-07 12:34:39 +00:00
|
|
|
import {
|
|
|
|
App,
|
|
|
|
DropdownComponent,
|
|
|
|
PluginSettingTab,
|
|
|
|
Setting,
|
|
|
|
TextAreaComponent,
|
|
|
|
ToggleComponent,
|
|
|
|
} from "obsidian";
|
2021-07-03 19:22:50 +00:00
|
|
|
import type BetterWordCount from "src/main";
|
2021-07-07 12:34:39 +00:00
|
|
|
import { PRESETS, PresetOption } from "../settings/settings";
|
2021-01-19 20:39:10 +00:00
|
|
|
|
|
|
|
export class BetterWordCountSettingsTab extends PluginSettingTab {
|
2021-07-07 12:34:39 +00:00
|
|
|
private disableTextAreas: boolean;
|
|
|
|
|
|
|
|
constructor(app: App, private plugin: BetterWordCount) {
|
2021-07-03 19:22:50 +00:00
|
|
|
super(app, plugin);
|
2021-07-07 12:34:39 +00:00
|
|
|
this.disableTextAreas =
|
|
|
|
this.plugin.settings.preset.name === "custom" ? false : true;
|
2021-07-03 19:22:50 +00:00
|
|
|
}
|
|
|
|
|
2021-01-19 20:39:10 +00:00
|
|
|
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" });
|
2021-01-19 20:39:10 +00:00
|
|
|
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-01-19 20:39:10 +00:00
|
|
|
|
2021-07-07 12:34:39 +00:00
|
|
|
// Status Bar Settings
|
|
|
|
containerEl.createEl("h3", { text: "Status Bar Settings" });
|
2021-01-19 20:39:10 +00:00
|
|
|
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-01-19 20:39:10 +00:00
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
2021-01-19 20:39:10 +00:00
|
|
|
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-01-19 20:39:10 +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-01-19 20:39:10 +00:00
|
|
|
}
|
|
|
|
}
|