diff --git a/src/common/shortcuts.ts b/src/common/shortcuts.ts index 474c98b4..4e8ed84f 100644 --- a/src/common/shortcuts.ts +++ b/src/common/shortcuts.ts @@ -1,29 +1,34 @@ -export const shortcutEvents: Record = { - 'run-or-reload': { l18n: 'application.runOrReload', context: 'tab' }, - 'open-new-tab': { l18n: 'application.openNewTab', context: 'tab' }, - 'close-tab': { l18n: 'application.closeTab', context: 'tab' }, - 'format-query': { l18n: 'database.formatQuery', context: 'tab' }, - 'kill-query': { l18n: 'database.killQuery', context: 'tab' }, - 'query-history': { l18n: 'database.queryHistory', context: 'tab' }, - 'clear-query': { l18n: 'database.clearQuery', context: 'tab' }, - // 'save-file': { l18n: 'application.saveFile', context: 'tab' }, - 'open-file': { l18n: 'application.openFile', context: 'tab' }, - 'save-file-as': { l18n: 'application.saveFileAs', context: 'tab' }, - 'next-tab': { l18n: 'application.nextTab' }, - 'prev-tab': { l18n: 'application.previousTab' }, - 'open-all-connections': { l18n: 'application.openAllConnections' }, - 'open-filter': { l18n: 'application.openFilter' }, - 'next-page': { l18n: 'application.nextResultsPage' }, - 'prev-page': { l18n: 'application.previousResultsPage' }, - 'toggle-console': { l18n: 'application.toggleConsole' }, - 'save-content': { l18n: 'application.saveContent' }, - 'create-connection': { l18n: 'connection.createNewConnection' }, - 'open-settings': { l18n: 'application.openSettings' }, - 'open-scratchpad': { l18n: 'application.openNotes' } +export const shortcutEvents: Record = { + 'run-or-reload': { i18n: 'application.runOrReload', context: 'tab' }, + 'open-new-tab': { i18n: 'application.openNewTab', context: 'tab' }, + 'close-tab': { i18n: 'application.closeTab', context: 'tab' }, + 'format-query': { i18n: 'database.formatQuery', context: 'tab' }, + 'kill-query': { i18n: 'database.killQuery', context: 'tab' }, + 'query-history': { i18n: 'database.queryHistory', context: 'tab' }, + 'clear-query': { i18n: 'database.clearQuery', context: 'tab' }, + // 'save-file': { i18n: 'application.saveFile', context: 'tab' }, + 'open-file': { i18n: 'application.openFile', context: 'tab' }, + 'save-file-as': { i18n: 'application.saveFileAs', context: 'tab' }, + 'next-tab': { i18n: 'application.nextTab' }, + 'prev-tab': { i18n: 'application.previousTab' }, + 'open-all-connections': { i18n: 'application.openAllConnections' }, + 'open-filter': { i18n: 'application.openFilter' }, + 'next-page': { i18n: 'application.nextResultsPage' }, + 'prev-page': { i18n: 'application.previousResultsPage' }, + 'toggle-console': { i18n: 'application.toggleConsole' }, + 'save-content': { i18n: 'application.saveContent' }, + 'create-connection': { i18n: 'connection.createNewConnection' }, + 'open-settings': { i18n: 'application.openSettings' }, + 'open-scratchpad': { i18n: 'application.openNotes' }, + setFullScreen: { i18n: 'application.fullScreen', context: 'main' }, + setZoomIn: { i18n: 'application.zoomIn', context: 'main' }, + setZoomOut: { i18n: 'application.zoomOut', context: 'main' }, + setZoomReset: { i18n: 'application.zoomReset', context: 'main' } }; interface ShortcutRecord { event: string; + isFunction?: boolean; keys: Electron.Accelerator[] | string[]; /** Needed for default shortcuts */ os: NodeJS.Platform[]; @@ -38,6 +43,30 @@ const shortcuts: ShortcutRecord[] = [ keys: ['F5'], os: ['darwin', 'linux', 'win32'] }, + { + event: 'setFullScreen', + isFunction: true, + keys: ['F11'], + os: ['darwin', 'linux', 'win32'] + }, + { + event: 'setZoomIn', + isFunction: true, + keys: ['CommandOrControl+='], + os: ['darwin', 'linux', 'win32'] + }, + { + event: 'setZoomOut', + isFunction: true, + keys: ['CommandOrControl+-'], + os: ['darwin', 'linux', 'win32'] + }, + { + event: 'setZoomReset', + isFunction: true, + keys: ['CommandOrControl+0'], + os: ['darwin', 'linux', 'win32'] + }, { event: 'save-content', keys: ['CommandOrControl+S'], @@ -142,8 +171,8 @@ const shortcuts: ShortcutRecord[] = [ for (let i = 1; i <= 9; i++) { shortcutEvents[`select-tab-${i}`] = { - l18n: 'application.selectTabNumber', - l18nParam: i + i18n: 'application.selectTabNumber', + i18nParam: i }; shortcuts.push({ diff --git a/src/main/libs/ShortcutRegister.ts b/src/main/libs/ShortcutRegister.ts index 320241d7..26557fc5 100644 --- a/src/main/libs/ShortcutRegister.ts +++ b/src/main/libs/ShortcutRegister.ts @@ -24,21 +24,6 @@ export class ShortcutRegister { this._menuTemplate = args.menuTemplate || {}; this._mode = args.mode; this.shortcuts = shortcutsStore.get('shortcuts', defaultShortcuts) as ShortcutRecord[]; - - globalShortcut.register('CommandOrControl+=', () => { - const currentZoom = this._mainWindow.webContents.getZoomLevel(); - this._mainWindow.webContents.setZoomLevel(currentZoom + 1); - }); - globalShortcut.register('CommandOrControl+-', () => { - const currentZoom = this._mainWindow.webContents.getZoomLevel(); - this._mainWindow.webContents.setZoomLevel(currentZoom - 1); - }); - globalShortcut.register('CommandOrControl+0', () => { - this._mainWindow.webContents.setZoomLevel(0); - }); - globalShortcut.register('F11', () => { - this._mainWindow.setFullScreen(!this._mainWindow.isFullScreen()); - }); } public static getInstance (args?: { mainWindow?: BrowserWindow; menuTemplate?: OsMenu; mode?: ShortcutMode }) { @@ -96,7 +81,15 @@ export class ShortcutRegister { accelerator: key, visible: isMenuVisible, click: () => { - this._mainWindow.webContents.send(shortcut.event); + if (shortcut.isFunction) { + if (shortcut.event in this) { + type exporterMethods = 'setFullScreen' | 'setZoomIn' | 'setZoomOut' | 'setZoomReset'; + this[shortcut.event as exporterMethods](); + } + } + else + this._mainWindow.webContents.send(shortcut.event); + if (isDevelopment) console.log('LOCAL EVENT:', shortcut); } }); @@ -136,6 +129,24 @@ export class ShortcutRegister { } } + setFullScreen () { + this._mainWindow.setFullScreen(!this._mainWindow.isFullScreen()); + } + + setZoomIn () { + const currentZoom = this._mainWindow.webContents.getZoomLevel(); + this._mainWindow.webContents.setZoomLevel(currentZoom + 1); + } + + setZoomOut () { + const currentZoom = this._mainWindow.webContents.getZoomLevel(); + this._mainWindow.webContents.setZoomLevel(currentZoom - 1); + } + + setZoomReset () { + this._mainWindow.webContents.setZoomLevel(0); + } + reload () { this.unregister(); this.init(); diff --git a/src/renderer/components/ModalSettingsShortcuts.vue b/src/renderer/components/ModalSettingsShortcuts.vue index 72161c86..41f4cd69 100644 --- a/src/renderer/components/ModalSettingsShortcuts.vue +++ b/src/renderer/components/ModalSettingsShortcuts.vue @@ -42,7 +42,7 @@ tabindex="0" >
- {{ t(shortcutEvents[shortcut.event].l18n, {param: shortcutEvents[shortcut.event].l18nParam}) }} + {{ t(shortcutEvents[shortcut.event].i18n, {param: shortcutEvents[shortcut.event].i18nParam}) }}
@@ -233,7 +233,7 @@ const { shortcuts } = storeToRefs(settingsStore); const eventOptions = computed(() => { return Object.keys(shortcutEvents) .map(key => { - return { value: key, label: t(shortcutEvents[key].l18n, { param: shortcutEvents[key].l18nParam }) }; + return { value: key, label: t(shortcutEvents[key].i18n, { param: shortcutEvents[key].i18nParam }) }; }) .sort((a, b) => { if (a.label < b.label) return -1; diff --git a/src/renderer/components/WorkspaceTabQueryEmptyState.vue b/src/renderer/components/WorkspaceTabQueryEmptyState.vue index 3c9c88ba..9fdb1d82 100644 --- a/src/renderer/components/WorkspaceTabQueryEmptyState.vue +++ b/src/renderer/components/WorkspaceTabQueryEmptyState.vue @@ -7,7 +7,7 @@ :key="i" class="mb-4" > - {{ t(shortcutEvents[shortcut.event].l18n, {param: shortcutEvents[shortcut.event].l18nParam}) }} + {{ t(shortcutEvents[shortcut.event].i18n, {param: shortcutEvents[shortcut.event].i18nParam}) }}
diff --git a/src/renderer/i18n/en-US.ts b/src/renderer/i18n/en-US.ts index 3eefdd7d..729cd7a6 100644 --- a/src/renderer/i18n/en-US.ts +++ b/src/renderer/i18n/en-US.ts @@ -416,7 +416,11 @@ export const enUS = { openNotes: 'Open notes', debugConsole: 'Debug console', // <- console tab name executedQueries: 'Executed queries', // <- console tab name - sizeLimitError: 'Maximum size of {size} exceeded' + sizeLimitError: 'Maximum size of {size} exceeded', + fullScreen: 'Full screen', + zoomIn: 'Zoom in', + zoomOut: 'Zoom out', + zoomReset: 'Reset zoom' }, faker: { // Faker.js methods, used in random generated content address: 'Address',