2024-03-17 18:37:06 -07:00
|
|
|
|
using System;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia.Data.Converters;
|
|
|
|
|
using Avalonia.Styling;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Converters
|
|
|
|
|
{
|
|
|
|
|
public static class StringConverters
|
|
|
|
|
{
|
|
|
|
|
public class ToLocaleConverter : IValueConverter
|
|
|
|
|
{
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return Models.Locale.Supported.Find(x => x.Key == value as string);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return (value as Models.Locale).Key;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
public static readonly ToLocaleConverter ToLocale = new ToLocaleConverter();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public class ToThemeConverter : IValueConverter
|
|
|
|
|
{
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var theme = (string)value;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return ThemeVariant.Light;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (theme.Equals("Dark", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return ThemeVariant.Dark;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return ThemeVariant.Default;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var theme = (ThemeVariant)value;
|
|
|
|
|
return theme.Key;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
public static readonly ToThemeConverter ToTheme = new ToThemeConverter();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public class FormatByResourceKeyConverter : IValueConverter
|
|
|
|
|
{
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var key = parameter as string;
|
|
|
|
|
return App.Text(key, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
public static readonly FormatByResourceKeyConverter FormatByResourceKey = new FormatByResourceKeyConverter();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
public static readonly FuncValueConverter<string, string> ToShortSHA =
|
2024-02-05 23:08:37 -08:00
|
|
|
|
new FuncValueConverter<string, string>(v => v.Length > 10 ? v.Substring(0, 10) : v);
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|