diff --git a/README.md b/README.md index 72530f3..1d549d2 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ If you are using Microsoft Office 365 to create xlsx files, you need to import t ### embed link to markdown +embed link rule: + +> ![[`file-folder`/`file-name`#`sheet-name`|`sri`-`sci`:`eri`-`eci`<`sheet-height`>]] + + + ![link](./doc/img/link.gif) ![link](./doc/img/part-link.gif) @@ -21,6 +27,10 @@ If you are using Microsoft Office 365 to create xlsx files, you need to import t ![html](./doc/img/html.gif) +### Setting + +![setting](./doc//img/setting.png) + ### E-mail - ljcoder@163.com diff --git a/doc/img/setting.png b/doc/img/setting.png new file mode 100644 index 0000000..b66c114 Binary files /dev/null and b/doc/img/setting.png differ diff --git a/src/main.ts b/src/main.ts index 36865a2..35dff90 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,7 +8,6 @@ import { Workspace, MenuItem, Menu, - MetadataCache } from "obsidian"; import { ExcelSettings, DEFAULT_SETTINGS } from "./utils/Settings"; import { PaneTarget } from "./utils/ModifierkeyHelper"; @@ -182,6 +181,56 @@ export default class ExcelPlugin extends Plugin { ); } + this.registerEvent( + this.app.workspace.on("editor-menu", (menu, editor, view) => { + if (!view || !(view instanceof MarkdownView)) return; + const file = view.file; + const leaf = view.leaf; + if (!file) return; + const cache = this.app.metadataCache.getFileCache(file); + console.log('---', cache) + if (!cache?.frontmatter || !cache?.frontmatter?.FRONTMATTER_KEY) + return; + + menu.addItem((item) => + item + .setTitle("OPEN_AS_EXCEL") + .setIcon("grid") + .setSection("excel") + .onClick(() => { + //@ts-ignore + this.excelFileModes[leaf.id || file.path] = + VIEW_TYPE_EXCEL; + this.setExcelView(leaf); + }) + ); + }) + ); + + this.registerEvent( + this.app.workspace.on("file-menu", (menu, file, source, leaf) => { + if (!leaf || !(leaf.view instanceof MarkdownView)) return; + if (!(file instanceof TFile)) return; + const cache = this.app.metadataCache.getFileCache(file); + if (!cache?.frontmatter || !cache?.frontmatter?.FRONTMATTER_KEY) + return; + + menu.addItem((item) => { + item.setTitle("OPEN_AS_EXCEL") + .setIcon("grid") + .setSection("pane") + .onClick(() => { + //@ts-ignore + this.excelFileModes[leaf.id || file.path] = + VIEW_TYPE_EXCEL; + this.setExcelView(leaf); + }); + }); + //@ts-ignore + menu.items.unshift(menu.items.pop()); + }) + ); + const self = this; // Monkey patch WorkspaceLeaf to open Excalidraw drawings with ExcalidrawView by default this.register( @@ -216,7 +265,7 @@ export default class ExcelPlugin extends Plugin { "markdown" ) { // Then check for the excalidraw frontMatterKey - const cache = this.app.metadataCache.getFileCache( + const cache = this.app.metadataCache.getCache( state.state.file ); @@ -323,7 +372,7 @@ export default class ExcelPlugin extends Plugin { } const fileCache = f ? this.app.metadataCache.getFileCache(f) : null; return ( - !!fileCache?.frontmatter && !!fileCache?.frontmatter?.FRONTMATTER_KEY + !!fileCache?.frontmatter && !!fileCache?.frontmatter[FRONTMATTER_KEY] ); } }