From 256331c9484942a4d4b6944aa4df0fd0d83a38bc Mon Sep 17 00:00:00 2001 From: Waiting Date: Sat, 11 Mar 2023 00:24:04 +0800 Subject: [PATCH] =?UTF-8?q?OB=20=E6=8C=89=E9=88=95=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SourceCodeView.ts | 12 +++++++++--- src/main.ts | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/SourceCodeView.ts b/src/SourceCodeView.ts index 3dcfce2..c63649b 100644 --- a/src/SourceCodeView.ts +++ b/src/SourceCodeView.ts @@ -1,9 +1,10 @@ -import {ItemView, View, WorkspaceLeaf} from "obsidian"; +import {ItemView, WorkspaceLeaf} from "obsidian"; import {initGraph} from "./Graph"; import {SOURCE_CODE_VIEW_TYPE} from "./main"; export default class SourceCodeView extends ItemView { + // 代碼塊內容 集合 codeBlocks: string[] constructor(codeBlocks: string[], leaf: WorkspaceLeaf) { @@ -12,7 +13,7 @@ export default class SourceCodeView extends ItemView { } getDisplayText(): string { - return "MySourceCodeView"; + return "Source Code View"; } getViewType(): string { @@ -20,12 +21,17 @@ export default class SourceCodeView extends ItemView { } async onOpen() { + + // 清空 容器內容 const container = this.containerEl.children[1]; container.empty(); + + // 創建 AntV 需要的容器 const div = document.createElement("div") div.id = 'container'; - this.containerEl.children[1].appendChild(div); + container.appendChild(div); + // 初始化 AntV 的 畫布 initGraph(this.codeBlocks); } diff --git a/src/main.ts b/src/main.ts index 697645b..f325a82 100644 --- a/src/main.ts +++ b/src/main.ts @@ -20,7 +20,7 @@ export default class SourceCodeViewPlugin extends Plugin { ); // 註冊 Obsidian 左側的按鈕 - this.addRibbonIcon("dice", "Activate view", () => { + this.addRibbonIcon("file-json", "Show Resource Code View", () => { this.initView() }); }