diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index d412584d59a..307cd71115b 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -2087,10 +2087,13 @@ 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) AddToRecentFiles(path); + if (!isBackup && hasSaved) + { + AddToRecentFiles(path); + } } catch (Exception ex) { @@ -2151,8 +2154,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 9dfa1c0691e..5835f3fd280 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs @@ -599,7 +599,7 @@ internal void ZoomOutInternal() /// /// /// 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)) { @@ -640,7 +640,7 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi if (result == MessageBoxResult.Cancel) { - return; + return false; } } } @@ -674,6 +674,8 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi Debug.WriteLine(ex.Message + " : " + ex.StackTrace); throw (ex); } + + return true; } /// /// This function appends view block to the model json diff --git a/test/DynamoCoreWpfTests/DynamoViewTests.cs b/test/DynamoCoreWpfTests/DynamoViewTests.cs index 298cf4a8558..f0f6e4d1c49 100644 --- a/test/DynamoCoreWpfTests/DynamoViewTests.cs +++ b/test/DynamoCoreWpfTests/DynamoViewTests.cs @@ -163,9 +163,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);