mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-30 06:25:22 -04:00
Refactor last commit
This commit is contained in:
parent
25d29dc079
commit
45926b0990
4 changed files with 68 additions and 25 deletions
|
@ -3,6 +3,7 @@
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="clr-namespace:DiscordChatExporter.Gui"
|
xmlns:local="clr-namespace:DiscordChatExporter.Gui"
|
||||||
|
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||||
xmlns:s="https://github.com/canton7/Stylet">
|
xmlns:s="https://github.com/canton7/Stylet">
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
<s:ApplicationLoader>
|
<s:ApplicationLoader>
|
||||||
|
@ -111,6 +112,10 @@
|
||||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
|
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
|
<Style BasedOn="{StaticResource MaterialDesignTimePicker}" TargetType="{x:Type materialDesign:TimePicker}">
|
||||||
|
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
|
||||||
|
</Style>
|
||||||
|
|
||||||
<Style
|
<Style
|
||||||
x:Key="MaterialDesignFlatDarkButton"
|
x:Key="MaterialDesignFlatDarkButton"
|
||||||
BasedOn="{StaticResource MaterialDesignFlatButton}"
|
BasedOn="{StaticResource MaterialDesignFlatButton}"
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
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 TimeSpanToDateTimeConverter();
|
||||||
|
|
||||||
|
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is TimeSpan timeSpanValue)
|
||||||
|
return DateTime.Today.Add(timeSpanValue);
|
||||||
|
|
||||||
|
return default(DateTime?);
|
||||||
|
}
|
||||||
|
|
||||||
|
public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is DateTime dateTimeValue)
|
||||||
|
return dateTimeValue.TimeOfDay;
|
||||||
|
|
||||||
|
return default(TimeSpan?);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,9 +26,23 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
|
||||||
|
|
||||||
public ExportFormat SelectedFormat { get; set; }
|
public ExportFormat SelectedFormat { get; set; }
|
||||||
|
|
||||||
public DateTimeOffset? After { get; set; }
|
// This date/time abomination is required because we use separate controls to set these
|
||||||
|
|
||||||
public DateTimeOffset? Before { get; set; }
|
public DateTimeOffset? AfterDate { get; set; }
|
||||||
|
|
||||||
|
public bool IsAfterDateSet => AfterDate != null;
|
||||||
|
|
||||||
|
public TimeSpan? AfterTime { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset? After => AfterDate?.Add(AfterTime ?? TimeSpan.Zero);
|
||||||
|
|
||||||
|
public DateTimeOffset? BeforeDate { get; set; }
|
||||||
|
|
||||||
|
public bool IsBeforeDateSet => BeforeDate != null;
|
||||||
|
|
||||||
|
public TimeSpan? BeforeTime { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset? Before => BeforeDate?.Add(BeforeTime ?? TimeSpan.Zero);
|
||||||
|
|
||||||
public int? PartitionLimit { get; set; }
|
public int? PartitionLimit { get; set; }
|
||||||
|
|
||||||
|
@ -60,12 +74,6 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
|
||||||
_settingsService.LastPartitionLimit = PartitionLimit;
|
_settingsService.LastPartitionLimit = PartitionLimit;
|
||||||
_settingsService.LastShouldDownloadMedia = ShouldDownloadMedia;
|
_settingsService.LastShouldDownloadMedia = ShouldDownloadMedia;
|
||||||
|
|
||||||
// Clamp 'after' and 'before' values
|
|
||||||
if (After > Before)
|
|
||||||
After = Before;
|
|
||||||
if (Before < After)
|
|
||||||
Before = After;
|
|
||||||
|
|
||||||
// If single channel - prompt file path
|
// If single channel - prompt file path
|
||||||
if (IsSingleChannel)
|
if (IsSingleChannel)
|
||||||
{
|
{
|
||||||
|
|
|
@ -89,43 +89,45 @@
|
||||||
<DatePicker
|
<DatePicker
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
Margin="16,8"
|
Margin="16,8,16,4"
|
||||||
materialDesign:HintAssist.Hint="From (optional)"
|
materialDesign:HintAssist.Hint="After (date)"
|
||||||
materialDesign:HintAssist.IsFloating="True"
|
materialDesign:HintAssist.IsFloating="True"
|
||||||
DisplayDateEnd="{Binding Before, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}"
|
DisplayDateEnd="{Binding BeforeDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}"
|
||||||
SelectedDate="{Binding After, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}"
|
SelectedDate="{Binding AfterDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}"
|
||||||
ToolTip="If this is set, only messages sent after this date will be exported" />
|
ToolTip="If this is set, only messages sent after this date will be exported" />
|
||||||
<DatePicker
|
<DatePicker
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Margin="16,8"
|
Margin="16,8,16,4"
|
||||||
materialDesign:HintAssist.Hint="To (optional)"
|
materialDesign:HintAssist.Hint="Before (date)"
|
||||||
materialDesign:HintAssist.IsFloating="True"
|
materialDesign:HintAssist.IsFloating="True"
|
||||||
DisplayDateStart="{Binding After, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}"
|
DisplayDateStart="{Binding AfterDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}"
|
||||||
SelectedDate="{Binding Before, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}"
|
SelectedDate="{Binding BeforeDate, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}"
|
||||||
ToolTip="If this is set, only messages sent before this date will be exported" />
|
ToolTip="If this is set, only messages sent before this date will be exported" />
|
||||||
<materialDesign:TimePicker
|
<materialDesign:TimePicker
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
Margin="16,8"
|
Margin="16,4,16,8"
|
||||||
materialDesign:HintAssist.Hint="From Time (optional)"
|
materialDesign:HintAssist.Hint="After (time)"
|
||||||
materialDesign:HintAssist.IsFloating="True"
|
materialDesign:HintAssist.IsFloating="True"
|
||||||
SelectedTime="{Binding After, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}"
|
IsEnabled="{Binding IsAfterDateSet}"
|
||||||
ToolTip="If this is set, only messages sent after this time/date will be exported" />
|
SelectedTime="{Binding AfterTime, Converter={x:Static converters:TimeSpanToDateTimeConverter.Instance}}"
|
||||||
|
ToolTip="If this is set, only messages sent after this time will be exported" />
|
||||||
<materialDesign:TimePicker
|
<materialDesign:TimePicker
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Margin="16,8"
|
Margin="16,4,16,8"
|
||||||
materialDesign:HintAssist.Hint="To Time (optional)"
|
materialDesign:HintAssist.Hint="Before (time)"
|
||||||
materialDesign:HintAssist.IsFloating="True"
|
materialDesign:HintAssist.IsFloating="True"
|
||||||
SelectedTime="{Binding Before, Converter={x:Static converters:DateTimeOffsetToDateTimeConverter.Instance}}"
|
IsEnabled="{Binding IsBeforeDateSet}"
|
||||||
ToolTip="If this is set, only messages sent before this time/date will be exported" />
|
SelectedTime="{Binding BeforeTime, Converter={x:Static converters:TimeSpanToDateTimeConverter.Instance}}"
|
||||||
|
ToolTip="If this is set, only messages sent before this time will be exported" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<!-- Partitioning -->
|
<!-- Partitioning -->
|
||||||
<TextBox
|
<TextBox
|
||||||
Margin="16,8"
|
Margin="16,8"
|
||||||
materialDesign:HintAssist.Hint="Messages per partition (optional)"
|
materialDesign:HintAssist.Hint="Messages per partition"
|
||||||
materialDesign:HintAssist.IsFloating="True"
|
materialDesign:HintAssist.IsFloating="True"
|
||||||
Text="{Binding PartitionLimit, TargetNullValue=''}"
|
Text="{Binding PartitionLimit, TargetNullValue=''}"
|
||||||
ToolTip="If this is set, the exported file will be split into multiple partitions, each containing no more than specified number of messages" />
|
ToolTip="If this is set, the exported file will be split into multiple partitions, each containing no more than specified number of messages" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue