diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index cfbc44b532d..1782422084c 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -2093,10 +2093,10 @@ private void InternalSaveAs(string path, SaveContext saveContext, bool isBackup { try { - Model.Logger.Log(String.Format(Properties.Resources.SavingInProgress, path)); - CurrentSpaceViewModel.Save(path, isBackup, Model.EngineController, saveContext); + Model.Logger.Log(string.Format(Properties.Resources.SavingInProgress, path)); + var hasSaved = CurrentSpaceViewModel.Save(path, isBackup, Model.EngineController, saveContext); - if (!isBackup) + if (!isBackup && hasSaved) { AddToRecentFiles(path); @@ -2168,8 +2168,10 @@ internal void SaveAs(Guid id, string path, bool isBackup = false, SaveContext sa try { Model.Logger.Log(String.Format(Properties.Resources.SavingInProgress, path)); - Workspaces.Where(w => w.Model.Guid == id).FirstOrDefault().Save(path, isBackup, Model.EngineController, saveContext); - if (!isBackup) AddToRecentFiles(path); + var hasSaved = Workspaces.FirstOrDefault(w => w.Model.Guid == id).Save( + path, isBackup, Model.EngineController, saveContext); + + if (!isBackup && hasSaved) AddToRecentFiles(path); } catch (Exception ex) { diff --git a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs index 38e8fb18017..4f1dcc9fa1c 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs @@ -710,7 +710,7 @@ internal JObject GetJsonRepresentation(EngineController engine = null) /// /// /// Thrown when the file path is null. - internal void Save(string filePath, bool isBackup = false, EngineController engine = null, SaveContext saveContext = SaveContext.None) + internal bool Save(string filePath, bool isBackup = false, EngineController engine = null, SaveContext saveContext = SaveContext.None) { if (String.IsNullOrEmpty(filePath)) { @@ -748,7 +748,7 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi if (result == MessageBoxResult.Cancel) { - return; + return false; } } } @@ -791,6 +791,8 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi throw ex; #pragma warning restore CA2200 // Rethrow to preserve stack details } + + return true; } /// /// This function appends view block to the model json diff --git a/test/DynamoCoreWpfTests/DynamoViewTests.cs b/test/DynamoCoreWpfTests/DynamoViewTests.cs index 79294e37f2f..66f57f02e8c 100644 --- a/test/DynamoCoreWpfTests/DynamoViewTests.cs +++ b/test/DynamoCoreWpfTests/DynamoViewTests.cs @@ -147,9 +147,9 @@ public void ElementBinding_SaveAs() Open(saveAsPathInTestDir); // Assert saved as file doesn't have binding data after open. - DynamoUtilities.PathHelper.isValidJson(filePath, out fileContents, out ex); + DynamoUtilities.PathHelper.isValidJson(saveAsPath, out fileContents, out ex); obj = DSCore.Data.ParseJSON(fileContents) as Dictionary; - Assert.AreEqual(1, (obj["Bindings"] as IEnumerable).Count()); + Assert.AreEqual(0, (obj["Bindings"] as IEnumerable).Count()); File.Delete(filePath); File.Delete(saveAsPath);