generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
80 lines (62 loc) · 2.08 KB
/
main.ts
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
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { Prec } from "@codemirror/state";
import { editorTooltips, editorTaskTooltip } from "livePreview";
import { ReadingViewTasksBuilder } from "readingView"
import { buildTaskListPickers } from 'dataviewTaskList';
import type { ICheckBoxApi } from 'checkBoxApi';
import { CheckBoxApi } from 'checkBoxApi';
// Remember to rename these classes and interfaces!
interface TaskCompletionSettings {
mySetting: string;
}
const DEFAULT_SETTINGS: TaskCompletionSettings = {
mySetting: 'default'
}
export default class TaskCompletion extends Plugin {
public api: ICheckBoxApi;
settings: TaskCompletionSettings;
dv: any
async onload() {
await this.loadSettings();
this.addSettingTab(new TaskCompletionSettingTab(this.app, this));
this.registerMarkdownPostProcessor((el, ctx) => {
(new ReadingViewTasksBuilder(this.app, el, ctx)).build();
});
this.registerEditorExtension(editorTooltips);
this.registerEditorExtension(editorTaskTooltip);
this.registerEvent(this.app.workspace.on("dataview:refresh-views", () => { console.log("view refresehd"); buildTaskListPickers() }))
this.api = new CheckBoxApi(this).make();
buildTaskListPickers();
console.log("task-completion loaded");
}
onunload() {
console.log("task-completion unloaded");
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}
class TaskCompletionSettingTab extends PluginSettingTab {
plugin: TaskCompletion;
constructor(app: App, plugin: TaskCompletion) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const { containerEl } = this;
containerEl.empty();
new Setting(containerEl)
.setName('Setting #1')
.setDesc('It\'s a secret')
.addText(text => text
.setPlaceholder('Enter your secret')
.setValue(this.plugin.settings.mySetting)
.onChange(async (value) => {
this.plugin.settings.mySetting = value;
await this.plugin.saveSettings();
}));
}
}