Added save check on close
This commit is contained in:
parent
92ebc51e7b
commit
b0b912c676
|
@ -17,7 +17,7 @@ using NLog;
|
||||||
|
|
||||||
namespace Filtration
|
namespace Filtration
|
||||||
{
|
{
|
||||||
public partial class App
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
private IWindsorContainer _container;
|
private IWindsorContainer _container;
|
||||||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
|
@ -490,7 +490,7 @@ namespace Filtration.ViewModels
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var result = _messageBoxService.Show("Filtration",
|
var result = _messageBoxService.Show("Filtration",
|
||||||
"Want to save your changes to this script?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
"Save script \"" + Filename + "\"?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
||||||
|
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
@ -33,6 +34,7 @@ namespace Filtration.ViewModels
|
||||||
{
|
{
|
||||||
RelayCommand OpenScriptCommand { get; }
|
RelayCommand OpenScriptCommand { get; }
|
||||||
RelayCommand NewScriptCommand { get; }
|
RelayCommand NewScriptCommand { get; }
|
||||||
|
bool CloseAllDocuments();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class MainWindowViewModel : FiltrationViewModelBase, IMainWindowViewModel
|
internal class MainWindowViewModel : FiltrationViewModelBase, IMainWindowViewModel
|
||||||
|
@ -626,5 +628,22 @@ namespace Filtration.ViewModels
|
||||||
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.DeleteThemeComponentCommand.Execute(
|
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.DeleteThemeComponentCommand.Execute(
|
||||||
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent);
|
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool CloseAllDocuments()
|
||||||
|
{
|
||||||
|
var openDocuments = _avalonDockWorkspaceViewModel.OpenDocuments.OfType<IEditableDocument>().ToList();
|
||||||
|
|
||||||
|
foreach (var document in openDocuments)
|
||||||
|
{
|
||||||
|
var docCount = _avalonDockWorkspaceViewModel.OpenDocuments.OfType<IEditableDocument>().Count();
|
||||||
|
document.Close();
|
||||||
|
if (_avalonDockWorkspaceViewModel.OpenDocuments.OfType<IEditableDocument>().Count() == docCount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
xmlns:views="clr-namespace:Filtration.Views"
|
xmlns:views="clr-namespace:Filtration.Views"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel}"
|
d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel}"
|
||||||
Title="{Binding WindowTitle}" Height="762" Width="1126" IsIconVisible="True" >
|
Title="{Binding WindowTitle}" Height="762" Width="1126" IsIconVisible="True"
|
||||||
|
Closing="MainWindow_OnClosing">
|
||||||
<fluent:RibbonWindow.InputBindings>
|
<fluent:RibbonWindow.InputBindings>
|
||||||
<KeyBinding Command="{Binding SaveCommand}" Modifiers="Control" Key="S" />
|
<KeyBinding Command="{Binding SaveCommand}" Modifiers="Control" Key="S" />
|
||||||
<KeyBinding Command="{Binding OpenScriptCommand}" Modifiers="Control" Key="O" />
|
<KeyBinding Command="{Binding OpenScriptCommand}" Modifiers="Control" Key="O" />
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
using System.Windows;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Windows;
|
||||||
|
using Filtration.Annotations;
|
||||||
using Filtration.ViewModels;
|
using Filtration.ViewModels;
|
||||||
|
|
||||||
namespace Filtration.Views
|
namespace Filtration.Views
|
||||||
|
@ -10,8 +13,11 @@ namespace Filtration.Views
|
||||||
|
|
||||||
internal partial class MainWindow : IMainWindow
|
internal partial class MainWindow : IMainWindow
|
||||||
{
|
{
|
||||||
|
private IMainWindowViewModel _mainWindowViewModel;
|
||||||
|
|
||||||
public MainWindow(IMainWindowViewModel mainWindowViewModel)
|
public MainWindow(IMainWindowViewModel mainWindowViewModel)
|
||||||
{
|
{
|
||||||
|
_mainWindowViewModel = mainWindowViewModel;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContext = mainWindowViewModel;
|
DataContext = mainWindowViewModel;
|
||||||
}
|
}
|
||||||
|
@ -31,5 +37,15 @@ namespace Filtration.Views
|
||||||
RibbonRoot.SelectedTabItem = ThemeToolsTabItem;
|
RibbonRoot.SelectedTabItem = ThemeToolsTabItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MainWindow_OnClosing(object sender, CancelEventArgs e)
|
||||||
|
{
|
||||||
|
var allDocumentsClosed = _mainWindowViewModel.CloseAllDocuments();
|
||||||
|
|
||||||
|
if (!allDocumentsClosed)
|
||||||
|
{
|
||||||
|
e.Cancel = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue