1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Combine quick-add and quick-join actions

This commit is contained in:
Nick O'Leary 2016-11-09 13:17:26 +00:00
parent a0e6628757
commit b85e562980

View File

@ -244,6 +244,7 @@ RED.view = (function() {
node.el = dragGroup.append("svg:path").attr("class", "drag_line"); node.el = dragGroup.append("svg:path").attr("class", "drag_line");
drag_lines.push(node); drag_lines.push(node);
} }
} }
function hideDragLines() { function hideDragLines() {
while(drag_lines.length) { while(drag_lines.length) {
@ -481,6 +482,8 @@ RED.view = (function() {
} }
function canvasMouseDown() { function canvasMouseDown() {
var point;
if (!mousedown_node && !mousedown_link) { if (!mousedown_node && !mousedown_link) {
selected_link = null; selected_link = null;
updateSelection(); updateSelection();
@ -490,11 +493,18 @@ RED.view = (function() {
lasso.remove(); lasso.remove();
lasso = null; lasso = null;
} }
var point; }
if (mouse_mode === 0 || mouse_mode === RED.state.QUICK_JOINING) {
if (d3.event.metaKey || d3.event.ctrlKey) { if (d3.event.metaKey || d3.event.ctrlKey) {
point = d3.mouse(this); point = d3.mouse(this);
d3.event.stopPropagation(); d3.event.stopPropagation();
var mainPos = $("#main-container").position(); var mainPos = $("#main-container").position();
if (mouse_mode !== RED.state.QUICK_JOINING) {
mouse_mode = RED.state.QUICK_JOINING;
$(window).on('keyup',disableQuickJoinEventHandler);
}
RED.typeSearch.show({ RED.typeSearch.show({
x:d3.event.clientX-mainPos.left-node_width/2, x:d3.event.clientX-mainPos.left-node_width/2,
y:d3.event.clientY-mainPos.top-node_height/2, y:d3.event.clientY-mainPos.top-node_height/2,
@ -507,6 +517,48 @@ RED.view = (function() {
var historyEvent = result.historyEvent; var historyEvent = result.historyEvent;
nn.x = point[0]; nn.x = point[0];
nn.y = point[1]; nn.y = point[1];
if (mouse_mode === RED.state.QUICK_JOINING) {
if (drag_lines.length > 0) {
var drag_line = drag_lines[0];
var src = null,dst,src_port;
if (drag_line.portType === 0 && nn.inputs > 0) {
src = drag_line.node;
src_port = drag_line.port;
dst = nn;
} else if (drag_line.portType === 1 && nn.outputs > 0) {
src = nn;
dst = drag_line.node;
src_port = 0;
}
if (src !== null) {
var link = {source: src, sourcePort:src_port, target: dst};
RED.nodes.addLink(link);
historyEvent.links = [link];
hideDragLines();
if (drag_line.portType === 0 && nn.outputs > 0) {
showDragLines([{node:nn,port:0,portType:0}]);
} else if (drag_line.portType === 1 && nn.inputs > 0) {
showDragLines([{node:nn,port:0,portType:1}]);
} else {
resetMouseVars();
}
} else {
hideDragLines();
resetMouseVars();
}
} else {
if (nn.outputs > 0) {
showDragLines([{node:nn,port:0,portType:0}]);
} else if (nn.inputs > 0) {
showDragLines([{node:nn,port:0,portType:1}]);
} else {
resetMouseVars();
}
}
}
RED.history.push(historyEvent); RED.history.push(historyEvent);
RED.nodes.add(nn); RED.nodes.add(nn);
RED.editor.validateNode(nn); RED.editor.validateNode(nn);
@ -518,16 +570,15 @@ RED.view = (function() {
updateActiveNodes(); updateActiveNodes();
updateSelection(); updateSelection();
redraw(); redraw();
if (nn._def.autoedit) {
RED.editor.edit(nn);
}
} }
}); });
updateActiveNodes(); updateActiveNodes();
updateSelection(); updateSelection();
redraw(); redraw();
} else { }
}
if (mouse_mode === 0 && !(d3.event.metaKey || d3.event.ctrlKey)) {
if (!touchStartTime) { if (!touchStartTime) {
point = d3.mouse(this); point = d3.mouse(this);
lasso = vis.append("rect") lasso = vis.append("rect")
@ -544,7 +595,6 @@ RED.view = (function() {
} }
} }
} }
}
function canvasMouseMove() { function canvasMouseMove() {
var i; var i;
@ -588,7 +638,7 @@ RED.view = (function() {
return; return;
} }
if (mouse_mode != RED.state.IMPORT_DRAGGING && !mousedown_node && selected_link == null) { if (mouse_mode != RED.state.QUICK_JOINING && mouse_mode != RED.state.IMPORT_DRAGGING && !mousedown_node && selected_link == null) {
return; return;
} }
@ -1267,6 +1317,7 @@ RED.view = (function() {
$(window).on('keyup',disableQuickJoinEventHandler); $(window).on('keyup',disableQuickJoinEventHandler);
} }
} }
d3.event.stopPropagation();
d3.event.preventDefault(); d3.event.preventDefault();
} }
@ -1420,6 +1471,7 @@ RED.view = (function() {
d3.event.stopPropagation(); d3.event.stopPropagation();
return; return;
} else if (mouse_mode == RED.state.QUICK_JOINING) { } else if (mouse_mode == RED.state.QUICK_JOINING) {
d3.event.stopPropagation();
return; return;
} }
mousedown_node = d; mousedown_node = d;