initial ctrl-z working

This commit is contained in:
Tim Young 2018-03-15 17:12:20 -05:00
parent d40d9aee58
commit 565ab9489d
8 changed files with 97 additions and 5 deletions

View File

@ -9,6 +9,7 @@ using System.Windows.Forms;
namespace EduNetworkBuilder
{
//Holds a little bit of information pertaining to the current animation.
[Serializable]
public class AnimationClass
{
Point ImageStartPoint = new Point();

View File

@ -8,6 +8,7 @@ using System.Text.RegularExpressions;
namespace EduNetworkBuilder
{
[Serializable]
public class LanguageString
{
@ -58,6 +59,7 @@ namespace EduNetworkBuilder
}
}
[Serializable]
public class LanguageStrings
{
List<LanguageString> TheStrings = new List<LanguageString>();

View File

@ -189,7 +189,7 @@ namespace EduNetworkBuilder
internalIP = internal_ip;
}
}
[Serializable]
public class PingTestStatus
{
public string Source;
@ -211,6 +211,7 @@ namespace EduNetworkBuilder
}
}
[Serializable]
public class PuzzleInfo
{
public string PuzzleName;
@ -320,6 +321,7 @@ namespace EduNetworkBuilder
}
}
[Serializable]
public class HelpURL
{
public string URL = "";

View File

@ -11,6 +11,7 @@ namespace EduNetworkBuilder
/// <summary>
/// For drawing shapes on a network. Rectangles, circles. Filled or not
/// </summary>
[Serializable]
public class NetShape
{
public NetShapeType MyShape = NetShapeType.none;

View File

@ -45,6 +45,7 @@ namespace EduNetworkBuilder
Image TheNetImage = new Bitmap(1024, 1024);
Image TheNetImageBackground = new Bitmap(1024, 1024);
public int itemsize = 100; //The size of network components
[NonSerialized]
PictureBox myPBox = null;
private int UniqueIdentifier = 100; //This gets used for all sorts of things. is auto-incremented every time someone asks for one
private List<Packet> myPackets = new List<Packet>();

View File

@ -61,6 +61,7 @@ namespace EduNetworkBuilder
public PersonClass CurrentUser;
private List<HelpURL> HelpURLs = new List<HelpURL>();
private List<Network> storedNetworkStates = new List<Network>(); //for ctrl-z going back in time to past state
public BuilderWindow(string FirstArg="")
{
@ -231,11 +232,55 @@ namespace EduNetworkBuilder
}
if (e.KeyCode == Keys.Z && e.Modifiers == Keys.Control)
{
//ctrl-z
if(storedNetworkStates.Count > 0)
{
ChangeToPastState(storedNetworkStates[0]);
storedNetworkStates.RemoveAt(0);
}
}
//MessageBox.Show(e.KeyCode.ToString());
}
public void StoreNetworkState(Network toStore)
{
//We should verify something has changed before storing it. Oh well...
storedNetworkStates.Insert(0,Network.DeepClone(toStore));
int maxCount = 30;
if(storedNetworkStates.Count > maxCount)
{
storedNetworkStates.RemoveRange(maxCount, storedNetworkStates.Count - maxCount);
}
}
/// <summary>
/// We do this every time we load a new network or create a network from scratch
/// </summary>
public void ClearStoredNetworkStates()
{
storedNetworkStates.Clear();
}
/// <summary>
/// Store the new state after a change has been made.
/// Do this before every change (add, delete, move)
/// </summary>
public void ProcessChange()
{
StoreNetworkState(myNetwork);
}
public void ChangeToPastState(Network OldNet)
{
if (OldNet != null)
{
myNetwork = OldNet;
myNetwork.RegisterDisplayArea(pbNetworkView);
UpdateMenu();
UpdateForm();
}
}
/// <summary>
/// Return the control with the given name. Used primarily to color help buttons
/// </summary>
@ -1059,6 +1104,8 @@ namespace EduNetworkBuilder
{
if (ItemClickedOn != null)
{
ProcessChange();
ItemClickedOn.Hide();
UpdateLinks();
UpdateVisuals();
@ -1069,6 +1116,7 @@ namespace EduNetworkBuilder
{
if (ItemClickedOn != null)
{
ProcessChange();
ItemClickedOn.PowerOff = false;
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);
@ -1106,6 +1154,7 @@ namespace EduNetworkBuilder
{
if (ItemClickedOn != null)
{
ProcessChange();
ItemClickedOn.PowerOff = true;
//Mark the replace test as "done"
myNetwork.RegisterDeviceReset(ItemClickedOn.hostname);
@ -1117,6 +1166,7 @@ namespace EduNetworkBuilder
//We will still do this for devices that are spraying the network
private void pbNetworkView_Replace_Click(object sender, EventArgs e)
{
ProcessChange();
if (ItemClickedOn != null)
{
if (ItemClickedOn == null) return;
@ -1135,6 +1185,8 @@ namespace EduNetworkBuilder
{
if (ItemClickedOn != null)
{
ProcessChange();
if (ItemClickedOn == null) return;
//Changing a UPS makes sure the power is off when done.
ItemClickedOn.PowerOff = true;
@ -1182,6 +1234,7 @@ namespace EduNetworkBuilder
private void pbNetworkView_RemoveLink_Click(object sender, EventArgs e)
{
ProcessChange();
ToolStripItem thing = (ToolStripItem)sender;
string released = thing.Text;
released = Regex.Replace(released, ".* ", "");
@ -1200,6 +1253,8 @@ namespace EduNetworkBuilder
ToolStripItem thing = (ToolStripItem)sender;
if (thing.Tag != null)
{
ProcessChange();
NetworkLink NL = (NetworkLink)thing.Tag;
//This may delete the old link and make a new one
LinkEditor LE = new LinkEditor(NL);
@ -1212,6 +1267,7 @@ namespace EduNetworkBuilder
private void pbNetworkView_ReplaceNetLink_Click(object sender, EventArgs e)
{
ProcessChange();
ToolStripItem thing = (ToolStripItem)sender;
if (thing.Tag != null)
{
@ -1234,6 +1290,7 @@ namespace EduNetworkBuilder
private void pbNetworkView_RemoveNetLink_Click(object sender, EventArgs e)
{
ProcessChange();
ToolStripItem thing = (ToolStripItem)sender;
if (thing.Tag != null)
{
@ -1249,6 +1306,8 @@ namespace EduNetworkBuilder
private void pbNetworkView_DHCPRequest_Click(object sender, EventArgs e)
{
ProcessChange();
ItemClickedOn.DHCPRequestFromHere();
myNetwork.ProcessPackets();
UpdateMessages();
@ -1260,6 +1319,7 @@ namespace EduNetworkBuilder
private void pbNetworkView_Reset_Click(object sender, EventArgs e)
{
if (ItemClickedOn == null) return;
ProcessChange();
ItemClickedOn.ClearIPs(); //reset the device
UpdateVisuals();
}
@ -1272,6 +1332,7 @@ namespace EduNetworkBuilder
return;
if (ItemClickedOn != null)
{
ProcessChange();
DeviceConfig editwindow = new DeviceConfig(ItemClickedOn);
editwindow.ShowDialog();
@ -1302,6 +1363,8 @@ namespace EduNetworkBuilder
{
if(ShapeForEditing != null)
{
ProcessChange();
myNetwork.RemoveShape(ShapeForEditing);
ShapeForEditing = null;
UpdateForm();
@ -1311,6 +1374,8 @@ namespace EduNetworkBuilder
{
if (ShapeForEditing != null)
{
ProcessChange();
ShapeEditor SE = new ShapeEditor(ShapeForEditing);
SE.ShowDialog();
@ -1322,11 +1387,14 @@ namespace EduNetworkBuilder
private void pbNetworkView_Delete_Click(object sender, EventArgs e)
{
if(ItemsSelected.Count ==0)
ProcessChange();
if (ItemsSelected.Count == 0)
{
TryDeleteOneItem(ItemClickedOn);
}
else
{
for(int i=ItemsSelected.Count -1; i>=0; i--)
for (int i = ItemsSelected.Count - 1; i >= 0; i--)
{
TryDeleteOneItem(ItemsSelected[i]);
}
@ -1370,6 +1438,8 @@ namespace EduNetworkBuilder
{
if (ItemClickedOn == null) return; //we do not have something chosen to ping from
ToolStripMenuItem Pressed = (ToolStripMenuItem)sender;
ProcessChange();
string itemname = Pressed.Text;
string dest = (string)Pressed.Tag;
NB_IPAddress destination;
@ -1384,6 +1454,7 @@ namespace EduNetworkBuilder
private void pbNetworkView_Traceroute_Name_Click(object sender, EventArgs e)
{
if (ItemClickedOn == null) return; //we do not have something chosen to ping from
ProcessChange();
ToolStripMenuItem Pressed = (ToolStripMenuItem)sender;
string itemname = Pressed.Text;
string dest = (string)Pressed.Tag;
@ -1428,6 +1499,7 @@ namespace EduNetworkBuilder
private void pbNetworkView_ArpClear_Click(object sender, EventArgs e)
{
if (ItemClickedOn == null) return; //we do not have something chosen to arp request from
ProcessChange();
ItemClickedOn.ClearArps();
}
@ -1495,8 +1567,11 @@ namespace EduNetworkBuilder
bool PoweredOff = false;
//This mouse-up is part of a double-click operation. Do an edit. But only if we are powered on
if (ItemClickedOn != null) PoweredOff = ItemClickedOn.PowerOff;
if(!PoweredOff)
if (!PoweredOff)
{
ProcessChange();
pbNetworkView_Edit_Click(sender, e);
}
}
else
{
@ -1532,6 +1607,8 @@ namespace EduNetworkBuilder
}
else
{
ProcessChange();
//We just made a shape.
try
{
@ -1570,6 +1647,8 @@ namespace EduNetworkBuilder
MouseIsDown = false;
if (selectedButton == "btnLink")
{
ProcessChange();
//We are making a link
LinkEditor myEditor = new LinkEditor(ItemClickedOn, ReleasedOn);
myEditor.ShowDialog();
@ -1578,6 +1657,8 @@ namespace EduNetworkBuilder
}
else if (ItemClickedOn == null)
{
ProcessChange();
NetworkComponent NC = null;
switch (selectedButton)
{
@ -1667,6 +1748,7 @@ namespace EduNetworkBuilder
{
if (!ItemClickedOn.IsLockedInLocation())
{
ProcessChange();
ItemClickedOn.ChangeLocation(CenteredLocation);
ItemClickedOn.UnHide(); //If it was hidden, unhide it
UpdateLinks();
@ -1857,6 +1939,7 @@ namespace EduNetworkBuilder
private void PrepForLoad()
{
processing = true;
ClearStoredNetworkStates();
myNetwork = new Network("");
myNetwork.RegisterDisplayArea(pbNetworkView);
GC.Collect();

View File

@ -12,6 +12,7 @@ namespace EduNetworkBuilder
/// <summary>
/// A class holding a project that needs to be done as either a test, quiz, or homework
/// </summary>
[Serializable]
public class SchoolworkClass
{
public Network theProject = null;

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
namespace EduNetworkBuilder
{
[Serializable]
public class TraversalClass
{
protected struct TraversalRecord