mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
enhance: use ~
to represent the home dir of current user
This commit is contained in:
parent
0b6ecc0388
commit
81b72f7c1c
2 changed files with 19 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Avalonia.Data.Converters;
|
||||
|
||||
|
@ -7,9 +8,23 @@ namespace SourceGit.Converters
|
|||
public static class PathConverters
|
||||
{
|
||||
public static readonly FuncValueConverter<string, string> PureFileName =
|
||||
new FuncValueConverter<string, string>(fullpath => Path.GetFileName(fullpath) ?? "");
|
||||
new(v => Path.GetFileName(v) ?? "");
|
||||
|
||||
public static readonly FuncValueConverter<string, string> PureDirectoryName =
|
||||
new FuncValueConverter<string, string>(fullpath => Path.GetDirectoryName(fullpath) ?? "");
|
||||
new(v => Path.GetDirectoryName(v) ?? "");
|
||||
|
||||
public static readonly FuncValueConverter<string, string> RelativeToHome =
|
||||
new(v =>
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
return v;
|
||||
|
||||
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
|
||||
if (v.StartsWith(home, StringComparison.Ordinal))
|
||||
return "~" + v.Substring(prefixLen);
|
||||
|
||||
return v;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@
|
|||
Margin="8,0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource Brush.FG2}"
|
||||
Text="{Binding Id}"
|
||||
Text="{Binding Id, Converter={x:Static c:PathConverters.RelativeToHome}}"
|
||||
IsVisible="{Binding IsRepository}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
|
Loading…
Reference in a new issue