@@ -41,6 +41,8 @@ public class CodeBlockNodeModel : NodeModel
4141 private string code = string . Empty ;
4242 private List < string > inputIdentifiers = new List < string > ( ) ;
4343 private List < string > inputPortNames = new List < string > ( ) ;
44+ private List < string > outputPortNames = new List < string > ( ) ;
45+ private List < string > outputPortTooltips = new List < string > ( ) ;
4446 private string previewVariable ;
4547 private readonly LibraryServices libraryServices ;
4648
@@ -783,6 +785,9 @@ private void ProcessCode(out string errorMessage, out string warningMessage,
783785 ParseParam = new ParseParam ( GUID , code , resolver ) ;
784786
785787 codeStatements . Clear ( ) ;
788+ outputPortNames . Clear ( ) ;
789+ outputPortTooltips . Clear ( ) ;
790+
786791 try
787792 {
788793 var priorNames = libraryServices . GetPriorNames ( ) ;
@@ -797,7 +802,20 @@ private void ProcessCode(out string errorMessage, out string warningMessage,
797802 {
798803 // Create a statement variable from the generated nodes
799804 codeStatements . Add ( Statement . CreateInstance ( parsedNode ) ) ;
800- }
805+
806+ if ( parsedNode is BinaryExpressionNode binExp )
807+ {
808+ var right = binExp . RightNode ;
809+ var left = binExp . LeftNode ;
810+
811+ var portLabel = IsTempIdentifier ( left . Name )
812+ ? CodeBlockUtils . InferStaticTypeFromNode ( right )
813+ : left . Name ;
814+
815+ outputPortNames . Add ( portLabel ) ;
816+ }
817+ }
818+ outputPortTooltips = CodeBlockUtils . GetCleanedCodeExpressionsForTooltips ( code ) ;
801819 }
802820 else
803821 {
@@ -1007,15 +1025,26 @@ private void SetOutputPorts()
10071025 // Clear out all the output port models
10081026 OutPorts . RemoveAll ( ( p ) => true ) ;
10091027
1028+ int i = 0 ;
1029+
10101030 foreach ( var def in allDefs )
10111031 {
1032+ if ( i >= outputPortNames . Count ) break ;
1033+
1034+ var label = outputPortNames [ i ] ;
10121035 var tooltip = IsTempIdentifier ( def . Key ) ? string . Format ( Resources . CodeBlockTempIdentifierOutputLabel , def . Value ) : def . Key ;
10131036
1014- OutPorts . Add ( new PortModel ( PortType . Output , this , new PortData ( string . Empty , tooltip )
1037+ // Trim long labels
1038+ int maxLength = Configurations . CBNMaxPortNameLength ;
1039+ if ( label . Length > maxLength ) label = label . Remove ( maxLength - 3 ) + "..." ;
1040+
1041+ OutPorts . Add ( new PortModel ( PortType . Output , this , new PortData ( label , tooltip )
10151042 {
10161043 LineIndex = def . Value - 1 , // Logical line index.
10171044 Height = Configurations . CodeBlockOutputPortHeightInPixels ,
10181045 } ) ) ;
1046+
1047+ i ++ ;
10191048 }
10201049 }
10211050
@@ -1269,7 +1298,7 @@ private string LocalizeIdentifier(string identifierName)
12691298 return string . Format ( "{0}_{1}" , identifierName , AstIdentifierGuid ) ;
12701299 }
12711300
1272-
1301+
12731302
12741303 private class IdentifierInPlaceMapper : AstReplacer
12751304 {
@@ -1496,7 +1525,7 @@ public static void GetReferencedVariables(Node astNode, List<Variable> refVariab
14961525 //Or node not completely implemented YET
14971526 }
14981527 }
1499-
1528+
15001529 /// <summary>
15011530 /// Returns the names of the variables that have been declared in the statement
15021531 /// </summary>
@@ -1708,7 +1737,7 @@ public Variable(IdentifierNode identNode)
17081737 Row = identNode . line ;
17091738 StartColumn = identNode . col ;
17101739 }
1711-
1740+
17121741 /// <summary>
17131742 /// Moves column index back only if variable is not an expression.
17141743 /// </summary>
0 commit comments