Browse Source

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.
pull/3202/head
TheGoddessInari 6 years ago
parent
commit
0ecf7db4f0
No known key found for this signature in database
GPG Key ID: 1209B1B7632D69A
  1. 59
      app.js
  2. 140
      app/Application.js
  3. 4
      app/view/main/Main.js
  4. 71
      electron/menu.js
  5. 2
      resources/languages/en.js

59
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();

140
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 ) {

4
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]']+'<br/><b>'+locale['app.main[18]']+': F1</b>'
,tooltip: locale['app.main[17]']+'<br/><b>'+locale['app.main[18]']+': Alt+F1</b>'
,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]']+'<br/><b>'+locale['app.main[18]']+': F2</b>'
,tooltip: locale['app.main[20]']+'<br/><b>'+locale['app.main[18]']+': Alt+F2</b>'
,handler: 'lockRambox'
,id: 'lockRamboxBtn'
}

71
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();
}

2
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.";

Loading…
Cancel
Save