basic ui created
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Massmailer.Shared.Events;
|
||||
using Massmailer.Shared.Logic;
|
||||
using Massmailer.Shared.Model;
|
||||
using Microsoft.Win32;
|
||||
using PubSub;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -23,8 +24,9 @@ namespace Massmailer.UI
|
||||
{
|
||||
private readonly Hub hub = new Hub();
|
||||
private SmtpSettings smtpSettings;
|
||||
private MassmailerProject project;
|
||||
private MassmailerProject project = new MassmailerProject();
|
||||
private string selectedFilePath = string.Empty;
|
||||
private bool isDirty = false;
|
||||
|
||||
public MainView()
|
||||
{
|
||||
@@ -32,7 +34,106 @@ namespace Massmailer.UI
|
||||
this.hub.Subscribe<MailSentEvent>(this.MailSentEventHandler);
|
||||
}
|
||||
|
||||
private async void Button_Click(object sender, RoutedEventArgs e)
|
||||
private async void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.smtpSettings = await SmtpSettingsLogic.Load(Path.Combine(Environment.CurrentDirectory, Constants.SmtpSettingsFileName));
|
||||
}
|
||||
|
||||
private void MailSentEventHandler(MailSentEvent mailSentEvent)
|
||||
{
|
||||
//this.BtnSend.Content = $"mail sent: {mailSentEvent.Recipient} at {mailSentEvent.Timestamp}";
|
||||
}
|
||||
|
||||
private void MnuFileNew_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (this.isDirty)
|
||||
{
|
||||
var result = MessageBox.Show("Aktuelle Änderungen speichern?", "Massmailer", MessageBoxButton.YesNoCancel);
|
||||
|
||||
if (result == MessageBoxResult.Cancel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
MassmailerProjectLogic.Save(this.project, this.GetSaveFilePath());
|
||||
}
|
||||
|
||||
// TODO untested
|
||||
this.project = new MassmailerProject();
|
||||
this.DataContext = this.project;
|
||||
this.Title = "Massmailer";
|
||||
}
|
||||
}
|
||||
|
||||
private async void MnuFileOpen_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (this.isDirty)
|
||||
{
|
||||
var result = MessageBox.Show("Aktuelle Änderungen speichern?", "Massmailer", MessageBoxButton.YesNoCancel);
|
||||
|
||||
if (result == MessageBoxResult.Cancel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
MassmailerProjectLogic.Save(this.project, this.GetSaveFilePath(false));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO untested
|
||||
var openFileDialog = new OpenFileDialog();
|
||||
openFileDialog.DefaultExt = $".{Constants.ProjectFileExtension}";
|
||||
openFileDialog.Filter = $"Massmailer Projekte|*.{Constants.ProjectFileExtension}|Alle Dateien|*.*";
|
||||
|
||||
if (openFileDialog.ShowDialog() == true)
|
||||
{
|
||||
this.project = await MassmailerProjectLogic.Load(openFileDialog.FileName);
|
||||
this.DataContext = this.project;
|
||||
this.selectedFilePath = openFileDialog.FileName;
|
||||
this.Title = $"Massmailer - {openFileDialog.FileName}";
|
||||
}
|
||||
}
|
||||
|
||||
private void MnuFileSave_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MassmailerProjectLogic.Save(this.project, this.GetSaveFilePath(false));
|
||||
}
|
||||
|
||||
private void MnuFileSaveAs_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MassmailerProjectLogic.Save(this.project, this.GetSaveFilePath(true));
|
||||
}
|
||||
|
||||
private void MnuFileQuit_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (this.isDirty)
|
||||
{
|
||||
var result = MessageBox.Show("Aktuelle Änderungen speichern?", "Massmailer", MessageBoxButton.YesNoCancel);
|
||||
|
||||
if (result == MessageBoxResult.Cancel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
MassmailerProjectLogic.Save(this.project, this.GetSaveFilePath(false));
|
||||
}
|
||||
}
|
||||
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
|
||||
private void MnuHelpAbout_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MessageBox.Show("todo");
|
||||
}
|
||||
|
||||
private async void BtnSend_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var smtpSettings = new SmtpSettings
|
||||
{
|
||||
@@ -87,14 +188,20 @@ namespace Massmailer.UI
|
||||
MessageBox.Show(result);
|
||||
}
|
||||
|
||||
private void MailSentEventHandler(MailSentEvent mailSentEvent)
|
||||
private string GetSaveFilePath(bool force)
|
||||
{
|
||||
this.BtnSend.Content = $"mail sent: {mailSentEvent.Recipient} at {mailSentEvent.Timestamp}";
|
||||
}
|
||||
if (string.IsNullOrEmpty(this.selectedFilePath) || force)
|
||||
{
|
||||
var savefileDialog = new SaveFileDialog();
|
||||
savefileDialog.DefaultExt = $".{Constants.ProjectFileExtension}";
|
||||
savefileDialog.Filter = $"Massmailer Projekte|*.{Constants.ProjectFileExtension}|Alle Dateien|*.*";
|
||||
if (savefileDialog.ShowDialog() == true)
|
||||
{
|
||||
this.selectedFilePath = savefileDialog.FileName;
|
||||
}
|
||||
}
|
||||
|
||||
private async void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.smtpSettings = await SmtpSettingsLogic.Load(Path.Combine(Environment.CurrentDirectory, Constants.SmtpSettingsFileName));
|
||||
return this.selectedFilePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user