Added code to save and restore the plot sensor selection.
1.1 --- a/GUI/HardwareNode.cs Sun Jan 01 15:46:42 2012 +0000
1.2 +++ b/GUI/HardwareNode.cs Sun Jan 01 17:12:34 2012 +0000
1.3 @@ -108,9 +108,14 @@
1.4 if (n != null && n.Sensor == sensor)
1.5 sensorNode = n;
1.6 }
1.7 - typeNode.Nodes.Remove(sensorNode);
1.8 - UpdateNode(typeNode);
1.9 + if (sensorNode != null) {
1.10 + sensorNode.PlotSelectionChanged -= SensorPlotSelectionChanged;
1.11 + typeNode.Nodes.Remove(sensorNode);
1.12 + UpdateNode(typeNode);
1.13 + }
1.14 }
1.15 + if (PlotSelectionChanged != null)
1.16 + PlotSelectionChanged(this, null);
1.17 }
1.18
1.19 private void InsertSorted(Node node, ISensor sensor) {
1.20 @@ -119,15 +124,25 @@
1.21 ((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index)
1.22 i++;
1.23 SensorNode sensorNode = new SensorNode(sensor, settings, unitManager);
1.24 + sensorNode.PlotSelectionChanged += SensorPlotSelectionChanged;
1.25 node.Nodes.Insert(i, sensorNode);
1.26 }
1.27
1.28 + private void SensorPlotSelectionChanged(object sender, EventArgs e) {
1.29 + if (PlotSelectionChanged != null)
1.30 + PlotSelectionChanged(this, null);
1.31 + }
1.32 +
1.33 private void SensorAdded(ISensor sensor) {
1.34 foreach (TypeNode typeNode in typeNodes)
1.35 if (typeNode.SensorType == sensor.SensorType) {
1.36 InsertSorted(typeNode, sensor);
1.37 UpdateNode(typeNode);
1.38 }
1.39 - }
1.40 + if (PlotSelectionChanged != null)
1.41 + PlotSelectionChanged(this, null);
1.42 + }
1.43 +
1.44 + public event EventHandler PlotSelectionChanged;
1.45 }
1.46 }
2.1 --- a/GUI/MainForm.cs Sun Jan 01 15:46:42 2012 +0000
2.2 +++ b/GUI/MainForm.cs Sun Jan 01 17:12:34 2012 +0000
2.3 @@ -116,7 +116,6 @@
2.4 plotPanel.Dock = DockStyle.Fill;
2.5
2.6 nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
2.7 - nodeCheckBox.CheckStateChanged += UpdatePlotSelection;
2.8 nodeTextBoxText.DrawText += nodeTextBoxText_DrawText;
2.9 nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText;
2.10 nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText;
2.11 @@ -160,14 +159,7 @@
2.12 gadget.HideShowCommand += hideShowClick;
2.13
2.14 wmiProvider = new WmiProvider(computer);
2.15 - }
2.16 -
2.17 - computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
2.18 - computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
2.19 -
2.20 - computer.Open();
2.21 -
2.22 - timer.Enabled = true;
2.23 + }
2.24
2.25 plotColorPalette = new Color[13];
2.26 plotColorPalette[0] = Color.Blue;
2.27 @@ -183,6 +175,13 @@
2.28 plotColorPalette[10] = Color.MediumSeaGreen;
2.29 plotColorPalette[11] = Color.Olive;
2.30 plotColorPalette[12] = Color.Firebrick;
2.31 +
2.32 + computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
2.33 + computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
2.34 +
2.35 + computer.Open();
2.36 +
2.37 + timer.Enabled = true;
2.38
2.39 showHiddenSensors = new UserOption("hiddenMenuItem", false,
2.40 hiddenMenuItem, settings);
2.41 @@ -234,7 +233,6 @@
2.42 settings);
2.43 readHddSensors.Changed += delegate(object sender, EventArgs e) {
2.44 computer.HDDEnabled = readHddSensors.Value;
2.45 - UpdatePlotSelection(null, null);
2.46 };
2.47
2.48 showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem,
2.49 @@ -368,28 +366,32 @@
2.50 }
2.51
2.52 private void SubHardwareAdded(IHardware hardware, Node node) {
2.53 - Node hardwareNode = new HardwareNode(hardware, settings, unitManager);
2.54 + HardwareNode hardwareNode =
2.55 + new HardwareNode(hardware, settings, unitManager);
2.56 + hardwareNode.PlotSelectionChanged += PlotSelectionChanged;
2.57 +
2.58 node.Nodes.Add(hardwareNode);
2.59 foreach (IHardware subHardware in hardware.SubHardware)
2.60 SubHardwareAdded(subHardware, hardwareNode);
2.61 }
2.62
2.63 - private void HardwareAdded(IHardware hardware) {
2.64 - Node hardwareNode = new HardwareNode(hardware, settings, unitManager);
2.65 - root.Nodes.Add(hardwareNode);
2.66 - foreach (IHardware subHardware in hardware.SubHardware)
2.67 - SubHardwareAdded(subHardware, hardwareNode);
2.68 + private void HardwareAdded(IHardware hardware) {
2.69 + SubHardwareAdded(hardware, root);
2.70 + PlotSelectionChanged(this, null);
2.71 }
2.72
2.73 - private void HardwareRemoved(IHardware hardware) {
2.74 - List<Node> nodesToRemove = new List<Node>();
2.75 + private void HardwareRemoved(IHardware hardware) {
2.76 + List<HardwareNode> nodesToRemove = new List<HardwareNode>();
2.77 foreach (Node node in root.Nodes) {
2.78 HardwareNode hardwareNode = node as HardwareNode;
2.79 if (hardwareNode != null && hardwareNode.Hardware == hardware)
2.80 - nodesToRemove.Add(node);
2.81 + nodesToRemove.Add(hardwareNode);
2.82 }
2.83 - foreach (Node node in nodesToRemove)
2.84 - root.Nodes.Remove(node);
2.85 + foreach (HardwareNode hardwareNode in nodesToRemove) {
2.86 + root.Nodes.Remove(hardwareNode);
2.87 + hardwareNode.PlotSelectionChanged -= PlotSelectionChanged;
2.88 + }
2.89 + PlotSelectionChanged(this, null);
2.90 }
2.91
2.92 private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {
2.93 @@ -407,15 +409,13 @@
2.94 }
2.95 }
2.96
2.97 - private void UpdatePlotSelection(object sender,
2.98 - TreePathEventArgs e)
2.99 - {
2.100 + private void PlotSelectionChanged(object sender, EventArgs e) {
2.101 List<ISensor> selected = new List<ISensor>();
2.102 IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
2.103 int colorIndex = 0;
2.104 foreach (TreeNodeAdv node in treeView.AllNodes) {
2.105 SensorNode sensorNode = node.Tag as SensorNode;
2.106 - if (sensorNode != null &&
2.107 + if (sensorNode != null &&
2.108 sensorNode.Sensor.SensorType == SensorType.Temperature) {
2.109 if (sensorNode.Plot) {
2.110 colors.Add(sensorNode.Sensor,
3.1 --- a/GUI/SensorNode.cs Sun Jan 01 15:46:42 2012 +0000
3.2 +++ b/GUI/SensorNode.cs Sun Jan 01 17:12:34 2012 +0000
3.3 @@ -82,6 +82,9 @@
3.4 bool hidden = settings.GetValue(new Identifier(sensor.Identifier,
3.5 "hidden").ToString(), sensor.IsDefaultHidden);
3.6 base.IsVisible = !hidden;
3.7 +
3.8 + this.Plot = settings.GetValue(new Identifier(sensor.Identifier,
3.9 + "plot").ToString(), false);
3.10 }
3.11
3.12 public override string Text {
3.13 @@ -100,9 +103,17 @@
3.14
3.15 public bool Plot {
3.16 get { return plot; }
3.17 - set { plot = value; }
3.18 + set {
3.19 + plot = value;
3.20 + settings.SetValue(new Identifier(sensor.Identifier, "plot").ToString(),
3.21 + value);
3.22 + if (PlotSelectionChanged != null)
3.23 + PlotSelectionChanged(this, null);
3.24 + }
3.25 }
3.26
3.27 + public event EventHandler PlotSelectionChanged;
3.28 +
3.29 public ISensor Sensor {
3.30 get { return sensor; }
3.31 }