Skip to content

Commit

Permalink
DYN-5674-CustomNode-Renamed (DynamoDS#13854)
Browse files Browse the repository at this point in the history
After the auto-save functionality is triggered when we are located in the Custom Node edit tab when the node in the Home Workspace is being renamed to "backup". Then after my fix first is checking if it has a name and file associated (that usually happen when you create/edit a custom node) if that is the case then we don't execute the rename process.
Also I added a test that will validate that the Save functionality doesn't rename the CustomNode name.
  • Loading branch information
RobertGlobant20 authored and sm6srw committed Mar 29, 2023
1 parent 1563088 commit e2563a4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,9 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi
// If a new CustomNodeWorkspaceModel is created, store that info in CustomNodeManager without creating an instance of the custom node.
if (this.Model is CustomNodeWorkspaceModel customNodeWorkspaceModel)
{
customNodeWorkspaceModel.SetInfo(Path.GetFileNameWithoutExtension(filePath));
//If the custom node Name is already set and the FileName is already set then we don't need to change the Name with "backup"
if(string.IsNullOrEmpty(customNodeWorkspaceModel.Name) && string.IsNullOrEmpty(customNodeWorkspaceModel.FileName))
customNodeWorkspaceModel.SetInfo(Path.GetFileNameWithoutExtension(filePath));
}
}
catch (Exception ex)
Expand Down
48 changes: 48 additions & 0 deletions test/DynamoCoreWpfTests/WorkspaceSaving.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Dynamo.ViewModels;
using Dynamo.Wpf;
using Dynamo.Wpf.ViewModels;
using Dynamo.Wpf.ViewModels.Core;
using Newtonsoft.Json.Linq;
using NUnit.Framework;

Expand Down Expand Up @@ -1411,6 +1412,53 @@ public void CustomNodeWorkspaceViewTestAfterSaving()

Assert.AreEqual(oldJObject["View"], newJObject["View"]);
}

/// <summary>
/// When focusing the Custom Node tab if the Save functionality is triggered was changing the CustomNode name automatically, then this test is validating that is not happening anymore
/// </summary>
[Test]
public void CustomNodeWorkspaceSaveBackupKeepNodeName()
{
var funcguid = GuidUtility.Create(GuidUtility.UrlNamespace, "NewCustomNodeKeepName");
var initialNodeName = "testnode";
//first create a new custom node.
this.ViewModel.ExecuteCommand(new DynamoModel.CreateCustomNodeCommand(funcguid, initialNodeName, "testcategory", "atest", true));

var customNodeWorspaceViewModel = this.ViewModel.Workspaces.OfType<WorkspaceViewModel>().FirstOrDefault();
var homeWorspaceViewModel = this.ViewModel.Workspaces.OfType<HomeWorkspaceViewModel>().FirstOrDefault();

//Adds the CustomNode to the HomeWorkspaceViewModel so later we can check that the node name is not renamed after saving
var customNodeInstance = this.ViewModel.Model.CustomNodeManager.CreateCustomNodeInstance(funcguid);
homeWorspaceViewModel.Model.AddAndRegisterNode(customNodeInstance);

Assert.True(initialNodeName == customNodeInstance.Name);

//Create nodes that will be added to the Custom Node Workspace
var outnode1 = new Output();
outnode1.Symbol = "out1";
var outnode2 = new Output();
outnode1.Symbol = "out2";
var cbn = new CodeBlockNodeModel(this.ViewModel.EngineController.LibraryServices);
cbn.SetCodeContent("5;", this.ViewModel.CurrentSpace.ElementResolver);

//Add nodes to the Custom Node Workspace
customNodeWorspaceViewModel.Model.AddAndRegisterNode(cbn);
customNodeWorspaceViewModel.Model.AddAndRegisterNode(outnode1);
customNodeWorspaceViewModel.Model.AddAndRegisterNode(outnode2);

//Get the path in which the temporary dyf file is created and then Save
var savePath = GetNewFileNameOnTempPath("dyf");

//Change to the CustomNodeWorkspaceViewModel (like focusing the Custom Node tab)
ViewModel.CurrentWorkspaceIndex = 1;

//Before was changing the CustomNode name but it shouldn't be changed
ViewModel.SaveAs(savePath, SaveContext.SaveAs, true);

//Verify that the CustomNode name remains in the same value that was created previously
Assert.True(initialNodeName == customNodeInstance.Name);
Assert.False(Path.GetFileNameWithoutExtension(savePath) == customNodeInstance.Name);
}
#endregion
}
}

0 comments on commit e2563a4

Please sign in to comment.