Vanessa 2024-03-14 12:41:08 +08:00
parent d1009f2333
commit 60beaf291d
3 changed files with 94 additions and 35 deletions

View File

@ -20,6 +20,7 @@ import {Constants} from "../constants";
import {exportImage} from "../protyle/export/util"; import {exportImage} from "../protyle/export/util";
import {App} from "../index"; import {App} from "../index";
import {renderAVAttribute} from "../protyle/render/av/blockAttr"; import {renderAVAttribute} from "../protyle/render/av/blockAttr";
import {openAssetNewWindow} from "../window/openNewWindow";
const bindAttrInput = (inputElement: HTMLInputElement, id: string) => { const bindAttrInput = (inputElement: HTMLInputElement, id: string) => {
inputElement.addEventListener("change", () => { inputElement.addEventListener("change", () => {
@ -679,12 +680,20 @@ export const exportMd = (id: string) => {
export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerator: boolean) => { export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerator: boolean) => {
const submenu = []; const submenu = [];
/// #if MOBILE
submenu.push({
label: window.siyuan.languages.useBrowserView,
accelerator: showAccelerator ? "Click" : "",
click: () => {
openByMobile(src);
}
});
/// #else
if (isLocalPath(src)) { if (isLocalPath(src)) {
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(src)) && if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(src)) &&
(!src.endsWith(".pdf") || (!src.endsWith(".pdf") ||
(src.endsWith(".pdf") && !src.startsWith("file://"))) (src.endsWith(".pdf") && !src.startsWith("file://")))
) { ) {
/// #if !MOBILE
submenu.push({ submenu.push({
icon: "iconLayoutRight", icon: "iconLayoutRight",
label: window.siyuan.languages.insertRight, 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"); 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 /// #if !BROWSER
submenu.push({ submenu.push({
label: window.siyuan.languages.useDefault, label: window.siyuan.languages.openByNewWindow,
accelerator: showAccelerator ? "⇧Click" : "", icon: "iconOpenWindow",
click() { click() {
openBy(src, "app"); openAssetNewWindow(src.trim());
} }
}); });
/// #endif /// #endif
} else { } else {
/// #if !BROWSER
submenu.push({ submenu.push({
label: window.siyuan.languages.useDefault, label: window.siyuan.languages.useBrowserView,
accelerator: showAccelerator ? "Click" : "", accelerator: showAccelerator ? "Click" : "",
click() { click: () => {
openBy(src, "app"); openByMobile(src);
} }
}); });
/// #endif
} }
/// #if !BROWSER /// #if !BROWSER
submenu.push({ submenu.push({
@ -723,8 +737,20 @@ export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerat
openBy(src, "folder"); openBy(src, "folder");
} }
}); });
submenu.push({
label: window.siyuan.languages.useDefault,
accelerator: showAccelerator ? "⇧Click" : "",
click() {
openBy(src, "app");
}
});
/// #endif /// #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 /// #if !BROWSER
submenu.push({ submenu.push({
label: window.siyuan.languages.useDefault, label: window.siyuan.languages.useDefault,
@ -735,9 +761,7 @@ export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerat
}); });
} }
}); });
/// #endif /// #else
}
/// #if BROWSER
submenu.push({ submenu.push({
label: window.siyuan.languages.useBrowserView, label: window.siyuan.languages.useBrowserView,
accelerator: showAccelerator ? "Click" : "", accelerator: showAccelerator ? "Click" : "",
@ -746,6 +770,8 @@ export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerat
} }
}); });
/// #endif /// #endif
}
/// #endif
if (onlyMenu) { if (onlyMenu) {
return submenu; return submenu;
} }

View File

@ -2077,7 +2077,7 @@ export class WYSIWYG {
return; return;
} }
if (aElement && !event.altKey) { if (aElement) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
let linkAddress = Lute.UnEscapeHTMLStr(aLink); let linkAddress = Lute.UnEscapeHTMLStr(aLink);
@ -2090,31 +2090,28 @@ export class WYSIWYG {
(!linkPathname.endsWith(".pdf") || (!linkPathname.endsWith(".pdf") ||
(linkPathname.endsWith(".pdf") && !linkAddress.startsWith("file://"))) (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) { if (ctrlIsPressed) {
openBy(linkAddress, "folder"); openBy(linkAddress, "folder");
} else if (event.shiftKey) { } else if (event.shiftKey) {
openBy(linkAddress, "app"); 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 /// #endif
}
} else if (linkAddress) { } else if (linkAddress) {
/// #if !BROWSER
if (0 > linkAddress.indexOf(":")) { if (0 > linkAddress.indexOf(":")) {
// 使用 : 判断,不使用 :// 判断 Open external application protocol invalid https://github.com/siyuan-note/siyuan/issues/10075 // 使用 : 判断,不使用 :// 判断 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 // Support click to open hyperlinks like `www.foo.com` https://github.com/siyuan-note/siyuan/issues/9986
linkAddress = `https://${linkAddress}`; linkAddress = `https://${linkAddress}`;
} }
/// #if !BROWSER
shell.openExternal(linkAddress).catch((e) => { shell.openExternal(linkAddress).catch((e) => {
showMessage(e); showMessage(e);
}); });

View File

@ -6,6 +6,8 @@ import {Constants} from "../constants";
import {Tab} from "../layout/Tab"; import {Tab} from "../layout/Tab";
import {fetchPost} from "../util/fetch"; import {fetchPost} from "../util/fetch";
import {showMessage} from "../dialog/message"; import {showMessage} from "../dialog/message";
import {getDisplayName, pathPosix} from "../util/pathName";
import {getSearch} from "../util/functions";
interface windowOptions { interface windowOptions {
position?: { position?: {
@ -62,5 +64,39 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => {
}); });
/// #endif /// #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
}; };