Skip to content

Commit 17ccf2b

Browse files
Attempt to Fix #35
* Any changes to an OD entry will change the save button to red and not allow you to switch the OD view until you have saved or allowed the changes to be lost * After saving an OD change, adding a PDO, deleting PDO, editing PDO, or saving Device Info window title for device will go red and you will be prompted to confirm a close or app quit operation * Pressing save to the XML file will reset the dirty flag and make clear the red banner saving the EDS file will not clear the red banner
1 parent 63792a2 commit 17ccf2b

File tree

9 files changed

+200
-19
lines changed

9 files changed

+200
-19
lines changed

‎EDSTest/DeviceInfoView.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ private void button_update_devfile_info_Click(object sender, EventArgs e)
160160
//These are read only and auto calculated
161161
//textBox_rxpdos.Text = eds.di.NrOfRXPDO.ToString();
162162
//textBox_txpdos.Text = eds.di.NrOfTXPDO.ToString();
163+
164+
eds.dirty = true;
163165
}
164166
catch (Exception ex)
165167
{

‎EDSTest/DeviceODView.Designer.cs‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎EDSTest/DeviceODView.cs‎

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,36 @@ public partial class DeviceODView : MyTabUserControl
3838
public EDSsharp eds = null;
3939

4040
ODentry selectedobject;
41+
ODentry lastselectedobject;
4142
ListViewItem selecteditem;
4243
ListViewItem selecteditemsub;
4344

4445
public DeviceODView()
4546
{
4647
InitializeComponent();
4748

48-
comboBox_datatype.Items.Add("");
49-
5049
foreach (DataType foo in Enum.GetValues(typeof(DataType)))
5150
{
5251
comboBox_datatype.Items.Add(foo.ToString());
5352
}
5453

55-
comboBox_objecttype.Items.Add("");
56-
5754
foreach (ObjectType foo in Enum.GetValues(typeof(ObjectType)))
5855
{
5956
comboBox_objecttype.Items.Add(foo.ToString());
6057
}
6158

62-
comboBox_accesstype.Items.Add("");
63-
6459
foreach (EDSsharp.AccessType foo in Enum.GetValues(typeof(EDSsharp.AccessType)))
6560
{
6661
comboBox_accesstype.Items.Add(foo.ToString());
6762
}
6863

6964
comboBox_accesstype.Items.Add("0x1003 rw/ro");
7065

71-
72-
comboBox_memory.Items.Add("");
73-
7466
foreach (StorageLocation foo in Enum.GetValues(typeof(StorageLocation)))
7567
{
7668
comboBox_memory.Items.Add(foo.ToString());
7769
}
7870

79-
comboBox_pdomap.Items.Add("");
8071
comboBox_pdomap.Items.Add("no");
8172
comboBox_pdomap.Items.Add("optional");
8273

@@ -85,14 +76,40 @@ public DeviceODView()
8576
listView_optional_objects.DoubleBuffering(true);
8677
listViewDetails.DoubleBuffering(true);
8778

79+
foreach(Control c in splitContainer4.Panel2.Controls)
80+
{
81+
if (c is CheckBox)
82+
{
83+
((CheckBox)c).CheckedChanged += DataDirty;
84+
}
85+
else
86+
{
87+
c.TextChanged += DataDirty;
88+
}
89+
}
90+
}
91+
92+
bool updating = false;
93+
94+
private void DataDirty(object sender, EventArgs e)
95+
{
96+
if (updating == true)
97+
return;
98+
99+
button_save_changes.BackColor = Color.Red;
100+
101+
88102
}
89103

90-
91104
private void button_save_changes_Click(object sender, EventArgs e)
92105
{
93106
if (selectedobject == null)
94107
return;
95108

109+
eds.dirty = true;
110+
111+
button_save_changes.BackColor = default(Color);
112+
96113
//Allow everything to be updated and control what is allowed via enable/disable for the control
97114

98115
selectedobject.parameter_name = textBox_name.Text;
@@ -132,6 +149,7 @@ private void button_save_changes_Click(object sender, EventArgs e)
132149
selectedobject.Disabled = !checkBox_enabled.Checked;
133150

134151
selectedobject.location = (StorageLocation)Enum.Parse(typeof(StorageLocation), comboBox_memory.SelectedItem.ToString());
152+
135153
}
136154

137155
if(selectedobject.parent == null && selectedobject.objecttype == ObjectType.ARRAY)
@@ -183,9 +201,15 @@ public void updatedetailslist()
183201
public void validateanddisplaydata()
184202
{
185203

204+
186205
if (selectedobject == null)
187206
return;
188207

208+
lastselectedobject = selectedobject;
209+
210+
updating = true;
211+
212+
189213
ODentry od = (ODentry)selectedobject;
190214

191215

@@ -265,6 +289,7 @@ public void validateanddisplaydata()
265289
textBox_defaultvalue.Enabled = false;
266290
}
267291

292+
updating = false;
268293
return; //nothing else to do at this point
269294
}
270295

@@ -301,6 +326,8 @@ public void validateanddisplaydata()
301326

302327
}
303328

329+
updating = false;
330+
304331
return;
305332
}
306333

