From a2ccd8670b2001290119b9add0fad38cd7834bcf Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 22 Sep 2024 22:13:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=80=E6=9C=89=E6=96=87=E6=9C=AC=E6=A1=86?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8F=B3=E9=94=AE=E5=89=AA=E5=88=87=E3=80=81?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E3=80=81=E7=B2=98=E8=B4=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commons/data/languages.ts | 9 +++++++++ electron/main/commons/ipcEvent.ts | 22 +++++++++++++++++++++- electron/preload/index.ts | 4 ++++ src/App.vue | 22 ++++++++++++++++++++++ src/index.d.ts | 1 + 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/commons/data/languages.ts b/commons/data/languages.ts index 4ba2f59..eff8e5a 100644 --- a/commons/data/languages.ts +++ b/commons/data/languages.ts @@ -77,10 +77,12 @@ let simplifiedChinese = { controlPanel: "控制面板", convertAbsolutePath: "转为绝对路径", convertRelativePath: "转为相对路径", + copy: "复制", copyFullPath: "复制完整路径", copyTo: "复制到", createShortcut: "创建快捷方式", ctrlNumberKey: "Ctrl + 数字键", + cut: "剪切", default: "默认", defaultIcon: "默认图标", delayDisplay: "延迟显示", @@ -206,6 +208,7 @@ let simplifiedChinese = { parameters: "参数", password: "密码", pasteIcon: "粘贴图标", + paste: "粘贴", path: "路径", powerOptions: "电源选项", powerShell: "PowerShell", @@ -384,10 +387,12 @@ let traditionalChinese = { controlPanel: "控製面板", convertAbsolutePath: "轉為絕對路徑", convertRelativePath: "轉為相對路徑", + copy: "復製", copyFullPath: "復製完整路徑", copyTo: "復製到", createShortcut: "創建快捷方式", ctrlNumberKey: "Ctrl + 數字鍵", + cut: "剪切", default: "默認", defaultIcon: "默認圖標", delayDisplay: "延遲顯示", @@ -513,6 +518,7 @@ let traditionalChinese = { parameters: "參數", password: "密碼", pasteIcon: "粘貼圖標", + paste: "粘貼", path: "路徑", powerOptions: "電源選項", powerShell: "PowerShell", @@ -699,10 +705,12 @@ let english = { controlPanel: "Control Panel", convertAbsolutePath: "Convert to Absolute Path", convertRelativePath: "Convert to Relative Path", + copy: "Copy", copyFullPath: "Copy Full Path", copyTo: "Copy to", createShortcut: "Create Shortcut", ctrlNumberKey: "Ctrl + Number Key", + cut: "Cut", default: "Default", defaultIcon: "Default Icon", delayDisplay: "Delay Display", @@ -830,6 +838,7 @@ let english = { parameters: "Parameters", password: "Password", pasteIcon: "Paste Icon", + paste: "Paste", path: "Path", powerOptions: "Power Options", powerShell: "PowerShell", diff --git a/electron/main/commons/ipcEvent.ts b/electron/main/commons/ipcEvent.ts index 46b7185..6d17666 100644 --- a/electron/main/commons/ipcEvent.ts +++ b/electron/main/commons/ipcEvent.ts @@ -1,4 +1,4 @@ -import { app, ipcMain, OpenDialogSyncOptions, shell } from "electron"; +import { app, ipcMain, Menu, OpenDialogSyncOptions, shell } from "electron"; import { getFileIcon } from "../../commons/utils"; import mime from "mime"; import { ShortcutInfo } from "../../../types/common"; @@ -164,4 +164,24 @@ export default function () { app.getPath("home") ); }); + // 文本框菜单 + ipcMain.on("textRightMenu", (event, args) => { + // 菜单 + let menu = Menu.buildFromTemplate([ + { + role: "cut", + label: global.language.cut, + }, + { + role: "copy", + label: global.language.copy, + }, + { + role: "paste", + label: global.language.paste, + }, + ]); + // 显示 + menu.popup(); + }); } diff --git a/electron/preload/index.ts b/electron/preload/index.ts index dafaa34..0b416ed 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -114,6 +114,10 @@ contextBridge.exposeInMainWorld("api", { ) => { ipcRenderer.send("run", { operation, target, params, startLocation }); }, + // 文本框菜单 + textRightMenu: () => { + ipcRenderer.send("textRightMenu"); + }, }); contextBridge.exposeInMainWorld("main", { diff --git a/src/App.vue b/src/App.vue index d795103..1451291 100644 --- a/src/App.vue +++ b/src/App.vue @@ -305,6 +305,24 @@ function keydown(e: any) { } } } +// 监听鼠标右键 +function contextmenu(e: MouseEvent) { + let target = e.target as HTMLInputElement; + if (target) { + if ( + (target.nodeName != null && + target.nodeName.toLowerCase() == "input" && + target.type != null && + target.type.toLowerCase() == "text") || + (target.nodeName != null && target.nodeName.toLowerCase() == "textarea") + ) { + window.api.textRightMenu(); + e.preventDefault(); + e.stopPropagation(); + return; + } + } +} // 监听 let onUpdateSettingUnListen: Function | null = null; // mounted @@ -313,6 +331,8 @@ onMounted(() => { createStyle(); // 监听键盘 window.addEventListener("keydown", keydown, true); + // 监听右键 + window.addEventListener("contextmenu", contextmenu, true); // 监听更新项目 onUpdateSettingUnListen = window.setting.onUpdate((data) => { store.setting = data; @@ -322,6 +342,8 @@ onMounted(() => { onUnmounted(() => { // 监听键盘 window.removeEventListener("keydown", keydown, true); + // 监听右键 + window.removeEventListener("contextmenu", contextmenu, true); // 删除监听 if (onUpdateSettingUnListen) { onUpdateSettingUnListen(); diff --git a/src/index.d.ts b/src/index.d.ts index b43ef85..9b2f490 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -37,6 +37,7 @@ declare global { params: string | null, startLocation: string | null ) => void; + textRightMenu: () => void; }; main: { showWindow: (blurHide: boolean, autoHide: boolean) => void;