From 9046b858b1e4608af4c01bc4d69e1a49d4009c07 Mon Sep 17 00:00:00 2001 From: Giulio Ganci Date: Sat, 16 Oct 2021 17:05:26 +0200 Subject: [PATCH 1/3] feat(UI): ctrl|cmd+t, ctrl|cmd+w shortcut to open/close workspace tabs --- src/main/index.js | 57 ++++++++++++++++++--------- src/renderer/components/Workspace.vue | 24 +++++++++++ 2 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 5f1a805d..753a3122 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -41,18 +41,18 @@ async function createMainWindow () { remoteMain.enable(window.webContents); try { - if (isDevelopment) { // + if (isDevelopment) { + // await window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`); // const { default: installExtension, VUEJS3_DEVTOOLS } = require('electron-devtools-installer'); - // const oldDevToolsID = session.defaultSession.getAllExtensions().find(ext => ext.name === 'Vue.js devtools').id; - // session.defaultSession.removeExtension(oldDevToolsID); - // const toolName = await installExtension(VUEJS3_DEVTOOLS); - // console.log(toolName, 'installed'); + // const oldDevToolsID = session.defaultSession.getAllExtensions().find(ext => ext.name === 'Vue.js devtools').id; + // session.defaultSession.removeExtension(oldDevToolsID); + // const toolName = await installExtension(VUEJS3_DEVTOOLS); + // console.log(toolName, 'installed'); } - else - await window.loadURL(new URL(`file:///${path.join(__dirname, 'index.html')}`).href); + else await window.loadURL(new URL(`file:///${path.join(__dirname, 'index.html')}`).href); } catch (err) { console.log(err); @@ -70,10 +70,9 @@ async function createMainWindow () { }); return window; -}; +} -if (!gotTheLock) - app.quit(); +if (!gotTheLock) app.quit(); else { require('@electron/remote/main').initialize(); @@ -83,33 +82,53 @@ else { // quit application when all windows are closed app.on('window-all-closed', () => { // on macOS it is common for applications to stay open until the user explicitly quits - if (process.platform !== 'darwin') - app.quit(); + if (process.platform !== 'darwin') app.quit(); }); app.on('activate', async () => { // on macOS it is common to re-create a window even after all windows have been closed if (mainWindow === null) { mainWindow = await createMainWindow(); - if (isDevelopment) - mainWindow.webContents.openDevTools(); + if (isDevelopment) mainWindow.webContents.openDevTools(); } }); // create main BrowserWindow when electron is ready app.on('ready', async () => { mainWindow = await createMainWindow(); - Menu.setApplicationMenu(null); + createAppMenu(); - if (isDevelopment) - mainWindow.webContents.openDevTools(); + if (isDevelopment) mainWindow.webContents.openDevTools(); - process.on('uncaughtException', error => { + process.on('uncaughtException', (error) => { mainWindow.webContents.send('unhandled-exception', error); }); - process.on('unhandledRejection', error => { + process.on('unhandledRejection', (error) => { mainWindow.webContents.send('unhandled-exception', error); }); }); } + +function createAppMenu () { + let menu = null; + + if (process.platform === 'darwin') { + menu = Menu.buildFromTemplate([ + { + label: app.name, + submenu: [ + { + role: 'about' + }, + { type: 'separator' }, + { + role: 'quit' + } + ] + } + ]); + } + + Menu.setApplicationMenu(menu); +} diff --git a/src/renderer/components/Workspace.vue b/src/renderer/components/Workspace.vue index bd437c56..da4869ad 100644 --- a/src/renderer/components/Workspace.vue +++ b/src/renderer/components/Workspace.vue @@ -586,11 +586,16 @@ export default { } }, async created () { + window.addEventListener('keydown', this.onKey); await this.addWorkspace(this.connection.uid); const isInitiated = await Connection.checkConnection(this.connection.uid); if (isInitiated) this.connectWorkspace(this.connection); }, + beforeDestroy () { + window.removeEventListener('keydown', this.onKey); + }, + methods: { ...mapActions({ addWorkspace: 'workspaces/addWorkspace', @@ -604,6 +609,25 @@ export default { addQueryTab () { this.newTab({ uid: this.connection.uid, type: 'query' }); }, + getSelectedTab () { + return this.workspace.tabs.find(tab => tab.uid === this.selectedTab); + }, + onKey (e) { + e.stopPropagation(); + + if (!this.isSelected) + return; + + if ((e.ctrlKey || e.metaKey) && e.keyCode === 84) { // CTRL|Command + t + this.addQueryTab(); + } + + if ((e.ctrlKey || e.metaKey) && e.keyCode === 87) { // CTRL|Command + w + const currentTab = this.getSelectedTab(); + if (currentTab) + this.closeTab(currentTab); + } + }, openAsPermanentTab (tab) { const permanentTabs = { table: 'data', From d2d0c3ca4112d38bb01b8220553394bdbb5e49e2 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Sat, 16 Oct 2021 18:43:23 +0200 Subject: [PATCH 2/3] refactor(UI): changed query clear shortcut --- src/renderer/components/Workspace.vue | 5 ++--- src/renderer/components/WorkspaceTabQuery.vue | 2 +- src/renderer/components/WorkspaceTabQueryTable.vue | 1 - src/renderer/i18n/en-US.js | 3 ++- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/renderer/components/Workspace.vue b/src/renderer/components/Workspace.vue index da4869ad..87cd730c 100644 --- a/src/renderer/components/Workspace.vue +++ b/src/renderer/components/Workspace.vue @@ -595,7 +595,6 @@ export default { beforeDestroy () { window.removeEventListener('keydown', this.onKey); }, - methods: { ...mapActions({ addWorkspace: 'workspaces/addWorkspace', @@ -618,11 +617,11 @@ export default { if (!this.isSelected) return; - if ((e.ctrlKey || e.metaKey) && e.keyCode === 84) { // CTRL|Command + t + if ((e.ctrlKey || e.metaKey) && e.keyCode === 84 && !e.altKey) { // CTRL|Command + t this.addQueryTab(); } - if ((e.ctrlKey || e.metaKey) && e.keyCode === 87) { // CTRL|Command + w + if ((e.ctrlKey || e.metaKey) && e.keyCode === 87 && !e.altKey) { // CTRL|Command + w const currentTab = this.getSelectedTab(); if (currentTab) this.closeTab(currentTab); diff --git a/src/renderer/components/WorkspaceTabQuery.vue b/src/renderer/components/WorkspaceTabQuery.vue index cfcfbe15..bbb72cc8 100644 --- a/src/renderer/components/WorkspaceTabQuery.vue +++ b/src/renderer/components/WorkspaceTabQuery.vue @@ -4,7 +4,7 @@ class="workspace-query-tab column col-12 columns col-gapless no-outline p-0" tabindex="0" @keydown.116="runQuery(query)" - @keydown.ctrl.87="clear" + @keydown.ctrl.alt.87="clear" @keydown.ctrl.66="beautify" @keydown.ctrl.71="openHistoryModal" > diff --git a/src/renderer/components/WorkspaceTabQueryTable.vue b/src/renderer/components/WorkspaceTabQueryTable.vue index 99bed1a9..610e00ef 100644 --- a/src/renderer/components/WorkspaceTabQueryTable.vue +++ b/src/renderer/components/WorkspaceTabQueryTable.vue @@ -451,7 +451,6 @@ export default { this.selectedRows = [row]; }, selectAllRows () { - console.log('select all'); this.selectedRows = this.localResults.reduce((acc, curr) => { acc.push(curr._id); return acc; diff --git a/src/renderer/i18n/en-US.js b/src/renderer/i18n/en-US.js index 6175849a..6858b542 100644 --- a/src/renderer/i18n/en-US.js +++ b/src/renderer/i18n/en-US.js @@ -244,7 +244,8 @@ module.exports = { newTriggerFunction: 'New trigger function', thereIsNoQueriesYet: 'There is no queries yet', searchForQueries: 'Search for queries', - killProcess: 'Kill process' + killProcess: 'Kill process', + closeTab: 'Close tab' }, faker: { address: 'Address', From 8a86344484b4ca2b9c5d043343cadbd9d0ca2a30 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Sat, 16 Oct 2021 18:46:17 +0200 Subject: [PATCH 3/3] refactor(UI): display new shortcuts in empty query tab --- .../components/WorkspaceTabQueryEmptyState.vue | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/renderer/components/WorkspaceTabQueryEmptyState.vue b/src/renderer/components/WorkspaceTabQueryEmptyState.vue index 22003d7e..473001a4 100644 --- a/src/renderer/components/WorkspaceTabQueryEmptyState.vue +++ b/src/renderer/components/WorkspaceTabQueryEmptyState.vue @@ -14,6 +14,12 @@
{{ $t('word.history') }}
+
+ {{ $t('message.openNewTab') }} +
+
+ {{ $t('message.closeTab') }} +
@@ -23,11 +29,17 @@ CTRL + B
- CTRL + W + CTRL + ALT + W
CTRL + G
+
+ CTRL + T +
+
+ CTRL + W +