11using Avalonia ;
22using Avalonia . Controls ;
3+ using Avalonia . Media ;
34using Avalonia . Threading ;
45using Avalonia . VisualTree ;
56using SourceGit . Views ;
@@ -10,9 +11,11 @@ internal static class Program
1011 private static void Main ( )
1112 {
1213 SourceGit . App . BuildAvaloniaApp ( ) . SetupWithoutStarting ( ) ;
13- var text = new ChangePathTextBlock { Path = "very/long/directory/structure/filename.cs" } ;
14+ var text = new ChangePathTextBlock { Foreground = Brushes . White , Path = "very/long/directory/structure/filename.cs" } ;
1415 Measure ( text , 1000 ) ;
1516 Check ( text . Text == text . Path , "Full path fits" ) ;
17+ text . DirectoryForeground = Brushes . DarkGray ;
18+ Measure ( text , 1000 ) ;
1619 Measure ( text , 180 ) ;
1720 Check ( text . Text . StartsWith ( "…" ) && text . Text . EndsWith ( "filename.cs" ) , "Leading ellipsis preserves filename" ) ;
1821 Check ( text . DesiredSize . Width <= 180 , "Trimmed path fits" ) ;
@@ -57,12 +60,14 @@ private static void Main()
5760 Dispatcher . UIThread . RunJobs ( ) ;
5861 var label = view . GetVisualDescendants ( ) . OfType < ChangePathTextBlock > ( ) . Single ( ) ;
5962 Check ( label . Text . StartsWith ( "…" ) && label . Text . EndsWith ( "filename.cs" ) , "Actual staged/unstaged template truncates correctly" ) ;
63+ CheckPathColors ( label ) ;
6064 var preferences = SourceGit . ViewModels . Preferences . Instance ;
6165 preferences . SetCanModify ( ) ;
6266 preferences . TrimLeadingPathsInChanges = false ;
6367 for ( var i = 0 ; i < 10 ; i ++ )
6468 Dispatcher . UIThread . RunJobs ( ) ;
6569 Check ( label . Text == label . Path , "Preference disables trimming immediately" ) ;
70+ CheckPathColors ( label ) ;
6671 preferences . TrimLeadingPathsInChanges = true ;
6772 for ( var i = 0 ; i < 10 ; i ++ )
6873 Dispatcher . UIThread . RunJobs ( ) ;
@@ -73,15 +78,33 @@ private static void Main()
7378 Check ( label . Text == label . Path , "Actual template responds to resize" ) ;
7479 window . Close ( ) ;
7580 }
76- Console . WriteLine ( "PASS: 18 changed-path layout checks" ) ;
81+ Console . WriteLine ( "PASS: 18 changed-path layout checks and directory/filename color checks " ) ;
7782 }
7883
7984 private static void Measure ( Control control , double width )
8085 {
8186 control . InvalidateMeasure ( ) ;
8287 control . Measure ( new Size ( width , 24 ) ) ;
88+ if ( control is ChangePathTextBlock path )
89+ CheckPathColors ( path ) ;
8390 }
8491
92+ private static void CheckPathColors ( ChangePathTextBlock label )
93+ {
94+ var filenameLength = label . Path . Length - ( label . Path . LastIndexOf ( '/' ) + 1 ) ;
95+ var directoryLength = label . Text . Length - filenameLength ;
96+ var position = 0 ;
97+ foreach ( var run in label . TextLayout . TextLines . SelectMany ( line => line . TextRuns ) )
98+ {
99+ if ( position >= label . Text . Length )
100+ break ;
101+ var expected = position < directoryLength ? label . DirectoryForeground : label . Foreground ;
102+ Check ( Equals ( run . Properties . ForegroundBrush , expected ) , "Directory is gray and filename keeps normal foreground" ) ;
103+ Check ( position >= directoryLength || position + run . Length <= directoryLength , "Color boundary preserves full filename" ) ;
104+ position += run . Length ;
105+ }
106+ Check ( position >= label . Text . Length , "Color checks cover displayed text" ) ;
107+ }
85108 private static void Check ( bool condition , string message )
86109 {
87110 if ( ! condition )
0 commit comments