From 0bb56291eddbf7b6a91ef469b9309fccb888a76e Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Thu, 19 May 2016 00:25:21 +0900 Subject: [PATCH] Add shortcuts to select next/previous tab --- src/browser/index.jsx | 9 ++++++++- src/main/menus/app.js | 25 +++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/browser/index.jsx b/src/browser/index.jsx index 6f254b3b..0f459d91 100644 --- a/src/browser/index.jsx +++ b/src/browser/index.jsx @@ -54,9 +54,16 @@ var MainPage = React.createClass({ loginQueue: loginQueue }); }); + // can't switch tabs sequencially for some reason... ipcRenderer.on('switch-tab', (event, key) => { this.handleSelect(key); }); + ipcRenderer.on('select-next-tab', (event) => { + this.handleSelect(this.state.key + 1); + }); + ipcRenderer.on('select-previous-tab', (event) => { + this.handleSelect(this.state.key - 1); + }); var focusListener = function() { var webview = document.getElementById('mattermostView' + thisObj.state.key); @@ -72,7 +79,7 @@ var MainPage = React.createClass({ }); }, handleSelect: function(key) { - const newKey = key % this.props.teams.length; + const newKey = (this.props.teams.length + key) % this.props.teams.length; this.setState({ key: newKey }); diff --git a/src/main/menus/app.js b/src/main/menus/app.js index 049dad41..c2a30c3f 100644 --- a/src/main/menus/app.js +++ b/src/main/menus/app.js @@ -136,7 +136,8 @@ var createTemplate = function(mainWindow, config) { } }, ] }); - template.push({ + + const window_menu = { label: '&Window', submenu: [{ label: 'Minimize', @@ -166,7 +167,27 @@ var createTemplate = function(mainWindow, config) { } }; })] - }); + } + + if (config.teams.length > 1) { + window_menu.submenu = window_menu.submenu.concat([{ + type: 'separator' + }, { + label: 'Select Next Team', + accelerator: (process.platform === 'darwin') ? 'Alt+Cmd+Right' : 'CmdOrCtrl+Tab', + click: () => { + mainWindow.webContents.send('select-next-tab'); + } + }, { + label: 'Select Previous Team', + accelerator: (process.platform === 'darwin') ? 'Alt+Cmd+Left' : 'CmdOrCtrl+Shift+Tab', + click: () => { + mainWindow.webContents.send('select-previous-tab'); + } + }]); + } + template.push(window_menu); + return template; };