Add export dialog and implement export as plain text

This commit is contained in:
Alexey Golub
2017-09-30 22:22:28 +03:00
parent 42bb4e72d2
commit 28a67ab60d
23 changed files with 409 additions and 77 deletions

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordChatExporter.Views
namespace DiscordChatExporter.Views
{
public partial class ErrorDialog
{
@@ -13,4 +7,4 @@ namespace DiscordChatExporter.Views
InitializeComponent();
}
}
}
}

View File

@@ -18,7 +18,8 @@ UserControl "DiscordChatExporter.Views.ExportDoneDialog" {
HorizontalAlignment: Right
// Open
Button {
Button "OpenButton" {
Click: OpenButton_Click
Command: bind OpenCommand
Content: "OPEN IT"
Margin: 8

View File

@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using MaterialDesignThemes.Wpf;
namespace DiscordChatExporter.Views
{
@@ -12,5 +9,10 @@ namespace DiscordChatExporter.Views
{
InitializeComponent();
}
public void OpenButton_Click(object sender, RoutedEventArgs args)
{
DialogHost.CloseDialogCommand.Execute(null, null);
}
}
}

View File

@@ -0,0 +1,58 @@
using MaterialDesignThemes.Wpf
UserControl "DiscordChatExporter.Views.ExportSetupDialog" {
DataContext: bind ExportSetupViewModel from $resource Container
Width: 350
StackPanel {
// File path
Grid {
#TwoColumns("*", "Auto")
TextBox {
Grid.Column: 0
Margin: "16 16 4 8"
HintAssist.Hint: "Output file"
HintAssist.IsFloating: true
Text: bind FilePath
set [ UpdateSourceTrigger: PropertyChanged ]
}
Button "LocateFilePathButton" {
Grid.Column: 1
Margin: "4 16 16 8"
Padding: 4
Click: LocateFilePathButton_Click
Style: resource dyn "MaterialDesignFlatButton"
PackIcon {
Kind: PackIconKind.DotsHorizontal
Width: 24
Height: 24
}
}
}
// Buttons
@StackPanelHorizontal {
HorizontalAlignment: Right
// Export
Button "ExportButton" {
Click: ExportButton_Click
Command: bind ExportCommand
Content: "EXPORT"
Margin: 8
Style: resource dyn "MaterialDesignFlatButton"
}
// Cancel
Button {
Command: DialogHost.CloseDialogCommand
Content: "CANCEL"
Margin: 8
Style: resource dyn "MaterialDesignFlatButton"
}
}
}
}

View File

@@ -0,0 +1,55 @@
using System.Collections.Generic;
using System.Windows;
using DiscordChatExporter.Models;
using DiscordChatExporter.ViewModels;
using MaterialDesignThemes.Wpf;
using Microsoft.Win32;
using Tyrrrz.Extensions;
namespace DiscordChatExporter.Views
{
public partial class ExportSetupDialog
{
public ExportSetupDialog()
{
InitializeComponent();
}
private IExportSetupViewModel ViewModel => (IExportSetupViewModel) DataContext;
private string GetOutputFileFilter()
{
var filters = new List<string>();
foreach (var format in ViewModel.AvailableFormats)
{
var ext = format.GetFileExtension();
filters.Add($"{format} (*.{ext})|*.{ext}");
}
return filters.JoinToString("|");
}
public void LocateFilePathButton_Click(object sender, RoutedEventArgs args)
{
var sfd = new SaveFileDialog
{
FileName = ViewModel.FilePath,
Filter = GetOutputFileFilter(),
FilterIndex = ViewModel.AvailableFormats.IndexOf(ViewModel.SelectedFormat) + 1,
AddExtension = true,
Title = "Select output file"
};
if (sfd.ShowDialog() == true)
{
ViewModel.FilePath = sfd.FileName;
ViewModel.SelectedFormat = ViewModel.AvailableFormats[sfd.FilterIndex - 1];
}
}
public void ExportButton_Click(object sender, RoutedEventArgs args)
{
DialogHost.CloseDialogCommand.Execute(null, null);
}
}
}

View File

@@ -167,7 +167,7 @@ Window "DiscordChatExporter.Views.MainWindow" {
Cursor: CursorType.Hand
InputBindings: [
MouseBinding {
Command: bind DataContext.ExportChannelCommand from $ancestor<ItemsControl>
Command: bind DataContext.ShowExportSetupCommand from $ancestor<ItemsControl>
CommandParameter: bind
MouseAction: LeftClick
}

View File

@@ -18,8 +18,9 @@ namespace DiscordChatExporter.Views
Title += $" v{Assembly.GetExecutingAssembly().GetName().Version}";
Messenger.Default.Register<ShowErrorMessage>(this, m => DialogHost.Show(new ErrorDialog()).Forget());
Messenger.Default.Register<ShowSettingsMessage>(this, m => DialogHost.Show(new SettingsDialog()).Forget());
Messenger.Default.Register<ShowExportDoneMessage>(this, m => DialogHost.Show(new ExportDoneDialog()).Forget());
Messenger.Default.Register<ShowExportSetupMessage>(this, m => DialogHost.Show(new ExportSetupDialog()).Forget());
Messenger.Default.Register<ShowSettingsMessage>(this, m => DialogHost.Show(new SettingsDialog()).Forget());
}
public void TokenTextBox_KeyDown(object sender, KeyEventArgs e)