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' }> = {
|
export const shortcutEvents: Record<string, { i18n: string; i18nParam?: string | number; context?: 'tab' | 'main' }> = {
|
||||||
'run-or-reload': { l18n: 'application.runOrReload', context: 'tab' },
|
'run-or-reload': { i18n: 'application.runOrReload', context: 'tab' },
|
||||||
'open-new-tab': { l18n: 'application.openNewTab', context: 'tab' },
|
'open-new-tab': { i18n: 'application.openNewTab', context: 'tab' },
|
||||||
'close-tab': { l18n: 'application.closeTab', context: 'tab' },
|
'close-tab': { i18n: 'application.closeTab', context: 'tab' },
|
||||||
'format-query': { l18n: 'database.formatQuery', context: 'tab' },
|
'format-query': { i18n: 'database.formatQuery', context: 'tab' },
|
||||||
'kill-query': { l18n: 'database.killQuery', context: 'tab' },
|
'kill-query': { i18n: 'database.killQuery', context: 'tab' },
|
||||||
'query-history': { l18n: 'database.queryHistory', context: 'tab' },
|
'query-history': { i18n: 'database.queryHistory', context: 'tab' },
|
||||||
'clear-query': { l18n: 'database.clearQuery', context: 'tab' },
|
'clear-query': { i18n: 'database.clearQuery', context: 'tab' },
|
||||||
// 'save-file': { l18n: 'application.saveFile', context: 'tab' },
|
// 'save-file': { i18n: 'application.saveFile', context: 'tab' },
|
||||||
'open-file': { l18n: 'application.openFile', context: 'tab' },
|
'open-file': { i18n: 'application.openFile', context: 'tab' },
|
||||||
'save-file-as': { l18n: 'application.saveFileAs', context: 'tab' },
|
'save-file-as': { i18n: 'application.saveFileAs', context: 'tab' },
|
||||||
'next-tab': { l18n: 'application.nextTab' },
|
'next-tab': { i18n: 'application.nextTab' },
|
||||||
'prev-tab': { l18n: 'application.previousTab' },
|
'prev-tab': { i18n: 'application.previousTab' },
|
||||||
'open-all-connections': { l18n: 'application.openAllConnections' },
|
'open-all-connections': { i18n: 'application.openAllConnections' },
|
||||||
'open-filter': { l18n: 'application.openFilter' },
|
'open-filter': { i18n: 'application.openFilter' },
|
||||||
'next-page': { l18n: 'application.nextResultsPage' },
|
'next-page': { i18n: 'application.nextResultsPage' },
|
||||||
'prev-page': { l18n: 'application.previousResultsPage' },
|
'prev-page': { i18n: 'application.previousResultsPage' },
|
||||||
'toggle-console': { l18n: 'application.toggleConsole' },
|
'toggle-console': { i18n: 'application.toggleConsole' },
|
||||||
'save-content': { l18n: 'application.saveContent' },
|
'save-content': { i18n: 'application.saveContent' },
|
||||||
'create-connection': { l18n: 'connection.createNewConnection' },
|
'create-connection': { i18n: 'connection.createNewConnection' },
|
||||||
'open-settings': { l18n: 'application.openSettings' },
|
'open-settings': { i18n: 'application.openSettings' },
|
||||||
'open-scratchpad': { l18n: 'application.openNotes' }
|
'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 {
|
interface ShortcutRecord {
|
||||||
event: string;
|
event: string;
|
||||||
|
isFunction?: boolean;
|
||||||
keys: Electron.Accelerator[] | string[];
|
keys: Electron.Accelerator[] | string[];
|
||||||
/** Needed for default shortcuts */
|
/** Needed for default shortcuts */
|
||||||
os: NodeJS.Platform[];
|
os: NodeJS.Platform[];
|
||||||
@ -38,6 +43,30 @@ const shortcuts: ShortcutRecord[] = [
|
|||||||
keys: ['F5'],
|
keys: ['F5'],
|
||||||
os: ['darwin', 'linux', 'win32']
|
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',
|
event: 'save-content',
|
||||||
keys: ['CommandOrControl+S'],
|
keys: ['CommandOrControl+S'],
|
||||||
@ -142,8 +171,8 @@ const shortcuts: ShortcutRecord[] = [
|
|||||||
|
|
||||||
for (let i = 1; i <= 9; i++) {
|
for (let i = 1; i <= 9; i++) {
|
||||||
shortcutEvents[`select-tab-${i}`] = {
|
shortcutEvents[`select-tab-${i}`] = {
|
||||||
l18n: 'application.selectTabNumber',
|
i18n: 'application.selectTabNumber',
|
||||||
l18nParam: i
|
i18nParam: i
|
||||||
};
|
};
|
||||||
|
|
||||||
shortcuts.push({
|
shortcuts.push({
|
||||||
|
@ -24,21 +24,6 @@ export class ShortcutRegister {
|
|||||||
this._menuTemplate = args.menuTemplate || {};
|
this._menuTemplate = args.menuTemplate || {};
|
||||||
this._mode = args.mode;
|
this._mode = args.mode;
|
||||||
this.shortcuts = shortcutsStore.get('shortcuts', defaultShortcuts) as ShortcutRecord[];
|
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 }) {
|
public static getInstance (args?: { mainWindow?: BrowserWindow; menuTemplate?: OsMenu; mode?: ShortcutMode }) {
|
||||||
@ -96,7 +81,15 @@ export class ShortcutRegister {
|
|||||||
accelerator: key,
|
accelerator: key,
|
||||||
visible: isMenuVisible,
|
visible: isMenuVisible,
|
||||||
click: () => {
|
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);
|
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 () {
|
reload () {
|
||||||
this.unregister();
|
this.unregister();
|
||||||
this.init();
|
this.init();
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
tabindex="0"
|
tabindex="0"
|
||||||
>
|
>
|
||||||
<div class="td py-1">
|
<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>
|
||||||
<div
|
<div
|
||||||
class="td py-1"
|
class="td py-1"
|
||||||
@ -167,7 +167,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<template #body>
|
<template #body>
|
||||||
<div class="mb-2">
|
<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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</ConfirmModal>
|
</ConfirmModal>
|
||||||
@ -233,7 +233,7 @@ const { shortcuts } = storeToRefs(settingsStore);
|
|||||||
const eventOptions = computed(() => {
|
const eventOptions = computed(() => {
|
||||||
return Object.keys(shortcutEvents)
|
return Object.keys(shortcutEvents)
|
||||||
.map(key => {
|
.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) => {
|
.sort((a, b) => {
|
||||||
if (a.label < b.label) return -1;
|
if (a.label < b.label) return -1;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
:key="i"
|
:key="i"
|
||||||
class="mb-4"
|
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>
|
</div>
|
||||||
<div class="column col-16">
|
<div class="column col-16">
|
||||||
|
@ -416,7 +416,11 @@ export const enUS = {
|
|||||||
openNotes: 'Open notes',
|
openNotes: 'Open notes',
|
||||||
debugConsole: 'Debug console', // <- console tab name
|
debugConsole: 'Debug console', // <- console tab name
|
||||||
executedQueries: 'Executed queries', // <- 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
|
faker: { // Faker.js methods, used in random generated content
|
||||||
address: 'Address',
|
address: 'Address',
|
||||||
|
Reference in New Issue
Block a user