From 0ecf7db4f0aa7caa1f8e68b050e5fae0c39cbd60 Mon Sep 17 00:00:00 2001 From: TheGoddessInari Date: Wed, 23 Jan 2019 11:42:05 -0800 Subject: [PATCH] Redo shortcuts via hidden menus, adds quit keybind, move F1 F2 keybinds. This fixes #66. Also adds Ctrl-Shift-Q to be able to quit via keyboard easily, but prevent accidents. Also move F1 and F2 keybinds to Alt+F1 and Alt+F2 respectively to also prevent accidents. --- app.js | 59 ++++++++++++++++ app/Application.js | 140 -------------------------------------- app/view/main/Main.js | 4 +- electron/menu.js | 71 ++++++++++++++++++- resources/languages/en.js | 2 +- 5 files changed, 130 insertions(+), 146 deletions(-) diff --git a/app.js b/app.js index bfe620d0..3bf38003 100644 --- a/app.js +++ b/app.js @@ -128,6 +128,65 @@ ipc.on('reloadCurrentService', function(e) { if ( tab.id !== 'ramboxTab' ) tab.reloadService(); }); +ipc.on('tabFocusNext', function() { + var tabPanel = Ext.cq1('app-main'); + var activeIndex = tabPanel.items.indexOf(tabPanel.getActiveTab()); + var i = activeIndex + 1; + + // "cycle" (go to the start) when the end is reached or the end is the spacer "tbfill" + if (i === tabPanel.items.items.length || i === tabPanel.items.items.length - 1 && tabPanel.items.items[i].id === 'tbfill') i = 0; + + // skip spacer + while (tabPanel.items.items[i].id === 'tbfill') i++; + + tabPanel.setActiveTab(i); +}); + +ipc.on('tabFocusPrevious', function() { + var tabPanel = Ext.cq1('app-main'); + var activeIndex = tabPanel.items.indexOf(tabPanel.getActiveTab()); + var i = activeIndex - 1; + if ( i < 0 ) i = tabPanel.items.items.length - 1; + while ( tabPanel.items.items[i].id === 'tbfill' || i < 0 ) i--; + tabPanel.setActiveTab( i ); +}); + +ipc.on('tabZoomIn', function(key) { + var tabPanel = Ext.cq1('app-main'); + if ( tabPanel.items.indexOf(tabPanel.getActiveTab()) === 0 ) return false; + + tabPanel.getActiveTab().zoomIn(); +}); + +ipc.on('tabZoomOut', function() { + var tabPanel = Ext.cq1('app-main'); + if ( tabPanel.items.indexOf(tabPanel.getActiveTab()) === 0 ) return false; + + tabPanel.getActiveTab().zoomOut(); +}); + +ipc.on('tabZoomReset', function() { + var tabPanel = Ext.cq1('app-main'); + if ( tabPanel.items.indexOf(tabPanel.getActiveTab()) === 0 ) return false; + + tabPanel.getActiveTab().resetZoom(); +}); + +ipc.on('toggleDoNotDisturb', function(key) { + var btn = Ext.getCmp('disturbBtn'); + btn.toggle(); + Ext.cq1('app-main').getController().dontDisturb(btn, true); +}); + +ipc.on('lockWindow', function(key) { + var btn = Ext.getCmp('lockRamboxBtn'); + Ext.cq1('app-main').getController().lockRambox(btn); +}); + +ipc.on('goHome', function() { + Ext.cq1('app-main').setActiveTab(0); +}); + // Focus the current service when Alt + Tab or click in webviews textfields window.addEventListener('focus', function() { if(Ext.cq1("app-main")) Ext.cq1("app-main").getActiveTab().down('component').el.dom.focus(); diff --git a/app/Application.js b/app/Application.js index adcdc8f1..621eaaa0 100644 --- a/app/Application.js +++ b/app/Application.js @@ -31,146 +31,6 @@ Ext.define('Rambox.Application', { // Check for updates if ( require('electron').remote.process.argv.indexOf('--without-update') === -1 ) Rambox.app.checkUpdate(true); - // Add shortcuts to switch services using CTRL + Number - var map = new Ext.util.KeyMap({ - target: document - ,binding: [ - { - key: "\t" - ,ctrl: true - ,alt: false - ,shift: false - ,handler: function(key) { - var tabPanel = Ext.cq1('app-main'); - var activeIndex = tabPanel.items.indexOf(tabPanel.getActiveTab()); - var i = activeIndex + 1; - - // "cycle" (go to the start) when the end is reached or the end is the spacer "tbfill" - if (i === tabPanel.items.items.length || i === tabPanel.items.items.length - 1 && tabPanel.items.items[i].id === 'tbfill') i = 0; - - // skip spacer - while (tabPanel.items.items[i].id === 'tbfill') i++; - - tabPanel.setActiveTab(i); - } - } - ,{ - key: "\t" - ,ctrl: true - ,alt: false - ,shift: true - ,handler: function(key) { - var tabPanel = Ext.cq1('app-main'); - var activeIndex = tabPanel.items.indexOf(tabPanel.getActiveTab()); - var i = activeIndex - 1; - if ( i < 0 ) i = tabPanel.items.items.length - 1; - while ( tabPanel.items.items[i].id === 'tbfill' || i < 0 ) i--; - tabPanel.setActiveTab( i ); - } - } - ,{ - key: Ext.event.Event.PAGE_DOWN - ,ctrl: true - ,alt: false - ,shift: false - ,handler: function(key) { - var tabPanel = Ext.cq1('app-main'); - var activeIndex = tabPanel.items.indexOf(tabPanel.getActiveTab()); - var i = activeIndex + 1; - - // "cycle" (go to the start) when the end is reached or the end is the spacer "tbfill" - if (i === tabPanel.items.items.length || i === tabPanel.items.items.length - 1 && tabPanel.items.items[i].id === 'tbfill') i = 0; - - // skip spacer - while (tabPanel.items.items[i].id === 'tbfill') i++; - - tabPanel.setActiveTab(i); - } - } - ,{ - key: Ext.event.Event.PAGE_UP - ,ctrl: true - ,alt: false - ,shift: false - ,handler: function(key) { - var tabPanel = Ext.cq1('app-main'); - var activeIndex = tabPanel.items.indexOf(tabPanel.getActiveTab()); - var i = activeIndex - 1; - if ( i < 0 ) i = tabPanel.items.items.length - 1; - while ( tabPanel.items.items[i].id === 'tbfill' || i < 0 ) i--; - tabPanel.setActiveTab( i ); - } - } - ,{ - key: [Ext.event.Event.NUM_PLUS, Ext.event.Event.NUM_MINUS, 187, 189] - ,ctrl: true - ,alt: false - ,shift: false - ,handler: function(key) { - var tabPanel = Ext.cq1('app-main'); - if ( tabPanel.items.indexOf(tabPanel.getActiveTab()) === 0 ) return false; - - if (key === Ext.event.Event.NUM_PLUS || key === 187) { - tabPanel.getActiveTab().zoomIn(); - } else { - tabPanel.getActiveTab().zoomOut(); - } - } - } - ,{ - key: [Ext.event.Event.NUM_ZERO, '0'] - ,ctrl: true - ,alt: false - ,shift: false - ,handler: function(key) { - var tabPanel = Ext.cq1('app-main'); - if ( tabPanel.items.indexOf(tabPanel.getActiveTab()) === 0 ) return false; - - tabPanel.getActiveTab().resetZoom(); - } - } - ,{ - key: "123456789" - ,ctrl: true - ,alt: false - ,handler: function(key) { - key = key - 48; - if ( key >= Ext.cq1('app-main').items.indexOf(Ext.getCmp('tbfill')) ) key++; - Ext.cq1('app-main').setActiveTab(key); - } - } - ,{ - key: 188 // comma - ,ctrl: true - ,alt: false - ,handler: function(key) { - Ext.cq1('app-main').setActiveTab(0); - } - } - ,{ - key: Ext.event.Event.F1 - ,ctrl: false - ,alt: false - ,shift: false - ,handler: function(key) { - var btn = Ext.getCmp('disturbBtn'); - btn.toggle(); - Ext.cq1('app-main').getController().dontDisturb(btn, true); - } - } - ,{ - key: Ext.event.Event.F2 - ,ctrl: false - ,alt: false - ,shift: false - ,handler: function(key) { - var btn = Ext.getCmp('lockRamboxBtn'); - Ext.cq1('app-main').getController().lockRambox(btn); - } - } - ] - }); - // Mouse Wheel zooming document.addEventListener('mousewheel', function(e) { if( e.ctrlKey ) { diff --git a/app/view/main/Main.js b/app/view/main/Main.js index 45cbb331..f9ea1544 100644 --- a/app/view/main/Main.js +++ b/app/view/main/Main.js @@ -238,7 +238,7 @@ Ext.define('Rambox.view.main.Main', { { glyph: 'xf1f7@FontAwesome' ,text: locale['app.main[16]']+': '+(JSON.parse(localStorage.getItem('dontDisturb')) ? locale['app.window[20]'] : locale['app.window[21]']) - ,tooltip: locale['app.main[17]']+'
'+locale['app.main[18]']+': F1' + ,tooltip: locale['app.main[17]']+'
'+locale['app.main[18]']+': Alt+F1' ,enableToggle: true ,handler: 'dontDisturb' ,reference: 'disturbBtn' @@ -248,7 +248,7 @@ Ext.define('Rambox.view.main.Main', { ,{ glyph: 'xf023@FontAwesome' ,text: locale['app.main[19]'] - ,tooltip: locale['app.main[20]']+'
'+locale['app.main[18]']+': F2' + ,tooltip: locale['app.main[20]']+'
'+locale['app.main[18]']+': Alt+F2' ,handler: 'lockRambox' ,id: 'lockRamboxBtn' } diff --git a/electron/menu.js b/electron/menu.js index 119b87db..13d8a548 100644 --- a/electron/menu.js +++ b/electron/menu.js @@ -157,13 +157,77 @@ module.exports = function(config) { type: 'separator' }, { - role: 'zoomin' + role: 'zoomin', + click() { + sendAction('tabZoomIn'); + } + }, + { + role: 'zoomout', + click() { + sendAction('tabZoomOut'); + } }, { - role: 'zoomout' + role: 'resetzoom', + click() { + sendAction("tabZoomReset"); + } }, { - role: 'resetzoom' + label: `&Commands`, + visible: false, + submenu: [ + { + label: `Next Tab`, + accelerator: 'CmdOrCtrl+Tab', + click() { + sendAction('tabFocusNext'); + } + }, + { + label: `Next Tab`, + accelerator: 'CmdOrCtrl+PageDown', + click() { + sendAction('tabFocusNext'); + } + }, + { + label: `Previous Tab`, + accelerator: 'CmdOrCtrl+Shift+Tab', + click() { + sendAction('tabFocusPrevious'); + } + }, + { + label: `Previous Tab`, + accelerator: 'CmdOrCtrl+PageUp', + click() { + sendAction('tabFocusPrevious'); + } + }, + { + label: `Do Not Disturb`, + accelerator: 'Alt+F1', + click() { + sendAction('toggleDoNotDisturb'); + } + }, + { + label: `Lock Rambox`, + accelerator: 'Alt+F2', + click() { + sendAction('lockWindow'); + } + }, + { + label: `Go Home`, + accelerator: 'CmdOrCtrl+,', + click() { + sendAction('goHome'); + } + } + ] } ] }, @@ -279,6 +343,7 @@ module.exports = function(config) { }, { label: locale['menu.file[1]'], + accelerator: 'CmdOrCtrl+Shift+Q', click() { app.exit(); } diff --git a/resources/languages/en.js b/resources/languages/en.js index 3a869b28..708a1df4 100644 --- a/resources/languages/en.js +++ b/resources/languages/en.js @@ -127,7 +127,7 @@ locale["menu.osx[1]"] = "Hide Rambox-OS"; locale["menu.osx[2]"] = "Hide Others"; locale["menu.osx[3]"] = "Show All"; locale["menu.file[0]"] = "File"; -locale["menu.file[1]"] = "Quit Rambox-OS"; +locale["menu.file[1]"] = "&Quit Rambox-OS"; locale["tray[0]"] = "Show/Hide Window"; locale["tray[1]"] = "Quit"; locale["services[0]"] = "WhatsApp is a cross-platform mobile messaging app for iPhone, BlackBerry, Android, Windows Phone and Nokia. Send text, video, images, audio for free.";