@@ -533,7 +533,7 @@ private void PopulateProjectReferenceGraph()
533533
534534 var searchButton = new Button
535535 {
536- Content = "Search" ,
536+ Content = "Search for $projectreference " ,
537537 VerticalAlignment = VerticalAlignment . Center ,
538538 Margin = new Thickness ( 0 , 0 , 8 , 0 ) ,
539539 BorderThickness = new Thickness ( ) ,
@@ -559,30 +559,47 @@ private void PopulateProjectReferenceGraph()
559559
560560 var showTextButton = new Button
561561 {
562- Content = "Show text" ,
562+ Content = "Show graph text" ,
563563 VerticalAlignment = VerticalAlignment . Center ,
564+ Padding = new Thickness ( 0 , 0 , 8 , 0 ) ,
564565 Margin = new Thickness ( 0 , 0 , 8 , 0 ) ,
565- BorderThickness = new Thickness ( )
566+ BorderThickness = new Thickness ( 0 , 0 , 1 , 0 )
566567 } ;
567568 showTextButton . Click += ( s , e ) =>
568569 {
569570 var text = graph . GetDotText ( ) ;
570571 DisplayText ( text , "Project Reference Graph" ) ;
571572 } ;
572573
574+ var searchTextBox = new TextBox
575+ {
576+ VerticalAlignment = VerticalAlignment . Center ,
577+ Margin = new Thickness ( 0 , 0 , 8 , 0 ) ,
578+ MinWidth = 200
579+ } ;
580+ var locateButton = new Button
581+ {
582+ Content = "Locate on canvas" ,
583+ VerticalAlignment = VerticalAlignment . Center ,
584+ Margin = new Thickness ( 0 , 0 , 8 , 0 ) ,
585+ BorderThickness = new Thickness ( )
586+ } ;
587+
573588 toolbar . Children . Add ( showTextButton ) ;
589+ toolbar . Children . Add ( searchTextBox ) ;
590+ toolbar . Children . Add ( locateButton ) ;
574591 toolbar . Children . Add ( projectNameTextBlock ) ;
575592 toolbar . Children . Add ( searchButton ) ;
576593
577594 var maxHeight = graph . Vertices . Max ( g => g . Height ) ;
578595 var maxDepth = graph . Vertices . Max ( g => g . Depth ) ;
579596
580597 var grid = new Grid ( ) ;
581- var control = new StackPanel ( ) { Orientation = Orientation . Vertical } ;
598+ var layersControl = new StackPanel ( ) { Orientation = Orientation . Vertical } ;
582599 var canvas = new Canvas ( ) ;
583600
584601 grid . Children . Add ( canvas ) ;
585- grid . Children . Add ( control ) ;
602+ grid . Children . Add ( layersControl ) ;
586603
587604 bool isDarkTheme = SettingsService . UseDarkTheme ;
588605
@@ -607,7 +624,7 @@ private void PopulateProjectReferenceGraph()
607624
608625 foreach ( var vertexGroup in graph . Vertices . GroupBy ( v => v . Height ) . OrderBy ( g => g . Key ) )
609626 {
610- var stack = new StackPanel ( ) { Orientation = Orientation . Horizontal } ;
627+ var layerPanel = new StackPanel { Orientation = Orientation . Horizontal } ;
611628
612629 foreach ( var vertex in vertexGroup . OrderByDescending ( s => s . InDegree ) . ThenBy ( s => s . Title ) )
613630 {
@@ -642,64 +659,12 @@ private void PopulateProjectReferenceGraph()
642659
643660 projectControl . MouseDown += ( s , e ) =>
644661 {
645- var node = projectControl . Tag as Vertex ;
646-
647- canvas . Children . Clear ( ) ;
648-
649- if ( selectedControls . Contains ( projectControl ) )
650- {
651- selectedControls . Remove ( projectControl ) ;
652- projectNameTextBlock . Text = "" ;
653- projectNameTextBlock . Visibility = Visibility . Hidden ;
654- searchButton . Visibility = Visibility . Hidden ;
655- return ;
656- }
657-
658- selectedControls . Clear ( ) ;
659- selectedControls . Add ( projectControl ) ;
660-
661- var sourceRect = GetRectOnCanvas ( projectControl ) ;
662-
663- projectNameTextBlock . Text = node ? . Value ;
664- projectNameTextBlock . Visibility = Visibility . Visible ;
665- searchButton . Visibility = Visibility . Visible ;
666-
667- if ( node . Outgoing != null )
668- {
669- foreach ( var outgoing in node . Outgoing )
670- {
671- if ( vertexByControl . TryGetValue ( outgoing , out var destinationControl ) )
672- {
673- var canvasRect = GetRectOnCanvas ( destinationControl ) ;
674- var sourcePoint = new Point ( sourceRect . Left + sourceRect . Width / 2 , sourceRect . Top ) ;
675- var destinationPoint = new Point ( canvasRect . Left + canvasRect . Width / 2 , canvasRect . Bottom ) ;
676- AddLine ( sourcePoint , destinationPoint , outgoingBrush ) ;
677- AddRectangle ( canvasRect , new SolidColorBrush ( outgoingColor ) ) ;
678- }
679- }
680- }
681-
682- if ( node . Incoming != null )
683- {
684- foreach ( var incoming in node . Incoming )
685- {
686- if ( vertexByControl . TryGetValue ( incoming , out var sourceControl ) )
687- {
688- var canvasRect = GetRectOnCanvas ( sourceControl ) ;
689- var sourcePoint = new Point ( sourceRect . Left + sourceRect . Width / 2 , sourceRect . Bottom ) ;
690- var destinationPoint = new Point ( canvasRect . Left + canvasRect . Width / 2 , canvasRect . Top ) ;
691- AddLine ( sourcePoint , destinationPoint , incomingBrush ) ;
692- AddRectangle ( canvasRect , new SolidColorBrush ( incomingColor ) ) ;
693- }
694- }
695- }
696-
697- AddRectangle ( sourceRect , new SolidColorBrush ( border ) , Brushes . PaleGreen ) ;
662+ SelectControl ( projectControl ) ;
698663 } ;
699- stack . Children . Add ( projectControl ) ;
664+ layerPanel . Children . Add ( projectControl ) ;
700665 }
701666
702- control . Children . Add ( stack ) ;
667+ layersControl . Children . Add ( layerPanel ) ;
703668 }
704669
705670 Rect GetRectOnCanvas ( FrameworkElement control )
@@ -737,13 +702,113 @@ void AddRectangle(Rect rect, Brush stroke, Brush fill = null)
737702 canvas . Children . Add ( rectangleShape ) ;
738703 }
739704
705+ IEnumerable < TextBlock > AllTextBlocks ( )
706+ {
707+ foreach ( var layer in layersControl . Children . OfType < Panel > ( ) )
708+ {
709+ foreach ( var textBlock in layer . Children . OfType < TextBlock > ( ) )
710+ {
711+ yield return textBlock ;
712+ }
713+ }
714+ }
715+
716+ void SelectControl ( TextBlock projectControl )
717+ {
718+ var node = projectControl . Tag as Vertex ;
719+
720+ canvas . Children . Clear ( ) ;
721+
722+ if ( selectedControls . Contains ( projectControl ) )
723+ {
724+ selectedControls . Remove ( projectControl ) ;
725+ projectNameTextBlock . Text = "" ;
726+ projectNameTextBlock . Visibility = Visibility . Hidden ;
727+ searchButton . Visibility = Visibility . Hidden ;
728+ return ;
729+ }
730+
731+ selectedControls . Clear ( ) ;
732+ selectedControls . Add ( projectControl ) ;
733+
734+ var sourceRect = GetRectOnCanvas ( projectControl ) ;
735+
736+ projectNameTextBlock . Text = node ? . Value ;
737+ projectNameTextBlock . Visibility = Visibility . Visible ;
738+ searchButton . Visibility = Visibility . Visible ;
739+
740+ if ( node . Outgoing != null )
741+ {
742+ foreach ( var outgoing in node . Outgoing )
743+ {
744+ if ( vertexByControl . TryGetValue ( outgoing , out var destinationControl ) )
745+ {
746+ var canvasRect = GetRectOnCanvas ( destinationControl ) ;
747+ var sourcePoint = new Point ( sourceRect . Left + sourceRect . Width / 2 , sourceRect . Top ) ;
748+ var destinationPoint = new Point ( canvasRect . Left + canvasRect . Width / 2 , canvasRect . Bottom ) ;
749+ AddLine ( sourcePoint , destinationPoint , outgoingBrush ) ;
750+ AddRectangle ( canvasRect , new SolidColorBrush ( outgoingColor ) ) ;
751+ }
752+ }
753+ }
754+
755+ if ( node . Incoming != null )
756+ {
757+ foreach ( var incoming in node . Incoming )
758+ {
759+ if ( vertexByControl . TryGetValue ( incoming , out var sourceControl ) )
760+ {
761+ var canvasRect = GetRectOnCanvas ( sourceControl ) ;
762+ var sourcePoint = new Point ( sourceRect . Left + sourceRect . Width / 2 , sourceRect . Bottom ) ;
763+ var destinationPoint = new Point ( canvasRect . Left + canvasRect . Width / 2 , canvasRect . Top ) ;
764+ AddLine ( sourcePoint , destinationPoint , incomingBrush ) ;
765+ AddRectangle ( canvasRect , new SolidColorBrush ( incomingColor ) ) ;
766+ }
767+ }
768+ }
769+
770+ AddRectangle ( sourceRect , new SolidColorBrush ( border ) , Brushes . PaleGreen ) ;
771+ }
772+
740773 var scrollViewer = new ScrollViewer ( )
741774 {
742775 HorizontalScrollBarVisibility = ScrollBarVisibility . Auto ,
743776 VerticalScrollBarVisibility = ScrollBarVisibility . Auto
744777 } ;
745778 scrollViewer . Content = grid ;
746779
780+ locateButton . Click += ( s , e ) =>
781+ {
782+ e . Handled = true ;
783+ Locate ( ) ;
784+ } ;
785+
786+ searchTextBox . KeyDown += ( s , e ) =>
787+ {
788+ if ( e . KeyboardDevice . Modifiers == ModifierKeys . None && e . Key == Key . Return )
789+ {
790+ e . Handled = true ;
791+ Locate ( ) ;
792+ }
793+ } ;
794+
795+ void Locate ( )
796+ {
797+ var text = searchTextBox . Text ;
798+ if ( ! string . IsNullOrWhiteSpace ( text ) )
799+ {
800+ var found = AllTextBlocks ( )
801+ . OrderBy ( t => t . Text . Length )
802+ . ThenBy ( t => t . Text )
803+ . FirstOrDefault ( t => t . Text . ContainsIgnoreCase ( text ) && ! selectedControls . Contains ( t ) ) ;
804+ if ( found != null )
805+ {
806+ found . BringIntoView ( ) ;
807+ SelectControl ( found ) ;
808+ }
809+ }
810+ }
811+
747812 dockPanel . Children . Add ( scrollViewer ) ;
748813
749814 projectReferenceGraphTab . Content = dockPanel ;
0 commit comments