From bb45f65447ecd3acdf6fbf4386c5132483dd54b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Sun, 6 Nov 2016 14:51:24 +0100 Subject: [PATCH] Added a menu item to reset the pen color (to use again the plotColorPalette based color). Moved the saving/loading code to the SensorNode class (as with the other properties). --- GUI/HardwareNode.cs | 2 -- GUI/MainForm.Designer.cs | 2 -- GUI/MainForm.cs | 26 ++++++++++++++++---------- GUI/MainForm.resx | 3 --- GUI/SensorNode.cs | 24 ++++++++++++++++++++++-- OpenHardwareMonitor.csproj | 1 - 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/GUI/HardwareNode.cs b/GUI/HardwareNode.cs index 0e2e463..a68289e 100644 --- a/GUI/HardwareNode.cs +++ b/GUI/HardwareNode.cs @@ -89,8 +89,6 @@ namespace OpenHardwareMonitor.GUI { ((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index) i++; SensorNode sensorNode = new SensorNode(sensor, settings, unitManager); - if (settings.Contains(sensor.Identifier + "/PenColor")) - sensorNode.penColor = settings.GetValue(sensor.Identifier + "/PenColor", Color.Black); sensorNode.PlotSelectionChanged += SensorPlotSelectionChanged; node.Nodes.Insert(i, sensorNode); } diff --git a/GUI/MainForm.Designer.cs b/GUI/MainForm.Designer.cs index ffc345e..f602030 100644 --- a/GUI/MainForm.Designer.cs +++ b/GUI/MainForm.Designer.cs @@ -111,7 +111,6 @@ namespace OpenHardwareMonitor.GUI { this.log1hMenuItem = new System.Windows.Forms.MenuItem(); this.log2hMenuItem = new System.Windows.Forms.MenuItem(); this.log6hMenuItem = new System.Windows.Forms.MenuItem(); - this.colorDialog = new System.Windows.Forms.ColorDialog(); this.splitContainer.Panel1.SuspendLayout(); this.splitContainer.SuspendLayout(); this.SuspendLayout(); @@ -763,7 +762,6 @@ namespace OpenHardwareMonitor.GUI { private System.Windows.Forms.MenuItem log1hMenuItem; private System.Windows.Forms.MenuItem log2hMenuItem; private System.Windows.Forms.MenuItem log6hMenuItem; - private System.Windows.Forms.ColorDialog colorDialog; } } diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index bee6263..9340faf 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -494,7 +494,7 @@ namespace OpenHardwareMonitor.GUI { SensorNode sensorNode = node.Tag as SensorNode; if (sensorNode != null) { if (sensorNode.Plot) { - if (sensorNode.penColor == null) { + if (!sensorNode.PenColor.HasValue) { colors.Add(sensorNode.Sensor, plotColorPalette[colorIndex % plotColorPalette.Length]); } @@ -528,8 +528,8 @@ namespace OpenHardwareMonitor.GUI { foreach (TreeNodeAdv node in treeView.AllNodes) { SensorNode sensorNode = node.Tag as SensorNode; - if (sensorNode != null && sensorNode.Plot && sensorNode.penColor != null) - colors.Add(sensorNode.Sensor, sensorNode.penColor.Value); + if (sensorNode != null && sensorNode.Plot && sensorNode.PenColor.HasValue) + colors.Add(sensorNode.Sensor, sensorNode.PenColor.Value); } sensorPlotColors = colors; @@ -683,17 +683,23 @@ namespace OpenHardwareMonitor.GUI { } treeContextMenu.MenuItems.Add(new MenuItem("-")); { - MenuItem item = new MenuItem("Pen color"); + MenuItem item = new MenuItem("Pen Color..."); item.Click += delegate(object obj, EventArgs args) { - colorDialog.Color = node.penColor.GetValueOrDefault(); - if (colorDialog.ShowDialog() == DialogResult.OK) { - node.penColor = colorDialog.Color; - settings.SetValue(node.Sensor.Identifier + "/PenColor", colorDialog.Color); - PlotSelectionChanged(this, null); - } + ColorDialog dialog = new ColorDialog(); + dialog.Color = node.PenColor.GetValueOrDefault(); + if (dialog.ShowDialog() == DialogResult.OK) + node.PenColor = dialog.Color; }; treeContextMenu.MenuItems.Add(item); } + { + MenuItem item = new MenuItem("Reset Pen Color"); + item.Click += delegate(object obj, EventArgs args) { + node.PenColor = null; + }; + treeContextMenu.MenuItems.Add(item); + } + treeContextMenu.MenuItems.Add(new MenuItem("-")); { MenuItem item = new MenuItem("Show in Tray"); item.Checked = systemTray.Contains(node.Sensor); diff --git a/GUI/MainForm.resx b/GUI/MainForm.resx index 1a380ff..9cb27cf 100644 --- a/GUI/MainForm.resx +++ b/GUI/MainForm.resx @@ -129,9 +129,6 @@ 293, 17 - - 483, 17 - diff --git a/GUI/SensorNode.cs b/GUI/SensorNode.cs index 7493b8b..a4fdc99 100644 --- a/GUI/SensorNode.cs +++ b/GUI/SensorNode.cs @@ -4,7 +4,7 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2009-2012 Michael Möller + Copyright (C) 2009-2016 Michael Möller */ @@ -22,7 +22,7 @@ namespace OpenHardwareMonitor.GUI { private UnitManager unitManager; private string format; private bool plot = false; - public Color? penColor = null; + private Color? penColor = null; public string ValueToString(float? value) { if (value.HasValue) { @@ -61,6 +61,10 @@ namespace OpenHardwareMonitor.GUI { this.Plot = settings.GetValue(new Identifier(sensor.Identifier, "plot").ToString(), false); + + string id = new Identifier(sensor.Identifier, "penColor").ToString(); + if (settings.Contains(id)) + this.PenColor = settings.GetValue(id, Color.Black); } public override string Text { @@ -77,6 +81,22 @@ namespace OpenHardwareMonitor.GUI { } } + public Color? PenColor { + get { return penColor; } + set { + penColor = value; + + string id = new Identifier(sensor.Identifier, "penColor").ToString(); + if (value.HasValue) + settings.SetValue(id, value.Value); + else + settings.Remove(id); + + if (PlotSelectionChanged != null) + PlotSelectionChanged(this, null); + } + } + public bool Plot { get { return plot; } set { diff --git a/OpenHardwareMonitor.csproj b/OpenHardwareMonitor.csproj index 68a994c..35e749b 100644 --- a/OpenHardwareMonitor.csproj +++ b/OpenHardwareMonitor.csproj @@ -66,7 +66,6 @@ -