File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1- using System . IO ;
1+ using System ;
2+ using System . IO ;
23
34using Avalonia . Data . Converters ;
45
@@ -7,9 +8,23 @@ namespace SourceGit.Converters
78 public static class PathConverters
89 {
910 public static readonly FuncValueConverter < string , string > PureFileName =
10- new FuncValueConverter < string , string > ( fullpath => Path . GetFileName ( fullpath ) ?? "" ) ;
11+ new ( v => Path . GetFileName ( v ) ?? "" ) ;
1112
1213 public static readonly FuncValueConverter < string , string > PureDirectoryName =
13- new FuncValueConverter < string , string > ( fullpath => Path . GetDirectoryName ( fullpath ) ?? "" ) ;
14+ new ( v => Path . GetDirectoryName ( v ) ?? "" ) ;
15+
16+ public static readonly FuncValueConverter < string , string > RelativeToHome =
17+ new ( v =>
18+ {
19+ if ( OperatingSystem . IsWindows ( ) )
20+ return v ;
21+
22+ var home = Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ;
23+ var prefixLen = home . EndsWith ( '/' ) ? home . Length - 1 : home . Length ;
24+ if ( v . StartsWith ( home , StringComparison . Ordinal ) )
25+ return "~" + v . Substring ( prefixLen ) ;
26+
27+ return v ;
28+ } ) ;
1429 }
1530}
Original file line number Diff line number Diff line change 140140 Margin =" 8,0"
141141 HorizontalAlignment =" Right" VerticalAlignment =" Center"
142142 Foreground =" {DynamicResource Brush.FG2}"
143- Text =" {Binding Id}"
143+ Text =" {Binding Id, Converter={x:Static c:PathConverters.RelativeToHome} }"
144144 IsVisible =" {Binding IsRepository}" />
145145 </Grid >
146146 </DataTemplate >
You can’t perform that action at this time.
0 commit comments