Skip to content

Commit

Permalink
feat(explorer): add keyboard shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Oct 11, 2024
1 parent 481c62c commit e28a356
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions addons/explorer/keybindings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"label": "Open Explorer#!explorer.1",
"accelerator": "CmdOrCtrl+O",
"command": "open-explorer"
}
]
3 changes: 3 additions & 0 deletions addons/explorer/locales/zh-CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Open Explorer#!explorer.1": "打开文件管理"
}
4 changes: 4 additions & 0 deletions addons/explorer/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ export default () => {
return path.join(path.dirname(file), target)
})

commas.i18n.addTranslationDirectory('locales')

commas.keybinding.addKeyBindingsFile('keybindings.json')

}
2 changes: 1 addition & 1 deletion addons/explorer/src/renderer/compositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })!
}

Expand Down
10 changes: 10 additions & 0 deletions addons/explorer/src/renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit e28a356

Please sign in to comment.