|
@@ -2,6 +2,7 @@
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Diagnostics;
|
|
|
|
+using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using System.Windows.Input;
|
|
using PixiEditor.Helpers;
|
|
using PixiEditor.Helpers;
|
|
@@ -147,8 +148,6 @@ namespace PixiEditor.ViewModels
|
|
UndoManager.RedoStack.Clear();
|
|
UndoManager.RedoStack.Clear();
|
|
SelectionSubViewModel.ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
SelectionSubViewModel.ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
ViewportSubViewModel.CenterViewport();
|
|
ViewportSubViewModel.CenterViewport();
|
|
- Exporter.SaveDocumentPath = null;
|
|
|
|
- DocumentSubViewModel.UnsavedDocumentModified = false;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public bool DocumentIsNotNull(object property)
|
|
public bool DocumentIsNotNull(object property)
|
|
@@ -163,10 +162,38 @@ namespace PixiEditor.ViewModels
|
|
throw new ArgumentException();
|
|
throw new ArgumentException();
|
|
}
|
|
}
|
|
|
|
|
|
- ((CancelEventArgs)property).Cancel = true;
|
|
|
|
|
|
+ ((CancelEventArgs)property).Cancel = !RemoveDocumentsWithSaveConfirmation();
|
|
|
|
+ }
|
|
|
|
|
|
- var result = ConfirmationType.No;
|
|
|
|
- if (DocumentSubViewModel.UnsavedDocumentModified)
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Removes documents with unsaved changes confirmation dialog.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns>If documents was removed successfully.</returns>
|
|
|
|
+ private bool RemoveDocumentsWithSaveConfirmation()
|
|
|
|
+ {
|
|
|
|
+ int docCount = BitmapManager.Documents.Count;
|
|
|
|
+ for (int i = 0; i < docCount; i++)
|
|
|
|
+ {
|
|
|
|
+ BitmapManager.ActiveDocument = BitmapManager.Documents.First();
|
|
|
|
+ bool canceled = !RemoveDocumentWithSaveConfirmation();
|
|
|
|
+ if (canceled)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Removes document with unsaved changes confirmation dialog.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns>If document was removed successfully.</returns>
|
|
|
|
+ private bool RemoveDocumentWithSaveConfirmation()
|
|
|
|
+ {
|
|
|
|
+ ConfirmationType result = ConfirmationType.No;
|
|
|
|
+
|
|
|
|
+ if (!BitmapManager.ActiveDocument.ChangesSaved)
|
|
{
|
|
{
|
|
result = ConfirmationDialog.Show(DocumentViewModel.ConfirmationDialogMessage);
|
|
result = ConfirmationDialog.Show(DocumentViewModel.ConfirmationDialogMessage);
|
|
if (result == ConfirmationType.Yes)
|
|
if (result == ConfirmationType.Yes)
|
|
@@ -177,8 +204,15 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
if (result != ConfirmationType.Canceled)
|
|
if (result != ConfirmationType.Canceled)
|
|
{
|
|
{
|
|
- ((CancelEventArgs)property).Cancel = false;
|
|
|
|
|
|
+ BitmapManager.Documents.Remove(BitmapManager.ActiveDocument);
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
private void OnStartup(object parameter)
|
|
private void OnStartup(object parameter)
|
|
@@ -188,14 +222,17 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
private void BitmapManager_DocumentChanged(object sender, DocumentChangedEventArgs e)
|
|
private void BitmapManager_DocumentChanged(object sender, DocumentChangedEventArgs e)
|
|
{
|
|
{
|
|
- e.NewDocument.DocumentSizeChanged += ActiveDocument_DocumentSizeChanged;
|
|
|
|
|
|
+ if (e.NewDocument != null)
|
|
|
|
+ {
|
|
|
|
+ e.NewDocument.DocumentSizeChanged += ActiveDocument_DocumentSizeChanged;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private void ActiveDocument_DocumentSizeChanged(object sender, DocumentSizeChangedEventArgs e)
|
|
private void ActiveDocument_DocumentSizeChanged(object sender, DocumentSizeChangedEventArgs e)
|
|
{
|
|
{
|
|
SelectionSubViewModel.ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
SelectionSubViewModel.ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
ViewportSubViewModel.CenterViewport();
|
|
ViewportSubViewModel.CenterViewport();
|
|
- DocumentSubViewModel.UnsavedDocumentModified = true;
|
|
|
|
|
|
+ BitmapManager.ActiveDocument.ChangesSaved = false;
|
|
}
|
|
}
|
|
|
|
|
|
private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
|
|
private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
|
|
@@ -208,7 +245,7 @@ namespace PixiEditor.ViewModels
|
|
ChangesController.AddChanges(
|
|
ChangesController.AddChanges(
|
|
new LayerChange(e.PixelsChanged, e.ChangedLayerIndex),
|
|
new LayerChange(e.PixelsChanged, e.ChangedLayerIndex),
|
|
new LayerChange(e.OldPixelsValues, e.ChangedLayerIndex));
|
|
new LayerChange(e.OldPixelsValues, e.ChangedLayerIndex));
|
|
- DocumentSubViewModel.UnsavedDocumentModified = true;
|
|
|
|
|
|
+ BitmapManager.ActiveDocument.ChangesSaved = false;
|
|
if (BitmapManager.IsOperationTool())
|
|
if (BitmapManager.IsOperationTool())
|
|
{
|
|
{
|
|
ColorsSubViewModel.AddSwatch(ColorsSubViewModel.PrimaryColor);
|
|
ColorsSubViewModel.AddSwatch(ColorsSubViewModel.PrimaryColor);
|