From fb3a08953a5f4beddb89013a5c6705a30edcadc1 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Tue, 5 Jul 2016 17:09:34 -0300 Subject: [PATCH] Added Keyboard Shortcuts - Ctrl + Tab to navigate tabs forward. - Ctrl + Shift + Tab to navigate tabs backward. - Fixed @ shortcut, because was switching always to tab number 2. - Added zoom to services with Ctrl + NumPlus, Ctrl + NumMinus and Ctrl + NumZero. - Fixes #31 . - Fixes #58 . --- app/Application.js | 77 ++++++++++++++++++++++++++++++++++++++++--- app/ux/WebView.js | 1 + app/view/main/Main.js | 1 + 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/app/Application.js b/app/Application.js index 9ba8e597..02374eb0 100644 --- a/app/Application.js +++ b/app/Application.js @@ -20,11 +20,78 @@ Ext.define('Rambox.Application', { // Add shortcuts to switch services using CTRL + Number var map = new Ext.util.KeyMap({ target: document - ,key: "0123456789" - ,ctrl: true - ,fn: function(key) { - Ext.cq1('app-main').setActiveTab(key - 48); - } + ,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()); + if ( !tabPanel.items.items[activeIndex + 1] ) { + activeIndex = -1; + } else if ( tabPanel.items.items[activeIndex + 1].tabConfig.xtype === 'tbfill' ) { + activeIndex++; + } + tabPanel.setActiveTab( activeIndex + 1 ); + } + } + ,{ + key: "\t" + ,ctrl: true + ,alt: false + ,shift: true + ,handler: function(key) { + var tabPanel = Ext.cq1('app-main'); + var activeIndex = tabPanel.items.indexOf(tabPanel.getActiveTab()); + if ( !tabPanel.items.items[activeIndex - 1] ) { + activeIndex = tabPanel.items.length; + } else if ( tabPanel.items.items[activeIndex - 1].tabConfig.xtype === 'tbfill' ) { + activeIndex--; + } + tabPanel.setActiveTab( activeIndex - 1 ); + } + } + ,{ + key: [Ext.event.Event.NUM_PLUS, Ext.event.Event.NUM_MINUS] + ,ctrl: true + ,alt: false + ,shift: false + ,handler: function(key) { + var tabPanel = Ext.cq1('app-main'); + if ( tabPanel.items.indexOf(tabPanel.getActiveTab()) === 0 ) return false; + var currentLevel = tabPanel.getActiveTab().zoomLevel; + if ( key === Ext.event.Event.NUM_PLUS ) { // Plus key + currentLevel = currentLevel + 0.25; + } else { // Minus Key + currentLevel = currentLevel - 0.25; + } + tabPanel.getActiveTab().down('component').el.dom.getWebContents().setZoomLevel(currentLevel); + tabPanel.getActiveTab().zoomLevel = currentLevel; + } + } + ,{ + key: Ext.event.Event.NUM_ZERO + ,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().down('component').el.dom.getWebContents().setZoomLevel(0); + tabPanel.getActiveTab().zoomLevel = 0; + } + } + ,{ + key: "0123456789" + ,ctrl: true + ,alt: false + ,handler: function(key) { + Ext.cq1('app-main').setActiveTab(key - 48); + } + } + ] }); // Remove spinner after 3 secs diff --git a/app/ux/WebView.js b/app/ux/WebView.js index aee7219c..a814e30b 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -7,6 +7,7 @@ Ext.define('Rambox.ux.WebView',{ // private ,notifications: 0 + ,zoomLevel: 0 // CONFIG ,hideMode: 'offsets' diff --git a/app/view/main/Main.js b/app/view/main/Main.js index f778be43..861fbeb8 100644 --- a/app/view/main/Main.js +++ b/app/view/main/Main.js @@ -45,6 +45,7 @@ Ext.define('Rambox.view.main.Main', { ,reorderable: false ,autoScroll: true ,layout: 'hbox' + ,tabConfig: {} // Created empty for Keyboard Shortcuts ,items: [ { xtype: 'panel'