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 ;
2
3
3
4
using Avalonia . Data . Converters ;
4
5
@@ -7,9 +8,23 @@ namespace SourceGit.Converters
7
8
public static class PathConverters
8
9
{
9
10
public static readonly FuncValueConverter < string , string > PureFileName =
10
- new FuncValueConverter < string , string > ( fullpath => Path . GetFileName ( fullpath ) ?? "" ) ;
11
+ new ( v => Path . GetFileName ( v ) ?? "" ) ;
11
12
12
13
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
+ } ) ;
14
29
}
15
30
}
Original file line number Diff line number Diff line change 140
140
Margin =" 8,0"
141
141
HorizontalAlignment =" Right" VerticalAlignment =" Center"
142
142
Foreground =" {DynamicResource Brush.FG2}"
143
- Text =" {Binding Id}"
143
+ Text =" {Binding Id, Converter={x:Static c:PathConverters.RelativeToHome} }"
144
144
IsVisible =" {Binding IsRepository}" />
145
145
</Grid >
146
146
</DataTemplate >
You can’t perform that action at this time.
0 commit comments