Browse Source

Merge pull request #54 from hackf5/save-as-cancel-issue-49

Resolved issue #49
Krzysztof Krysiński 4 years ago
parent
commit
c788b8fd92
2 changed files with 16 additions and 4 deletions
  1. 9 2
      PixiEditor/Models/IO/Exporter.cs
  2. 7 2
      PixiEditor/ViewModels/ViewModelMain.cs

+ 9 - 2
PixiEditor/Models/IO/Exporter.cs

@@ -11,6 +11,7 @@ namespace PixiEditor.Models.IO
     public class Exporter
     public class Exporter
     {
     {
         public static Size FileDimensions;
         public static Size FileDimensions;
+
         public static string SaveDocumentPath { get; set; }
         public static string SaveDocumentPath { get; set; }
 
 
         /// <summary>
         /// <summary>
@@ -18,14 +19,20 @@ namespace PixiEditor.Models.IO
         /// </summary>
         /// </summary>
         /// <param name="document">Document to save</param>
         /// <param name="document">Document to save</param>
         /// <param name="updateWorkspacePath">Should editor remember dialog path for further saves</param>
         /// <param name="updateWorkspacePath">Should editor remember dialog path for further saves</param>
-        public static void SaveAsEditableFileWithDialog(Document document, bool updateWorkspacePath = false)
+        public static bool SaveAsEditableFileWithDialog(Document document, bool updateWorkspacePath = false)
         {
         {
             SaveFileDialog dialog = new SaveFileDialog
             SaveFileDialog dialog = new SaveFileDialog
             {
             {
                 Filter = "PixiEditor Files | *.pixi",
                 Filter = "PixiEditor Files | *.pixi",
                 DefaultExt = "pixi"
                 DefaultExt = "pixi"
             };
             };
-            if ((bool) dialog.ShowDialog()) SaveAsEditableFile(document, dialog.FileName, updateWorkspacePath);
+            if ((bool)dialog.ShowDialog())
+            {
+                SaveAsEditableFile(document, dialog.FileName, updateWorkspacePath);
+                return true;
+            }
+
+            return false;
         }
         }
 
 
         public static void SaveAsEditableFile(Document document, string path, bool updateWorkspacePath = false)
         public static void SaveAsEditableFile(Document document, string path, bool updateWorkspacePath = false)

+ 7 - 2
PixiEditor/ViewModels/ViewModelMain.cs

@@ -408,10 +408,15 @@ namespace PixiEditor.ViewModels
         {
         {
             bool paramIsAsNew = parameter != null && parameter.ToString()?.ToLower() == "asnew";
             bool paramIsAsNew = parameter != null && parameter.ToString()?.ToLower() == "asnew";
             if (paramIsAsNew || Exporter.SaveDocumentPath == null)
             if (paramIsAsNew || Exporter.SaveDocumentPath == null)
-                Exporter.SaveAsEditableFileWithDialog(BitmapManager.ActiveDocument, !paramIsAsNew);
+            {
+                var saved = Exporter.SaveAsEditableFileWithDialog(BitmapManager.ActiveDocument, !paramIsAsNew);
+                _unsavedDocumentModified = _unsavedDocumentModified && !saved;
+            }
             else
             else
+            {
                 Exporter.SaveAsEditableFile(BitmapManager.ActiveDocument, Exporter.SaveDocumentPath);
                 Exporter.SaveAsEditableFile(BitmapManager.ActiveDocument, Exporter.SaveDocumentPath);
-            _unsavedDocumentModified = false;
+                _unsavedDocumentModified = false;
+            }
         }
         }
 
 
         private void RemoveSwatch(object parameter)
         private void RemoveSwatch(object parameter)