From 24148d0d8d4b89473729bc3c2280a54ba4ac2d96 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 14 Oct 2019 16:29:54 +0200 Subject: [PATCH] Setting shortcuts working --- Canvas.js | 24 ++++++++++++++++++++---- StrategySpace/Workspace/Workspace.js | 5 +++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Canvas.js b/Canvas.js index ae6478c70..98b7d1a56 100644 --- a/Canvas.js +++ b/Canvas.js @@ -186,6 +186,7 @@ function newCanvas () { } function onKeyDown (event) { + event.preventDefault() if (event.altKey === true && event.code === 'ArrowUp') { thisObject.cockpitSpace.toTop() return @@ -237,12 +238,27 @@ function newCanvas () { } if (event.ctrlKey === true) { - if (event.keyCode > 52 && event.keyCode < 100) { + if (event.keyCode >= 65 && event.keyCode <= 90) { let nodeOnFocus = canvas.strategySpace.workspace.getNodeThatIsOnFocus() - if (nodeOnFocus !== undefined) { - nodeOnFocus.payload.uiObject.shortcutKey = event.code - nodeOnFocus.payload.uiObject.setValue('Shortcut Key: Ctrl + ' + event.code) + if (nodeOnFocus === undefined) { + return } + + let nodeUsingThisKey = canvas.strategySpace.workspace.getNodeByShortcutKey(event.key) + + if (nodeUsingThisKey !== undefined) { + if (nodeUsingThisKey.id === nodeOnFocus.id) { + nodeOnFocus.payload.uiObject.shortcutKey = '' + nodeOnFocus.payload.uiObject.setValue('Shortcut Key Removed ') + return + } else { + nodeOnFocus.payload.uiObject.setErrorMessage('Key already in use by ' + nodeUsingThisKey.type + ' ' + nodeUsingThisKey.name) + return + } + } + + nodeOnFocus.payload.uiObject.shortcutKey = event.key + nodeOnFocus.payload.uiObject.setValue('Shortcut Key: Ctrl + ' + event.key) } return } diff --git a/StrategySpace/Workspace/Workspace.js b/StrategySpace/Workspace/Workspace.js index 2025e408d..d22b2a769 100644 --- a/StrategySpace/Workspace/Workspace.js +++ b/StrategySpace/Workspace/Workspace.js @@ -11,6 +11,7 @@ function newWorkspace () { container: undefined, enabled: false, nodeChildren: undefined, + getNodeThatIsOnFocus: getNodeThatIsOnFocus, getNodeByShortcutKey: getNodeByShortcutKey, getAllTradingEngines: getAllTradingEngines, stopAllRunningTasks: stopAllRunningTasks, @@ -197,7 +198,7 @@ function newWorkspace () { let rootNode = thisObject.workspaceNode.rootNodes[i] if (rootNode.type === 'Definition') { let definition = rootNode - let node = functionLibraryShortcutKeys.getNodeByShortcutKey(searchingKey) + let node = functionLibraryShortcutKeys.getNodeByShortcutKey(rootNode, searchingKey) if (node !== undefined) { return node } } } @@ -208,7 +209,7 @@ function newWorkspace () { let rootNode = thisObject.workspaceNode.rootNodes[i] if (rootNode.type === 'Definition') { let definition = rootNode - let node = functionLibraryOnFocus.getNodeThatIsOnFocus() + let node = functionLibraryOnFocus.getNodeThatIsOnFocus(rootNode) if (node !== undefined) { return node } } }