Skip to content

Commit

Permalink
Attempt to Fix #35
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
robincornelius committed Dec 4, 2016
1 parent 63792a2 commit 17ccf2b
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 19 deletions.
2 changes: 2 additions & 0 deletions EDSTest/DeviceInfoView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ private void button_update_devfile_info_Click(object sender, EventArgs e)
//These are read only and auto calculated
//textBox_rxpdos.Text = eds.di.NrOfRXPDO.ToString();
//textBox_txpdos.Text = eds.di.NrOfTXPDO.ToString();

eds.dirty = true;
}
catch (Exception ex)
{
Expand Down
5 changes: 5 additions & 0 deletions EDSTest/DeviceODView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 82 additions & 12 deletions EDSTest/DeviceODView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,45 +38,36 @@ public partial class DeviceODView : MyTabUserControl
public EDSsharp eds = null;

ODentry selectedobject;
ODentry lastselectedobject;
ListViewItem selecteditem;
ListViewItem selecteditemsub;

public DeviceODView()
{
InitializeComponent();

comboBox_datatype.Items.Add("");

foreach (DataType foo in Enum.GetValues(typeof(DataType)))
{
comboBox_datatype.Items.Add(foo.ToString());
}

comboBox_objecttype.Items.Add("");

foreach (ObjectType foo in Enum.GetValues(typeof(ObjectType)))
{
comboBox_objecttype.Items.Add(foo.ToString());
}

comboBox_accesstype.Items.Add("");

foreach (EDSsharp.AccessType foo in Enum.GetValues(typeof(EDSsharp.AccessType)))
{
comboBox_accesstype.Items.Add(foo.ToString());
}

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


comboBox_memory.Items.Add("");

foreach (StorageLocation foo in Enum.GetValues(typeof(StorageLocation)))
{
comboBox_memory.Items.Add(foo.ToString());
}

comboBox_pdomap.Items.Add("");
comboBox_pdomap.Items.Add("no");
comboBox_pdomap.Items.Add("optional");

Expand All @@ -85,14 +76,40 @@ public DeviceODView()
listView_optional_objects.DoubleBuffering(true);
listViewDetails.DoubleBuffering(true);

foreach(Control c in splitContainer4.Panel2.Controls)
{
if (c is CheckBox)
{
((CheckBox)c).CheckedChanged += DataDirty;
}
else
{
c.TextChanged += DataDirty;
}
}
}

bool updating = false;

private void DataDirty(object sender, EventArgs e)
{
if (updating == true)
return;

button_save_changes.BackColor = Color.Red;


}


private void button_save_changes_Click(object sender, EventArgs e)
{
if (selectedobject == null)
return;

eds.dirty = true;

button_save_changes.BackColor = default(Color);

//Allow everything to be updated and control what is allowed via enable/disable for the control

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

selectedobject.location = (StorageLocation)Enum.Parse(typeof(StorageLocation), comboBox_memory.SelectedItem.ToString());

}

if(selectedobject.parent == null && selectedobject.objecttype == ObjectType.ARRAY)
Expand Down Expand Up @@ -183,9 +201,15 @@ public void updatedetailslist()
public void validateanddisplaydata()
{


if (selectedobject == null)
return;

lastselectedobject = selectedobject;

updating = true;


ODentry od = (ODentry)selectedobject;


Expand Down Expand Up @@ -265,6 +289,7 @@ public void validateanddisplaydata()
textBox_defaultvalue.Enabled = false;
}

updating = false;
return; //nothing else to do at this point
}

Expand Down Expand Up @@ -301,6 +326,8 @@ public void validateanddisplaydata()

}

updating = false;

return;
}

Expand Down Expand Up @@ -412,6 +439,8 @@ private void listView_mandatory_objects_MouseClick(object sender, MouseEventArgs

ListViewItem lvi = listView_mandatory_objects.SelectedItems[0];

if (checkdirty())
return;

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

if (checkdirty())
return;

ListViewItem lvi = listview.SelectedItems[0];
UInt16 idx = Convert.ToUInt16(lvi.Text, 16);

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

private void listView_MouseDown(ListView listview, MouseEventArgs e)
{


ListViewHitTestInfo HI = listview.HitTest(e.Location);
if (e.Button == MouseButtons.Right)
{
Expand Down Expand Up @@ -516,6 +550,9 @@ private void listViewDetails_MouseClick(object sender, MouseEventArgs e)
if (listViewDetails.SelectedItems.Count == 0)
return;

if (checkdirty())
return;

selecteditemsub = lvi;

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

eds.dirty = true;

ODentry od = new ODentry();

od.objecttype = ni.ot;
Expand Down Expand Up @@ -744,13 +783,15 @@ private void deleteObjectToolStripMenuItem_Click(object sender, EventArgs e)
}
}



}
}


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

ODentry od = (ODentry)item.Tag;

eds.dirty = true;
od.Disabled = !od.Disabled;
populateindexlists();

Expand Down Expand Up @@ -819,6 +861,7 @@ private void addSubItemToolStripMenuItem_Click(object sender, EventArgs e)
}
}

eds.dirty = true;
updateselectedindexdisplay(selectedobject.index);
validateanddisplaydata();

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

od.parent.subobjects = newlist;

eds.dirty = true;
updateselectedindexdisplay(selectedobject.index);
validateanddisplaydata();
}
Expand Down Expand Up @@ -930,12 +974,38 @@ private void listViewDetails_SelectedIndexChanged(object sender, EventArgs e)
if (listViewDetails.SelectedItems.Count == 0)
return;

if (checkdirty())
return;


ListViewItem lvi = listViewDetails.SelectedItems[0];

selecteditemsub = lvi;
selectedobject = (ODentry)lvi.Tag;
validateanddisplaydata();
}

private bool checkdirty()
{

if (button_save_changes.BackColor == Color.Red)
{
if (button_save_changes.BackColor == Color.Red)
{
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)
{
return true;
}
else
{
button_save_changes.BackColor = default(Color);
}

}
}

return false;
}
}

public static class ControlExtensions
Expand Down
11 changes: 8 additions & 3 deletions EDSTest/DevicePDOView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ void updatePDOTXslot(ODentry od , int row)

void listView_TXCOBmap_onComboBoxIndexChanged(int row, int col, string Text)
{

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

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

eds.dirty = true;

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

}

eds.dirty = true;


}
Expand All @@ -506,7 +507,9 @@ private void button_deletePDO_Click(object sender, EventArgs e)
doUpdatePDOs();
doUpdateOD();
}


eds.dirty = true;

}
catch (Exception ex)
{
Expand Down Expand Up @@ -585,6 +588,8 @@ private void button_savepdochanges_Click(object sender, EventArgs e)

doUpdatePDOs();
doUpdateOD();

eds.dirty = true;
}
catch (Exception ex)
{
Expand Down
1 change: 1 addition & 0 deletions EDSTest/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 17ccf2b

Please sign in to comment.