Skip to content

Commit 4fbd188

Browse files
authored
[DYN-8655] Custom selections node loses contents on Copy (#16202)
1 parent de3dd4c commit 4fbd188

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/Libraries/CoreNodeModels/Input/CustomSelection.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,53 @@ private void OnSerializing(StreamingContext context)
147147
{
148148
serializedItems = Items.ToList();
149149
}
150+
151+
protected override void SerializeCore(XmlElement nodeElement, SaveContext context)
152+
{
153+
base.SerializeCore(nodeElement, context);
154+
155+
if (context == SaveContext.Copy)
156+
{
157+
var doc = nodeElement.OwnerDocument;
158+
159+
foreach (var item in Items)
160+
{
161+
var itemElement = doc.CreateElement("CustomItem");
162+
itemElement.SetAttribute("Name", item.Name);
163+
itemElement.SetAttribute("Value", item.Item?.ToString() ?? string.Empty);
164+
nodeElement.AppendChild(itemElement);
165+
}
166+
}
167+
}
168+
169+
protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
170+
{
171+
base.DeserializeCore(nodeElement, context);
172+
173+
if (context == SaveContext.Copy)
174+
{
175+
Items.Clear();
176+
foreach (XmlNode child in nodeElement.ChildNodes)
177+
{
178+
if (child is XmlElement itemElement && itemElement.Name == "CustomItem")
179+
{
180+
var name = itemElement.GetAttribute("Name");
181+
var value = itemElement.GetAttribute("Value");
182+
Items.Add(new DynamoDropDownItem(name, value));
183+
}
184+
}
185+
// Restore the selected index from the attribute
186+
var attrib = nodeElement.Attributes["index"];
187+
if (attrib != null && Items.Count > 0)
188+
{
189+
var indexStr = attrib.Value;
190+
SelectedIndex = ParseSelectedIndex(indexStr, Items);
191+
}
192+
else
193+
{
194+
SelectedIndex = 0;
195+
}
196+
}
197+
}
150198
}
151199
}

0 commit comments

Comments
 (0)