From 968f666d19c51ae2a8405312dc61d68dbb1fc0b1 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 29 Jun 2022 10:35:35 +0800 Subject: [PATCH] :recycle: --- app/src/editor/util.ts | 85 +----------------------- app/src/layout/dock/util.ts | 86 +++++++++++++++++++++++++ app/src/menus/commonMenuItem.ts | 25 ++++--- app/src/protyle/header/Title.ts | 3 +- app/src/protyle/preview/index.ts | 2 +- app/src/protyle/wysiwyg/commonHotkey.ts | 2 +- app/src/protyle/wysiwyg/index.ts | 3 +- 7 files changed, 109 insertions(+), 97 deletions(-) create mode 100644 app/src/layout/dock/util.ts diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index ea2a6235b..62e1e7ca9 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -1,19 +1,16 @@ import {Tab} from "../layout/Tab"; import {Editor} from "./index"; import {Wnd} from "../layout/Wnd"; -import {getDockByType, getInstanceById, getWndByLayout, switchWnd} from "../layout/util"; +import {getDockByType, getInstanceById, getWndByLayout} from "../layout/util"; import {getAllModels} from "../layout/getAll"; import {highlightById, scrollCenter} from "../util/highlightById"; import {getDisplayName, pathPosix} from "../util/pathName"; import {Constants} from "../constants"; -import {Outline} from "../layout/dock/Outline"; import {setEditMode} from "../protyle/util/setEditMode"; import {Files} from "../layout/dock/Files"; import {setPadding} from "../protyle/ui/initUI"; import {fetchPost} from "../util/fetch"; import {showMessage} from "../dialog/message"; -import {Backlinks} from "../layout/dock/Backlinks"; -import {Graph} from "../layout/dock/Graph"; import {focusBlock, focusByRange} from "../protyle/util/selection"; import {onGet} from "../protyle/util/onGet"; /// #if !BROWSER @@ -32,86 +29,6 @@ import {lockFile, setTitle} from "../dialog/processSystem"; import {zoomOut} from "../menus/protyle"; import {confirmDialog} from "../dialog/confirmDialog"; -export const openOutline = (protyle: IProtyle) => { - const outlinePanel = getAllModels().outline.find(item => { - if (item.blockId === protyle.block.rootID && item.type === "local") { - item.parent.parent.removeTab(item.parent.id); - return true; - } - }); - if (outlinePanel) { - return; - } - const newWnd = protyle.model.parent.parent.split("lr"); - const tab = new Tab({ - icon: "iconAlignCenter", - title: protyle.title.editElement.textContent, - callback(tab: Tab) { - tab.addModel(new Outline({ - type: "local", - tab, - blockId: protyle.block.rootID, - })); - } - }); - newWnd.addTab(tab); - newWnd.element.classList.remove("fn__flex-1"); - newWnd.element.style.width = "200px"; - switchWnd(newWnd, protyle.model.parent.parent); -}; - -export const openBacklink = (protyle: IProtyle) => { - const backlink = getAllModels().backlinks.find(item => { - if (item.blockId === protyle.block.id && item.type === "local") { - item.parent.parent.removeTab(item.parent.id); - return true; - } - }); - if (backlink) { - return; - } - const newWnd = protyle.model.parent.parent.split("lr"); - const tab = new Tab({ - icon: "iconLink", - title: protyle.title.editElement.textContent, - callback(tab: Tab) { - tab.addModel(new Backlinks({ - type: "local", - tab, - blockId: protyle.block.id, - rootId: protyle.block.rootID, - })); - } - }); - newWnd.addTab(tab); -}; - -export const openGraph = (protyle: IProtyle) => { - const graph = getAllModels().graph.find(item => { - if (item.blockId === protyle.block.id && item.type === "local") { - item.parent.parent.removeTab(item.parent.id); - return true; - } - }); - if (graph) { - return; - } - const wnd = protyle.model.parent.parent.split("lr"); - const tab = new Tab({ - icon: "iconGraph", - title: protyle.title.editElement.textContent, - callback(tab: Tab) { - tab.addModel(new Graph({ - type: "local", - tab, - blockId: protyle.block.id, - rootId: protyle.block.rootID, - })); - } - }); - wnd.addTab(tab); -}; - export const openFileById = (options: { id: string, position?: string, diff --git a/app/src/layout/dock/util.ts b/app/src/layout/dock/util.ts new file mode 100644 index 000000000..d4646baef --- /dev/null +++ b/app/src/layout/dock/util.ts @@ -0,0 +1,86 @@ +import {getAllModels} from "../getAll"; +import {Tab} from "../Tab"; +import {Backlinks} from "./Backlinks"; +import {Graph} from "./Graph"; +import {Outline} from "./Outline"; +import {switchWnd} from "../util"; + +export const openBacklink = (protyle: IProtyle) => { + const backlink = getAllModels().backlinks.find(item => { + if (item.blockId === protyle.block.id && item.type === "local") { + item.parent.parent.removeTab(item.parent.id); + return true; + } + }); + if (backlink) { + return; + } + const newWnd = protyle.model.parent.parent.split("lr"); + const tab = new Tab({ + icon: "iconLink", + title: protyle.title.editElement.textContent, + callback(tab: Tab) { + tab.addModel(new Backlinks({ + type: "local", + tab, + blockId: protyle.block.id, + rootId: protyle.block.rootID, + })); + } + }); + newWnd.addTab(tab); +}; + +export const openGraph = (protyle: IProtyle) => { + const graph = getAllModels().graph.find(item => { + if (item.blockId === protyle.block.id && item.type === "local") { + item.parent.parent.removeTab(item.parent.id); + return true; + } + }); + if (graph) { + return; + } + const wnd = protyle.model.parent.parent.split("lr"); + const tab = new Tab({ + icon: "iconGraph", + title: protyle.title.editElement.textContent, + callback(tab: Tab) { + tab.addModel(new Graph({ + type: "local", + tab, + blockId: protyle.block.id, + rootId: protyle.block.rootID, + })); + } + }); + wnd.addTab(tab); +}; + +export const openOutline = (protyle: IProtyle) => { + const outlinePanel = getAllModels().outline.find(item => { + if (item.blockId === protyle.block.rootID && item.type === "local") { + item.parent.parent.removeTab(item.parent.id); + return true; + } + }); + if (outlinePanel) { + return; + } + const newWnd = protyle.model.parent.parent.split("lr"); + const tab = new Tab({ + icon: "iconAlignCenter", + title: protyle.title.editElement.textContent, + callback(tab: Tab) { + tab.addModel(new Outline({ + type: "local", + tab, + blockId: protyle.block.rootID, + })); + } + }); + newWnd.addTab(tab); + newWnd.element.classList.remove("fn__flex-1"); + newWnd.element.style.width = "200px"; + switchWnd(newWnd, protyle.model.parent.parent); +}; diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts index 2d76f63e4..5db2449bf 100644 --- a/app/src/menus/commonMenuItem.ts +++ b/app/src/menus/commonMenuItem.ts @@ -752,24 +752,31 @@ export const openMenu = (src: string, onlyMenu = false) => { }); /// #endif } else { + /// #if !BROWSER submenu.push({ label: window.siyuan.languages.useDefault, accelerator: "Click", click: () => { - /// #if !BROWSER shell.openExternal(src).catch((e) => { - console.log("openExternal error:" + e); + showMessage(e); }); - /// #else - if (window.siyuan.config.system.container === "ios") { - window.location.href = src; - } else { - window.open(src); - } - /// #endif } }); + /// #endif } + /// #if BROWSER + submenu.push({ + label: window.siyuan.languages.useBrowserView, + accelerator: "Click", + click: () => { + if (window.siyuan.config.system.container === "ios") { + window.location.href = src; + } else { + window.open(src); + } + } + }); + /// #endif if (onlyMenu) { return submenu; } diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 7021df7a3..dd7265602 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -18,13 +18,14 @@ import {matchHotKey} from "../util/hotKey"; import {updateHotkeyTip, writeText} from "../util/compatibility"; import {setPanelFocus} from "../../layout/util"; import {escapeHtml} from "../../util/escape"; -import {deleteFile, openBacklink, openGraph, openOutline, updatePanelByEditor} from "../../editor/util"; +import {deleteFile, updatePanelByEditor} from "../../editor/util"; import * as dayjs from "dayjs"; import {setTitle} from "../../dialog/processSystem"; import {getNoContainerElement} from "../wysiwyg/getBlock"; import {commonHotkey} from "../wysiwyg/commonHotkey"; import {setPosition} from "../../util/setPosition"; import {code160to32} from "../util/code160to32"; +import {openBacklink, openGraph, openOutline} from "../../layout/dock/util"; export class Title { public element: HTMLElement; diff --git a/app/src/protyle/preview/index.ts b/app/src/protyle/preview/index.ts index 4b90c3143..f0f1d2e9c 100644 --- a/app/src/protyle/preview/index.ts +++ b/app/src/protyle/preview/index.ts @@ -56,7 +56,7 @@ export class Preview { } else { /// #if !BROWSER shell.openExternal(linkAddress).catch((e) => { - console.log("openExternal error:" + e); + showMessage(e); }); /// #else window.open(linkAddress); diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts index e1c268d5b..d4f1a59fe 100644 --- a/app/src/protyle/wysiwyg/commonHotkey.ts +++ b/app/src/protyle/wysiwyg/commonHotkey.ts @@ -1,12 +1,12 @@ import {matchHotKey} from "../util/hotKey"; import {fetchPost} from "../../util/fetch"; import {writeText} from "../util/compatibility"; -import {openBacklink, openGraph, openOutline} from "../../editor/util"; import {focusByOffset, getSelectionOffset} from "../util/selection"; import {fullscreen} from "../breadcrumb/action"; import {addLoading, setPadding} from "../ui/initUI"; import {Constants} from "../../constants"; import {onGet} from "../util/onGet"; +import {openBacklink, openGraph, openOutline} from "../../layout/dock/util"; export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => { const target = event.target as HTMLElement; diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 3285ed9d5..3b047d6ae 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -55,6 +55,7 @@ import {fetchPost} from "../../util/fetch"; import {onGet} from "../util/onGet"; import {setTableAlign} from "../util/table"; import {countBlockWord, countSelectWord} from "../../layout/status"; +import {showMessage} from "../../dialog/message"; export class WYSIWYG { public lastHTMLs: { [key: string]: string } = {}; @@ -1463,7 +1464,7 @@ export class WYSIWYG { } else { /// #if !BROWSER shell.openExternal(linkAddress).catch((e) => { - console.log("openExternal error:" + e); + showMessage(e); }); /// #else if (window.siyuan.config.system.container === "ios") {