From e28a3564e26e992054f1ac59d53e3678057d3199 Mon Sep 17 00:00:00 2001 From: CyanSalt Date: Fri, 11 Oct 2024 10:02:27 +0800 Subject: [PATCH] feat(explorer): add keyboard shortcut --- addons/explorer/keybindings.json | 7 +++++++ addons/explorer/locales/zh-CN.json | 3 +++ addons/explorer/src/main/index.ts | 4 ++++ addons/explorer/src/renderer/compositions.ts | 2 +- addons/explorer/src/renderer/index.ts | 10 ++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 addons/explorer/keybindings.json create mode 100644 addons/explorer/locales/zh-CN.json diff --git a/addons/explorer/keybindings.json b/addons/explorer/keybindings.json new file mode 100644 index 00000000..6908612d --- /dev/null +++ b/addons/explorer/keybindings.json @@ -0,0 +1,7 @@ +[ + { + "label": "Open Explorer#!explorer.1", + "accelerator": "CmdOrCtrl+O", + "command": "open-explorer" + } +] diff --git a/addons/explorer/locales/zh-CN.json b/addons/explorer/locales/zh-CN.json new file mode 100644 index 00000000..f70ff176 --- /dev/null +++ b/addons/explorer/locales/zh-CN.json @@ -0,0 +1,3 @@ +{ + "Open Explorer#!explorer.1": "打开文件管理" +} diff --git a/addons/explorer/src/main/index.ts b/addons/explorer/src/main/index.ts index 024a1786..ad43c939 100644 --- a/addons/explorer/src/main/index.ts +++ b/addons/explorer/src/main/index.ts @@ -43,4 +43,8 @@ export default () => { return path.join(path.dirname(file), target) }) + commas.i18n.addTranslationDirectory('locales') + + commas.keybinding.addKeyBindingsFile('keybindings.json') + } diff --git a/addons/explorer/src/renderer/compositions.ts b/addons/explorer/src/renderer/compositions.ts index 33f30853..25b02f29 100644 --- a/addons/explorer/src/renderer/compositions.ts +++ b/addons/explorer/src/renderer/compositions.ts @@ -5,7 +5,7 @@ export function getDirectoryProcess(directory: string) { return directory.endsWith(path.sep) ? directory : directory + path.sep } -export function openFileExplorerTab(directory: string) { +export function openFileExplorerTab(directory?: string) { return commas.workspace.openPaneTab('explorer', { cwd: directory })! } diff --git a/addons/explorer/src/renderer/index.ts b/addons/explorer/src/renderer/index.ts index d6ff1462..85c0e50c 100644 --- a/addons/explorer/src/renderer/index.ts +++ b/addons/explorer/src/renderer/index.ts @@ -3,6 +3,12 @@ import * as commas from 'commas:api/renderer' import FileExplorerPane from './FileExplorerPane.vue' import { getDirectoryProcess, openFileExplorerTab, splitOrCloseFileExplorerTab } from './compositions' +declare module '@commas/electron-ipc' { + export interface RendererEvents { + 'open-explorer': (directory?: string) => void, + } +} + export default () => { commas.ui.addCSSFile('dist/renderer/style.css') @@ -28,6 +34,10 @@ export default () => { openFileExplorerTab(directory) }) + commas.ipcRenderer.on('open-explorer', (event, directory) => { + openFileExplorerTab(directory) + }) + if (handleOpen) { commas.app.onCleanup(() => { commas.context.handle('global-renderer:open-directory', handleOpen)