Migrate to Avalonia (#1220)

This commit is contained in:
Oleksii Holub
2024-04-27 04:17:46 +03:00
committed by GitHub
parent 74f99b4e59
commit b9c1c47474
89 changed files with 2467 additions and 2810 deletions

View File

@@ -1,35 +0,0 @@
using System;
using System.Globalization;
using System.Windows.Data;
using DiscordChatExporter.Core.Discord.Data;
namespace DiscordChatExporter.Gui.Converters;
[ValueConversion(typeof(Channel), typeof(string))]
public class ChannelToGroupKeyConverter : IValueConverter
{
public static ChannelToGroupKeyConverter Instance { get; } = new();
public object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) =>
value switch
{
Channel { IsThread: true, Parent: not null } channel
=> $"Threads in #{channel.Parent.Name}",
Channel channel => channel.Parent?.Name ?? "???",
_ => null
};
public object ConvertBack(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => throw new NotSupportedException();
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Globalization;
using Avalonia.Data.Converters;
using DiscordChatExporter.Core.Discord.Data;
namespace DiscordChatExporter.Gui.Converters;
public class ChannelToHierarchicalNameStringConverter : IValueConverter
{
public static ChannelToHierarchicalNameStringConverter Instance { get; } = new();
public object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is Channel channel ? channel.GetHierarchicalName() : null;
public object ConvertBack(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => throw new NotSupportedException();
}

View File

@@ -1,31 +0,0 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace DiscordChatExporter.Gui.Converters;
[ValueConversion(typeof(DateTimeOffset?), typeof(DateTime?))]
public class DateTimeOffsetToDateTimeConverter : IValueConverter
{
public static DateTimeOffsetToDateTimeConverter Instance { get; } = new();
public object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) =>
value is DateTimeOffset dateTimeOffsetValue
? dateTimeOffsetValue.DateTime
: default(DateTime?);
public object? ConvertBack(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) =>
value is DateTime dateTimeValue
? new DateTimeOffset(dateTimeValue)
: default(DateTimeOffset?);
}

View File

@@ -1,11 +1,10 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Avalonia.Data.Converters;
using DiscordChatExporter.Core.Exporting;
namespace DiscordChatExporter.Gui.Converters;
[ValueConversion(typeof(ExportFormat), typeof(string))]
public class ExportFormatToStringConverter : IValueConverter
{
public static ExportFormatToStringConverter Instance { get; } = new();
@@ -15,7 +14,7 @@ public class ExportFormatToStringConverter : IValueConverter
Type targetType,
object? parameter,
CultureInfo culture
) => value is ExportFormat exportFormatValue ? exportFormatValue.GetDisplayName() : default;
) => value is ExportFormat format ? format.GetDisplayName() : default;
public object ConvertBack(
object? value,

View File

@@ -1,21 +0,0 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace DiscordChatExporter.Gui.Converters;
[ValueConversion(typeof(bool), typeof(bool))]
public class InverseBoolConverter : IValueConverter
{
public static InverseBoolConverter Instance { get; } = new();
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value is false;
public object ConvertBack(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is false;
}

View File

@@ -1,13 +1,12 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Avalonia.Data.Converters;
namespace DiscordChatExporter.Gui.Converters;
[ValueConversion(typeof(string), typeof(string))]
public class LocaleToDisplayNameConverter : IValueConverter
public class LocaleToDisplayNameStringConverter : IValueConverter
{
public static LocaleToDisplayNameConverter Instance { get; } = new();
public static LocaleToDisplayNameStringConverter Instance { get; } = new();
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value is string locale && !string.IsNullOrWhiteSpace(locale)

View File

@@ -1,21 +1,20 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Avalonia.Data.Converters;
using DiscordChatExporter.Core.Discord;
namespace DiscordChatExporter.Gui.Converters;
[ValueConversion(typeof(Snowflake?), typeof(DateTimeOffset?))]
public class SnowflakeToDateTimeOffsetConverter : IValueConverter
public class SnowflakeToTimestampStringConverter : IValueConverter
{
public static SnowflakeToDateTimeOffsetConverter Instance { get; } = new();
public static SnowflakeToTimestampStringConverter Instance { get; } = new();
public object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is Snowflake snowflake ? snowflake.ToDate() : null;
) => value is Snowflake snowflake ? snowflake.ToDate().ToString("g", culture) : null;
public object ConvertBack(
object? value,

View File

@@ -1,25 +0,0 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace DiscordChatExporter.Gui.Converters;
[ValueConversion(typeof(TimeSpan?), typeof(DateTime?))]
public class TimeSpanToDateTimeConverter : IValueConverter
{
public static TimeSpanToDateTimeConverter Instance { get; } = new();
public object? Convert(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is TimeSpan timeSpanValue ? DateTime.Today.Add(timeSpanValue) : default(DateTime?);
public object? ConvertBack(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
) => value is DateTime dateTimeValue ? dateTimeValue.TimeOfDay : default(TimeSpan?);
}