2024-09-21 20:00:30 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia.Data.Converters;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Converters
|
|
|
|
|
{
|
|
|
|
|
public static class PathConverters
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
public static readonly FuncValueConverter<string, string> PureFileName =
|
2024-09-21 20:00:30 -07:00
|
|
|
|
new(v => Path.GetFileName(v) ?? "");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
public static readonly FuncValueConverter<string, string> PureDirectoryName =
|
2024-09-21 20:00:30 -07:00
|
|
|
|
new(v => Path.GetDirectoryName(v) ?? "");
|
|
|
|
|
|
|
|
|
|
public static readonly FuncValueConverter<string, string> RelativeToHome =
|
|
|
|
|
new(v =>
|
|
|
|
|
{
|
|
|
|
|
if (OperatingSystem.IsWindows())
|
|
|
|
|
return v;
|
2024-09-25 01:24:04 -07:00
|
|
|
|
|
2024-09-21 20:00:30 -07:00
|
|
|
|
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;
|
|
|
|
|
});
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|