-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tsx
150 lines (119 loc) · 3.84 KB
/
main.tsx
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import {Plugin, WorkspaceLeaf} from 'obsidian';
import SmartGanttSibeBarView from "@/sidebar/SmartGanttSibeBarView";
import {Helper} from "@/lib/Helper";
import SettingManager, {SmartGanttSettings} from "./src/SettingManager";
import GanttBlockManager from "./src/GanttBlockManager";
import {ViewMode} from "gantt-task-react";
import './src/lib/codemirror';
import './src/mode/gantt/gantt'
import './src/mode/gantt/gantt-list'
const DEFAULT_SETTINGS: SmartGanttSettings = {
pathListFilter: ["AllFiles"],
todoShowQ: true,
doneShowQ: true,
leftBarChartDisplayQ: true,
viewMode: ViewMode.Day
}
export default class SmartGanttPlugin extends Plugin {
settingManager = new SettingManager(this, DEFAULT_SETTINGS);
public helper = new Helper(this)
ganttBlockManager = new GanttBlockManager(this)
modesToKeep = ["hypermd", "markdown", "null", "xml"];
refreshLeaves = () => {
// re-set the editor mode to refresh the syntax highlighting
//@ts-ignore
this.app.workspace.iterateCodeMirrors(cm => cm.setOption("mode", cm.getOption("mode")))
}
darkModeAdapt = () => {
if (document.body.hasClass("theme-dark")) {
document.body.addClass("dark")
} else {
document.body.removeClass("dark")
}
}
override async onload() {
this.darkModeAdapt()
await this.settingManager.loadSettings()
this.app.workspace.onLayoutReady(() => {
this.refreshLeaves()
})
// console.log(this.settingManager.settings)
this.addCommand({
id: 'smart-gantt-reload',
name: 'Reload',
callback: () => {
this.helper.reloadView()
}
})
this.registerView("smart-gantt", (leaf) => {
return new SmartGanttSibeBarView(leaf, this);
})
this.addRibbonIcon('egg', 'Smart Gantt', () => {
let leafs = this.app.workspace.getLeavesOfType("smart-gantt");
if (leafs.length > 0) {
// this.app.workspace.detachLeavesOfType("smart-gantt")
let leaf = leafs[0];
// console.log(leaf.getEphemeralState())
if (this.app.workspace.rightSplit.collapsed) {
this.app.workspace.revealLeaf(leaf)
} else {
this.app.workspace.rightSplit.collapse()
}
} else {
let leaf = this.app.workspace.getRightLeaf(false);
leaf?.setViewState({
type: "smart-gantt",
active: true
})
if (leaf instanceof WorkspaceLeaf) {
this.app.workspace.revealLeaf(leaf);
}
}
})
// await this.ganttBlockManager.registerGanttBlock()
await this.ganttBlockManager.registerGanttBlockNg()
await this.ganttBlockManager.registerTaskListBlock()
this.registerEvent(this.app.workspace.on('css-change', this.darkModeAdapt))
// This adds a settings tab so the user can configure various aspects of the plugin
// this.addSettingTab(new SampleSettingTab(this.app, this));
}
override async onunload() {
// this.app.workspace.detachLeavesOfType("gantt-chart")
await this.settingManager.saveSettings(this.settingManager.settings)
//@ts-ignore
for (const key in CodeMirror.modes) {
// @ts-ignore
if (CodeMirror.modes.hasOwnProperty(key) && !this.modesToKeep.includes(key)) {
// @ts-ignore
delete CodeMirror.modes[key];
}
this.refreshLeaves()
}
this.app.workspace.off('css-change', this.darkModeAdapt)
}
}
// class SampleSettingTab extends PluginSettingTab {
// plugin: SmartGanttPlugin;
//
// constructor(app: App, plugin: SmartGanttPlugin) {
// 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.settingManager.settings.mySetting)
// .onChange(async (value) => {
// this.plugin.settingManager.settings.mySetting = value;
// await this.plugin.settingManager.saveSettings(this.plugin.settingManager.settings)
// }));
// }
// }