Fixed cancel on exit not working

This commit is contained in:
Ben Wallis 2018-12-06 21:20:42 +00:00
parent 065e56e0a6
commit 290547cbba
8 changed files with 35 additions and 28 deletions

View File

@ -8,7 +8,7 @@ namespace Filtration.Interface
{ {
bool IsScript { get; } bool IsScript { get; }
bool IsTheme { get; } bool IsTheme { get; }
Task Close(); Task<bool> Close();
RelayCommand CloseCommand { get; } RelayCommand CloseCommand { get; }
} }
} }

View File

@ -186,10 +186,11 @@ namespace Filtration.ThemeEditor.ViewModels
} }
#pragma warning disable 1998 #pragma warning disable 1998
public async Task Close() public async Task<bool> Close()
#pragma warning restore 1998 #pragma warning restore 1998
{ {
Messenger.Default.Send(new ThemeClosedMessage {ClosedViewModel = this}); Messenger.Default.Send(new ThemeClosedMessage {ClosedViewModel = this});
return true;
} }
private void OnAddThemeComponentCommand(ThemeComponentType themeComponentType) private void OnAddThemeComponentCommand(ThemeComponentType themeComponentType)

View File

@ -39,7 +39,7 @@ namespace Filtration.ViewModels.DesignTime
public bool IsScript { get; } public bool IsScript { get; }
public bool IsTheme { get; } public bool IsTheme { get; }
public Task Close() public Task<bool> Close()
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }

View File

@ -799,34 +799,37 @@ namespace Filtration.ViewModels
await Close(); await Close();
} }
public async Task Close() public async Task<bool> Close()
{ {
if (!IsDirty) if (!IsDirty)
{ {
CloseScript(); CloseScript();
return true;
} }
else
{
var result = _messageBoxService.Show("Filtration",
"Save script \"" + Filename + "\"?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
switch (result) var result = _messageBoxService.Show("Filtration",
"Save script \"" + Filename + "\"?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
switch (result)
{
case MessageBoxResult.Yes:
{ {
case MessageBoxResult.Yes: await SaveAsync();
{ CloseScript();
await SaveAsync(); return true;
CloseScript(); }
break; case MessageBoxResult.No:
} {
case MessageBoxResult.No: CloseScript();
{ return true;
CloseScript(); }
break; case MessageBoxResult.Cancel:
} {
case MessageBoxResult.Cancel: return false;
{ }
return; default:
} {
return false;
} }
} }
} }

View File

@ -768,7 +768,10 @@ namespace Filtration.ViewModels
continue; continue;
} }
await document.Close(); if (!await document.Close())
{
return false;
}
} }
return true; return true;

View File

@ -25,7 +25,7 @@ namespace Filtration.ViewModels
public bool IsScript => false; public bool IsScript => false;
public bool IsTheme => false; public bool IsTheme => false;
public Task Close() public Task<bool> Close()
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }

View File

@ -65,9 +65,10 @@ namespace Filtration.ViewModels
public bool IsInErrorState => UpdateStatus == UpdateStatus.Error; public bool IsInErrorState => UpdateStatus == UpdateStatus.Error;
public async Task Close() public async Task<bool> Close()
{ {
await Task.FromResult(true); await Task.FromResult(true);
return true;
} }
public RelayCommand CloseCommand { get; } public RelayCommand CloseCommand { get; }

View File

@ -44,7 +44,6 @@ namespace Filtration.Views
if (!allDocumentsClosed) if (!allDocumentsClosed)
{ {
e.Cancel = true; e.Cancel = true;
} }
} }