[info-sidebar] Handle node/group/flows with \\n in their name

This commit is contained in:
Nick O'Leary 2020-05-19 17:53:20 +01:00
parent b8784185e8
commit 15cc88de6c
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 34 additions and 8 deletions

View File

@ -69,6 +69,10 @@ RED.sidebar.info.outliner = (function() {
console.log("Definition error: "+type+".label",err); console.log("Definition error: "+type+".label",err);
} }
} }
var newlineIndex = label.indexOf("\\n");
if (newlineIndex > -1) {
label = label.substring(0,newlineIndex)+"...";
}
return label; return label;
} }
@ -92,7 +96,12 @@ RED.sidebar.info.outliner = (function() {
function getFlowLabel(n) { function getFlowLabel(n) {
var div = $('<div>',{class:"red-ui-info-outline-item red-ui-info-outline-item-flow"}); var div = $('<div>',{class:"red-ui-info-outline-item red-ui-info-outline-item-flow"});
var contentDiv = $('<div>',{class:"red-ui-search-result-description red-ui-info-outline-item-label"}).appendTo(div); var contentDiv = $('<div>',{class:"red-ui-search-result-description red-ui-info-outline-item-label"}).appendTo(div);
contentDiv.text(typeof n === "string"? n : n.label); var label = (typeof n === "string")? n : n.label;
var newlineIndex = label.indexOf("\\n");
if (newlineIndex > -1) {
label = label.substring(0,newlineIndex)+"...";
}
contentDiv.text(label);
addControls(n, div); addControls(n, div);
return div; return div;
} }
@ -292,7 +301,13 @@ RED.sidebar.info.outliner = (function() {
} }
function onFlowChange(n) { function onFlowChange(n) {
var existingObject = objects[n.id]; var existingObject = objects[n.id];
existingObject.element.find(".red-ui-info-outline-item-label").text(n.label || n.id);
var label = n.label || n.id;
var newlineIndex = label.indexOf("\\n");
if (newlineIndex > -1) {
label = label.substring(0,newlineIndex)+"...";
}
existingObject.element.find(".red-ui-info-outline-item-label").text(label);
existingObject.element.toggleClass("red-ui-info-outline-item-disabled", !!n.disabled) existingObject.element.toggleClass("red-ui-info-outline-item-disabled", !!n.disabled)
existingObject.treeList.container.toggleClass("red-ui-info-outline-item-disabled", !!n.disabled) existingObject.treeList.container.toggleClass("red-ui-info-outline-item-disabled", !!n.disabled)
} }

View File

@ -251,7 +251,12 @@ RED.sidebar.info = (function() {
propertiesPanelHeaderIcon.empty(); propertiesPanelHeaderIcon.empty();
RED.utils.createNodeIcon(node).appendTo(propertiesPanelHeaderIcon); RED.utils.createNodeIcon(node).appendTo(propertiesPanelHeaderIcon);
propertiesPanelHeaderLabel.text(RED.utils.getNodeLabel(node, node.type+": "+node.id)); var objectLabel = RED.utils.getNodeLabel(node, node.type+": "+node.id)
var newlineIndex = objectLabel.indexOf("\\n");
if (newlineIndex > -1) {
objectLabel = objectLabel.substring(0,newlineIndex)+"...";
}
propertiesPanelHeaderLabel.text(objectLabel);
propertiesPanelHeaderReveal.show(); propertiesPanelHeaderReveal.show();
selectedObject = node; selectedObject = node;

View File

@ -2186,7 +2186,7 @@ if (DEBUG_EVENTS) { console.warn("clearSelection", mouse_mode); }
result_temp += str.charAt(i); result_temp += str.charAt(i);
i++; i++;
} else if (str.charAt(i+1) == 'n') { } else if (str.charAt(i+1) == 'n') {
result.push(result_temp); result.push(result_temp.trim());
if (i+1 == str.length-1) { if (i+1 == str.length-1) {
result.push(''); result.push('');
} }
@ -2201,7 +2201,7 @@ if (DEBUG_EVENTS) { console.warn("clearSelection", mouse_mode); }
} }
} }
if (count == 0 || count < str.length) { if (count == 0 || count < str.length) {
result.push(result_temp); result.push(result_temp.trim());
} }
separateTextByLineBreak = result; separateTextByLineBreak = result;
return result; return result;
@ -2503,6 +2503,12 @@ if (DEBUG_EVENTS) { console.warn("portMouseUp", mouse_mode,d); }
.attr("transform","translate("+x+","+y+")") .attr("transform","translate("+x+","+y+")")
.attr("class","red-ui-flow-port-tooltip"); .attr("class","red-ui-flow-port-tooltip");
// First check for a user-provided newline - "\\n"
var newContent = content.split(/\\n/,1)[0];
if (newContent.length !== content.length) {
content = newContent+"...";
}
var lines = content.split("\n"); var lines = content.split("\n");
var labelWidth = 6; var labelWidth = 6;
var labelHeight = 12; var labelHeight = 12;
@ -4214,7 +4220,7 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
} }
d.w = Math.max(d.minWidth,d.w); d.w = Math.max(d.minWidth,d.w);
if (d.style.label && d.labels) { if (d.style.label && d.labels) {
var h = (d.labels.length -1) *15; var h = (d.labels.length -1) * 16;
var labelPos = d.style["label-position"] || "nw"; var labelPos = d.style["label-position"] || "nw";
d.h += h; d.h += h;
if (labelPos[0] === "n") { if (labelPos[0] === "n") {
@ -4271,7 +4277,7 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
if (labelPos[0] === 'n') { if (labelPos[0] === 'n') {
labelY = 0+15; // Allow for font-height labelY = 0+15; // Allow for font-height
} else { } else {
labelY = d.h - 5 -(d.labels.length -1) *15; labelY = d.h - 5 -(d.labels.length -1) * 16;
} }
if (labelPos[1] === 'w') { if (labelPos[1] === 'w') {
labelX = 5; labelX = 5;
@ -4296,7 +4302,7 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
.text(name) .text(name)
.attr("x", 0) .attr("x", 0)
.attr("y", ypos); .attr("y", ypos);
ypos += 15; ypos += 16;
}); });
} }
} }