Skip to content

Commit

Permalink
Bind 'h' and '/' keys to toggle help screen
Browse files Browse the repository at this point in the history
Fixed anvaka#8
  • Loading branch information
anvaka committed Oct 2, 2015
1 parent cbd881d commit 155ccd9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/galaxy/help.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
import React from 'react';
import appEvents from './service/appEvents.js';
import Key from './utils/key.js';

export default require('maco')(help);

Expand Down Expand Up @@ -101,6 +102,7 @@ function help(x) {
if (window.orientation !== undefined) return;
appEvents.graphDownloaded.on(showHelpIfNeeded);
appEvents.downloadGraphRequested.on(resetHelp);
appEvents.toggleHelp.on(toggleHelp);

listenToKeys();
listenToWheel();
Expand All @@ -110,6 +112,7 @@ function help(x) {
if (window.orientation !== undefined) return;
appEvents.graphDownloaded.off(showHelpIfNeeded);
appEvents.downloadGraphRequested.off(resetHelp);
appEvents.toggleHelp.off(toggleHelp);

releaseKeyListener();
releaseWheel();
Expand All @@ -122,12 +125,21 @@ function help(x) {
x.forceUpdate();
}

function toggleHelp() {
helpWasShown = !helpWasShown;
x.forceUpdate();
}

function resetHelp() {
graphDownloaded = false;
x.forceUpdate();
}

function handlekey(e) {
if (Key.isModifier(e)) {
// ignore modifiers
return;
}
var needsUpdate = !helpWasShown;
helpWasShown = true;

Expand Down
11 changes: 9 additions & 2 deletions src/galaxy/native/sceneKeyboardBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export default sceneKeyboardBinding;

import events from '../service/appEvents.js';
import Key from '../utils/key.js';

function sceneKeyboardBinding(container) {
var api = {
Expand All @@ -23,12 +24,18 @@ function sceneKeyboardBinding(container) {
}

function keydown(e) {
if (e.which === 32) { // spacebar
if (e.which === Key.Space) {
events.toggleSteering.fire();
} else if (e.which === 76) { // L - toggle links
} else if (e.which === Key.L) { // L - toggle links
if (!e.ctrlKey && !e.metaKey) {
events.toggleLinks.fire();
}
} else if (e.which === Key.H || (e.which === Key['/'] && e.shiftKey)) { // 'h' or '?' key
// Need to stop propagation, since help screen attempts to close itself
// once user presses any key. We don't want that now, since this is
// explicit request to render help
e.stopPropagation();
events.toggleHelp.fire();
}
if (e.shiftKey && !lastShiftKey) {
lastShiftKey = true;
Expand Down
9 changes: 9 additions & 0 deletions src/galaxy/service/appEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export default eventMirror([
*/
'toggleSteering',

/**
* Fired when user wants to show or hide links
*/
'toggleLinks',

/**
Expand All @@ -65,6 +68,12 @@ export default eventMirror([
*/
'commandBarChanged',

/**
* fired when user requesed to show or hide help screen
*/
'toggleHelp',

// These events are not documented since I'm not sure whether to keep them
'showNodeListWindow',
'hideNodeListWindow',
'showDegree',
Expand Down
12 changes: 12 additions & 0 deletions src/galaxy/utils/key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
isModifier,

H: 72,
L: 76,
Space: 32,
'/': 191
};

function isModifier(e) {
return e.altKey || e.ctrlKey || e.metaKey || e.shiftKey;
}

0 comments on commit 155ccd9

Please sign in to comment.