Disable Options menu when we loaded a puzzle from a resource. Cleaned up the load system a little bit.

This commit is contained in:
Tim Young 2017-07-20 14:50:03 -05:00
parent 66db081eab
commit 437bb2601e
2 changed files with 48 additions and 29 deletions

View File

@ -28,6 +28,11 @@ namespace EduNetworkBuilder
public bool ShowLabelsHere = false; public bool ShowLabelsHere = false;
public bool VLANsEnabled = false; public bool VLANsEnabled = false;
public bool VLANPacketColors = false; public bool VLANPacketColors = false;
private bool _LoadedFromResource = false; //If we are a puzzle that is built-into the program
public bool LoadedFromResource {
get { return _LoadedFromResource; }
private set { _LoadedFromResource = value; }
}
public LanguageStrings NetMessage; public LanguageStrings NetMessage;
public LanguageStrings NetTitle; public LanguageStrings NetTitle;
List<NetworkComponent> NetComponents = new List<NetworkComponent>(); List<NetworkComponent> NetComponents = new List<NetworkComponent>();
@ -113,13 +118,14 @@ namespace EduNetworkBuilder
} }
} }
public void Load(XmlNode TheNode, string Name) public void Load(XmlNode TheNode, string Name, bool FromResource=false)
{ {
_isDirty = true; _isDirty = true;
NetworkDevice newND; NetworkDevice newND;
NetworkLink newNL; NetworkLink newNL;
int newUnique=-1; int newUnique=-1;
PuzzleName = Name; PuzzleName = Name;
LoadedFromResource = FromResource;
foreach (XmlNode Individual in TheNode.ChildNodes) foreach (XmlNode Individual in TheNode.ChildNodes)
{ {
XmlNodeType myNodetype = Individual.NodeType; XmlNodeType myNodetype = Individual.NodeType;
@ -129,7 +135,7 @@ namespace EduNetworkBuilder
{ {
case "edunetworkbuilder": case "edunetworkbuilder":
case "network": case "network":
Load(Individual,PuzzleName); Load(Individual,PuzzleName, FromResource);
break; break;
case "showlabels": case "showlabels":
bool.TryParse(Individual.InnerText, out OptionShowLabels); bool.TryParse(Individual.InnerText, out OptionShowLabels);
@ -1522,6 +1528,14 @@ namespace EduNetworkBuilder
return -1; return -1;
} }
/// <summary>
/// For solved puzzles. We can add options to them
/// </summary>
public void OverrideFromResources()
{
LoadedFromResource = false;
}
public void DoAllClearArp() public void DoAllClearArp()
{ {
NetworkDevice nd; NetworkDevice nd;

View File

@ -400,6 +400,10 @@ namespace EduNetworkBuilder
UpdateMenu(); UpdateMenu();
UpdateMessages(); UpdateMessages();
UpdateVisuals(); UpdateVisuals();
if (myNetwork != null && myNetwork.LoadedFromResource)
optionsToolStripMenuItem.Visible = false;
else
optionsToolStripMenuItem.Visible = true;
processing = true; processing = true;
cbViewTitles.Checked = myNetwork.ShowLabelsHere; cbViewTitles.Checked = myNetwork.ShowLabelsHere;
Text = NB.Translate("NB_UpdteFrmName", OurSettings); Text = NB.Translate("NB_UpdteFrmName", OurSettings);
@ -1530,76 +1534,77 @@ namespace EduNetworkBuilder
//myString = System.Text.Encoding.Default.GetString(item); //myString = System.Text.Encoding.Default.GetString(item);
xmlDoc.LoadXml(myString); xmlDoc.LoadXml(myString);
PrepForLoad(); PrepForLoad();
myNetwork.Load(xmlDoc,resource); myNetwork.Load(xmlDoc,resource, true);//Load it from resource. Set the bool saying it was from resource
UpdateMenu(); UpdateMenu();
UpdateForm(); UpdateForm();
} }
private void LoadSolvedResource(string what)
{
LoadNetworkFromResource(what);
myNetwork.OverrideFromResources();
UpdateForm();
UpdateMessages();
}
private void LoadUnsolvedResource(string what)
{
//Load the puzzle & everything we need to do with it
LoadSolvedResource(what);
//Then "unsolve" it
myNetwork.DoAllClearIPs();
}
private void oneNetworkToolStripMenuItem_Click(object sender, EventArgs e) private void oneNetworkToolStripMenuItem_Click(object sender, EventArgs e)
{ {
LoadNetworkFromResource("OneNet"); LoadSolvedResource("OneNet");
UpdateMessages();
} }
private void twoNetworksToolStripMenuItem_Click(object sender, EventArgs e) private void twoNetworksToolStripMenuItem_Click(object sender, EventArgs e)
{ {
LoadNetworkFromResource("TwoNets"); LoadSolvedResource("TwoNets");
UpdateMessages();
} }
private void dHCPToolStripMenuItem_Click(object sender, EventArgs e) private void dHCPToolStripMenuItem_Click(object sender, EventArgs e)
{ {
LoadNetworkFromResource("DHCP"); LoadSolvedResource("DHCP");
UpdateMessages();
} }
private void solvedOneNetworkToolStripMenuItem_Click(object sender, EventArgs e) private void solvedOneNetworkToolStripMenuItem_Click(object sender, EventArgs e)
{ {
LoadNetworkFromResource("OneNet"); LoadUnsolvedResource("OneNet");
myNetwork.DoAllClearIPs();
UpdateMessages();
} }
private void solvedTwoNetworksToolStripMenuItem_Click(object sender, EventArgs e) private void solvedTwoNetworksToolStripMenuItem_Click(object sender, EventArgs e)
{ {
LoadNetworkFromResource("TwoNets"); LoadUnsolvedResource("TwoNets");
myNetwork.DoAllClearIPs();
UpdateMessages();
} }
private void solvedDHCPToolStripMenuItem_Click(object sender, EventArgs e) private void solvedDHCPToolStripMenuItem_Click(object sender, EventArgs e)
{ {
LoadNetworkFromResource("DHCP"); //Umm. The function name is solved, but we are doing the unsolved version?
myNetwork.DoAllClearIPs(); LoadUnsolvedResource("DHCP");
UpdateMessages();
} }
private void VLANToolStripMenuItem_Click(object sender, EventArgs e) private void VLANToolStripMenuItem_Click(object sender, EventArgs e)
{ {
LoadNetworkFromResource("VLAN"); LoadSolvedResource("VLAN");
UpdateMessages();
} }
private void SolvedVLANToolStripMenuItem1_Click(object sender, EventArgs e) private void SolvedVLANToolStripMenuItem1_Click(object sender, EventArgs e)
{ {
LoadNetworkFromResource("VLAN"); LoadUnsolvedResource("VLAN");
myNetwork.DoAllClearIPs();
UpdateMessages();
UpdateVisuals();
} }
private void threeNetworksToolStripMenuItem_Click(object sender, EventArgs e) private void threeNetworksToolStripMenuItem_Click(object sender, EventArgs e)
{ {
LoadNetworkFromResource("ThreeNets"); LoadSolvedResource("ThreeNets");
UpdateMessages();
} }
private void SolvedThreeNetworksToolStripMenuItem_Click(object sender, EventArgs e) private void SolvedThreeNetworksToolStripMenuItem_Click(object sender, EventArgs e)
{ {
LoadNetworkFromResource("ThreeNets"); LoadUnsolvedResource("ThreeNets");
myNetwork.DoAllClearIPs();
UpdateMessages();
} }
private void newToolStripMenuItem_Click(object sender, EventArgs e) private void newToolStripMenuItem_Click(object sender, EventArgs e)