mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #2569 from node-red/node-labels
Add action to toggle node label visiblity
This commit is contained in:
commit
fdc721baa1
@ -120,8 +120,69 @@ RED.view.tools = (function() {
|
||||
}
|
||||
}
|
||||
|
||||
function setSelectedNodeLabelState(labelShown) {
|
||||
var selection = RED.view.selection();
|
||||
var historyEvents = [];
|
||||
var nodes = [];
|
||||
if (selection.nodes) {
|
||||
selection.nodes.forEach(function(n) {
|
||||
if (n.type !== 'subflow' && n.type !== 'group') {
|
||||
nodes.push(n);
|
||||
} else if (n.type === 'group') {
|
||||
nodes = nodes.concat( RED.group.getNodes(n,true));
|
||||
}
|
||||
});
|
||||
}
|
||||
nodes.forEach(function(n) {
|
||||
var modified = false;
|
||||
var oldValue = n.l === undefined?true:n.l;
|
||||
var isLink = /^link (in|out)$/.test(n._def.type);
|
||||
|
||||
if (labelShown) {
|
||||
if (n.l === false || (isLink && !n.hasOwnProperty('l'))) {
|
||||
n.l = true;
|
||||
modified = true;
|
||||
}
|
||||
} else {
|
||||
if ((!isLink && (!n.hasOwnProperty('l') || n.l === true)) || (isLink && n.l === true) ) {
|
||||
n.l = false;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (modified) {
|
||||
historyEvents.push({
|
||||
t: "edit",
|
||||
node: n,
|
||||
changed: n.changed,
|
||||
changes: {
|
||||
l: oldValue
|
||||
}
|
||||
})
|
||||
n.changed = true;
|
||||
n.dirty = true;
|
||||
n.resize = true;
|
||||
}
|
||||
})
|
||||
|
||||
if (historyEvents.length > 0) {
|
||||
RED.history.push({
|
||||
t: "multi",
|
||||
events: historyEvents,
|
||||
dirty: RED.nodes.dirty()
|
||||
})
|
||||
RED.nodes.dirty(true);
|
||||
}
|
||||
|
||||
RED.view.redraw();
|
||||
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
init: function() {
|
||||
RED.actions.add("core:show-selected-node-labels", function() { setSelectedNodeLabelState(true); })
|
||||
RED.actions.add("core:hide-selected-node-labels", function() { setSelectedNodeLabelState(false); })
|
||||
|
||||
RED.actions.add("core:align-selection-to-grid", alignToGrid);
|
||||
|
||||
RED.actions.add("core:scroll-view-up", function() { RED.view.scroll(0,-RED.view.gridSize());});
|
||||
|
Loading…
Reference in New Issue
Block a user