mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-12 01:43:05 +00:00
Migrate to Stylet and refactor view/view-model framework
This commit is contained in:
@@ -1,22 +1,26 @@
|
||||
<UserControl
|
||||
x:Class="DiscordChatExporter.Gui.Views.ExportSetupDialog"
|
||||
x:Class="DiscordChatExporter.Gui.Views.Dialogs.ExportSetupView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:converters="clr-namespace:DiscordChatExporter.Gui.Converters"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:dialogs="clr-namespace:DiscordChatExporter.Gui.ViewModels.Dialogs"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
Width="325"
|
||||
DataContext="{Binding ExportSetupViewModel, Source={StaticResource Container}}">
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
MinWidth="325"
|
||||
d:DataContext="{d:DesignInstance Type=dialogs:ExportSetupViewModel}"
|
||||
SnapsToDevicePixels="True"
|
||||
TextElement.FontSize="13"
|
||||
TextElement.FontWeight="Regular"
|
||||
TextElement.Foreground="{DynamicResource SecondaryTextBrush}"
|
||||
TextOptions.TextFormattingMode="Ideal"
|
||||
TextOptions.TextRenderingMode="Auto"
|
||||
mc:Ignorable="d">
|
||||
<StackPanel>
|
||||
<!-- File path -->
|
||||
<TextBox
|
||||
Margin="16,16,16,8"
|
||||
materialDesign:HintAssist.Hint="Output file"
|
||||
materialDesign:HintAssist.IsFloating="True"
|
||||
IsReadOnly="True"
|
||||
Text="{Binding FilePath, UpdateSourceTrigger=PropertyChanged}" />
|
||||
|
||||
<!-- Format -->
|
||||
<ComboBox
|
||||
Margin="16,8,16,8"
|
||||
Margin="16,16,16,8"
|
||||
materialDesign:HintAssist.Hint="Export format"
|
||||
materialDesign:HintAssist.IsFloating="True"
|
||||
IsReadOnly="True"
|
||||
@@ -24,7 +28,7 @@
|
||||
SelectedItem="{Binding SelectedFormat}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={StaticResource ExportFormatToStringConverter}}" />
|
||||
<TextBlock Text="{Binding Converter={x:Static converters:ExportFormatToStringConverter.Instance}}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
@@ -36,22 +40,20 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<DatePicker
|
||||
x:Name="FromDatePicker"
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="16,20,8,8"
|
||||
materialDesign:HintAssist.Hint="From (optional)"
|
||||
materialDesign:HintAssist.IsFloating="True"
|
||||
DisplayDateEnd="{Binding SelectedDate, ElementName=ToDatePicker}"
|
||||
DisplayDateEnd="{Binding To}"
|
||||
SelectedDate="{Binding From}" />
|
||||
<DatePicker
|
||||
x:Name="ToDatePicker"
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="8,20,16,8"
|
||||
materialDesign:HintAssist.Hint="To (optional)"
|
||||
materialDesign:HintAssist.IsFloating="True"
|
||||
DisplayDateStart="{Binding SelectedDate, ElementName=FromDatePicker}"
|
||||
DisplayDateStart="{Binding From}"
|
||||
SelectedDate="{Binding To}" />
|
||||
</Grid>
|
||||
|
||||
@@ -65,22 +67,14 @@
|
||||
<!-- Buttons -->
|
||||
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<Button
|
||||
x:Name="BrowseButton"
|
||||
Margin="8"
|
||||
Click="BrowseButton_Click"
|
||||
Content="BROWSE"
|
||||
Style="{DynamicResource MaterialDesignFlatButton}" />
|
||||
<Button
|
||||
x:Name="ExportButton"
|
||||
Margin="8"
|
||||
Click="ExportButton_Click"
|
||||
Command="{Binding ExportCommand}"
|
||||
Command="{s:Action Confirm}"
|
||||
Content="EXPORT"
|
||||
IsDefault="True"
|
||||
Style="{DynamicResource MaterialDesignFlatButton}" />
|
||||
<Button
|
||||
Margin="8"
|
||||
Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
|
||||
Command="{s:Action Close}"
|
||||
Content="CANCEL"
|
||||
IsCancel="True"
|
||||
Style="{DynamicResource MaterialDesignFlatButton}" />
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace DiscordChatExporter.Gui.Views.Dialogs
|
||||
{
|
||||
public partial class ExportSetupView
|
||||
{
|
||||
public ExportSetupView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,21 @@
|
||||
<UserControl
|
||||
x:Class="DiscordChatExporter.Gui.Views.SettingsDialog"
|
||||
x:Class="DiscordChatExporter.Gui.Views.Dialogs.SettingsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:dialogs="clr-namespace:DiscordChatExporter.Gui.ViewModels.Dialogs"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
Width="250"
|
||||
DataContext="{Binding SettingsViewModel, Source={StaticResource Container}}">
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
MinWidth="250"
|
||||
d:DataContext="{d:DesignInstance Type=dialogs:SettingsViewModel}"
|
||||
SnapsToDevicePixels="True"
|
||||
TextElement.FontSize="13"
|
||||
TextElement.FontWeight="Regular"
|
||||
TextElement.Foreground="{DynamicResource SecondaryTextBrush}"
|
||||
TextOptions.TextFormattingMode="Ideal"
|
||||
TextOptions.TextRenderingMode="Auto"
|
||||
mc:Ignorable="d">
|
||||
<StackPanel>
|
||||
<!-- Date format -->
|
||||
<TextBox
|
||||
@@ -36,7 +47,7 @@
|
||||
<Button
|
||||
Margin="8"
|
||||
HorizontalAlignment="Right"
|
||||
Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}"
|
||||
Command="{s:Action Close}"
|
||||
Content="SAVE"
|
||||
IsCancel="True"
|
||||
IsDefault="True"
|
||||
10
DiscordChatExporter.Gui/Views/Dialogs/SettingsView.xaml.cs
Normal file
10
DiscordChatExporter.Gui/Views/Dialogs/SettingsView.xaml.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace DiscordChatExporter.Gui.Views.Dialogs
|
||||
{
|
||||
public partial class SettingsView
|
||||
{
|
||||
public SettingsView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using System.Windows;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Gui.ViewModels;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace DiscordChatExporter.Gui.Views
|
||||
{
|
||||
public partial class ExportSetupDialog
|
||||
{
|
||||
private IExportSetupViewModel ViewModel => (IExportSetupViewModel)DataContext;
|
||||
|
||||
public ExportSetupDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void BrowseButton_Click(object sender, RoutedEventArgs args)
|
||||
{
|
||||
// Get file extension of the selected format
|
||||
var ext = ViewModel.SelectedFormat.GetFileExtension();
|
||||
|
||||
// Open dialog
|
||||
var sfd = new SaveFileDialog
|
||||
{
|
||||
FileName = ViewModel.FilePath,
|
||||
Filter = $"{ext.ToUpperInvariant()} Files|*.{ext}|All Files|*.*",
|
||||
AddExtension = true,
|
||||
Title = "Select output file"
|
||||
};
|
||||
|
||||
// Assign new file path if dialog was successful
|
||||
if (sfd.ShowDialog() == true)
|
||||
{
|
||||
ViewModel.FilePath = sfd.FileName;
|
||||
}
|
||||
}
|
||||
|
||||
public void ExportButton_Click(object sender, RoutedEventArgs args)
|
||||
{
|
||||
DialogHost.CloseDialogCommand.Execute(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using DiscordChatExporter.Gui.Messages;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Tyrrrz.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Gui.Views
|
||||
{
|
||||
public partial class MainWindow
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
Title += $" v{Assembly.GetExecutingAssembly().GetName().Version}";
|
||||
|
||||
Snackbar.MessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(5));
|
||||
|
||||
// Notification messages
|
||||
Messenger.Default.Register<ShowNotificationMessage>(this, m =>
|
||||
{
|
||||
if (m.CallbackCaption != null && m.Callback != null)
|
||||
Snackbar.MessageQueue.Enqueue(m.Message, m.CallbackCaption, m.Callback);
|
||||
else
|
||||
Snackbar.MessageQueue.Enqueue(m.Message);
|
||||
});
|
||||
|
||||
// Dialog messages
|
||||
Messenger.Default.Register<ShowExportSetupMessage>(this,
|
||||
m => DialogHost.Show(new ExportSetupDialog()).Forget());
|
||||
Messenger.Default.Register<ShowSettingsMessage>(this,
|
||||
m => DialogHost.Show(new SettingsDialog()).Forget());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
<Window
|
||||
x:Class="DiscordChatExporter.Gui.Views.MainWindow"
|
||||
x:Class="DiscordChatExporter.Gui.Views.RootView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
Title="DiscordChatExporter"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:viewModels="clr-namespace:DiscordChatExporter.Gui.ViewModels"
|
||||
Width="600"
|
||||
Height="550"
|
||||
MinWidth="325"
|
||||
d:DataContext="{d:DesignInstance Type=viewModels:RootViewModel}"
|
||||
Background="{DynamicResource MaterialDesignPaper}"
|
||||
DataContext="{Binding MainViewModel, Source={StaticResource Container}}"
|
||||
FocusManager.FocusedElement="{Binding ElementName=TokenValueTextBox}"
|
||||
FontFamily="{DynamicResource MaterialDesignFont}"
|
||||
Icon="/DiscordChatExporter;component/favicon.ico"
|
||||
@@ -19,22 +22,15 @@
|
||||
TextOptions.TextFormattingMode="Ideal"
|
||||
TextOptions.TextRenderingMode="Auto"
|
||||
UseLayoutRounding="True"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="Loaded">
|
||||
<i:InvokeCommandAction Command="{Binding ViewLoadedCommand}" />
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="Closed">
|
||||
<i:InvokeCommandAction Command="{Binding ViewClosedCommand}" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<materialDesign:DialogHost SnackbarMessageQueue="{Binding ElementName=Snackbar}">
|
||||
WindowStartupLocation="CenterScreen"
|
||||
mc:Ignorable="d">
|
||||
<materialDesign:DialogHost SnackbarMessageQueue="{Binding Notifications}">
|
||||
<DockPanel>
|
||||
<!-- Toolbar -->
|
||||
<Border
|
||||
Background="{DynamicResource PrimaryHueMidBrush}"
|
||||
DockPanel.Dock="Top"
|
||||
IsEnabled="{Binding IsBusy, Converter={StaticResource InvertBoolConverter}}"
|
||||
IsEnabled="{Binding IsEnabled}"
|
||||
TextElement.Foreground="{DynamicResource SecondaryInverseTextBrush}">
|
||||
<StackPanel>
|
||||
<Grid>
|
||||
@@ -45,7 +41,7 @@
|
||||
<materialDesign:Card
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="6,6,0,6">
|
||||
Margin="12,12,0,12">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
@@ -91,7 +87,7 @@
|
||||
Grid.Column="2"
|
||||
Margin="0,6,6,6"
|
||||
Padding="4"
|
||||
Command="{Binding PullDataCommand}"
|
||||
Command="{s:Action PopulateGuildsAndChannels}"
|
||||
IsDefault="True"
|
||||
Style="{DynamicResource MaterialDesignFlatButton}">
|
||||
<materialDesign:PackIcon
|
||||
@@ -109,8 +105,8 @@
|
||||
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}"
|
||||
PlacementMode="LeftAndAlignTopEdges">
|
||||
<StackPanel>
|
||||
<Button Command="{Binding ShowSettingsCommand}" Content="Settings" />
|
||||
<Button Command="{Binding ShowAboutCommand}" Content="About" />
|
||||
<Button Command="{s:Action ShowSettings}" Content="Settings" />
|
||||
<Button Command="{s:Action ShowAbout}" Content="About" />
|
||||
</StackPanel>
|
||||
</materialDesign:PopupBox>
|
||||
</Grid>
|
||||
@@ -119,7 +115,6 @@
|
||||
<ProgressBar
|
||||
Background="Transparent"
|
||||
IsIndeterminate="{Binding IsProgressIndeterminate}"
|
||||
Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibilityConverter}}"
|
||||
Value="{Binding Progress, Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
@@ -128,8 +123,8 @@
|
||||
<Grid>
|
||||
<DockPanel
|
||||
Background="{DynamicResource MaterialDesignCardBackground}"
|
||||
IsEnabled="{Binding IsBusy, Converter={StaticResource InvertBoolConverter}}"
|
||||
Visibility="{Binding IsDataAvailable, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
IsEnabled="{Binding IsEnabled}"
|
||||
Visibility="{Binding AvailableGuilds, Converter={x:Static s:BoolToVisibilityConverter.Instance}}">
|
||||
|
||||
<!-- Guilds -->
|
||||
<Border
|
||||
@@ -194,7 +189,8 @@
|
||||
Orientation="Horizontal">
|
||||
<StackPanel.InputBindings>
|
||||
<MouseBinding
|
||||
Command="{Binding DataContext.ShowExportSetupCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"
|
||||
s:View.ActionTarget="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
|
||||
Command="{s:Action ExportChannel}"
|
||||
CommandParameter="{Binding}"
|
||||
MouseAction="LeftClick" />
|
||||
</StackPanel.InputBindings>
|
||||
@@ -216,10 +212,10 @@
|
||||
</DockPanel>
|
||||
|
||||
<!-- Usage instructions -->
|
||||
<Grid Margin="32,32,8,8" Visibility="{Binding IsDataAvailable, Converter={StaticResource InvertBoolToVisibilityConverter}}">
|
||||
<Grid Margin="32,32,8,8" Visibility="{Binding AvailableGuilds, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}}">
|
||||
<!-- User token -->
|
||||
<StackPanel Visibility="{Binding IsBotToken, Converter={StaticResource InvertBoolToVisibilityConverter}}">
|
||||
<TextBlock FontSize="18" Text="DiscordChatExporter needs your user token to work." />
|
||||
<StackPanel Visibility="{Binding IsBotToken, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}}">
|
||||
<TextBlock FontSize="18" Text="DiscordChatExporter needs your user token to work" />
|
||||
<TextBlock
|
||||
Margin="0,8,0,0"
|
||||
FontSize="16"
|
||||
@@ -254,8 +250,8 @@
|
||||
</StackPanel>
|
||||
|
||||
<!-- Bot token -->
|
||||
<StackPanel Visibility="{Binding IsBotToken, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<TextBlock FontSize="18" Text="DiscordChatExporter needs your bot token to work." />
|
||||
<StackPanel Visibility="{Binding IsBotToken, Converter={x:Static s:BoolToVisibilityConverter.Instance}}">
|
||||
<TextBlock FontSize="18" Text="DiscordChatExporter needs your bot token to work" />
|
||||
<TextBlock
|
||||
Margin="0,8,0,0"
|
||||
FontSize="16"
|
||||
@@ -278,7 +274,8 @@
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<materialDesign:Snackbar x:Name="Snackbar" />
|
||||
|
||||
<materialDesign:Snackbar MessageQueue="{Binding Notifications}" />
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
</materialDesign:DialogHost>
|
||||
10
DiscordChatExporter.Gui/Views/RootView.xaml.cs
Normal file
10
DiscordChatExporter.Gui/Views/RootView.xaml.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace DiscordChatExporter.Gui.Views
|
||||
{
|
||||
public partial class RootView
|
||||
{
|
||||
public RootView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace DiscordChatExporter.Gui.Views
|
||||
{
|
||||
public partial class SettingsDialog
|
||||
{
|
||||
public SettingsDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user