Skip to content

Commit

Permalink
ensure unique property name
Browse files Browse the repository at this point in the history
  • Loading branch information
saintentropy committed May 7, 2024
1 parent 47871d4 commit d70525b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/GraphMetadataViewExtension/GraphMetadataViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows.Media.Imaging;
using Dynamo.Core;
using Dynamo.Graph.Workspaces;
Expand Down Expand Up @@ -236,8 +237,19 @@ private void OpenGraphStatusExecute(object obj)

private void AddCustomPropertyExecute(object obj)
{
var propName = Properties.Resources.CustomPropertyControl_CustomPropertyDefault + " " + (CustomProperties.Count + 1);
int increment = CustomProperties.Count + 1;
string propName = DefaultPropertyName(increment);

//Ensure the property name is unique
while (CustomProperties.Any(x => x.PropertyName == propName))
{
increment++;
propName = DefaultPropertyName(increment);
}

AddCustomProperty(propName, string.Empty);

string DefaultPropertyName(int number) => Properties.Resources.CustomPropertyControl_CustomPropertyDefault + " " + number;
}

internal void AddCustomProperty(string propertyName, string propertyValue, bool markChange = true)
Expand Down

0 comments on commit d70525b

Please sign in to comment.