@@ -412,6 +439,8 @@ private void listView_mandatory_objects_MouseClick(object sender, MouseEventArgs
412439

413440
ListViewItem lvi = listView_mandatory_objects.SelectedItems[0];
414441

442+
if (checkdirty())
443+
return;
415444

416445
UInt16 idx = Convert.ToUInt16(lvi.Text, 16);
417446
updateselectedindexdisplay(idx);
@@ -429,6 +458,9 @@ private void list_mouseclick(ListView listview, MouseEventArgs e)
429458
if (listview.SelectedItems.Count == 0)
430459
return;
431460

461+
if (checkdirty())
462+
return;
463+
432464
ListViewItem lvi = listview.SelectedItems[0];
433465
UInt16 idx = Convert.ToUInt16(lvi.Text, 16);
434466

@@ -469,6 +501,8 @@ private void list_mouseclick(ListView listview, MouseEventArgs e)
469501

470502
private void listView_MouseDown(ListView listview, MouseEventArgs e)
471503
{
504+
505+
472506
ListViewHitTestInfo HI = listview.HitTest(e.Location);
473507
if (e.Button == MouseButtons.Right)
474508
{
@@ -516,6 +550,9 @@ private void listViewDetails_MouseClick(object sender, MouseEventArgs e)
516550
if (listViewDetails.SelectedItems.Count == 0)
517551
return;
518552

553+
if (checkdirty())
554+
return;
555+
519556
selecteditemsub = lvi;
520557

521558
ODentry od = (ODentry)lvi.Tag;
@@ -645,6 +682,8 @@ private void addNewObjectToolStripMenuItem_Click(object sender, EventArgs e)
645682
if (ni.ShowDialog() == DialogResult.OK)
646683
{
647684

685+
eds.dirty = true;
686+
648687
ODentry od = new ODentry();
649688

650689
od.objecttype = ni.ot;
@@ -744,13 +783,15 @@ private void deleteObjectToolStripMenuItem_Click(object sender, EventArgs e)
744783
}
745784
}
746785

786+
747787

748788
}
749789
}
750790

751791

752-
if (MessageBox.Show(string.Format("Really delete index 0x{0:x4} ?", od.index), "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
792+
if (MessageBox.Show(string.Format("Really delete index 0x{0:x4} ?", od.index), "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
753793
{
794+
eds.dirty = true;
754795
eds.ods.Remove(od.index);
755796
populateindexlists();
756797
}
@@ -765,6 +806,7 @@ private void disableObjectToolStripMenuItem_Click(object sender, EventArgs e)
765806

766807
ODentry od = (ODentry)item.Tag;
767808

809+
eds.dirty = true;
768810
od.Disabled = !od.Disabled;
769811
populateindexlists();
770812

@@ -819,6 +861,7 @@ private void addSubItemToolStripMenuItem_Click(object sender, EventArgs e)
819861
}
820862
}
821863

864+
eds.dirty = true;
822865
updateselectedindexdisplay(selectedobject.index);
823866
validateanddisplaydata();
824867

@@ -855,6 +898,7 @@ private void removeSubItemToolStripMenuItem_Click(object sender, EventArgs e)
855898

856899
od.parent.subobjects = newlist;
857900

901+
eds.dirty = true;
858902
updateselectedindexdisplay(selectedobject.index);
859903
validateanddisplaydata();
860904
}
@@ -930,12 +974,38 @@ private void listViewDetails_SelectedIndexChanged(object sender, EventArgs e)
930974
if (listViewDetails.SelectedItems.Count == 0)
931975
return;
932976

977+
if (checkdirty())
978+
return;
979+
980+
933981
ListViewItem lvi = listViewDetails.SelectedItems[0];
934982

935983
selecteditemsub = lvi;
936984
selectedobject = (ODentry)lvi.Tag;
937985
validateanddisplaydata();
938986
}
987+
988+
private bool checkdirty()
989+
{
990+
991+
if (button_save_changes.BackColor == Color.Red)
992+
{
993+
if (button_save_changes.BackColor == Color.Red)
994+
{
995+
if (MessageBox.Show(String.Format("Unsaved changes on Index 0x{0:x4}/{1:x2}\nDo you wish to change objects and loose your changes", lastselectedobject.index, lastselectedobject.subindex), "Unsaved changes",MessageBoxButtons.YesNo) == DialogResult.No)
996+
{
997+
return true;
998+
}
999+
else
1000+
{
1001+
button_save_changes.BackColor = default(Color);
1002+
}
1003+
1004+
}
1005+
}
1006+
1007+
return false;
1008+
}
9391009
}
9401010

9411011
public static class ControlExtensions

‎EDSTest/DevicePDOView.cs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ void updatePDOTXslot(ODentry od , int row)
308308

309309
void listView_TXCOBmap_onComboBoxIndexChanged(int row, int col, string Text)
310310
{
311-
312-
//row+0x1a00 will be the slot to adjust
313311

312+
//row+0x1a00 will be the slot to adjust
314313

314+
eds.dirty = true;
315315

316316
UInt16 slot = (UInt16)(0x200 + Convert.ToUInt16(listView_TXCOBmap.Items[row].SubItems[1].Text, 16));
317317
ODentry slotod = eds.ods[slot];
@@ -486,6 +486,7 @@ private void button_addPDO_Click(object sender, EventArgs e)
486486

487487
}
488488

489+
eds.dirty = true;
489490

490491

491492
}
@@ -506,7 +507,9 @@ private void button_deletePDO_Click(object sender, EventArgs e)
506507
doUpdatePDOs();
507508
doUpdateOD();
508509
}
509-
510+
511+
eds.dirty = true;
512+
510513
}
511514
catch (Exception ex)
512515
{
@@ -585,6 +588,8 @@ private void button_savepdochanges_Click(object sender, EventArgs e)
585588

586589
doUpdatePDOs();
587590
doUpdateOD();
591+
592+
eds.dirty = true;
588593
}
589594
catch (Exception ex)
590595
{

‎EDSTest/Form1.Designer.cs‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)