Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick: don't save file to recent files list if saveas is canceled #14747

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
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 @@ -710,7 +710,7 @@ internal JObject GetJsonRepresentation(EngineController engine = null)
/// <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 @@ -748,7 +748,7 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi

if (result == MessageBoxResult.Cancel)
{
return;
return false;
}
}
}
Expand Down Expand Up @@ -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;
}
/// <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 @@ -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<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
Loading