From efae0e99b888dcae9df0b7d956b5d6a892d85d3d Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Thu, 28 Sep 2017 21:57:57 +0300 Subject: [PATCH] Add a dialog that shows when export completes --- DiscordChatExporter/Container.cs | 2 + .../DiscordChatExporter.csproj | 12 ++++++ .../Messages/ShowExportDoneMessage.cs | 12 ++++++ .../ViewModels/ExportDoneViewModel.cs | 28 ++++++++++++++ .../ViewModels/IExportDoneViewModel.cs | 9 +++++ .../ViewModels/MainViewModel.cs | 3 ++ DiscordChatExporter/Views/ErrorDialog.ammy | 6 +-- .../Views/ExportDoneDialog.ammy | 37 +++++++++++++++++++ .../Views/ExportDoneDialog.ammy.cs | 16 ++++++++ DiscordChatExporter/Views/MainWindow.ammy.cs | 1 + DiscordChatExporter/Views/SettingsDialog.ammy | 5 ++- 11 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 DiscordChatExporter/Messages/ShowExportDoneMessage.cs create mode 100644 DiscordChatExporter/ViewModels/ExportDoneViewModel.cs create mode 100644 DiscordChatExporter/ViewModels/IExportDoneViewModel.cs create mode 100644 DiscordChatExporter/Views/ExportDoneDialog.ammy create mode 100644 DiscordChatExporter/Views/ExportDoneDialog.ammy.cs diff --git a/DiscordChatExporter/Container.cs b/DiscordChatExporter/Container.cs index b5a90fa..3fcf05d 100644 --- a/DiscordChatExporter/Container.cs +++ b/DiscordChatExporter/Container.cs @@ -20,6 +20,7 @@ namespace DiscordChatExporter SimpleIoc.Default.Register(true); SimpleIoc.Default.Register(true); SimpleIoc.Default.Register(true); + SimpleIoc.Default.Register(true); // Load settings ServiceLocator.Current.GetInstance().Load(); @@ -34,5 +35,6 @@ namespace DiscordChatExporter public IErrorViewModel ErrorViewModel => ServiceLocator.Current.GetInstance(); public IMainViewModel MainViewModel => ServiceLocator.Current.GetInstance(); public ISettingsViewModel SettingsViewModel => ServiceLocator.Current.GetInstance(); + public IExportDoneViewModel ExportDoneViewModel => ServiceLocator.Current.GetInstance(); } } \ No newline at end of file diff --git a/DiscordChatExporter/DiscordChatExporter.csproj b/DiscordChatExporter/DiscordChatExporter.csproj index c227baa..52be983 100644 --- a/DiscordChatExporter/DiscordChatExporter.csproj +++ b/DiscordChatExporter/DiscordChatExporter.csproj @@ -86,6 +86,7 @@ + @@ -93,10 +94,15 @@ + + ErrorDialog.ammy + + ExportDoneDialog.ammy + SettingsDialog.ammy @@ -110,6 +116,11 @@ MSBuild:Compile ErrorDialog.ammy + + Designer + MSBuild:Compile + ExportDoneDialog.ammy + Designer MSBuild:Compile @@ -163,6 +174,7 @@ Designer + diff --git a/DiscordChatExporter/Messages/ShowExportDoneMessage.cs b/DiscordChatExporter/Messages/ShowExportDoneMessage.cs new file mode 100644 index 0000000..1181e6b --- /dev/null +++ b/DiscordChatExporter/Messages/ShowExportDoneMessage.cs @@ -0,0 +1,12 @@ +namespace DiscordChatExporter.Messages +{ + public class ShowExportDoneMessage + { + public string FilePath { get; } + + public ShowExportDoneMessage(string filePath) + { + FilePath = filePath; + } + } +} \ No newline at end of file diff --git a/DiscordChatExporter/ViewModels/ExportDoneViewModel.cs b/DiscordChatExporter/ViewModels/ExportDoneViewModel.cs new file mode 100644 index 0000000..27bd996 --- /dev/null +++ b/DiscordChatExporter/ViewModels/ExportDoneViewModel.cs @@ -0,0 +1,28 @@ +using System.Diagnostics; +using DiscordChatExporter.Messages; +using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight.CommandWpf; + +namespace DiscordChatExporter.ViewModels +{ + public class ExportDoneViewModel : ViewModelBase, IExportDoneViewModel + { + private string _filePath; + + // Commands + public RelayCommand OpenCommand { get; } + + public ExportDoneViewModel() + { + MessengerInstance.Register(this, m => _filePath = m.FilePath); + + // Commands + OpenCommand = new RelayCommand(Open); + } + + private void Open() + { + Process.Start(_filePath); + } + } +} \ No newline at end of file diff --git a/DiscordChatExporter/ViewModels/IExportDoneViewModel.cs b/DiscordChatExporter/ViewModels/IExportDoneViewModel.cs new file mode 100644 index 0000000..6ed4b46 --- /dev/null +++ b/DiscordChatExporter/ViewModels/IExportDoneViewModel.cs @@ -0,0 +1,9 @@ +using GalaSoft.MvvmLight.CommandWpf; + +namespace DiscordChatExporter.ViewModels +{ + public interface IExportDoneViewModel + { + RelayCommand OpenCommand { get; } + } +} \ No newline at end of file diff --git a/DiscordChatExporter/ViewModels/MainViewModel.cs b/DiscordChatExporter/ViewModels/MainViewModel.cs index 181756f..4d903fd 100644 --- a/DiscordChatExporter/ViewModels/MainViewModel.cs +++ b/DiscordChatExporter/ViewModels/MainViewModel.cs @@ -171,6 +171,9 @@ namespace DiscordChatExporter.ViewModels // Export _exportService.Export(sfd.FileName, chatLog, _settingsService.Theme); + + // Show dialog + MessengerInstance.Send(new ShowExportDoneMessage(sfd.FileName)); } catch (UnathorizedException) { diff --git a/DiscordChatExporter/Views/ErrorDialog.ammy b/DiscordChatExporter/Views/ErrorDialog.ammy index add0a11..7eb89d3 100644 --- a/DiscordChatExporter/Views/ErrorDialog.ammy +++ b/DiscordChatExporter/Views/ErrorDialog.ammy @@ -7,18 +7,18 @@ UserControl "DiscordChatExporter.Views.ErrorDialog" { StackPanel { // Message TextBlock { - Margin: 8 + Margin: 16 FontSize: 16 - HorizontalAlignment: Center TextWrapping: WrapWithOverflow Text: bind Message } // OK Button { + Margin: 8 Command: DialogHost.CloseDialogCommand Content: "OK" - Margin: 8 + HorizontalAlignment: Right Style: resource dyn "MaterialDesignFlatButton" } } diff --git a/DiscordChatExporter/Views/ExportDoneDialog.ammy b/DiscordChatExporter/Views/ExportDoneDialog.ammy new file mode 100644 index 0000000..b997994 --- /dev/null +++ b/DiscordChatExporter/Views/ExportDoneDialog.ammy @@ -0,0 +1,37 @@ +using MaterialDesignThemes.Wpf + +UserControl "DiscordChatExporter.Views.ExportDoneDialog" { + DataContext: bind ExportDoneViewModel from $resource Container + Width: 250 + + StackPanel { + // Message + TextBlock { + Margin: 16 + FontSize: 16 + TextWrapping: WrapWithOverflow + Text: "Finished exporting chat log" + } + + // Buttons + @StackPanelHorizontal { + HorizontalAlignment: Right + + // Open + Button { + Command: bind OpenCommand + Content: "OPEN IT" + Margin: 8 + Style: resource dyn "MaterialDesignFlatButton" + } + + // Dismiss + Button { + Command: DialogHost.CloseDialogCommand + Content: "DISMISS" + Margin: 8 + Style: resource dyn "MaterialDesignFlatButton" + } + } + } +} \ No newline at end of file diff --git a/DiscordChatExporter/Views/ExportDoneDialog.ammy.cs b/DiscordChatExporter/Views/ExportDoneDialog.ammy.cs new file mode 100644 index 0000000..21d3bc2 --- /dev/null +++ b/DiscordChatExporter/Views/ExportDoneDialog.ammy.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DiscordChatExporter.Views +{ + public partial class ExportDoneDialog + { + public ExportDoneDialog() + { + InitializeComponent(); + } + } +} diff --git a/DiscordChatExporter/Views/MainWindow.ammy.cs b/DiscordChatExporter/Views/MainWindow.ammy.cs index e0a8268..1b56ac9 100644 --- a/DiscordChatExporter/Views/MainWindow.ammy.cs +++ b/DiscordChatExporter/Views/MainWindow.ammy.cs @@ -19,6 +19,7 @@ namespace DiscordChatExporter.Views Messenger.Default.Register(this, m => DialogHost.Show(new ErrorDialog()).Forget()); Messenger.Default.Register(this, m => DialogHost.Show(new SettingsDialog()).Forget()); + Messenger.Default.Register(this, m => DialogHost.Show(new ExportDoneDialog()).Forget()); } public void TokenTextBox_KeyDown(object sender, KeyEventArgs e) diff --git a/DiscordChatExporter/Views/SettingsDialog.ammy b/DiscordChatExporter/Views/SettingsDialog.ammy index edb06e7..834cfbc 100644 --- a/DiscordChatExporter/Views/SettingsDialog.ammy +++ b/DiscordChatExporter/Views/SettingsDialog.ammy @@ -7,9 +7,9 @@ UserControl "DiscordChatExporter.Views.SettingsDialog" { StackPanel { // Theme ComboBox { + Margin: 16 HintAssist.Hint: "Theme" HintAssist.IsFloating: true - Margin: 8 IsReadOnly: true ItemsSource: bind AvailableThemes SelectedItem: bind Theme @@ -17,9 +17,10 @@ UserControl "DiscordChatExporter.Views.SettingsDialog" { // Save Button { + Margin: 8 Command: DialogHost.CloseDialogCommand Content: "SAVE" - Margin: 8 + HorizontalAlignment: Right Style: resource dyn "MaterialDesignFlatButton" } }