Skip to content

Commit

Permalink
🎨 fix #9383
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Oct 11, 2023
1 parent 37f950b commit 23c3f9f
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 81 deletions.
4 changes: 3 additions & 1 deletion app/src/layout/dock/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,9 @@ export class Graph extends Model {
if (id) {
this.blockId = id;
}
if (!isCurrentEditor(this.blockId)) {
if (!isCurrentEditor(this.blockId) &&
this.graphElement.firstElementChild.classList.contains("fn__none") // 引用右键打开关系图
) {
return;
}
this.graphData = response.data;
Expand Down
119 changes: 90 additions & 29 deletions app/src/layout/dock/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,112 @@ import {getAllModels} from "../getAll";
import {Tab} from "../Tab";
import {Graph} from "./Graph";
import {Outline} from "./Outline";
import {resizeTabs, switchWnd} from "../util";
import {getInstanceById, getWndByLayout, resizeTabs, switchWnd} from "../util";
import {Backlink} from "./Backlink";
import {App} from "../../index";
import {Wnd} from "../Wnd";
import {fetchSyncPost} from "../../util/fetch";

export const openBacklink = (protyle: IProtyle) => {
export const openBacklink = async (options: {
app: App,
blockId: string,
rootId?: string,
title?: string,
useBlockId?: boolean,
}) => {
const backlink = getAllModels().backlink.find(item => {
if (item.blockId === protyle.block.id && item.type === "local") {
if (item.blockId === options.blockId && 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({
let wnd: Wnd = undefined;
const element = document.querySelector(".layout__wnd--active");
if (element) {
wnd = getInstanceById(element.getAttribute("data-id")) as Wnd;
}
if (!wnd) {
wnd = getWndByLayout(window.siyuan.layout.centerLayout);
}
const newWnd = wnd.split("lr");
if (!options.rootId) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
options.rootId = response.data.rootID
options.useBlockId = response.data.rootID !== response.data.id
options.title = response.data.name || "Untitled"
} else if (!options.title) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
options.title = response.data.name || "Untitled"
}
newWnd.addTab(new Tab({
icon: "iconLink",
title: protyle.title.editElement.textContent || "Untitled",
title: options.title,
callback(tab: Tab) {
tab.addModel(new Backlink({
app: protyle.app,
app: options.app,
type: "local",
tab,
// 通过搜索打开的包含上下文,但不是缩放,因此需要传 rootID https://ld246.com/article/1666786639708
blockId: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
rootId: protyle.block.rootID,
blockId: options.useBlockId ? options.blockId : options.rootId,
rootId: options.rootId,
}));
}
});
newWnd.addTab(tab);
}));
};

export const openGraph = (protyle: IProtyle) => {
export const openGraph = async (options: {
app: App,
blockId: string,
rootId?: string,
title?: string,
useBlockId?: boolean,
}) => {
const graph = getAllModels().graph.find(item => {
if (item.blockId === protyle.block.id && item.type === "local") {
if (item.blockId === options.blockId && 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({
let wnd: Wnd = undefined;
const element = document.querySelector(".layout__wnd--active");
if (element) {
wnd = getInstanceById(element.getAttribute("data-id")) as Wnd;
}
if (!wnd) {
wnd = getWndByLayout(window.siyuan.layout.centerLayout);
}
const newWnd = wnd.split("lr");
if (!options.rootId) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
options.rootId = response.data.rootID
options.useBlockId = response.data.rootID !== response.data.id
options.title = response.data.name || "Untitled"
} else if (!options.title) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
options.title = response.data.name || "Untitled"
}
newWnd.addTab(new Tab({
icon: "iconGraph",
title: protyle.title.editElement.textContent || "Untitled",
title: options.title,
callback(tab: Tab) {
tab.addModel(new Graph({
app: protyle.app,
app: options.app,
type: "local",
tab,
blockId: protyle.block.id,
rootId: protyle.block.rootID,
blockId: options.blockId,
rootId: options.rootId,
}));
}
});
wnd.addTab(tab);
}));
};

export const openOutline = (protyle: IProtyle) => {
export const openOutline = async (protyle: IProtyle) => {
const outlinePanel = getAllModels().outline.find(item => {
if (item.blockId === protyle.block.rootID && item.type === "local") {
item.parent.parent.removeTab(item.parent.id);
Expand All @@ -70,10 +117,25 @@ export const openOutline = (protyle: IProtyle) => {
if (outlinePanel) {
return;
}
const newWnd = protyle.model.parent.parent.split("lr");
const tab = new Tab({
let wnd: Wnd = undefined;
const element = document.querySelector(".layout__wnd--active");
if (element) {
wnd = getInstanceById(element.getAttribute("data-id")) as Wnd;
}
if (!wnd) {
wnd = getWndByLayout(window.siyuan.layout.centerLayout);
}
const newWnd = wnd.split("lr");
let title = ""
if (!protyle.title) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: protyle.block.rootID});
title = response.data.name || "Untitled"
} else {
title = protyle.title.editElement.textContent || "Untitled"
}
newWnd.addTab(new Tab({
icon: "iconAlignCenter",
title: protyle.title.editElement.textContent || "Untitled",
title,
callback(tab: Tab) {
tab.addModel(new Outline({
app: protyle.app,
Expand All @@ -83,11 +145,10 @@ export const openOutline = (protyle: IProtyle) => {
isPreview: !protyle.preview.element.classList.contains("fn__none")
}));
}
});
newWnd.addTab(tab);
}));
newWnd.element.classList.remove("fn__flex-1");
newWnd.element.style.width = "200px";
switchWnd(newWnd, protyle.model.parent.parent);
switchWnd(newWnd, wnd);
};

export const resetFloatDockSize = () => {
Expand All @@ -102,7 +163,7 @@ export const resetFloatDockSize = () => {
}
};

export const toggleDockBar = (useElement:Element)=> {
export const toggleDockBar = (useElement: Element) => {
const dockIsShow = useElement.getAttribute("xlink:href") === "#iconHideDock";
if (dockIsShow) {
useElement.setAttribute("xlink:href", "#iconDock");
Expand Down
25 changes: 25 additions & 0 deletions app/src/menus/protyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {renameTag} from "../util/noRelyPCFunction";
import {hideElements} from "../protyle/ui/hideElements";
import {emitOpenMenu} from "../plugin/EventBus";
import {openMobileFileById} from "../mobile/editor";
import {openBacklink, openGraph} from "../layout/dock/util";

export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElement) => {
const nodeElement = hasClosestBlock(refElement);
Expand Down Expand Up @@ -255,6 +256,30 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
}
}).element);
/// #endif
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconLink",
label: window.siyuan.languages.backlinks,
accelerator: window.siyuan.config.keymap.editor.general.backlinks.custom,
click: () => {
openBacklink({
app: protyle.app,
blockId: refBlockId,
});
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconGraph",
label: window.siyuan.languages.graphView,
accelerator: window.siyuan.config.keymap.editor.general.graphView.custom,
click: () => {
openGraph({
app: protyle.app,
blockId: refBlockId,
});
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
/// #endif
let submenu: IMenu[] = [];
if (element.getAttribute("data-subtype") === "s") {
Expand Down
71 changes: 43 additions & 28 deletions app/src/protyle/header/openTitleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,43 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
}).element);
}
/// #if !MOBILE
if (protyle.model) {
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconAlignCenter",
label: window.siyuan.languages.outline,
accelerator: window.siyuan.config.keymap.editor.general.outline.custom,
click: () => {
openOutline(protyle);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconLink",
label: window.siyuan.languages.backlinks,
accelerator: window.siyuan.config.keymap.editor.general.backlinks.custom,
click: () => {
openBacklink(protyle);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconGraph",
label: window.siyuan.languages.graphView,
accelerator: window.siyuan.config.keymap.editor.general.graphView.custom,
click: () => {
openGraph(protyle);
}
}).element);
}
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconAlignCenter",
label: window.siyuan.languages.outline,
accelerator: window.siyuan.config.keymap.editor.general.outline.custom,
click: () => {
openOutline(protyle);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconLink",
label: window.siyuan.languages.backlinks,
accelerator: window.siyuan.config.keymap.editor.general.backlinks.custom,
click: () => {
openBacklink({
app: protyle.app,
blockId: protyle.block.id,
rootId: protyle.block.rootID,
useBlockId: protyle.block.showAll,
title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null
});
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconGraph",
label: window.siyuan.languages.graphView,
accelerator: window.siyuan.config.keymap.editor.general.graphView.custom,
click: () => {
openGraph({
app: protyle.app,
blockId: protyle.block.id,
rootId: protyle.block.rootID,
useBlockId: protyle.block.showAll,
title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null
});
}
}).element);
/// #endif
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
Expand Down Expand Up @@ -209,7 +219,12 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
label: window.siyuan.languages.fileHistory,
icon: "iconHistory",
click() {
openDocHistory({app: protyle.app, id: protyle.block.rootID, notebookId: protyle.notebookId, pathString: response.data.name});
openDocHistory({
app: protyle.app,
id: protyle.block.rootID,
notebookId: protyle.notebookId,
pathString: response.data.name
});
}
}).element);
}
Expand Down
Loading

0 comments on commit 23c3f9f

Please sign in to comment.