Skip to content

Commit 292d620

Browse files
author
Michael Menzi
committed
MainForm gets notified about changes in the OD of an EDS and dispatches the updateOD in the corresponding deviceView.
1 parent eb1a6f1 commit 292d620

5 files changed

Lines changed: 65 additions & 1 deletion

File tree

EDSEditorGUI/DeviceODView.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public partial class DeviceODView : MyTabUserControl
3939
bool justUpdating = false;
4040
bool ExporterOld = false;
4141
bool ExporterV4 = false;
42+
43+
public event EventHandler<UpdateODViewEventArgs> UpdateODViewForEDS;
4244

4345
public DeviceODView()
4446
{
@@ -679,6 +681,10 @@ private void ContextMenu_object_clone_ToolStripMenuItem_Click(object sender, Eve
679681
PopulateSubList();
680682
PopulateObject();
681683
}
684+
else
685+
{
686+
UpdateODViewForEDS?.Invoke(this, new UpdateODViewEventArgs(modifiedEds));
687+
}
682688
}
683689
}
684690
}

EDSEditorGUI/DeviceView.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public partial class DeviceView : MyTabUserControl
3030
readonly public EDSsharp eds;
3131
readonly private List<EDSsharp> network;
3232

33+
public event EventHandler<UpdateODViewEventArgs> UpdateODViewForEDS;
34+
3335
public DeviceView(EDSsharp eds_target, List<EDSsharp> network)
3436
{
3537
eds = eds_target;
@@ -38,6 +40,7 @@ public DeviceView(EDSsharp eds_target, List<EDSsharp> network)
3840
InitializeComponent();
3941

4042
this.deviceODView1.network = network;
43+
this.deviceODView1.UpdateODViewForEDS += DeviceODView1_UpdateODView;
4144

4245
foreach (TabPage tp in tabControl1.TabPages)
4346
{
@@ -59,6 +62,15 @@ public DeviceView(EDSsharp eds_target, List<EDSsharp> network)
5962

6063
}
6164

65+
private void DeviceODView1_UpdateODView(object sender, UpdateODViewEventArgs e)
66+
{
67+
EventHandler<UpdateODViewEventArgs> handler = UpdateODViewForEDS;
68+
if(handler != null)
69+
{
70+
handler(this, e);
71+
}
72+
}
73+
6274
#region UpdateDispatchEvents
6375

6476
// This region handles update requests that are dispatched to the various user controls on the tabs

EDSEditorGUI/EDSEditorGUI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
<Compile Include="TableLayoutDB.cs">
153153
<SubType>Component</SubType>
154154
</Compile>
155+
<Compile Include="UpdateODViewEventArgs.cs" />
155156
<Compile Include="Warnings.cs">
156157
<SubType>Form</SubType>
157158
</Compile>

EDSEditorGUI/Form1.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ You should have received a copy of the GNU General Public License
2626
using System.IO;
2727
using libEDSsharp;
2828
using Xml2CSharp;
29+
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
2930

3031
namespace ODEditor
3132
{
@@ -183,6 +184,7 @@ private void openEDSfile(string path,InfoSection.Filetype ft)
183184

184185
DeviceView device = new DeviceView(eds, network);
185186

187+
device.UpdateODViewForEDS += Device_UpdateODViewForEDS;
186188
eds.OnDataDirty += Eds_onDataDirty;
187189

188190
tabControl1.TabPages.Add(eds.di.ProductName);
@@ -337,6 +339,7 @@ private void openXDDfile(string path)
337339

338340
DeviceView device = new DeviceView(eds, network);
339341

342+
device.UpdateODViewForEDS += Device_UpdateODViewForEDS;
340343
eds.OnDataDirty += Eds_onDataDirty;
341344

342345
tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(device);
@@ -382,7 +385,7 @@ private void openXMLfile(string path)
382385
tabControl1.TabPages.Add(eds.di.ProductName);
383386

384387
DeviceView device = new DeviceView(eds, network);
385-
388+
device.UpdateODViewForEDS += Device_UpdateODViewForEDS;
386389
eds.OnDataDirty += Eds_onDataDirty;
387390

388391
tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(device);
@@ -405,6 +408,26 @@ private void openXMLfile(string path)
405408

406409
}
407410

411+
private void Device_UpdateODViewForEDS(object sender, UpdateODViewEventArgs e)
412+
{
413+
foreach (TabPage page in tabControl1.TabPages)
414+
{
415+
foreach (Control c in page.Controls)
416+
{
417+
if (c.GetType() == typeof(DeviceView))
418+
{
419+
DeviceView d = (DeviceView)c;
420+
if (d.eds == e.EDS)
421+
{
422+
d.dispatch_updateOD();
423+
}
424+
}
425+
426+
}
427+
}
428+
}
429+
430+
408431
private void Eds_onDataDirty(bool dirty, EDSsharp sender)
409432
{
410433
foreach(TabPage page in tabControl1.TabPages)
@@ -648,6 +671,7 @@ private void newToolStripMenuItem_Click(object sender, EventArgs e)
648671
tabControl1.TabPages.Add(eds.di.ProductName);
649672

650673
DeviceView device = new DeviceView(eds, network);
674+
device.UpdateODViewForEDS += Device_UpdateODViewForEDS;
651675

652676
eds.OnDataDirty += Eds_onDataDirty;
653677

@@ -896,6 +920,7 @@ private void openXDDNetworkfile(string file)
896920
device.Dock = DockStyle.Fill;
897921

898922
network.Add(eds);
923+
device.UpdateODViewForEDS += Device_UpdateODViewForEDS;
899924
eds.OnDataDirty += Eds_onDataDirty;
900925

901926
device.dispatch_updateOD();
@@ -927,6 +952,7 @@ private void openNetworkfile(string file)
927952
device.Dock = DockStyle.Fill;
928953

929954
network.Add(eds);
955+
device.UpdateODViewForEDS += Device_UpdateODViewForEDS;
930956
eds.OnDataDirty += Eds_onDataDirty;
931957

932958
device.dispatch_updateOD();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using libEDSsharp;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace ODEditor
9+
{
10+
public class UpdateODViewEventArgs : EventArgs
11+
{
12+
public EDSsharp EDS { get; set; }
13+
14+
public UpdateODViewEventArgs(EDSsharp eds)
15+
{
16+
EDS = eds;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)