Always store the state when a button clicked. This does a much better getting ctrl-z to work.

This commit is contained in:
Tim Young 2018-03-17 11:59:11 -05:00
parent e1060523ab
commit c705ac0db3

View File

@ -1105,8 +1105,6 @@ namespace EduNetworkBuilder
{ {
if (ItemClickedOn != null) if (ItemClickedOn != null)
{ {
ProcessChange();
ItemClickedOn.Hide(); ItemClickedOn.Hide();
UpdateLinks(); UpdateLinks();
UpdateVisuals(); UpdateVisuals();
@ -1117,7 +1115,6 @@ namespace EduNetworkBuilder
{ {
if (ItemClickedOn != null) if (ItemClickedOn != null)
{ {
ProcessChange();
ItemClickedOn.PowerOff = false; ItemClickedOn.PowerOff = false;
bool BlowUpOnce = myNetwork.ItemHasTest(ItemClickedOn.hostname, NetTestType.DeviceBlowsUpWithPower) && !myNetwork.ItemTestIsComplete(ItemClickedOn.hostname, NetTestType.DeviceBlowsUpWithPower); bool BlowUpOnce = myNetwork.ItemHasTest(ItemClickedOn.hostname, NetTestType.DeviceBlowsUpWithPower) && !myNetwork.ItemTestIsComplete(ItemClickedOn.hostname, NetTestType.DeviceBlowsUpWithPower);
bool BlowUpMultiple = myNetwork.ItemHasTest(ItemClickedOn.hostname, NetTestType.DeviceNeedsUPS) && !myNetwork.ItemTestIsComplete(ItemClickedOn.hostname, NetTestType.DeviceNeedsUPS); bool BlowUpMultiple = myNetwork.ItemHasTest(ItemClickedOn.hostname, NetTestType.DeviceNeedsUPS) && !myNetwork.ItemTestIsComplete(ItemClickedOn.hostname, NetTestType.DeviceNeedsUPS);
@ -1155,7 +1152,6 @@ namespace EduNetworkBuilder
{ {
if (ItemClickedOn != null) if (ItemClickedOn != null)
{ {
ProcessChange();
ItemClickedOn.PowerOff = true; ItemClickedOn.PowerOff = true;
//Mark the replace test as "done" //Mark the replace test as "done"
myNetwork.RegisterDeviceReset(ItemClickedOn.hostname); myNetwork.RegisterDeviceReset(ItemClickedOn.hostname);
@ -1167,7 +1163,6 @@ namespace EduNetworkBuilder
//We will still do this for devices that are spraying the network //We will still do this for devices that are spraying the network
private void pbNetworkView_Replace_Click(object sender, EventArgs e) private void pbNetworkView_Replace_Click(object sender, EventArgs e)
{ {
ProcessChange();
if (ItemClickedOn != null) if (ItemClickedOn != null)
{ {
if (ItemClickedOn == null) return; if (ItemClickedOn == null) return;
@ -1186,8 +1181,6 @@ namespace EduNetworkBuilder
{ {
if (ItemClickedOn != null) if (ItemClickedOn != null)
{ {
ProcessChange();
if (ItemClickedOn == null) return; if (ItemClickedOn == null) return;
//Changing a UPS makes sure the power is off when done. //Changing a UPS makes sure the power is off when done.
ItemClickedOn.PowerOff = true; ItemClickedOn.PowerOff = true;
@ -1235,7 +1228,6 @@ namespace EduNetworkBuilder
private void pbNetworkView_RemoveLink_Click(object sender, EventArgs e) private void pbNetworkView_RemoveLink_Click(object sender, EventArgs e)
{ {
ProcessChange();
ToolStripItem thing = (ToolStripItem)sender; ToolStripItem thing = (ToolStripItem)sender;
string released = thing.Text; string released = thing.Text;
released = Regex.Replace(released, ".* ", ""); released = Regex.Replace(released, ".* ", "");
@ -1254,8 +1246,6 @@ namespace EduNetworkBuilder
ToolStripItem thing = (ToolStripItem)sender; ToolStripItem thing = (ToolStripItem)sender;
if (thing.Tag != null) if (thing.Tag != null)
{ {
ProcessChange();
NetworkLink NL = (NetworkLink)thing.Tag; NetworkLink NL = (NetworkLink)thing.Tag;
//This may delete the old link and make a new one //This may delete the old link and make a new one
LinkEditor LE = new LinkEditor(NL); LinkEditor LE = new LinkEditor(NL);
@ -1268,7 +1258,6 @@ namespace EduNetworkBuilder
private void pbNetworkView_ReplaceNetLink_Click(object sender, EventArgs e) private void pbNetworkView_ReplaceNetLink_Click(object sender, EventArgs e)
{ {
ProcessChange();
ToolStripItem thing = (ToolStripItem)sender; ToolStripItem thing = (ToolStripItem)sender;
if (thing.Tag != null) if (thing.Tag != null)
{ {
@ -1291,7 +1280,6 @@ namespace EduNetworkBuilder
private void pbNetworkView_RemoveNetLink_Click(object sender, EventArgs e) private void pbNetworkView_RemoveNetLink_Click(object sender, EventArgs e)
{ {
ProcessChange();
ToolStripItem thing = (ToolStripItem)sender; ToolStripItem thing = (ToolStripItem)sender;
if (thing.Tag != null) if (thing.Tag != null)
{ {
@ -1307,8 +1295,6 @@ namespace EduNetworkBuilder
private void pbNetworkView_DHCPRequest_Click(object sender, EventArgs e) private void pbNetworkView_DHCPRequest_Click(object sender, EventArgs e)
{ {
ProcessChange();
ItemClickedOn.DHCPRequestFromHere(); ItemClickedOn.DHCPRequestFromHere();
myNetwork.ProcessPackets(); myNetwork.ProcessPackets();
UpdateMessages(); UpdateMessages();
@ -1320,7 +1306,6 @@ namespace EduNetworkBuilder
private void pbNetworkView_Reset_Click(object sender, EventArgs e) private void pbNetworkView_Reset_Click(object sender, EventArgs e)
{ {
if (ItemClickedOn == null) return; if (ItemClickedOn == null) return;
ProcessChange();
ItemClickedOn.ClearIPs(); //reset the device ItemClickedOn.ClearIPs(); //reset the device
UpdateVisuals(); UpdateVisuals();
} }
@ -1333,8 +1318,6 @@ namespace EduNetworkBuilder
return; return;
if (ItemClickedOn != null) if (ItemClickedOn != null)
{ {
ProcessChange();
DeviceConfig editwindow = new DeviceConfig(ItemClickedOn); DeviceConfig editwindow = new DeviceConfig(ItemClickedOn);
editwindow.ShowDialog(); editwindow.ShowDialog();
} }
@ -1364,8 +1347,6 @@ namespace EduNetworkBuilder
{ {
if(ShapeForEditing != null) if(ShapeForEditing != null)
{ {
ProcessChange();
myNetwork.RemoveShape(ShapeForEditing); myNetwork.RemoveShape(ShapeForEditing);
ShapeForEditing = null; ShapeForEditing = null;
UpdateForm(); UpdateForm();
@ -1375,8 +1356,6 @@ namespace EduNetworkBuilder
{ {
if (ShapeForEditing != null) if (ShapeForEditing != null)
{ {
ProcessChange();
ShapeEditor SE = new ShapeEditor(ShapeForEditing); ShapeEditor SE = new ShapeEditor(ShapeForEditing);
SE.ShowDialog(); SE.ShowDialog();
@ -1388,7 +1367,6 @@ namespace EduNetworkBuilder
private void pbNetworkView_Delete_Click(object sender, EventArgs e) private void pbNetworkView_Delete_Click(object sender, EventArgs e)
{ {
ProcessChange();
if (ItemsSelected.Count == 0) if (ItemsSelected.Count == 0)
{ {
TryDeleteOneItem(ItemClickedOn); TryDeleteOneItem(ItemClickedOn);
@ -1439,7 +1417,6 @@ namespace EduNetworkBuilder
{ {
if (ItemClickedOn == null) return; //we do not have something chosen to ping from if (ItemClickedOn == null) return; //we do not have something chosen to ping from
ToolStripMenuItem Pressed = (ToolStripMenuItem)sender; ToolStripMenuItem Pressed = (ToolStripMenuItem)sender;
ProcessChange();
string itemname = Pressed.Text; string itemname = Pressed.Text;
string dest = (string)Pressed.Tag; string dest = (string)Pressed.Tag;
@ -1455,7 +1432,6 @@ namespace EduNetworkBuilder
private void pbNetworkView_Traceroute_Name_Click(object sender, EventArgs e) private void pbNetworkView_Traceroute_Name_Click(object sender, EventArgs e)
{ {
if (ItemClickedOn == null) return; //we do not have something chosen to ping from if (ItemClickedOn == null) return; //we do not have something chosen to ping from
ProcessChange();
ToolStripMenuItem Pressed = (ToolStripMenuItem)sender; ToolStripMenuItem Pressed = (ToolStripMenuItem)sender;
string itemname = Pressed.Text; string itemname = Pressed.Text;
string dest = (string)Pressed.Tag; string dest = (string)Pressed.Tag;
@ -1500,7 +1476,6 @@ namespace EduNetworkBuilder
private void pbNetworkView_ArpClear_Click(object sender, EventArgs e) private void pbNetworkView_ArpClear_Click(object sender, EventArgs e)
{ {
if (ItemClickedOn == null) return; //we do not have something chosen to arp request from if (ItemClickedOn == null) return; //we do not have something chosen to arp request from
ProcessChange();
ItemClickedOn.ClearArps(); ItemClickedOn.ClearArps();
} }
@ -1570,7 +1545,6 @@ namespace EduNetworkBuilder
if (ItemClickedOn != null) PoweredOff = ItemClickedOn.PowerOff; if (ItemClickedOn != null) PoweredOff = ItemClickedOn.PowerOff;
if (!PoweredOff) if (!PoweredOff)
{ {
ProcessChange();
pbNetworkView_Edit_Click(sender, e); pbNetworkView_Edit_Click(sender, e);
} }
} }
@ -1608,8 +1582,6 @@ namespace EduNetworkBuilder
} }
else else
{ {
ProcessChange();
//We just made a shape. //We just made a shape.
try try
{ {
@ -1648,8 +1620,6 @@ namespace EduNetworkBuilder
MouseIsDown = false; MouseIsDown = false;
if (selectedButton == "btnLink") if (selectedButton == "btnLink")
{ {
ProcessChange();
//We are making a link //We are making a link
LinkEditor myEditor = new LinkEditor(ItemClickedOn, ReleasedOn); LinkEditor myEditor = new LinkEditor(ItemClickedOn, ReleasedOn);
myEditor.ShowDialog(); myEditor.ShowDialog();
@ -1658,8 +1628,6 @@ namespace EduNetworkBuilder
} }
else if (ItemClickedOn == null) else if (ItemClickedOn == null)
{ {
ProcessChange();
NetworkComponent NC = null; NetworkComponent NC = null;
switch (selectedButton) switch (selectedButton)
{ {
@ -1749,7 +1717,6 @@ namespace EduNetworkBuilder
{ {
if (!ItemClickedOn.IsLockedInLocation()) if (!ItemClickedOn.IsLockedInLocation())
{ {
ProcessChange();
ItemClickedOn.ChangeLocation(CenteredLocation); ItemClickedOn.ChangeLocation(CenteredLocation);
ItemClickedOn.UnHide(); //If it was hidden, unhide it ItemClickedOn.UnHide(); //If it was hidden, unhide it
UpdateLinks(); UpdateLinks();
@ -1769,6 +1736,7 @@ namespace EduNetworkBuilder
private void pbNetworkView_MouseDown(object sender, MouseEventArgs e) private void pbNetworkView_MouseDown(object sender, MouseEventArgs e)
{ {
ProcessChange(); //Before anything happens, store this state if we need to.
Point location = myNetwork.clickedPos(e.Location); Point location = myNetwork.clickedPos(e.Location);
ClickedLocation = location; ClickedLocation = location;
OrigClickPoint = myNetwork.clickedPosCentered(e.Location); OrigClickPoint = myNetwork.clickedPosCentered(e.Location);