Skip to content

Commit

Permalink
Replaced missing windowclosing code.
Browse files Browse the repository at this point in the history
  • Loading branch information
JCWiley committed Jun 11, 2021
1 parent 0d4a7a6 commit ff94375
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion CharacterManager/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using CharacterManager.Model.Entities;
using CharacterManager.Model.RedundantTree;
using CharacterManager.Model.Services;
using CharacterManager.ViewModels.Helpers;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
Expand All @@ -11,11 +13,12 @@ namespace CharacterManager.ViewModels
{
public class ShellViewModel : BindableBase
{
public ShellViewModel (IEventAggregator eventAggregator, IRegionManager regionManager, ISettingsService settingsService)
public ShellViewModel (IEventAggregator eventAggregator, IRegionManager regionManager, ISettingsService settingsService, IDialogServiceHelper dialogServiceHelper)
{
RM = regionManager;
EA = eventAggregator;
SS = settingsService;
DSH = dialogServiceHelper;

EA.GetEvent<SelectedEntityChangedEvent>().Subscribe(SelectedEntityChangedExecute);
EA.GetEvent<DataLoadSuccessEvent>().Subscribe(DataLoadSuccessEventExecute);
Expand All @@ -27,6 +30,7 @@ public ShellViewModel (IEventAggregator eventAggregator, IRegionManager regionMa
private IEventAggregator EA;
private readonly IRegionManager RM;
private ISettingsService SS;
private IDialogServiceHelper DSH;
#endregion

#region Binding Targets
Expand All @@ -40,6 +44,42 @@ public string Filename
}
#endregion

#region Commands
private DelegateCommand<System.ComponentModel.CancelEventArgs> _commandwindowclosing;

public DelegateCommand<System.ComponentModel.CancelEventArgs> CommandWindowClosing => _commandwindowclosing ??= new DelegateCommand<System.ComponentModel.CancelEventArgs>(CommandWindowClosingExecute);

#endregion
#region Command handlers
private void CommandWindowClosingExecute(System.ComponentModel.CancelEventArgs e)
{
System.Windows.MessageBoxResult result = DSH.ShowYesNoCancelMessage("Would you like to save your changes?", "Save Changes");
switch (result)
{
case System.Windows.MessageBoxResult.None:
e.Cancel = false;
break;
case System.Windows.MessageBoxResult.OK:
throw new Exception("YesNoCancel Messagebox returned OK");
case System.Windows.MessageBoxResult.Cancel:
e.Cancel = true;
break;
case System.Windows.MessageBoxResult.Yes:
e.Cancel = false;
EA.GetEvent<DataSaveRequestEvent>().Publish(SaveRequestTypes.Save);
break;
case System.Windows.MessageBoxResult.No:
e.Cancel = false;
break;
default:
break;
}



}
#endregion

#region Event Handlers
void SelectedEntityChangedExecute(IRTreeMember<IEntity> Selected_Item)
{
Expand Down

0 comments on commit ff94375

Please sign in to comment.