From cef378d8204b25eb2084af38a19eac5c664fc30d Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 4 Mar 2015 13:19:13 +0000 Subject: [PATCH] Add selection-changed event on RED.view --- public/red/ui/view.js | 48 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/public/red/ui/view.js b/public/red/ui/view.js index 128c182b1..006e122d5 100644 --- a/public/red/ui/view.js +++ b/public/red/ui/view.js @@ -799,6 +799,17 @@ RED.view = (function() { RED.keyboard.add(/* left */ 37, function() { if(d3.event.shiftKey){moveSelection(-20, 0)}else{moveSelection(-1, 0);}d3.event.preventDefault();},endKeyboardMove); RED.keyboard.add(/* right*/ 39, function() { if(d3.event.shiftKey){moveSelection( 20, 0)}else{moveSelection( 1, 0);}d3.event.preventDefault();},endKeyboardMove); } + var selection = {}; + + if (moving_set.length > 0) { + selection.nodes = moving_set.map(function(n) { return n.n;}); + } + if (selected_link != null) { + selection.link = selected_link; + } + + eventHandler.emit("selection-changed",selection); + if (moving_set.length == 1) { if (moving_set[0].n.type === "subflow" && moving_set[0].n.direction) { RED.sidebar.info.refresh(RED.nodes.subflow(moving_set[0].n.z)); @@ -810,6 +821,8 @@ RED.view = (function() { } else { RED.sidebar.info.clear(); } + + } function endKeyboardMove() { var ns = []; @@ -2092,8 +2105,29 @@ RED.view = (function() { event.preventDefault(); }); + // TODO: DRY + var eventHandler = (function() { + var handlers = {}; + + return { + on: function(evt,func) { + handlers[evt] = handlers[evt]||[]; + handlers[evt].push(func); + }, + emit: function(evt,arg) { + if (handlers[evt]) { + for (var i=0;i