Skip to content

Commit

Permalink
Merge pull request #921 from curiouslad/develop
Browse files Browse the repository at this point in the history
Zoom in/out and fullscreen shortcuts
  • Loading branch information
Fabio286 authored Jan 20, 2025
2 parents 8d0ff49 + f25f665 commit 6709a75
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 30 deletions.
77 changes: 53 additions & 24 deletions src/common/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
export const shortcutEvents: Record<string, { l18n: string; l18nParam?: string | number; context?: 'tab' }> = {
'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<string, { i18n: string; i18nParam?: string | number; context?: 'tab' | 'main' }> = {
'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[];
Expand All @@ -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'],
Expand Down Expand Up @@ -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({
Expand Down
28 changes: 27 additions & 1 deletion src/main/libs/ShortcutRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,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);
}
});
Expand Down Expand Up @@ -121,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();
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/ModalSettingsShortcuts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
tabindex="0"
>
<div class="td py-1">
{{ t(shortcutEvents[shortcut.event].l18n, {param: shortcutEvents[shortcut.event].l18nParam}) }}
{{ t(shortcutEvents[shortcut.event].i18n, {param: shortcutEvents[shortcut.event].i18nParam}) }}
</div>
<div
class="td py-1"
Expand Down Expand Up @@ -167,7 +167,7 @@
</template>
<template #body>
<div class="mb-2">
{{ t('general.deleteConfirm') }} <b>{{ t(shortcutEvents[shortcutToDelete.event].l18n, {param: shortcutEvents[shortcutToDelete.event].l18nParam}) }} (<span v-html="parseKeys(shortcutToDelete.keys)" />)</b>?
{{ t('general.deleteConfirm') }} <b>{{ t(shortcutEvents[shortcutToDelete.event].i18n, {param: shortcutEvents[shortcutToDelete.event].i18nParam}) }} (<span v-html="parseKeys(shortcutToDelete.keys)" />)</b>?
</div>
</template>
</ConfirmModal>
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/WorkspaceTabQueryEmptyState.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}) }}
</div>
</div>
<div class="column col-16">
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/i18n/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6709a75

Please sign in to comment.