mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Support select-all inside active group
This commit is contained in:
parent
d590bbdd2c
commit
a8e7627184
@ -74,7 +74,6 @@ RED.view = (function() {
|
||||
var mouse_position = null;
|
||||
var mouse_mode = 0;
|
||||
var mousedown_group_handle = null;
|
||||
var moving_set = [];
|
||||
var lasso = null;
|
||||
var ghostNode = null;
|
||||
var showStatus = false;
|
||||
@ -116,6 +115,49 @@ RED.view = (function() {
|
||||
var groupLayer;
|
||||
var drag_lines;
|
||||
|
||||
var movingSet = (function() {
|
||||
var setIds = new Set();
|
||||
var set = [];
|
||||
var api = {
|
||||
add: function(node) {
|
||||
if (Array.isArray(node)) {
|
||||
for (var i=0;i<node.length;i++) {
|
||||
api.add(node[i]);
|
||||
}
|
||||
} else {
|
||||
if (!setIds.has(node.id)) {
|
||||
set.push({n:node});
|
||||
setIds.add(node.id);
|
||||
}
|
||||
}
|
||||
},
|
||||
remove: function(node, index) {
|
||||
if (setIds.has(node.id)) {
|
||||
setIds.delete(node.id);
|
||||
if (index !== undefined && set[index].n === node) {
|
||||
set.splice(index,1);
|
||||
} else {
|
||||
for (var i=0;i<set.length;i++) {
|
||||
if (set[i].n === node) {
|
||||
set.splice(i,1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
clear: function() {
|
||||
setIds.clear();
|
||||
set = [];
|
||||
},
|
||||
length: function() { return set.length},
|
||||
get: function(i) { return set[i] },
|
||||
forEach: function(func) { set.forEach(func) },
|
||||
nodes: function() { return set.map(function(n) { return n.n })}
|
||||
}
|
||||
return api;
|
||||
})();
|
||||
|
||||
function init() {
|
||||
|
||||
chart = $("#red-ui-workspace-chart");
|
||||
@ -433,7 +475,7 @@ RED.view = (function() {
|
||||
exitActiveGroup();
|
||||
clearSelection();
|
||||
nn.selected = true;
|
||||
moving_set.push({n:nn});
|
||||
movingSet.add(nn);
|
||||
if (group) {
|
||||
selectGroup(group,false);
|
||||
enterActiveGroup(group);
|
||||
@ -1113,7 +1155,7 @@ RED.view = (function() {
|
||||
selectGroup(targetGroup,false);
|
||||
enterActiveGroup(targetGroup);
|
||||
}
|
||||
moving_set.push({n:nn});
|
||||
movingSet.add(nn);
|
||||
updateActiveNodes();
|
||||
updateSelection();
|
||||
redraw();
|
||||
@ -1314,8 +1356,8 @@ RED.view = (function() {
|
||||
mouse_mode = RED.state.MOVING_ACTIVE;
|
||||
clickElapsed = 0;
|
||||
spliceActive = false;
|
||||
if (moving_set.length === 1) {
|
||||
node = moving_set[0];
|
||||
if (movingSet.length() === 1) {
|
||||
node = movingSet.get(0);
|
||||
spliceActive = node.n.hasOwnProperty("_def") &&
|
||||
((node.n.hasOwnProperty("inputs") && node.n.inputs > 0) || (!node.n.hasOwnProperty("inputs") && node.n._def.inputs > 0)) &&
|
||||
((node.n.hasOwnProperty("outputs") && node.n.outputs > 0) || (!node.n.hasOwnProperty("outputs") && node.n._def.outputs > 0)) &&
|
||||
@ -1329,8 +1371,8 @@ RED.view = (function() {
|
||||
var minY = 0;
|
||||
var maxX = space_width;
|
||||
var maxY = space_height;
|
||||
for (var n = 0; n<moving_set.length; n++) {
|
||||
node = moving_set[n];
|
||||
for (var n = 0; n<movingSet.length(); n++) {
|
||||
node = movingSet.get(n);
|
||||
if (d3.event.shiftKey) {
|
||||
node.n.ox = node.n.x;
|
||||
node.n.oy = node.n.y;
|
||||
@ -1339,7 +1381,9 @@ RED.view = (function() {
|
||||
node.n.y = mousePos[1]+node.dy;
|
||||
node.n.dirty = true;
|
||||
if (node.n.type === "group") {
|
||||
node.n.groupMoved = true;
|
||||
if (node.n.groupMoved !== false) {
|
||||
node.n.groupMoved = true;
|
||||
}
|
||||
RED.group.markDirty(node.n);
|
||||
minX = Math.min(node.n.x-5,minX);
|
||||
minY = Math.min(node.n.y-5,minY);
|
||||
@ -1353,15 +1397,15 @@ RED.view = (function() {
|
||||
}
|
||||
}
|
||||
if (minX !== 0 || minY !== 0) {
|
||||
for (i = 0; i<moving_set.length; i++) {
|
||||
node = moving_set[i];
|
||||
for (i = 0; i<movingSet.length(); i++) {
|
||||
node = movingSet.get(i);
|
||||
node.n.x -= minX;
|
||||
node.n.y -= minY;
|
||||
}
|
||||
}
|
||||
if (maxX !== space_width || maxY !== space_height) {
|
||||
for (i = 0; i<moving_set.length; i++) {
|
||||
node = moving_set[i];
|
||||
for (i = 0; i<movingSet.length(); i++) {
|
||||
node = movingSet.get(i);
|
||||
node.n.x -= (maxX - space_width);
|
||||
node.n.y -= (maxY - space_height);
|
||||
}
|
||||
@ -1372,13 +1416,13 @@ RED.view = (function() {
|
||||
// mousedown_group.dirty = true;
|
||||
// }
|
||||
var gridOffset = [0,0];
|
||||
if (snapGrid != d3.event.shiftKey && moving_set.length > 0) {
|
||||
if (snapGrid != d3.event.shiftKey && movingSet.length() > 0) {
|
||||
var i = 0;
|
||||
|
||||
// Prefer to snap nodes to the grid if there is one in the selection
|
||||
do {
|
||||
node = moving_set[i++];
|
||||
} while(i<moving_set.length && node.n.type === "group")
|
||||
node = movingSet.get(i++);
|
||||
} while(i<movingSet.length() && node.n.type === "group")
|
||||
|
||||
if (node.n.type === "group") {
|
||||
// TODO: Group snap to grid
|
||||
@ -1389,8 +1433,8 @@ RED.view = (function() {
|
||||
gridOffset[1] = node.n.y-(gridSize*Math.floor(node.n.y/gridSize));
|
||||
}
|
||||
if (gridOffset[0] !== 0 || gridOffset[1] !== 0) {
|
||||
for (i = 0; i<moving_set.length; i++) {
|
||||
node = moving_set[i];
|
||||
for (i = 0; i<movingSet.length(); i++) {
|
||||
node = movingSet.get(i);
|
||||
node.n.x -= gridOffset[0];
|
||||
node.n.y -= gridOffset[1];
|
||||
if (node.n.x == node.n.ox && node.n.y == node.n.oy) {
|
||||
@ -1401,8 +1445,8 @@ RED.view = (function() {
|
||||
}
|
||||
|
||||
// Check link splice or group-add
|
||||
if (moving_set.length === 1 && moving_set[0].n.type !== "group") {
|
||||
node = moving_set[0];
|
||||
if (movingSet.length() === 1 && movingSet.get(0).n.type !== "group") {
|
||||
node = movingSet.get(0);
|
||||
if (spliceActive) {
|
||||
if (!spliceTimer) {
|
||||
spliceTimer = setTimeout(function() {
|
||||
@ -1544,7 +1588,7 @@ RED.view = (function() {
|
||||
} else {
|
||||
n.selected = true;
|
||||
n.dirty = true;
|
||||
moving_set.push({n:n});
|
||||
movingSet.add(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1568,21 +1612,21 @@ RED.view = (function() {
|
||||
n.selected = (n.x > x && n.x < x2 && n.y > y && n.y < y2);
|
||||
if (n.selected) {
|
||||
n.dirty = true;
|
||||
moving_set.push({n:n});
|
||||
movingSet.add(n);
|
||||
}
|
||||
});
|
||||
activeSubflow.out.forEach(function(n) {
|
||||
n.selected = (n.x > x && n.x < x2 && n.y > y && n.y < y2);
|
||||
if (n.selected) {
|
||||
n.dirty = true;
|
||||
moving_set.push({n:n});
|
||||
movingSet.add(n);
|
||||
}
|
||||
});
|
||||
if (activeSubflow.status) {
|
||||
activeSubflow.status.selected = (activeSubflow.status.x > x && activeSubflow.status.x < x2 && activeSubflow.status.y > y && activeSubflow.status.y < y2);
|
||||
if (activeSubflow.status.selected) {
|
||||
activeSubflow.status.dirty = true;
|
||||
moving_set.push({n:activeSubflow.status});
|
||||
movingSet.add(activeSubflow.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1594,11 +1638,11 @@ RED.view = (function() {
|
||||
updateSelection();
|
||||
}
|
||||
if (mouse_mode == RED.state.MOVING_ACTIVE) {
|
||||
if (moving_set.length > 0) {
|
||||
if (movingSet.length() > 0) {
|
||||
var addedToGroup = null;
|
||||
if (activeHoverGroup) {
|
||||
for (var j=0;j<moving_set.length;j++) {
|
||||
var n = moving_set[j];
|
||||
for (var j=0;j<movingSet.length();j++) {
|
||||
var n = movingSet.get(j);
|
||||
RED.group.addToGroup(activeHoverGroup,n.n);
|
||||
}
|
||||
addedToGroup = activeHoverGroup;
|
||||
@ -1611,8 +1655,8 @@ RED.view = (function() {
|
||||
}
|
||||
|
||||
var ns = [];
|
||||
for (var j=0;j<moving_set.length;j++) {
|
||||
var n = moving_set[j];
|
||||
for (var j=0;j<movingSet.length();j++) {
|
||||
var n = movingSet.get(j);
|
||||
if (n.ox !== n.n.x || n.oy !== n.n.y) {
|
||||
ns.push({n:n.n,ox:n.ox,oy:n.oy,moved:n.n.moved});
|
||||
n.n.dirty = true;
|
||||
@ -1629,10 +1673,10 @@ RED.view = (function() {
|
||||
var link1 = {
|
||||
source:spliceLink.source,
|
||||
sourcePort:spliceLink.sourcePort,
|
||||
target: moving_set[0].n
|
||||
target: movingSet.get(0).n
|
||||
};
|
||||
var link2 = {
|
||||
source:moving_set[0].n,
|
||||
source:movingSet.get(0).n,
|
||||
sourcePort:0,
|
||||
target: spliceLink.target
|
||||
};
|
||||
@ -1660,16 +1704,17 @@ RED.view = (function() {
|
||||
// RED.nodes.group(mousedown_node.g).selected = true;
|
||||
// mousedown_node.selected = true;
|
||||
// mousedown_node.dirty = true;
|
||||
// moving_set.push({n:mousedown_node});
|
||||
// movingSet.add(mousedown_node);
|
||||
// }
|
||||
// }
|
||||
if (mouse_mode == RED.state.MOVING || mouse_mode == RED.state.MOVING_ACTIVE) {
|
||||
// if (mousedown_node) {
|
||||
// delete mousedown_node.gSelected;
|
||||
// }
|
||||
for (i=0;i<moving_set.length;i++) {
|
||||
delete moving_set[i].ox;
|
||||
delete moving_set[i].oy;
|
||||
for (i=0;i<movingSet.length();i++) {
|
||||
var node = movingSet.get(i);
|
||||
delete node.ox;
|
||||
delete node.oy;
|
||||
}
|
||||
}
|
||||
if (mouse_mode == RED.state.IMPORT_DRAGGING) {
|
||||
@ -1712,58 +1757,77 @@ RED.view = (function() {
|
||||
if (mouse_mode === RED.state.SELECTING_NODE && selectNodesOptions.single) {
|
||||
return;
|
||||
}
|
||||
clearSelection();
|
||||
exitActiveGroup();
|
||||
activeGroups.forEach(function(g) {
|
||||
if (!g.g) {
|
||||
selectGroup(g, true);
|
||||
if (!g.selected) {
|
||||
g.selected = true;
|
||||
|
||||
if (activeGroup) {
|
||||
var ag = activeGroup;
|
||||
clearSelection();
|
||||
enterActiveGroup(ag);
|
||||
|
||||
var groupNodes = RED.group.getNodes(ag,false);
|
||||
groupNodes.forEach(function(n) {
|
||||
if (n.type === 'group') {
|
||||
selectGroup(n,true,true);
|
||||
} else {
|
||||
movingSet.add(n)
|
||||
n.selected = true;
|
||||
n.dirty = true;
|
||||
}
|
||||
})
|
||||
activeGroup.selected = true;
|
||||
} else {
|
||||
|
||||
clearSelection();
|
||||
exitActiveGroup();
|
||||
activeGroups.forEach(function(g) {
|
||||
if (!g.g) {
|
||||
selectGroup(g, true);
|
||||
if (!g.selected) {
|
||||
g.selected = true;
|
||||
g.dirty = true;
|
||||
}
|
||||
} else {
|
||||
g.selected = false;
|
||||
g.dirty = true;
|
||||
}
|
||||
} else {
|
||||
g.selected = false;
|
||||
g.dirty = true;
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
activeNodes.forEach(function(n) {
|
||||
if (mouse_mode === RED.state.SELECTING_NODE) {
|
||||
if (selectNodesOptions.filter && !selectNodesOptions.filter(n)) {
|
||||
return;
|
||||
activeNodes.forEach(function(n) {
|
||||
if (mouse_mode === RED.state.SELECTING_NODE) {
|
||||
if (selectNodesOptions.filter && !selectNodesOptions.filter(n)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!n.g && !n.selected) {
|
||||
n.selected = true;
|
||||
n.dirty = true;
|
||||
moving_set.push({n:n});
|
||||
}
|
||||
});
|
||||
|
||||
if (mouse_mode !== RED.state.SELECTING_NODE && activeSubflow) {
|
||||
activeSubflow.in.forEach(function(n) {
|
||||
if (!n.selected) {
|
||||
if (!n.g && !n.selected) {
|
||||
n.selected = true;
|
||||
n.dirty = true;
|
||||
moving_set.push({n:n});
|
||||
movingSet.add(n);
|
||||
}
|
||||
});
|
||||
activeSubflow.out.forEach(function(n) {
|
||||
if (!n.selected) {
|
||||
n.selected = true;
|
||||
n.dirty = true;
|
||||
moving_set.push({n:n});
|
||||
}
|
||||
});
|
||||
if (activeSubflow.status) {
|
||||
if (!activeSubflow.status.selected) {
|
||||
activeSubflow.status.selected = true;
|
||||
activeSubflow.status.dirty = true;
|
||||
moving_set.push({n:activeSubflow.status});
|
||||
|
||||
if (mouse_mode !== RED.state.SELECTING_NODE && activeSubflow) {
|
||||
activeSubflow.in.forEach(function(n) {
|
||||
if (!n.selected) {
|
||||
n.selected = true;
|
||||
n.dirty = true;
|
||||
movingSet.add(n);
|
||||
}
|
||||
});
|
||||
activeSubflow.out.forEach(function(n) {
|
||||
if (!n.selected) {
|
||||
n.selected = true;
|
||||
n.dirty = true;
|
||||
movingSet.add(n);
|
||||
}
|
||||
});
|
||||
if (activeSubflow.status) {
|
||||
if (!activeSubflow.status.selected) {
|
||||
activeSubflow.status.selected = true;
|
||||
activeSubflow.status.dirty = true;
|
||||
movingSet.add(activeSubflow.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selected_link = null;
|
||||
if (mouse_mode !== RED.state.SELECTING_NODE) {
|
||||
updateSelection();
|
||||
@ -1772,13 +1836,13 @@ RED.view = (function() {
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
if (RED.view.DEBUG) { console.warn("clearSelection", mouse_mode,"moving_set.length:",moving_set.length); }
|
||||
for (var i=0;i<moving_set.length;i++) {
|
||||
var n = moving_set[i];
|
||||
if (RED.view.DEBUG) { console.warn("clearSelection", mouse_mode,"movingSet.length():",movingSet.length()); }
|
||||
for (var i=0;i<movingSet.length();i++) {
|
||||
var n = movingSet.get(i);
|
||||
n.n.dirty = true;
|
||||
n.n.selected = false;
|
||||
}
|
||||
moving_set = [];
|
||||
movingSet.clear();
|
||||
selected_link = null;
|
||||
if (activeGroup) {
|
||||
activeGroup.active = false
|
||||
@ -1812,9 +1876,10 @@ RED.view = (function() {
|
||||
activeLinkNodes[n].dirty = true;
|
||||
})
|
||||
activeLinkNodes = {};
|
||||
for (var i=0;i<moving_set.length;i++) {
|
||||
if (moving_set[i].n.type === "link out" || moving_set[i].n.type === "link in") {
|
||||
var linkNode = moving_set[i].n;
|
||||
for (var i=0;i<movingSet.length();i++) {
|
||||
var msn = movingSet.get(i);
|
||||
if (msn.n.type === "link out" || msn.n.type === "link in") {
|
||||
var linkNode = msn.n;
|
||||
activeLinkNodes[linkNode.id] = linkNode;
|
||||
var offFlowLinks = {};
|
||||
linkNode.links.forEach(function(id) {
|
||||
@ -1896,8 +1961,8 @@ RED.view = (function() {
|
||||
}
|
||||
|
||||
function editSelection() {
|
||||
if (moving_set.length > 0) {
|
||||
var node = moving_set[0].n;
|
||||
if (movingSet.length() > 0) {
|
||||
var node = movingSet.get(0).n;
|
||||
if (node.type === "subflow") {
|
||||
RED.editor.editSubflow(activeSubflow);
|
||||
} else if (node.type === "group") {
|
||||
@ -1955,7 +2020,7 @@ RED.view = (function() {
|
||||
updateActiveNodes();
|
||||
updateSelection();
|
||||
redraw();
|
||||
} else if (moving_set.length > 0 || selected_link != null) {
|
||||
} else if (movingSet.length() > 0 || selected_link != null) {
|
||||
var result;
|
||||
var node;
|
||||
var removedNodes = [];
|
||||
@ -1969,10 +2034,10 @@ RED.view = (function() {
|
||||
var startDirty = RED.nodes.dirty();
|
||||
var startChanged = false;
|
||||
var selectedGroups = [];
|
||||
if (moving_set.length > 0) {
|
||||
if (movingSet.length() > 0) {
|
||||
|
||||
for (var i=0;i<moving_set.length;i++) {
|
||||
node = moving_set[i].n;
|
||||
for (var i=0;i<movingSet.length();i++) {
|
||||
node = movingSet.get(i).n;
|
||||
if (node.type === "group") {
|
||||
selectedGroups.push(node);
|
||||
}
|
||||
@ -1985,8 +2050,8 @@ RED.view = (function() {
|
||||
}
|
||||
})
|
||||
}
|
||||
for (var i=0;i<moving_set.length;i++) {
|
||||
node = moving_set[i].n;
|
||||
for (var i=0;i<movingSet.length();i++) {
|
||||
node = movingSet.get(i).n;
|
||||
node.selected = false;
|
||||
if (node.type !== "group" && node.type !== "subflow") {
|
||||
if (node.x < 0) {
|
||||
@ -2049,7 +2114,7 @@ RED.view = (function() {
|
||||
if (instances) {
|
||||
subflowInstances = instances.instances;
|
||||
}
|
||||
moving_set = [];
|
||||
movingSet.clear();
|
||||
if (removedNodes.length > 0 || removedSubflowOutputs.length > 0 || removedSubflowInputs.length > 0 || removedSubflowStatus || removedGroups.length > 0) {
|
||||
RED.nodes.dirty(true);
|
||||
}
|
||||
@ -2700,12 +2765,13 @@ RED.view = (function() {
|
||||
|
||||
function prepareDrag(mouse) {
|
||||
mouse_mode = RED.state.MOVING;
|
||||
// Called when moving_set should be prepared to be dragged
|
||||
for (i=0;i<moving_set.length;i++) {
|
||||
moving_set[i].ox = moving_set[i].n.x;
|
||||
moving_set[i].oy = moving_set[i].n.y;
|
||||
moving_set[i].dx = moving_set[i].n.x-mouse[0];
|
||||
moving_set[i].dy = moving_set[i].n.y-mouse[1];
|
||||
// Called when movingSet should be prepared to be dragged
|
||||
for (i=0;i<movingSet.length();i++) {
|
||||
var msn = movingSet.get(i);
|
||||
msn.ox = msn.n.x;
|
||||
msn.oy = msn.n.y;
|
||||
msn.dx = msn.n.x-mouse[0];
|
||||
msn.dy = msn.n.y-mouse[1];
|
||||
}
|
||||
|
||||
mouse_offset = d3.mouse(document.body);
|
||||
@ -2740,7 +2806,7 @@ RED.view = (function() {
|
||||
enterActiveGroup(RED.nodes.group(d.g))
|
||||
|
||||
mousedown_node.selected = true;
|
||||
moving_set.push({n:mousedown_node});
|
||||
movingSet.add(mousedown_node);
|
||||
var mouse = d3.touches(this)[0]||d3.mouse(this);
|
||||
mouse[0] += d.x-d.w/2;
|
||||
mouse[1] += d.y-d.h/2;
|
||||
@ -2797,10 +2863,10 @@ RED.view = (function() {
|
||||
var link1 = {
|
||||
source:spliceLink.source,
|
||||
sourcePort:spliceLink.sourcePort,
|
||||
target: moving_set[0].n
|
||||
target: movingSet.get(0).n
|
||||
};
|
||||
var link2 = {
|
||||
source:moving_set[0].n,
|
||||
source:movingSet.get(0).n,
|
||||
sourcePort:0,
|
||||
target: spliceLink.target
|
||||
};
|
||||
@ -2829,16 +2895,11 @@ RED.view = (function() {
|
||||
}
|
||||
if (d.selected) {
|
||||
d.selected = false;
|
||||
for (i=0;i<moving_set.length;i+=1) {
|
||||
if (moving_set[i].n === d) {
|
||||
moving_set.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
movingSet.remove(d);
|
||||
} else {
|
||||
if (!selectNodesOptions.filter || selectNodesOptions.filter(d)) {
|
||||
d.selected = true;
|
||||
moving_set.push({n:d});
|
||||
movingSet.add(d);
|
||||
}
|
||||
}
|
||||
d.dirty = true;
|
||||
@ -2878,15 +2939,34 @@ RED.view = (function() {
|
||||
selectGroup(nodeGroup,true);
|
||||
}
|
||||
} else if (nodeGroup === activeGroup ) {
|
||||
// Clicked on a node in the active group
|
||||
if (!d3.event.ctrlKey && !d3.event.metaKey) {
|
||||
// Ctrl not pressed so clear selection
|
||||
deselectGroup(nodeGroup);
|
||||
selectGroup(nodeGroup,false,false);
|
||||
if (d3.event.shiftKey) {
|
||||
if (!d3.event.ctrlKey && !d3.event.metaKey) {
|
||||
var ag = activeGroup;
|
||||
clearSelection();
|
||||
enterActiveGroup(ag);
|
||||
activeGroup.selected = true;
|
||||
}
|
||||
var cnodes = RED.nodes.getAllFlowNodes(mousedown_node);
|
||||
for (var n=0;n<cnodes.length;n++) {
|
||||
if (!cnodes[n].selected) {
|
||||
cnodes[n].selected = true;
|
||||
cnodes[n].dirty = true;
|
||||
movingSet.add(cnodes[n]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Clicked on a node in the active group
|
||||
if (!d3.event.ctrlKey && !d3.event.metaKey) {
|
||||
// Ctrl not pressed so clear selection
|
||||
clearSelection();
|
||||
deselectGroup(nodeGroup);
|
||||
selectGroup(nodeGroup,false,false);
|
||||
}
|
||||
|
||||
// Select this node
|
||||
mousedown_node.selected = true;
|
||||
movingSet.add(mousedown_node);
|
||||
}
|
||||
// Select this node
|
||||
mousedown_node.selected = true;
|
||||
moving_set.push({n:mousedown_node});
|
||||
} else {
|
||||
// Clicked on a node in a group
|
||||
// - if this group is not selected, clear current selection
|
||||
@ -2917,7 +2997,7 @@ RED.view = (function() {
|
||||
selectGroup(nodeGroup, !activeGroup, !!groupNodeSelectPrimed);
|
||||
if (activeGroup) {
|
||||
mousedown_node.selected = true;
|
||||
moving_set.push({n:mousedown_node});
|
||||
movingSet.add(mousedown_node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2930,12 +3010,7 @@ RED.view = (function() {
|
||||
}
|
||||
} else if (d.selected && (d3.event.ctrlKey||d3.event.metaKey)) {
|
||||
mousedown_node.selected = false;
|
||||
for (i=0;i<moving_set.length;i+=1) {
|
||||
if (moving_set[i].n === mousedown_node) {
|
||||
moving_set.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
movingSet.remove(mousedown_node);
|
||||
} else {
|
||||
|
||||
// if (d.g && !RED.nodes.group(d.g).selected) {
|
||||
@ -2958,7 +3033,7 @@ RED.view = (function() {
|
||||
for (var n=0;n<cnodes.length;n++) {
|
||||
cnodes[n].selected = true;
|
||||
cnodes[n].dirty = true;
|
||||
moving_set.push({n:cnodes[n]});
|
||||
movingSet.add(cnodes[n]);
|
||||
}
|
||||
} else if (!d.selected) {
|
||||
if (!d3.event.ctrlKey && !d3.event.metaKey) {
|
||||
@ -2967,7 +3042,7 @@ RED.view = (function() {
|
||||
exitActiveGroup();
|
||||
}
|
||||
mousedown_node.selected = true;
|
||||
moving_set.push({n:mousedown_node});
|
||||
movingSet.add(mousedown_node);
|
||||
}
|
||||
selected_link = null;
|
||||
if (d3.event.button != 2) {
|
||||
@ -3219,14 +3294,14 @@ RED.view = (function() {
|
||||
g.dirty = true;
|
||||
}
|
||||
if (addToMovingSet !== false) {
|
||||
moving_set.push({n:g});
|
||||
movingSet.add(g);
|
||||
}
|
||||
if (includeNodes) {
|
||||
var currentSet = new Set(moving_set.map(function(n) { return n.n }));
|
||||
var currentSet = new Set(movingSet.nodes());
|
||||
var allNodes = RED.group.getNodes(g,true);
|
||||
allNodes.forEach(function(n) {
|
||||
if (!currentSet.has(n)) {
|
||||
moving_set.push({n:n})
|
||||
movingSet.add(n)
|
||||
// n.selected = true;
|
||||
}
|
||||
n.dirty = true;
|
||||
@ -3240,12 +3315,7 @@ RED.view = (function() {
|
||||
group.active = true;
|
||||
group.dirty = true;
|
||||
activeGroup = group;
|
||||
for (var i = moving_set.length-1; i >= 0; i -= 1) {
|
||||
if (moving_set[i].n === group) {
|
||||
moving_set.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
movingSet.remove(group);
|
||||
}
|
||||
function exitActiveGroup() {
|
||||
if (activeGroup) {
|
||||
@ -3263,11 +3333,12 @@ RED.view = (function() {
|
||||
}
|
||||
var nodeSet = new Set(g.nodes);
|
||||
nodeSet.add(g);
|
||||
for (var i = moving_set.length-1; i >= 0; i -= 1) {
|
||||
if (nodeSet.has(moving_set[i].n) || moving_set[i].n === g) {
|
||||
moving_set[i].n.selected = false;
|
||||
moving_set[i].n.dirty = true;
|
||||
moving_set.splice(i,1);
|
||||
for (var i = movingSet.length()-1; i >= 0; i -= 1) {
|
||||
var msn = movingSet.get(i);
|
||||
if (nodeSet.has(msn.n) || msn.n === g) {
|
||||
msn.n.selected = false;
|
||||
msn.n.dirty = true;
|
||||
movingSet.remove(msn.n,i)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3351,11 +3422,11 @@ RED.view = (function() {
|
||||
function showTouchMenu(obj,pos) {
|
||||
var mdn = mousedown_node;
|
||||
var options = [];
|
||||
options.push({name:"delete",disabled:(moving_set.length===0 && selected_link === null),onselect:function() {deleteSelection();}});
|
||||
options.push({name:"cut",disabled:(moving_set.length===0),onselect:function() {copySelection();deleteSelection();}});
|
||||
options.push({name:"copy",disabled:(moving_set.length===0),onselect:function() {copySelection();}});
|
||||
options.push({name:"delete",disabled:(movingSet.length()===0 && selected_link === null),onselect:function() {deleteSelection();}});
|
||||
options.push({name:"cut",disabled:(movingSet.length()===0),onselect:function() {copySelection();deleteSelection();}});
|
||||
options.push({name:"copy",disabled:(movingSet.length()===0),onselect:function() {copySelection();}});
|
||||
options.push({name:"paste",disabled:(clipboard.length===0),onselect:function() {importNodes(clipboard,false,true);}});
|
||||
options.push({name:"edit",disabled:(moving_set.length != 1),onselect:function() { RED.editor.edit(mdn);}});
|
||||
options.push({name:"edit",disabled:(movingSet.length() != 1),onselect:function() { RED.editor.edit(mdn);}});
|
||||
options.push({name:"select",onselect:function() {selectAll();}});
|
||||
options.push({name:"undo",disabled:(RED.history.depth() === 0),onselect:function() {RED.history.pop();}});
|
||||
options.push({name:"add",onselect:function() {
|
||||
@ -4173,7 +4244,7 @@ RED.view = (function() {
|
||||
targets.forEach(function(n) {
|
||||
n.selected = true;
|
||||
n.dirty = true;
|
||||
moving_set.push({n:n});
|
||||
movingSet.add(n);
|
||||
});
|
||||
updateSelection();
|
||||
redraw();
|
||||
@ -4340,6 +4411,13 @@ RED.view = (function() {
|
||||
d.y = minY;
|
||||
d.w = maxX - minX;
|
||||
d.h = maxY - minY;
|
||||
// if set explicitly to false, this group has just been
|
||||
// imported so needed this initial resize calculation.
|
||||
// Now that's done, delete the flag so the normal
|
||||
// logic kicks in.
|
||||
if (d.groupMoved === false) {
|
||||
delete d.groupMoved;
|
||||
}
|
||||
} else {
|
||||
delete d.groupMoved;
|
||||
}
|
||||
@ -4388,12 +4466,12 @@ RED.view = (function() {
|
||||
var selectGroupRect = selectGroup.children[0];
|
||||
selectGroupRect.setAttribute("width",d.w+8)
|
||||
selectGroupRect.setAttribute("height",d.h+8)
|
||||
selectGroupRect.style.strokeOpacity = (d.selected || d.highlighted)?0.8:0;
|
||||
selectGroupRect.style.strokeOpacity = (d.active || d.selected || d.highlighted)?0.8:0;
|
||||
selectGroupRect.style.strokeDasharray = (d.active)?"10 4":"";
|
||||
selectGroupRect = selectGroup.children[1];
|
||||
selectGroupRect.setAttribute("width",d.w+8)
|
||||
selectGroupRect.setAttribute("height",d.h+8)
|
||||
selectGroupRect.style.strokeOpacity = (d.selected || d.highlighted)?0.8:0;
|
||||
selectGroupRect.style.strokeOpacity = (d.active || d.selected || d.highlighted)?0.8:0;
|
||||
selectGroupRect.style.strokeDasharray = (d.active)?"10 4":"";
|
||||
|
||||
if (d.highlighted) {
|
||||
@ -4517,21 +4595,25 @@ RED.view = (function() {
|
||||
if (addNewFlow && new_default_workspace) {
|
||||
RED.workspaces.show(new_default_workspace.id);
|
||||
}
|
||||
var new_ms = new_nodes.filter(function(n) { return n.hasOwnProperty("x") && n.hasOwnProperty("y") && n.z == RED.workspaces.active() }).map(function(n) { return {n:n};});
|
||||
new_ms = new_ms.concat(new_groups.filter(function(g) { return g.z === RED.workspaces.active()}).map(function(g) { return {n:g}}))
|
||||
var new_ms = new_nodes.filter(function(n) { return n.hasOwnProperty("x") && n.hasOwnProperty("y") && n.z == RED.workspaces.active() });
|
||||
new_ms = new_ms.concat(new_groups.filter(function(g) { return g.z === RED.workspaces.active()}))
|
||||
var new_node_ids = new_nodes.map(function(n){ n.changed = true; return n.id; });
|
||||
|
||||
clearSelection();
|
||||
movingSet.clear();
|
||||
movingSet.add(new_ms);
|
||||
|
||||
|
||||
// TODO: pick a more sensible root node
|
||||
if (new_ms.length > 0) {
|
||||
|
||||
|
||||
if (movingSet.length() > 0) {
|
||||
if (mouse_position == null) {
|
||||
mouse_position = [0,0];
|
||||
}
|
||||
|
||||
var dx = mouse_position[0];
|
||||
var dy = mouse_position[1];
|
||||
if (new_ms.length > 0) {
|
||||
var root_node = new_ms[0].n;
|
||||
if (movingSet.length() > 0) {
|
||||
var root_node = movingSet.get(0).n;
|
||||
dx = root_node.x;
|
||||
dy = root_node.y;
|
||||
}
|
||||
@ -4540,9 +4622,9 @@ RED.view = (function() {
|
||||
var minY = 0;
|
||||
var i;
|
||||
var node,group;
|
||||
|
||||
for (i=0;i<new_ms.length;i++) {
|
||||
node = new_ms[i];
|
||||
var l =movingSet.length();
|
||||
for (i=0;i<l;i++) {
|
||||
node = movingSet.get(i);
|
||||
node.n.selected = true;
|
||||
node.n.changed = true;
|
||||
node.n.moved = true;
|
||||
@ -4554,6 +4636,7 @@ RED.view = (function() {
|
||||
node.dx = node.n.x - mouse_position[0];
|
||||
node.dy = node.n.y - mouse_position[1];
|
||||
if (node.n.type === "group") {
|
||||
node.n.groupMoved = false;
|
||||
minX = Math.min(node.n.x-5,minX);
|
||||
minY = Math.min(node.n.y-5,minY);
|
||||
} else {
|
||||
@ -4561,8 +4644,8 @@ RED.view = (function() {
|
||||
minY = Math.min(node.n.y-node_height/2-5,minY);
|
||||
}
|
||||
}
|
||||
for (i=0;i<new_ms.length;i++) {
|
||||
node = new_ms[i];
|
||||
for (i=0;i<l;i++) {
|
||||
node = movingSet.get(i);
|
||||
node.n.x -= minX;
|
||||
node.n.y -= minY;
|
||||
node.dx -= minX;
|
||||
@ -4579,8 +4662,8 @@ RED.view = (function() {
|
||||
if (!touchImport) {
|
||||
mouse_mode = RED.state.IMPORT_DRAGGING;
|
||||
spliceActive = false;
|
||||
if (new_ms.length === 1) {
|
||||
node = new_ms[0];
|
||||
if (movingSet.length() === 1) {
|
||||
node = movingSet.get(0);
|
||||
spliceActive = node.n.hasOwnProperty("_def") &&
|
||||
((node.n.hasOwnProperty("inputs") && node.n.inputs > 0) || (!node.n.hasOwnProperty("inputs") && node.n._def.inputs > 0)) &&
|
||||
((node.n.hasOwnProperty("outputs") && node.n.outputs > 0) || (!node.n.hasOwnProperty("outputs") && node.n._def.outputs > 0))
|
||||
@ -4594,8 +4677,6 @@ RED.view = (function() {
|
||||
RED.history.pop();
|
||||
mouse_mode = 0;
|
||||
});
|
||||
clearSelection();
|
||||
moving_set = new_ms;
|
||||
}
|
||||
|
||||
var historyEvent = {
|
||||
@ -4607,7 +4688,7 @@ RED.view = (function() {
|
||||
subflows:new_subflows,
|
||||
dirty:RED.nodes.dirty()
|
||||
};
|
||||
if (new_ms.length === 0) {
|
||||
if (movingSet.length() === 0) {
|
||||
RED.nodes.dirty(true);
|
||||
}
|
||||
if (activeSubflow) {
|
||||
@ -4692,10 +4773,10 @@ RED.view = (function() {
|
||||
var changed = false;
|
||||
if (workspaceSelection.length > 0) {
|
||||
// TODO: toggle workspace state
|
||||
} else if (moving_set.length > 0) {
|
||||
} else if (movingSet.length() > 0) {
|
||||
var historyEvents = [];
|
||||
for (var i=0;i<moving_set.length;i++) {
|
||||
var node = moving_set[i].n;
|
||||
for (var i=0;i<movingSet.length();i++) {
|
||||
var node = movingSet.get(i).n;
|
||||
if (node.type !== "group" && node.type !== "subflow") {
|
||||
if (isDisabled != node.d) {
|
||||
historyEvents.push({
|
||||
@ -4734,8 +4815,8 @@ RED.view = (function() {
|
||||
|
||||
var allNodes = new Set();
|
||||
|
||||
if (moving_set.length > 0) {
|
||||
moving_set.forEach(function(n) {
|
||||
if (movingSet.length() > 0) {
|
||||
movingSet.forEach(function(n) {
|
||||
if (n.n.type !== 'group') {
|
||||
allNodes.add(n.n);
|
||||
}
|
||||
@ -4796,12 +4877,13 @@ RED.view = (function() {
|
||||
if (selectedNode) {
|
||||
selectedNode.selected = true;
|
||||
selectedNode.dirty = true;
|
||||
moving_set = [{n:selectedNode}];
|
||||
movingSet.clear();
|
||||
movingSet.add(selectedNode);
|
||||
}
|
||||
} else if (selection) {
|
||||
if (selection.nodes) {
|
||||
updateActiveNodes();
|
||||
moving_set = [];
|
||||
movingSet.clear();
|
||||
// TODO: this selection group span groups
|
||||
// - if all in one group -> activate the group
|
||||
// - if in multiple groups (or group/no-group)
|
||||
@ -4810,7 +4892,7 @@ RED.view = (function() {
|
||||
if (n.type !== "group") {
|
||||
n.selected = true;
|
||||
n.dirty = true;
|
||||
moving_set.push({n:n});
|
||||
movingSet.add(n);
|
||||
} else {
|
||||
selectGroup(n,true);
|
||||
}
|
||||
@ -4917,7 +4999,7 @@ RED.view = (function() {
|
||||
if (n) {
|
||||
n.selected = true;
|
||||
n.dirty = true;
|
||||
moving_set.push({n:n});
|
||||
movingSet.add(n);
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -4953,7 +5035,7 @@ RED.view = (function() {
|
||||
text: RED._("common.label.done"),
|
||||
class: "primary",
|
||||
click: function(e) {
|
||||
var selection = moving_set.map(function(n) { return n.n;});
|
||||
var selection = movingSet.nodes()
|
||||
selectNodesOptions.done(selection);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user