generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.ts
79 lines (67 loc) · 2.84 KB
/
view.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
import { ItemView, WorkspaceLeaf, Setting, Notice, Editor, MarkdownView, MarkdownEditView, IconName } from "obsidian";
export const UUHIMSY_VIEW_TYPE = "uuhimsy-view"
export class UUhimsyView extends ItemView{
constructor(leaf: WorkspaceLeaf) {
super(leaf);
}
getViewType(): string {
return UUHIMSY_VIEW_TYPE;
}
getDisplayText(): string {
return "UUhimsy Tags";
}
getIcon(): IconName {
return "wand-sparkles";
}
async onOpen() {
const container = this.containerEl.children[1];
container.empty();
container.createDiv('Header')
new Setting(container).setName('UUhimsy Tags')
.setHeading()
.setDesc('refresh the view after running a "Get tags" command')
.addButton((button) =>{
button.setButtonText("refresh view")
.onClick(() => {this.addTagButtons(tagsContainer)})
})
const tagsContainer = container.createDiv('tags')
this.addTagButtons(tagsContainer)
}
addTagButtons(container){
container.empty()
const files = this.app.vault.getFolderByPath("_slide_Tags").children;
files.forEach(file => {
let tag = file.basename.split(' - ')
tag[0] = tag[0].toLowerCase()
new Setting(container).setName(file.basename)
.addButton((item) =>{
item.setButtonText("Entrance")
.setCta()
.onClick(() => {
const lastLeaf = this.app.workspace.getMostRecentLeaf()
const lastLeafWorkspace = this.app.workspace.getLeafById(lastLeaf?.id)
this.app.workspace.setActiveLeaf(lastLeafWorkspace,true,true);
lastLeaf?.setEphemeralState(lastLeaf?.getEphemeralState())
this.app.workspace.activeEditor?.editor?.replaceSelection(`<!-- slide data-${tag[0]}-entrance="${tag[1]}" -->
`)
//new Notice(`Inserted tag ${tag[1]}`)
})
})
.addButton( item => {
item.setButtonText("Exit")
.onClick(() => {
const lastLeaf = this.app.workspace.getMostRecentLeaf()
const lastLeafWorkspace = this.app.workspace.getLeafById(lastLeaf?.id)
this.app.workspace.setActiveLeaf(lastLeafWorkspace,true,true);
lastLeaf?.setEphemeralState(lastLeaf?.getEphemeralState())
this.app.workspace.activeEditor?.editor?.replaceSelection(`<!-- slide data-${tag[0]}-exit="${tag[1]}" -->
`)
//new Notice(`Inserted tag ${tag[1]}`)
})
})
});
}
async onClose() {
// Nothing to clean up.
}
}