@@ -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}\n Do 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
0 commit comments