generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ts
53 lines (43 loc) · 1.45 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
import { MarkdownView, Plugin } from 'obsidian';
import { MultiSelectSettings, DEFAULT_SETTINGS } from "src/settings/settings"
import Query from "src/queries/Query"
import QueryResultModal from "src/queries/queryResultsModal"
import settingTab from "src/settings/settingTab"
export default class MultiSelect extends Plugin {
settings: MultiSelectSettings;
initialQueries: Array<Query> = []
addMultiSelectQueryCommand(query: Query) {
this.addCommand({
id: `multiSelect-${query.name}`,
name: `Multi Select from ${query.name}`,
callback: () => {
const leaf = this.app.workspace.activeLeaf
if (leaf.view instanceof MarkdownView && leaf.view.editor) {
const queryResultModal = new QueryResultModal(this.app, this, query, leaf.view.editor.getCursor(), leaf.view.file)
queryResultModal.open()
}
},
});
}
async onload() {
await this.loadSettings();
this.settings.queries.forEach(savedQuery => {
const query = new Query()
Object.assign(query, savedQuery)
this.initialQueries.push(query)
})
this.addSettingTab(new settingTab(this.app, this));
this.settings.queries.forEach(query => {
this.addMultiSelectQueryCommand(query)
})
}
onunload() {
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
this.settings.queries = this.initialQueries
await this.saveData(this.settings);
}
}