mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-10 22:23:28 +08:00
This commit is contained in:
parent
d1009f2333
commit
60beaf291d
@ -20,6 +20,7 @@ import {Constants} from "../constants";
|
||||
import {exportImage} from "../protyle/export/util";
|
||||
import {App} from "../index";
|
||||
import {renderAVAttribute} from "../protyle/render/av/blockAttr";
|
||||
import {openAssetNewWindow} from "../window/openNewWindow";
|
||||
|
||||
const bindAttrInput = (inputElement: HTMLInputElement, id: string) => {
|
||||
inputElement.addEventListener("change", () => {
|
||||
@ -679,12 +680,20 @@ export const exportMd = (id: string) => {
|
||||
|
||||
export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerator: boolean) => {
|
||||
const submenu = [];
|
||||
/// #if MOBILE
|
||||
submenu.push({
|
||||
label: window.siyuan.languages.useBrowserView,
|
||||
accelerator: showAccelerator ? "Click" : "",
|
||||
click: () => {
|
||||
openByMobile(src);
|
||||
}
|
||||
});
|
||||
/// #else
|
||||
if (isLocalPath(src)) {
|
||||
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(src)) &&
|
||||
(!src.endsWith(".pdf") ||
|
||||
(src.endsWith(".pdf") && !src.startsWith("file://")))
|
||||
) {
|
||||
/// #if !MOBILE
|
||||
submenu.push({
|
||||
icon: "iconLayoutRight",
|
||||
label: window.siyuan.languages.insertRight,
|
||||
@ -693,26 +702,31 @@ export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerat
|
||||
openAsset(app, src.trim(), parseInt(getSearch("page", src)), "right");
|
||||
}
|
||||
});
|
||||
/// #endif
|
||||
submenu.push({
|
||||
label: window.siyuan.languages.openBy,
|
||||
icon: "iconOpen",
|
||||
accelerator: showAccelerator ? "⌥Click" : "",
|
||||
click() {
|
||||
openAsset(app, src.trim(), parseInt(getSearch("page", src)));
|
||||
}
|
||||
});
|
||||
/// #if !BROWSER
|
||||
submenu.push({
|
||||
label: window.siyuan.languages.useDefault,
|
||||
accelerator: showAccelerator ? "⇧Click" : "",
|
||||
label: window.siyuan.languages.openByNewWindow,
|
||||
icon: "iconOpenWindow",
|
||||
click() {
|
||||
openBy(src, "app");
|
||||
openAssetNewWindow(src.trim());
|
||||
}
|
||||
});
|
||||
/// #endif
|
||||
} else {
|
||||
/// #if !BROWSER
|
||||
submenu.push({
|
||||
label: window.siyuan.languages.useDefault,
|
||||
label: window.siyuan.languages.useBrowserView,
|
||||
accelerator: showAccelerator ? "Click" : "",
|
||||
click() {
|
||||
openBy(src, "app");
|
||||
click: () => {
|
||||
openByMobile(src);
|
||||
}
|
||||
});
|
||||
/// #endif
|
||||
}
|
||||
/// #if !BROWSER
|
||||
submenu.push({
|
||||
@ -723,8 +737,20 @@ export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerat
|
||||
openBy(src, "folder");
|
||||
}
|
||||
});
|
||||
submenu.push({
|
||||
label: window.siyuan.languages.useDefault,
|
||||
accelerator: showAccelerator ? "⇧Click" : "",
|
||||
click() {
|
||||
openBy(src, "app");
|
||||
}
|
||||
});
|
||||
/// #endif
|
||||
} else {
|
||||
} else if (src) {
|
||||
if (0 > src.indexOf(":")) {
|
||||
// 使用 : 判断,不使用 :// 判断 Open external application protocol invalid https://github.com/siyuan-note/siyuan/issues/10075
|
||||
// Support click to open hyperlinks like `www.foo.com` https://github.com/siyuan-note/siyuan/issues/9986
|
||||
src = `https://${src}`;
|
||||
}
|
||||
/// #if !BROWSER
|
||||
submenu.push({
|
||||
label: window.siyuan.languages.useDefault,
|
||||
@ -735,9 +761,7 @@ export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerat
|
||||
});
|
||||
}
|
||||
});
|
||||
/// #endif
|
||||
}
|
||||
/// #if BROWSER
|
||||
/// #else
|
||||
submenu.push({
|
||||
label: window.siyuan.languages.useBrowserView,
|
||||
accelerator: showAccelerator ? "Click" : "",
|
||||
@ -746,6 +770,8 @@ export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerat
|
||||
}
|
||||
});
|
||||
/// #endif
|
||||
}
|
||||
/// #endif
|
||||
if (onlyMenu) {
|
||||
return submenu;
|
||||
}
|
||||
|
@ -2077,7 +2077,7 @@ export class WYSIWYG {
|
||||
return;
|
||||
}
|
||||
|
||||
if (aElement && !event.altKey) {
|
||||
if (aElement) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
let linkAddress = Lute.UnEscapeHTMLStr(aLink);
|
||||
@ -2090,31 +2090,28 @@ export class WYSIWYG {
|
||||
(!linkPathname.endsWith(".pdf") ||
|
||||
(linkPathname.endsWith(".pdf") && !linkAddress.startsWith("file://")))
|
||||
) {
|
||||
if (event.altKey) {
|
||||
openAsset(protyle.app, linkAddress, parseInt(getSearch("page", linkAddress)));
|
||||
} else if (!ctrlIsPressed && !event.shiftKey) {
|
||||
openAsset(protyle.app, linkPathname, parseInt(getSearch("page", linkAddress)), "right");
|
||||
}
|
||||
} else {
|
||||
openByMobile(linkAddress);
|
||||
}
|
||||
/// #if !BROWSER
|
||||
if (ctrlIsPressed) {
|
||||
openBy(linkAddress, "folder");
|
||||
} else if (event.shiftKey) {
|
||||
openBy(linkAddress, "app");
|
||||
} else {
|
||||
openAsset(protyle.app, linkPathname, parseInt(getSearch("page", linkAddress)), "right");
|
||||
}
|
||||
} else {
|
||||
/// #if !BROWSER
|
||||
if (ctrlIsPressed) {
|
||||
openBy(linkAddress, "folder");
|
||||
} else {
|
||||
openBy(linkAddress, "app");
|
||||
}
|
||||
/// #else
|
||||
openByMobile(linkAddress);
|
||||
/// #endif
|
||||
}
|
||||
} else if (linkAddress) {
|
||||
/// #if !BROWSER
|
||||
if (0 > linkAddress.indexOf(":")) {
|
||||
// 使用 : 判断,不使用 :// 判断 Open external application protocol invalid https://github.com/siyuan-note/siyuan/issues/10075
|
||||
// Support click to open hyperlinks like `www.foo.com` https://github.com/siyuan-note/siyuan/issues/9986
|
||||
linkAddress = `https://${linkAddress}`;
|
||||
}
|
||||
/// #if !BROWSER
|
||||
shell.openExternal(linkAddress).catch((e) => {
|
||||
showMessage(e);
|
||||
});
|
||||
|
@ -6,6 +6,8 @@ import {Constants} from "../constants";
|
||||
import {Tab} from "../layout/Tab";
|
||||
import {fetchPost} from "../util/fetch";
|
||||
import {showMessage} from "../dialog/message";
|
||||
import {getDisplayName, pathPosix} from "../util/pathName";
|
||||
import {getSearch} from "../util/functions";
|
||||
|
||||
interface windowOptions {
|
||||
position?: {
|
||||
@ -62,5 +64,39 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => {
|
||||
});
|
||||
/// #endif
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
export const openAssetNewWindow = (assetPath: string, options: windowOptions = {}) => {
|
||||
/// #if !BROWSER
|
||||
const suffix = pathPosix().extname(assetPath.split("?page")[0]);
|
||||
if (Constants.SIYUAN_ASSETS_EXTS.includes(suffix)) {
|
||||
let docIcon = "iconPDF";
|
||||
if (Constants.SIYUAN_ASSETS_IMAGE.includes(suffix)) {
|
||||
docIcon = "iconImage";
|
||||
} else if (Constants.SIYUAN_ASSETS_AUDIO.includes(suffix)) {
|
||||
docIcon = "iconRecord";
|
||||
} else if (Constants.SIYUAN_ASSETS_VIDEO.includes(suffix)) {
|
||||
docIcon = "iconVideo";
|
||||
}
|
||||
const json: any = {
|
||||
title: getDisplayName(assetPath),
|
||||
docIcon,
|
||||
pin: false,
|
||||
active: true,
|
||||
instance: "Tab",
|
||||
action: "Tab",
|
||||
children: {
|
||||
path: assetPath,
|
||||
page: parseInt(getSearch("page", assetPath)),
|
||||
instance: "Asset",
|
||||
}
|
||||
};
|
||||
ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
|
||||
position: options.position,
|
||||
width: options.width,
|
||||
height: options.height,
|
||||
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
|
||||
});
|
||||
}
|
||||
/// #endif
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user