From 742f09666cc5830921e5edf2e4dbaca5af0d8cc7 Mon Sep 17 00:00:00 2001 From: Robin Cornelius Date: Tue, 31 Jan 2017 14:47:56 +0000 Subject: [PATCH] Allow parent or subitem to be clicked on when adding new sub items Fixes #49 --- EDSTest/DeviceODView.cs | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/EDSTest/DeviceODView.cs b/EDSTest/DeviceODView.cs index 0d6a5eee..89eaf44b 100644 --- a/EDSTest/DeviceODView.cs +++ b/EDSTest/DeviceODView.cs @@ -830,49 +830,52 @@ private void addSubItemToolStripMenuItem_Click(object sender, EventArgs e) { ODentry od = (ODentry)selecteditemsub.Tag; - if (od.parent.objecttype == ObjectType.ARRAY) + if (od.parent != null) + od = od.parent; + + if (od.objecttype == ObjectType.ARRAY) { ODentry newsub = new ODentry(); - newsub.parent = od.parent; - newsub.datatype = od.parent.datatype; - newsub.accesstype = od.parent.accesstype; - newsub.PDOtype = od.parent.PDOtype; + newsub.parent = od; + newsub.datatype = od.datatype; + newsub.accesstype = od.accesstype; + newsub.PDOtype = od.PDOtype; newsub.index = od.index; newsub.objecttype = ObjectType.VAR; - newsub.subindex = (UInt16)od.parent.subobjects.Count; - od.parent.subobjects.Add((UInt16)(od.parent.subobjects.Count), newsub); + newsub.subindex = (UInt16)od.subobjects.Count; + od.subobjects.Add((UInt16)(od.subobjects.Count), newsub); - UInt16 def = EDSsharp.ConvertToUInt16(od.parent.subobjects[0].defaultvalue); + UInt16 def = EDSsharp.ConvertToUInt16(od.subobjects[0].defaultvalue); def++; - od.parent.subobjects[0].defaultvalue = def.ToString(); + od.subobjects[0].defaultvalue = def.ToString(); } - if (od.parent.objecttype == ObjectType.REC) + if (od.objecttype == ObjectType.REC) { DataType dt = od.datatype; - NewIndex ni = new NewIndex(eds, dt, od.parent.objecttype, od.parent); + NewIndex ni = new NewIndex(eds, dt, od.objecttype, od); if (ni.ShowDialog() == DialogResult.OK) { ODentry newsub = new ODentry(); - newsub.parent = od.parent; + newsub.parent = od; newsub.datatype = ni.dt; - newsub.accesstype = od.parent.accesstype; - newsub.PDOtype = od.parent.PDOtype; + newsub.accesstype = od.accesstype; + newsub.PDOtype = od.PDOtype; newsub.index = od.index; newsub.objecttype = ObjectType.VAR; - newsub.subindex = (UInt16)od.parent.subobjects.Count; + newsub.subindex = (UInt16)od.subobjects.Count; newsub.parameter_name = ni.name; - od.parent.subobjects.Add((UInt16)(od.parent.subobjects.Count), newsub); + od.subobjects.Add((UInt16)(od.subobjects.Count), newsub); - UInt16 def = EDSsharp.ConvertToUInt16(od.parent.subobjects[0].defaultvalue); + UInt16 def = EDSsharp.ConvertToUInt16(od.subobjects[0].defaultvalue); def++; - od.parent.subobjects[0].defaultvalue = def.ToString(); + od.subobjects[0].defaultvalue = def.ToString(); } }