-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
TagFolderList.ts
103 lines (88 loc) · 2.5 KB
/
TagFolderList.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Menu, type ViewStateResult, WorkspaceLeaf } from "obsidian";
import TagFolderViewComponent from "./TagFolderViewComponent.svelte";
import {
type TagFolderListState,
VIEW_TYPE_TAGFOLDER_LIST
} from "./types";
import TagFolderPlugin from "./main";
import { TagFolderViewBase } from "./TagFolderViewBase";
import { mount, unmount } from "svelte";
import { writable } from "svelte/store";
export class TagFolderList extends TagFolderViewBase {
plugin: TagFolderPlugin;
icon = "stacked-levels";
title: string = "";
onPaneMenu(menu: Menu, source: string): void {
super.onPaneMenu(menu, source);
menu.addItem(item => {
item.setIcon("pin")
.setTitle("Pin")
.onClick(() => {
this.leaf.togglePinned();
})
})
}
getIcon(): string {
return "stacked-levels";
}
state: TagFolderListState = { tags: [], title: "" };
async setState(state: TagFolderListState, result: ViewStateResult): Promise<void> {
this.state = { ...this.state, ...state };
this.title = state.tags.join(",");
this.stateStore.set(this.state);
result = {
history: false
};
return await Promise.resolve();
}
stateStore = writable<TagFolderListState>(this.state);
getState() {
return this.state;
}
constructor(leaf: WorkspaceLeaf, plugin: TagFolderPlugin) {
super(leaf);
this.plugin = plugin;
this.showMenu = this.showMenu.bind(this);
this.showOrder = this.showOrder.bind(this);
this.newNote = this.newNote.bind(this);
this.showLevelSelect = this.showLevelSelect.bind(this);
this.switchView = this.switchView.bind(this);
}
async newNote(evt: MouseEvent) {
await this.plugin.createNewNote(this.state.tags);
}
getViewType() {
return VIEW_TYPE_TAGFOLDER_LIST;
}
getDisplayText() {
return `Files with ${this.state.title}`;
}
async onOpen() {
this.containerEl.empty();
this.component = mount(TagFolderViewComponent, {
target: this.containerEl,
props: {
openFile: this.plugin.focusFile,
hoverPreview: this.plugin.hoverPreview,
title: "",
showMenu: this.showMenu,
showLevelSelect: this.showLevelSelect,
showOrder: this.showOrder,
newNote: this.newNote,
openScrollView: this.plugin.openScrollView,
isViewSwitchable: this.plugin.settings.useMultiPaneList,
switchView: this.switchView,
saveSettings: this.saveSettings.bind(this),
stateStore: this.stateStore,
},
});
return await Promise.resolve();
}
async onClose() {
if (this.component) {
unmount(this.component);
this.component = undefined!;
}
return await Promise.resolve();
}
}