# HG changeset patch # User moel.mich # Date 1325437954 0 # Node ID e837e1e4b282ee694e19cbcbba10c48f651457b3 # Parent a41745e3828dbe6f06d489fdfbbdd32fb96a7cef Added code to save and restore the plot sensor selection. diff -r a41745e3828d -r e837e1e4b282 GUI/HardwareNode.cs --- a/GUI/HardwareNode.cs Sun Jan 01 15:46:42 2012 +0000 +++ b/GUI/HardwareNode.cs Sun Jan 01 17:12:34 2012 +0000 @@ -108,9 +108,14 @@ if (n != null && n.Sensor == sensor) sensorNode = n; } - typeNode.Nodes.Remove(sensorNode); - UpdateNode(typeNode); + if (sensorNode != null) { + sensorNode.PlotSelectionChanged -= SensorPlotSelectionChanged; + typeNode.Nodes.Remove(sensorNode); + UpdateNode(typeNode); + } } + if (PlotSelectionChanged != null) + PlotSelectionChanged(this, null); } private void InsertSorted(Node node, ISensor sensor) { @@ -119,15 +124,25 @@ ((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index) i++; SensorNode sensorNode = new SensorNode(sensor, settings, unitManager); + sensorNode.PlotSelectionChanged += SensorPlotSelectionChanged; node.Nodes.Insert(i, sensorNode); } + private void SensorPlotSelectionChanged(object sender, EventArgs e) { + if (PlotSelectionChanged != null) + PlotSelectionChanged(this, null); + } + private void SensorAdded(ISensor sensor) { foreach (TypeNode typeNode in typeNodes) if (typeNode.SensorType == sensor.SensorType) { InsertSorted(typeNode, sensor); UpdateNode(typeNode); } - } + if (PlotSelectionChanged != null) + PlotSelectionChanged(this, null); + } + + public event EventHandler PlotSelectionChanged; } } diff -r a41745e3828d -r e837e1e4b282 GUI/MainForm.cs --- a/GUI/MainForm.cs Sun Jan 01 15:46:42 2012 +0000 +++ b/GUI/MainForm.cs Sun Jan 01 17:12:34 2012 +0000 @@ -116,7 +116,6 @@ plotPanel.Dock = DockStyle.Fill; nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded; - nodeCheckBox.CheckStateChanged += UpdatePlotSelection; nodeTextBoxText.DrawText += nodeTextBoxText_DrawText; nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText; nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText; @@ -160,14 +159,7 @@ gadget.HideShowCommand += hideShowClick; wmiProvider = new WmiProvider(computer); - } - - computer.HardwareAdded += new HardwareEventHandler(HardwareAdded); - computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved); - - computer.Open(); - - timer.Enabled = true; + } plotColorPalette = new Color[13]; plotColorPalette[0] = Color.Blue; @@ -183,6 +175,13 @@ plotColorPalette[10] = Color.MediumSeaGreen; plotColorPalette[11] = Color.Olive; plotColorPalette[12] = Color.Firebrick; + + computer.HardwareAdded += new HardwareEventHandler(HardwareAdded); + computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved); + + computer.Open(); + + timer.Enabled = true; showHiddenSensors = new UserOption("hiddenMenuItem", false, hiddenMenuItem, settings); @@ -234,7 +233,6 @@ settings); readHddSensors.Changed += delegate(object sender, EventArgs e) { computer.HDDEnabled = readHddSensors.Value; - UpdatePlotSelection(null, null); }; showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem, @@ -368,28 +366,32 @@ } private void SubHardwareAdded(IHardware hardware, Node node) { - Node hardwareNode = new HardwareNode(hardware, settings, unitManager); + HardwareNode hardwareNode = + new HardwareNode(hardware, settings, unitManager); + hardwareNode.PlotSelectionChanged += PlotSelectionChanged; + node.Nodes.Add(hardwareNode); foreach (IHardware subHardware in hardware.SubHardware) SubHardwareAdded(subHardware, hardwareNode); } - private void HardwareAdded(IHardware hardware) { - Node hardwareNode = new HardwareNode(hardware, settings, unitManager); - root.Nodes.Add(hardwareNode); - foreach (IHardware subHardware in hardware.SubHardware) - SubHardwareAdded(subHardware, hardwareNode); + private void HardwareAdded(IHardware hardware) { + SubHardwareAdded(hardware, root); + PlotSelectionChanged(this, null); } - private void HardwareRemoved(IHardware hardware) { - List nodesToRemove = new List(); + private void HardwareRemoved(IHardware hardware) { + List nodesToRemove = new List(); foreach (Node node in root.Nodes) { HardwareNode hardwareNode = node as HardwareNode; if (hardwareNode != null && hardwareNode.Hardware == hardware) - nodesToRemove.Add(node); + nodesToRemove.Add(hardwareNode); } - foreach (Node node in nodesToRemove) - root.Nodes.Remove(node); + foreach (HardwareNode hardwareNode in nodesToRemove) { + root.Nodes.Remove(hardwareNode); + hardwareNode.PlotSelectionChanged -= PlotSelectionChanged; + } + PlotSelectionChanged(this, null); } private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) { @@ -407,15 +409,13 @@ } } - private void UpdatePlotSelection(object sender, - TreePathEventArgs e) - { + private void PlotSelectionChanged(object sender, EventArgs e) { List selected = new List(); IDictionary colors = new Dictionary(); int colorIndex = 0; foreach (TreeNodeAdv node in treeView.AllNodes) { SensorNode sensorNode = node.Tag as SensorNode; - if (sensorNode != null && + if (sensorNode != null && sensorNode.Sensor.SensorType == SensorType.Temperature) { if (sensorNode.Plot) { colors.Add(sensorNode.Sensor, diff -r a41745e3828d -r e837e1e4b282 GUI/SensorNode.cs --- a/GUI/SensorNode.cs Sun Jan 01 15:46:42 2012 +0000 +++ b/GUI/SensorNode.cs Sun Jan 01 17:12:34 2012 +0000 @@ -82,6 +82,9 @@ bool hidden = settings.GetValue(new Identifier(sensor.Identifier, "hidden").ToString(), sensor.IsDefaultHidden); base.IsVisible = !hidden; + + this.Plot = settings.GetValue(new Identifier(sensor.Identifier, + "plot").ToString(), false); } public override string Text { @@ -100,9 +103,17 @@ public bool Plot { get { return plot; } - set { plot = value; } + set { + plot = value; + settings.SetValue(new Identifier(sensor.Identifier, "plot").ToString(), + value); + if (PlotSelectionChanged != null) + PlotSelectionChanged(this, null); + } } + public event EventHandler PlotSelectionChanged; + public ISensor Sensor { get { return sensor; } }