mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
refactor: enhancement of new shortcuts implementation
This commit is contained in:
@ -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[];
|
||||
@ -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({
|
||||
|
@ -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: () => {
|
||||
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();
|
||||
|
@ -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"
|
||||
@ -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>
|
||||
@ -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;
|
||||
|
@ -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">
|
||||
|
@ -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',
|
||||
|
Reference in New Issue
Block a user