-
Notifications
You must be signed in to change notification settings - Fork 675
DYN-10313 - Python Port Copy Paste + Undo Redo Fixes #17021
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
Changes from all commits
f0eb3c5
2c41bf4
e140677
ac56b36
aba8439
f860e53
93b0076
c365a7e
39524ae
df57ae6
831c5a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| using System.Collections.Generic; | ||
| using System.Collections.ObjectModel; | ||
| using System.ComponentModel; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
|
|
@@ -173,6 +174,88 @@ | |
| return base.UpdateValueCore(updateValueParams); | ||
| } | ||
|
|
||
| #region SerializeCore/DeserializeCore | ||
|
|
||
| /// <summary> | ||
| /// Preserves custom input and output port names and tooltips during XML serialization. | ||
| /// The base NodeModel serialization writes PortInfo elements for input ports; | ||
| /// this override adds "portName" and "portToolTip" attributes to each of those | ||
| /// elements and appends OutPortInfo elements for output ports. | ||
| /// These fields are emitted and consumed for all SaveContext values (Copy, Undo, Save, etc.). | ||
| /// </summary> | ||
| protected override void SerializeCore(XmlElement element, SaveContext context) | ||
| { | ||
| base.SerializeCore(element, context); | ||
|
|
||
| // Add portName and portToolTip attributes to each PortInfo element written by NodeModel.SerializeCore. | ||
| foreach (XmlNode child in element.ChildNodes) | ||
| { | ||
| if (child.Name == "PortInfo" && child is XmlElement portInfo) | ||
| { | ||
| var indexAttr = portInfo.GetAttribute("index"); | ||
|
Check warning on line 195 in src/Libraries/PythonNodeModels/PythonNode.cs
|
||
| if (int.TryParse(indexAttr, NumberStyles.Integer, CultureInfo.InvariantCulture, out int index) | ||
| && index >= 0 && index < InPorts.Count) | ||
| { | ||
| portInfo.SetAttribute("portName", InPorts[index].Name); | ||
|
Check warning on line 199 in src/Libraries/PythonNodeModels/PythonNode.cs
|
||
| portInfo.SetAttribute("portToolTip", InPorts[index].ToolTip); | ||
|
Check warning on line 200 in src/Libraries/PythonNodeModels/PythonNode.cs
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| // Write output port names and tooltips as separate elements (NodeModel does not serialize output PortInfo). | ||
| for (int i = 0; i < OutPorts.Count; i++) | ||
| { | ||
| XmlElement outPortInfo = element.OwnerDocument.CreateElement("OutPortInfo"); | ||
| outPortInfo.SetAttribute("index", i.ToString(CultureInfo.InvariantCulture)); | ||
| outPortInfo.SetAttribute("portName", OutPorts[i].Name); | ||
| outPortInfo.SetAttribute("portToolTip", OutPorts[i].ToolTip); | ||
| element.AppendChild(outPortInfo); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Restores custom input and output port names after base deserialization has | ||
| /// recreated the ports with their default names. | ||
| /// </summary> | ||
| protected override void DeserializeCore(XmlElement nodeElement, SaveContext context) | ||
|
Check failure on line 220 in src/Libraries/PythonNodeModels/PythonNode.cs
|
||
| { | ||
| base.DeserializeCore(nodeElement, context); | ||
|
|
||
| // After base.DeserializeCore, all ports exist with default names and tooltips. | ||
| // Re-apply any custom values that were serialized. | ||
| foreach (XmlNode child in nodeElement.ChildNodes) | ||
| { | ||
| if (child.Name == "PortInfo" && child is XmlElement portInfo) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, so this is not |
||
| { | ||
| var indexAttr = portInfo.GetAttribute("index"); | ||
| if (int.TryParse(indexAttr, NumberStyles.Integer, CultureInfo.InvariantCulture, out int index) | ||
| && index >= 0 && index < InPorts.Count) | ||
| { | ||
| if (portInfo.HasAttribute("portName")) | ||
| InPorts[index].Name = portInfo.GetAttribute("portName"); | ||
|
|
||
| if (portInfo.HasAttribute("portToolTip")) | ||
| InPorts[index].ToolTip = portInfo.GetAttribute("portToolTip"); | ||
| } | ||
| } | ||
| else if (child.Name == "OutPortInfo" && child is XmlElement outPortInfo) | ||
| { | ||
| var indexAttr = outPortInfo.GetAttribute("index"); | ||
| if (int.TryParse(indexAttr, NumberStyles.Integer, CultureInfo.InvariantCulture, out int outIndex) | ||
| && outIndex >= 0 && outIndex < OutPorts.Count) | ||
| { | ||
| if (outPortInfo.HasAttribute("portName")) | ||
| OutPorts[outIndex].Name = outPortInfo.GetAttribute("portName"); | ||
|
|
||
|
johnpierson marked this conversation as resolved.
|
||
| if (outPortInfo.HasAttribute("portToolTip")) | ||
| OutPorts[outIndex].ToolTip = outPortInfo.GetAttribute("portToolTip"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| } | ||
|
|
||
| [NodeName("Python Script")] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.