@@ -259,11 +259,11 @@ private void OnConnectionUpdated(BaseLinkModel baseLinkModel, Anchor old, Anchor
259259 {
260260 if ( source . Connection . Type . IsAssignableTo ( destination . Connection . Type , out var newTypes ) && newTypes . Count != 0 )
261261 {
262- PropagateNewGeneric ( source . Connection . Parent , newTypes ) ;
262+ PropagateNewGeneric ( source . Connection . Parent , newTypes , false ) ;
263263 }
264264 }
265265 else if ( destination . Connection . Type is UndefinedGenericType destinationType && source . Connection . Type is not UndefinedGenericType )
266- PropagateNewGeneric ( destination . Connection . Parent , new Dictionary < UndefinedGenericType , TypeBase > ( ) { [ destinationType ] = source . Connection . Type } ) ;
266+ PropagateNewGeneric ( destination . Connection . Parent , new Dictionary < UndefinedGenericType , TypeBase > ( ) { [ destinationType ] = source . Connection . Type } , false ) ;
267267
268268 // we have to remove the textbox ?
269269 if ( destination . Connection . Connections . Count == 1 && destination . Connection . Type . AllowTextboxEdit )
@@ -277,12 +277,14 @@ private void OnConnectionUpdated(BaseLinkModel baseLinkModel, Anchor old, Anchor
277277 if ( source . Connection . Type . IsExec && source . Connection . Connections . Count > 1 && link . Target . Model is GraphPortModel target )
278278 {
279279 Diagram . Links . Remove ( Diagram . Links . First ( x => ( x . Source . Model as GraphPortModel ) ? . Connection == source . Connection && ( x . Target . Model as GraphPortModel ) ? . Connection != target . Connection ) ) ;
280- Graph . Disconnect ( source . Connection , source . Connection . Connections . First ( x => x != target . Connection ) , true ) ;
280+ Graph . Disconnect ( source . Connection , source . Connection . Connections . First ( x => x != target . Connection ) , false ) ;
281281 }
282282
283283 }
284284
285285 UpdateVerticesInConnection ( source . Connection , destination . Connection , baseLinkModel ) ;
286+
287+ Graph . RaiseGraphChanged ( true ) ;
286288 } ) ;
287289 }
288290
@@ -422,7 +424,7 @@ public void OnPortDroppedOnCanvas(Connection connection, global::Blazor.Diagrams
422424
423425 private void OnNewNodeTypeSelected ( NodeProvider . NodeSearchResult searchResult )
424426 {
425- var node = Graph . AddNode ( searchResult ) ;
427+ var node = Graph . AddNode ( searchResult , false ) ;
426428 node . AddDecoration ( new NodeDecorationPosition ( new ( PopupNodePosition . X , PopupNodePosition . Y ) ) ) ;
427429
428430 Diagram . Batch ( ( ) =>
@@ -452,7 +454,7 @@ private void OnNewNodeTypeSelected(NodeProvider.NodeSearchResult searchResult)
452454 // if we found a connection, connect them together
453455 if ( destination != null )
454456 {
455- Graph . Connect ( PopupNodeConnection , destination , true ) ;
457+ Graph . Connect ( PopupNodeConnection , destination , false ) ;
456458
457459 if ( destination . Connections . Count == 1 && destination . Type . AllowTextboxEdit )
458460 UpdateConnectionType ( destination ) ;
@@ -465,15 +467,15 @@ private void OnNewNodeTypeSelected(NodeProvider.NodeSearchResult searchResult)
465467 // check if we need to propagate some generic
466468 if ( ! destination . Type . IsExec && source . Type . IsAssignableTo ( target . Type , out var changedGenerics ) )
467469 {
468- PropagateNewGeneric ( node , changedGenerics ) ;
469- PropagateNewGeneric ( destination . Parent , changedGenerics ) ;
470+ PropagateNewGeneric ( node , changedGenerics , false ) ;
471+ PropagateNewGeneric ( destination . Parent , changedGenerics , false ) ;
470472 }
471473 else if ( source . Type . IsExec && source . Connections . Count > 1 ) // check if we have to disconnect the previously connected exec
472474 {
473475 Diagram . Links . Remove ( Diagram . Links . First ( x => ( x . Source . Model as GraphPortModel ) ? . Connection == source && ( x . Target . Model as GraphPortModel ) ? . Connection != target ) ) ;
474476 var toRemove = source . Connections . FirstOrDefault ( x => x != target ) ;
475477 if ( toRemove != null )
476- Graph . Disconnect ( source , toRemove , true ) ;
478+ Graph . Disconnect ( source , toRemove , false ) ;
477479 }
478480 }
479481 }
@@ -482,7 +484,10 @@ private void OnNewNodeTypeSelected(NodeProvider.NodeSearchResult searchResult)
482484
483485 CreateGraphNodeModel ( node ) ;
484486 AddNodeLinks ( node , false ) ;
487+
488+ UpdateNodes ( Graph . Nodes . Values . ToList ( ) ) ;
485489 } ) ;
490+
486491 }
487492
488493 #endregion
@@ -535,14 +540,15 @@ private void OnGenericTypeSelected(TypeBase type)
535540 if ( PopupNode == null || GenericTypeSelectionMenuGeneric == null )
536541 return ;
537542
538- PropagateNewGeneric ( PopupNode , new Dictionary < UndefinedGenericType , TypeBase > ( ) { [ GenericTypeSelectionMenuGeneric ] = type } ) ;
543+ PropagateNewGeneric ( PopupNode , new Dictionary < UndefinedGenericType , TypeBase > ( ) { [ GenericTypeSelectionMenuGeneric ] = type } , false ) ;
539544
545+ // Prefer updating the nodes directly instead of calling Graph.RaiseGraphChanged(true) to be sure it is called as soon as possible
540546 UpdateNodes ( Graph . Nodes . Values . ToList ( ) ) ;
541547
542548 CancelPopup ( ) ;
543549 }
544550
545- private void PropagateNewGeneric ( Node node , IReadOnlyDictionary < UndefinedGenericType , TypeBase > changedGenerics )
551+ private void PropagateNewGeneric ( Node node , IReadOnlyDictionary < UndefinedGenericType , TypeBase > changedGenerics , bool requireUIRefresh )
546552 {
547553 foreach ( var port in node . InputsAndOutputs ) // check if any of the ports have the generic we just solved
548554 {
@@ -560,14 +566,14 @@ private void PropagateNewGeneric(Node node, IReadOnlyDictionary<UndefinedGeneric
560566 var source = isPortInput ? other : port ;
561567 var target = isPortInput ? port : other ;
562568 if ( source . Type . IsAssignableTo ( target . Type , out var changedGenerics2 ) && changedGenerics2 . Count != 0 )
563- PropagateNewGeneric ( other . Parent , changedGenerics2 ) ;
569+ PropagateNewGeneric ( other . Parent , changedGenerics2 , requireUIRefresh ) ;
564570 else if ( ( changedGenerics2 ? . Count ?? 0 ) != 0 ) // damn, looks like changing the generic made it so we can't link to this connection anymore
565571 Graph . Disconnect ( port , other , false ) ; // no need to refresh UI here as it'll already be refresh at the end of this method
566572 }
567573 }
568574 }
569575
570- Graph . RaiseGraphChanged ( true ) ;
576+ Graph . RaiseGraphChanged ( requireUIRefresh ) ;
571577 }
572578
573579 #endregion
0 commit comments