From 06eb8965585d0ceafd30bea8e85390eb6db1a76a Mon Sep 17 00:00:00 2001 From: Tim Young Date: Sat, 23 Feb 2019 12:11:20 -0600 Subject: [PATCH] cancel should also cancel auto-filled lastIP values The problem is seen in the first puzzle if you ping pc0, and then edit the 0.0.0.0 gateway. It auto-fills in the last-used pc0 IP address, and canceling saves that change instead of leaving the gateway at 0.0.0.0. lastIP nicely saves some typing (although it has also confused my student quite a bit I think), but since it updates WhatToEdit, that becomes the "saved" value even during a cancel. Instead, save the original value as a copy, and set back to the original value when cancellng. Perhaps it would be worth creating a reparse( NB_IPAddress) function, but this was easy to just hack together. Tested by pinging pc0, then editing the gateway and cancellng, editing the IP address and canceling. Next: don't add a canceled route --- EduNetworkBuilder/IPAddressEntry.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/EduNetworkBuilder/IPAddressEntry.cs b/EduNetworkBuilder/IPAddressEntry.cs index 3d9732d..6c50d24 100644 --- a/EduNetworkBuilder/IPAddressEntry.cs +++ b/EduNetworkBuilder/IPAddressEntry.cs @@ -21,6 +21,8 @@ namespace EduNetworkBuilder NetworkDevice ParentDevice = null; Point StartLocation = new Point (50,50); + NB_IPAddress SavedIPAddress = null; + public IPAddressEntry(NB_IPAddress toEdit, NetworkDevice ToEdit, Form ParentForm, bool JustPinging=false) { @@ -34,6 +36,7 @@ namespace EduNetworkBuilder ParentDevice = ToEdit; Network myNet = NB.GetNetwork(); NB_IPAddress lastIP = myNet.RetrieveLastIP(); + SavedIPAddress = new NB_IPAddress(toEdit); WhatToEdit = toEdit; string hostname = ""; if (ToEdit != null) @@ -182,6 +185,8 @@ namespace EduNetworkBuilder private void btnCancel_Click(object sender, EventArgs e) { + if(SavedIPAddress != null) + WhatToEdit.Reparse(SavedIPAddress.GetIPString, SavedIPAddress.GetMaskString, SavedIPAddress.GetGateway.ToIpString()); UpdateFieldsFromAddress(); WellDone = false; Close();