Skip to content

Commit

Permalink
cherry-pick PR 14740
Browse files Browse the repository at this point in the history
  • Loading branch information
aparajit-pratap committed Mar 19, 2024
1 parent d7ec867 commit af32824
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
15 changes: 10 additions & 5 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 4 additions & 2 deletions src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ internal void ZoomOutInternal()
/// <param name="engine"></param>
/// <param name="saveContext"></param>
/// <exception cref="ArgumentNullException">Thrown when the file path is null.</exception>
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))
{
Expand Down Expand Up @@ -640,7 +640,7 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi

if (result == MessageBoxResult.Cancel)
{
return;
return false;
}
}
}
Expand Down Expand Up @@ -674,6 +674,8 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi
Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
throw (ex);
}

return true;
}
/// <summary>
/// This function appends view block to the model json
Expand Down
4 changes: 2 additions & 2 deletions test/DynamoCoreWpfTests/DynamoViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object>;
Assert.AreEqual(1, (obj["Bindings"] as IEnumerable<object>).Count());
Assert.AreEqual(0, (obj["Bindings"] as IEnumerable<object>).Count());

File.Delete(filePath);
File.Delete(saveAsPath);
Expand Down

0 comments on commit af32824

Please sign in to comment.