Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
77 lines (62 sloc)
2.1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| Plugin, | |
| Vault, | |
| Workspace, | |
| WorkspaceLeaf, | |
| } from 'obsidian'; | |
| import MindmapView from './mindmap-view'; | |
| import { MM_VIEW_TYPE } from './constants'; | |
| import { MindMapSettings } from './settings'; | |
| import { MindMapSettingsTab } from './settings-tab'; | |
| export default class MindMap extends Plugin { | |
| vault: Vault; | |
| workspace: Workspace; | |
| mindmapView: MindmapView; | |
| settings: MindMapSettings; | |
| async onload() { | |
| console.log("Loading Mind Map plugin"); | |
| this.vault = this.app.vault; | |
| this.workspace = this.app.workspace; | |
| this.settings = Object.assign({ | |
| splitDirection: 'Horizontal', | |
| nodeMinHeight: 16, | |
| lineHeight: '1em', | |
| spacingVertical: 5, | |
| spacingHorizontal: 80, | |
| paddingX: 8 | |
| }, await this.loadData()); | |
| this.registerView( | |
| MM_VIEW_TYPE, | |
| (leaf: WorkspaceLeaf) => | |
| (this.mindmapView = new MindmapView(this.settings, leaf, {path:this.activeLeafPath(this.workspace), basename: this.activeLeafName(this.workspace)})) | |
| ); | |
| this.addCommand({ | |
| id: 'app:markmap-preview', | |
| name: 'Preview the current note as a Mind Map', | |
| callback: () => this.markMapPreview(), | |
| hotkeys: [] | |
| }); | |
| this.addSettingTab(new MindMapSettingsTab(this.app, this)); | |
| } | |
| markMapPreview() { | |
| const fileInfo = {path: this.activeLeafPath(this.workspace), basename: this.activeLeafName(this.workspace)}; | |
| this.initPreview(fileInfo); | |
| } | |
| async initPreview(fileInfo: any) { | |
| if (this.app.workspace.getLeavesOfType(MM_VIEW_TYPE).length > 0) { | |
| return; | |
| } | |
| const preview = this.app.workspace.splitActiveLeaf(this.settings.splitDirection); | |
| const mmPreview = new MindmapView(this.settings, preview, fileInfo); | |
| preview.open(mmPreview); | |
| } | |
| onunload() { | |
| console.log("Unloading Mind Map plugin"); | |
| } | |
| activeLeafPath(workspace: Workspace) { | |
| return workspace.activeLeaf?.view.getState().file; | |
| } | |
| activeLeafName(workspace: Workspace) { | |
| return workspace.activeLeaf?.getDisplayText(); | |
| } | |
| } |