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

DYN-5674-CustomNode-Renamed #13854

Merged
merged 1 commit into from
Mar 28, 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
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
}
}