From f4ab85f3597869ab04a0d1361724bc54354c5370 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Sat, 25 Feb 2017 10:33:56 +0300 Subject: [PATCH] IPAddress edit box should now appear inside the network box. --- EduNetworkBuilder/DeviceConfig.cs | 4 ++-- EduNetworkBuilder/IPAddress.cs | 8 ++++---- EduNetworkBuilder/IPAddressEntry.cs | 6 +++++- EduNetworkBuilder/ListBoxWindow.cs | 6 +++--- EduNetworkBuilder/NetworkBuilder.cs | 6 +++--- EduNetworkBuilder/NetworkCard.cs | 5 +++-- EduNetworkBuilder/NetworkCardEditor.cs | 2 +- EduNetworkBuilder/NetworkDevice.cs | 20 ++++++++++---------- EduNetworkBuilder/NetworkInterface.cs | 5 +++-- 9 files changed, 34 insertions(+), 28 deletions(-) diff --git a/EduNetworkBuilder/DeviceConfig.cs b/EduNetworkBuilder/DeviceConfig.cs index 65baecd..e16c174 100644 --- a/EduNetworkBuilder/DeviceConfig.cs +++ b/EduNetworkBuilder/DeviceConfig.cs @@ -432,7 +432,7 @@ namespace EduNetworkBuilder //selectedNIC = Regex.Replace(selectedNIC, " .*", ""); //selectedNIC = Regex.Replace(selectedNIC, "\\*", ""); - ndCLonedItem.EditNicInterface(selectedNIC, lbAddresses.SelectedIndex); + ndCLonedItem.EditNicInterface(selectedNIC, lbAddresses.SelectedIndex, this); UpdateForm(); } } @@ -483,7 +483,7 @@ namespace EduNetworkBuilder if (NB.GetComponentType(ClonedItem) == GeneralComponentType.device) { NetworkDevice nd = (NetworkDevice)ClonedItem; - nd.EditGateway(); + nd.EditGateway(this); UpdateForm(); } } diff --git a/EduNetworkBuilder/IPAddress.cs b/EduNetworkBuilder/IPAddress.cs index 1e7f2f7..38dc9e5 100644 --- a/EduNetworkBuilder/IPAddress.cs +++ b/EduNetworkBuilder/IPAddress.cs @@ -96,17 +96,17 @@ namespace EduNetworkBuilder return false; } - public bool Edit(NetworkDevice FromWhat, string message="") + public bool Edit(NetworkDevice FromWhat, Form ParentForm, string message="") { - IPAddressEntry IPe = new IPAddressEntry(this, FromWhat); + IPAddressEntry IPe = new IPAddressEntry(this, FromWhat, ParentForm); if (message != "") IPe.Text = message; return IPe.Edit(); } - public bool Edit(NetworkDevice FromWhat, IPAddress DHCPif) + public bool Edit(NetworkDevice FromWhat, IPAddress DHCPif, Form ParentForm) { - IPAddressEntry IPe = new IPAddressEntry(this, FromWhat); + IPAddressEntry IPe = new IPAddressEntry(this, FromWhat, ParentForm); return IPe.Edit(FromWhat, DHCPif); } diff --git a/EduNetworkBuilder/IPAddressEntry.cs b/EduNetworkBuilder/IPAddressEntry.cs index 0de312e..098b872 100644 --- a/EduNetworkBuilder/IPAddressEntry.cs +++ b/EduNetworkBuilder/IPAddressEntry.cs @@ -21,10 +21,14 @@ namespace EduNetworkBuilder NetworkDevice ParentDevice = null; - public IPAddressEntry(IPAddress toEdit, NetworkDevice ToEdit) + public IPAddressEntry(IPAddress toEdit, NetworkDevice ToEdit, Form ParentForm) { InitializeComponent(); LanguagifyComponents(); + if(ParentForm != null) + { + Location = new Point(ParentForm.Location.X + (ParentForm.Width / 2), ParentForm.Location.Y + (ParentForm.Height / 2)); + } ParentDevice = ToEdit; Network myNet = NB.GetNetwork(); IPAddress lastIP = myNet.RetrieveLastIP(); diff --git a/EduNetworkBuilder/ListBoxWindow.cs b/EduNetworkBuilder/ListBoxWindow.cs index d265dc6..1676c30 100644 --- a/EduNetworkBuilder/ListBoxWindow.cs +++ b/EduNetworkBuilder/ListBoxWindow.cs @@ -385,7 +385,7 @@ namespace EduNetworkBuilder private void AddRoute() { IPAddress newip = new IPAddress(NB.ZeroIPString, NB.ZeroIPString, NB.ZeroIPString); - newip.Edit(myNetDevice,NB.Translate("LBW_AddRouteCreate")); + newip.Edit(myNetDevice, this, NB.Translate("LBW_AddRouteCreate")); myNetDevice.AddRoute(newip); UpdateForm(); } @@ -398,12 +398,12 @@ namespace EduNetworkBuilder if (lbWindowData.SelectedIndex >= EditableCount) return; if (lbWindowData.SelectedIndex < 1) return; //we always subtract 1 since we have added one line of comment to the list - myNetDevice.EditRoute(lbWindowData.SelectedIndex - 1); + myNetDevice.EditRoute(lbWindowData.SelectedIndex - 1, this); } if(MyMode == LBContents.dhcp) { //We always add one since we are skipping the loopback device - myNetDevice.EditDHCP(lbWindowData.SelectedIndex + 1); + myNetDevice.EditDHCP(lbWindowData.SelectedIndex + 1, this); } if (MyMode == LBContents.puzzles) { diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index 825d5fa..800a5c3 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -773,7 +773,7 @@ namespace EduNetworkBuilder bool todo = true; if (ItemClickedOn == null) return; //we do not have something chosen to ping from IPAddress destination = new IPAddress(NB.ZeroIPString, NB.ZeroIPString, IPAddressType.ip_only); - todo = destination.Edit(ItemClickedOn, NB.Translate("_Ping")); + todo = destination.Edit(ItemClickedOn, this, NB.Translate("_Ping")); if(todo) { ItemClickedOn.PingFromHere(destination); @@ -815,7 +815,7 @@ namespace EduNetworkBuilder bool todo = true; if (ItemClickedOn == null) return; //we do not have something chosen to arp request from IPAddress destination = new IPAddress(NB.ZeroIPString, "255.255.255.255", IPAddressType.ip_only); - todo = destination.Edit(ItemClickedOn, NB.Translate("H_ARP_Title2")); + todo = destination.Edit(ItemClickedOn, this, NB.Translate("H_ARP_Title2")); if (todo) { ItemClickedOn.AskArpFromHere(destination); @@ -1155,7 +1155,7 @@ namespace EduNetworkBuilder { bool todo = true; IPAddress destination = new IPAddress(NB.ZeroIPString, NB.ZeroIPString, IPAddressType.ip_only); - todo = destination.Edit(null, NB.Translate("NB_NetViewPng")); + todo = destination.Edit(null, this, NB.Translate("NB_NetViewPng")); if (todo) { myNetwork.DoAllPing(destination); diff --git a/EduNetworkBuilder/NetworkCard.cs b/EduNetworkBuilder/NetworkCard.cs index e7e8e04..f7c11f1 100644 --- a/EduNetworkBuilder/NetworkCard.cs +++ b/EduNetworkBuilder/NetworkCard.cs @@ -7,6 +7,7 @@ using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization; using System.IO; using System.Xml; +using System.Windows.Forms; namespace EduNetworkBuilder @@ -251,11 +252,11 @@ namespace EduNetworkBuilder return false; } - public void EditInterface(int index) + public void EditInterface(int index, Form ParentForm) { if (index < 0 || index > interfaces.Count()) return; - interfaces[index].EditAddress(); + interfaces[index].EditAddress(ParentForm); } public void DeleteInterface(int index) { diff --git a/EduNetworkBuilder/NetworkCardEditor.cs b/EduNetworkBuilder/NetworkCardEditor.cs index e9fcf72..9ed73ad 100644 --- a/EduNetworkBuilder/NetworkCardEditor.cs +++ b/EduNetworkBuilder/NetworkCardEditor.cs @@ -191,7 +191,7 @@ namespace EduNetworkBuilder { MyNicToEdit.TunnelEndpoint = new IPAddress(NB.ZeroIPString, "255.255.255.0", IPAddressType.ip_only); } - MyNicToEdit.TunnelEndpoint.Edit(nd, NB.Translate("_Endpt")); + MyNicToEdit.TunnelEndpoint.Edit(nd, this, NB.Translate("_Endpt")); UpdateForm(); } } diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index 025d81b..3e0fa64 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -293,9 +293,9 @@ namespace EduNetworkBuilder } } - public void EditGateway() + public void EditGateway(Form ParentForm) { - DefaultGW.Edit(this,NB.Translate("ND_EdtGteway")); + DefaultGW.Edit(this,ParentForm,NB.Translate("ND_EdtGteway")); } public IPAddress GetGateway() @@ -703,11 +703,11 @@ namespace EduNetworkBuilder } } - public void EditNicInterface(int NicIndex, int ifIndex) + public void EditNicInterface(int NicIndex, int ifIndex, Form ParentForm) { if(NicIndex >=0 && NicIndex < NICs.Count()) { - NICs[NicIndex].EditInterface(ifIndex); + NICs[NicIndex].EditInterface(ifIndex, ParentForm); } } public void DeleteNicInterface(int NicIndex, int ifIndex) @@ -717,12 +717,12 @@ namespace EduNetworkBuilder NICs[NicIndex].DeleteInterface(ifIndex); } } - public void EditNicInterface(string NicName, int ifIndex) + public void EditNicInterface(string NicName, int ifIndex, Form ParentForm) { NetworkCard nic = NicFromName(NicName); if (nic != null) { - nic.EditInterface(ifIndex); + nic.EditInterface(ifIndex, ParentForm); } } @@ -2402,11 +2402,11 @@ namespace EduNetworkBuilder return RouteTable; } - public void EditRoute(int index) + public void EditRoute(int index, Form ParentForm) { if (index < 0) return; if (index >= RouteTable.Count) return; - RouteTable[index].Edit(this); + RouteTable[index].Edit(this, ParentForm); } public void DeleteRoute(int index) { @@ -2740,7 +2740,7 @@ namespace EduNetworkBuilder } return null; } - public void EditDHCP(int index) + public void EditDHCP(int index, Form ParentForm) { if (index > DHCPRanges.Count) return; if (index < 0) return; @@ -2756,7 +2756,7 @@ namespace EduNetworkBuilder } } if (!found) return; - DHCPRanges[index].Edit(this, ifIP); //We need to pass the interface that is local to this + DHCPRanges[index].Edit(this, ifIP, ParentForm); //We need to pass the interface that is local to this DHCPLeases.Clear(); } diff --git a/EduNetworkBuilder/NetworkInterface.cs b/EduNetworkBuilder/NetworkInterface.cs index 11efc1e..d1670fe 100644 --- a/EduNetworkBuilder/NetworkInterface.cs +++ b/EduNetworkBuilder/NetworkInterface.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; +using System.Windows.Forms; using System.Text.RegularExpressions; namespace EduNetworkBuilder @@ -167,11 +168,11 @@ namespace EduNetworkBuilder /// /// Pop up a window to edit this address. /// - public void EditAddress() + public void EditAddress(Form ParentForm) { Network myNet = NB.GetNetwork(); NetworkDevice ND = myNet.GetDeviceFromID(AttachedToHostNic); - IPAddressEntry ipe = new IPAddressEntry(myIP,ND); + IPAddressEntry ipe = new IPAddressEntry(myIP,ND, ParentForm); ipe.ShowDialog(); } public bool isLocal(IPAddress tIp, bool AllowZeroMatch = true)