Fixed Issue 65.

This commit is contained in:
Michael Möller
2010-06-05 18:59:54 +00:00
parent cb6594ba7f
commit c641a6a2fc
10 changed files with 173 additions and 93 deletions
+6 -44
View File
@@ -102,10 +102,6 @@ namespace OpenHardwareMonitor.GUI {
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.splitContainer = new System.Windows.Forms.SplitContainer();
this.plotPanel = new OpenHardwareMonitor.GUI.PlotPanel();
this.notifyContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.hideShowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.sensorContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.timer = new System.Windows.Forms.Timer(this.components);
@@ -113,7 +109,6 @@ namespace OpenHardwareMonitor.GUI {
this.splitContainer.Panel1.SuspendLayout();
this.splitContainer.Panel2.SuspendLayout();
this.splitContainer.SuspendLayout();
this.notifyContextMenuStrip.SuspendLayout();
this.SuspendLayout();
//
// treeView
@@ -269,7 +264,7 @@ namespace OpenHardwareMonitor.GUI {
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitClick);
//
// viewToolStripMenuItem
//
@@ -393,9 +388,9 @@ namespace OpenHardwareMonitor.GUI {
this.startupMenuItem.Text = "Run On Windows Startup";
this.startupMenuItem.CheckedChanged += new System.EventHandler(this.runOnWindowsStartupToolStripMenuItem_CheckedChanged);
//
// toolStripMenuItem3
// separatorMenuItem
//
this.separatorMenuItem.Name = "toolStripMenuItem3";
this.separatorMenuItem.Name = "separatorMenuItem";
this.separatorMenuItem.Size = new System.Drawing.Size(204, 6);
//
// temperatureUnitsToolStripMenuItem
@@ -410,14 +405,14 @@ namespace OpenHardwareMonitor.GUI {
// celciusToolStripMenuItem
//
this.celciusToolStripMenuItem.Name = "celciusToolStripMenuItem";
this.celciusToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.celciusToolStripMenuItem.Size = new System.Drawing.Size(130, 22);
this.celciusToolStripMenuItem.Text = "Celcius";
this.celciusToolStripMenuItem.Click += new System.EventHandler(this.celciusToolStripMenuItem_Click);
//
// fahrenheitToolStripMenuItem
//
this.fahrenheitToolStripMenuItem.Name = "fahrenheitToolStripMenuItem";
this.fahrenheitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.fahrenheitToolStripMenuItem.Size = new System.Drawing.Size(130, 22);
this.fahrenheitToolStripMenuItem.Text = "Fahrenheit";
this.fahrenheitToolStripMenuItem.Click += new System.EventHandler(this.fahrenheitToolStripMenuItem_Click);
//
@@ -478,38 +473,10 @@ namespace OpenHardwareMonitor.GUI {
this.plotPanel.Size = new System.Drawing.Size(410, 171);
this.plotPanel.TabIndex = 0;
//
// notifyContextMenuStrip
//
this.notifyContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.hideShowToolStripMenuItem,
this.toolStripMenuItem2,
this.exitToolStripMenuItem1});
this.notifyContextMenuStrip.Name = "notifyContextMenuStrip";
this.notifyContextMenuStrip.Size = new System.Drawing.Size(134, 54);
//
// hideShowToolStripMenuItem
//
this.hideShowToolStripMenuItem.Name = "hideShowToolStripMenuItem";
this.hideShowToolStripMenuItem.Size = new System.Drawing.Size(133, 22);
this.hideShowToolStripMenuItem.Text = "Hide/Show";
this.hideShowToolStripMenuItem.Click += new System.EventHandler(this.hideShowClick);
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(130, 6);
//
// exitToolStripMenuItem1
//
this.exitToolStripMenuItem1.Name = "exitToolStripMenuItem1";
this.exitToolStripMenuItem1.Size = new System.Drawing.Size(133, 22);
this.exitToolStripMenuItem1.Text = "Exit";
this.exitToolStripMenuItem1.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
// sensorContextMenuStrip
//
this.sensorContextMenuStrip.Name = "sensorContextMenuStrip";
this.sensorContextMenuStrip.Size = new System.Drawing.Size(61, 4);
this.sensorContextMenuStrip.Size = new System.Drawing.Size(153, 26);
//
// saveFileDialog
//
@@ -542,7 +509,6 @@ namespace OpenHardwareMonitor.GUI {
this.splitContainer.Panel1.ResumeLayout(false);
this.splitContainer.Panel2.ResumeLayout(false);
this.splitContainer.ResumeLayout(false);
this.notifyContextMenuStrip.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@@ -575,10 +541,6 @@ namespace OpenHardwareMonitor.GUI {
private System.Windows.Forms.ToolStripMenuItem saveReportToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem hddMenuItem;
private System.Windows.Forms.ContextMenuStrip notifyContextMenuStrip;
private System.Windows.Forms.ToolStripMenuItem hideShowToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem minTrayMenuItem;
private System.Windows.Forms.ToolStripSeparator separatorMenuItem;
private System.Windows.Forms.ContextMenuStrip sensorContextMenuStrip;
+20 -34
View File
@@ -57,8 +57,7 @@ namespace OpenHardwareMonitor.GUI {
private IDictionary<ISensor, Color> sensorPlotColors =
new Dictionary<ISensor, Color>();
private Color[] plotColorPalette;
private SensorSystemTray sensorSystemTray;
private NotifyIcon notifyIcon;
private SystemTray systemTray;
private StartupManager startupManager = new StartupManager();
private UpdateVisitor updateVisitor = new UpdateVisitor();
@@ -68,21 +67,13 @@ namespace OpenHardwareMonitor.GUI {
treeView.Font = SystemFonts.MessageBoxFont;
plotPanel.Font = SystemFonts.MessageBoxFont;
nodeCheckBox.IsVisibleValueNeeded +=
new EventHandler<NodeControlValueEventArgs>(
nodeCheckBox_IsVisibleValueNeeded);
nodeCheckBox.CheckStateChanged +=
new EventHandler<TreePathEventArgs>(UpdatePlotSelection);
nodeTextBoxText.DrawText +=
new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
nodeTextBoxValue.DrawText +=
new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
nodeTextBoxMin.DrawText +=
new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
nodeTextBoxMax.DrawText +=
new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
nodeTextBoxLimit.DrawText +=
new EventHandler<DrawEventArgs>(nodeTextBoxLimit_DrawText);
nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
nodeCheckBox.CheckStateChanged += UpdatePlotSelection;
nodeTextBoxText.DrawText += nodeTextBoxText_DrawText;
nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText;
nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText;
nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
nodeTextBoxLimit.DrawText += nodeTextBoxLimit_DrawText;
if (Utilities.Config.Contains("mainForm.Location.X")) {
int x = Utilities.Config.Get("mainForm.Location.X", Location.X);
@@ -107,15 +98,11 @@ namespace OpenHardwareMonitor.GUI {
root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
treeModel.Nodes.Add(root);
treeView.Model = treeModel;
notifyIcon = new NotifyIcon();
notifyIcon.ContextMenuStrip = this.notifyContextMenuStrip;
notifyIcon.Icon = EmbeddedResources.GetIcon("smallicon.ico");
notifyIcon.Text = "Open Hardware Monitor";
notifyIcon.DoubleClick += new EventHandler(this.hideShowClick);
treeView.Model = treeModel;
sensorSystemTray = new SensorSystemTray(computer);
systemTray = new SystemTray(computer);
systemTray.HideShowCommand += hideShowClick;
systemTray.ExitCommand += exitClick;
computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
@@ -257,7 +244,7 @@ namespace OpenHardwareMonitor.GUI {
plotMenuItem.Checked;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
private void exitClick(object sender, EventArgs e) {
Close();
}
@@ -265,7 +252,7 @@ namespace OpenHardwareMonitor.GUI {
computer.Accept(updateVisitor);
treeView.Invalidate();
plotPanel.Invalidate();
sensorSystemTray.Redraw();
systemTray.Redraw();
}
private void SaveConfiguration() {
@@ -299,8 +286,7 @@ namespace OpenHardwareMonitor.GUI {
SaveConfiguration();
timer.Enabled = false;
sensorSystemTray.Dispose();
notifyIcon.Dispose();
systemTray.Dispose();
computer.Close();
}
@@ -347,16 +333,16 @@ namespace OpenHardwareMonitor.GUI {
};
sensorContextMenuStrip.Items.Add(item);
}
if (sensorSystemTray.Contains(node.Sensor)) {
if (systemTray.Contains(node.Sensor)) {
ToolStripMenuItem item = new ToolStripMenuItem("Remove From Tray");
item.Click += delegate(object obj, EventArgs args) {
sensorSystemTray.Remove(node.Sensor);
systemTray.Remove(node.Sensor);
};
sensorContextMenuStrip.Items.Add(item);
} else {
ToolStripMenuItem item = new ToolStripMenuItem("Add To Tray");
item.Click += delegate(object obj, EventArgs args) {
sensorSystemTray.Add(node.Sensor, true);
systemTray.Add(node.Sensor, true);
};
sensorContextMenuStrip.Items.Add(item);
}
@@ -411,7 +397,7 @@ namespace OpenHardwareMonitor.GUI {
if (sensor == null)
return;
sensorSystemTray.Remove(sensor);
systemTray.Remove(sensor);
}
private void ShowParameterForm(ISensor sensor) {
@@ -437,7 +423,7 @@ namespace OpenHardwareMonitor.GUI {
}
private void minTrayMenuItem_CheckedChanged(object sender, EventArgs e) {
notifyIcon.Visible = minTrayMenuItem.Checked;
systemTray.IsMainIconEnabled = minTrayMenuItem.Checked;
}
private void hiddenSensorsMenuItem_CheckedChanged(object sender,
+3 -6
View File
@@ -120,17 +120,14 @@
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="notifyContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="sensorContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>125, 17</value>
</metadata>
<metadata name="sensorContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>307, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>493, 17</value>
<value>311, 17</value>
</metadata>
<metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>622, 17</value>
<value>440, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>55</value>
+17 -2
View File
@@ -61,7 +61,7 @@ namespace OpenHardwareMonitor.GUI {
private Pen pen;
private Font font;
public SensorNotifyIcon(SensorSystemTray sensorSystemTray, ISensor sensor,
public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor,
bool balloonTip)
{
this.sensor = sensor;
@@ -78,7 +78,13 @@ namespace OpenHardwareMonitor.GUI {
this.font = SystemFonts.MessageBoxFont;
ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
ToolStripMenuItem removeItem = new ToolStripMenuItem("Remove");
ToolStripMenuItem hideShowItem = new ToolStripMenuItem("Hide/Show");
hideShowItem.Click += delegate(object obj, EventArgs args) {
sensorSystemTray.SendHideShowCommand();
};
contextMenuStrip.Items.Add(hideShowItem);
contextMenuStrip.Items.Add(new ToolStripSeparator());
ToolStripMenuItem removeItem = new ToolStripMenuItem("Remove Sensor");
removeItem.Click += delegate(object obj, EventArgs args) {
sensorSystemTray.Remove(this.sensor);
};
@@ -94,7 +100,16 @@ namespace OpenHardwareMonitor.GUI {
}
};
contextMenuStrip.Items.Add(colorItem);
contextMenuStrip.Items.Add(new ToolStripSeparator());
ToolStripMenuItem exitItem = new ToolStripMenuItem("Exit");
exitItem.Click += delegate(object obj, EventArgs args) {
sensorSystemTray.SendExitCommand();
};
contextMenuStrip.Items.Add(exitItem);
this.notifyIcon.ContextMenuStrip = contextMenuStrip;
this.notifyIcon.DoubleClick += delegate(object obj, EventArgs args) {
sensorSystemTray.SendHideShowCommand();
};
this.bitmap = new Bitmap(16, 16, PixelFormat.Format32bppArgb);
this.graphics = Graphics.FromImage(this.bitmap);
+59 -3
View File
@@ -44,14 +44,36 @@ using OpenHardwareMonitor.Hardware;
using OpenHardwareMonitor.Utilities;
namespace OpenHardwareMonitor.GUI {
public class SensorSystemTray : IDisposable {
public class SystemTray : IDisposable {
private IComputer computer;
private List<SensorNotifyIcon> list = new List<SensorNotifyIcon>();
private bool mainIconEnabled = false;
private NotifyIcon mainIcon;
public SensorSystemTray(IComputer computer) {
public SystemTray(IComputer computer) {
this.computer = computer;
computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
this.mainIcon = new NotifyIcon();
ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
ToolStripMenuItem hideShowItem = new ToolStripMenuItem("Hide/Show");
hideShowItem.Click += delegate(object obj, EventArgs args) {
SendHideShowCommand();
};
contextMenuStrip.Items.Add(hideShowItem);
contextMenuStrip.Items.Add(new ToolStripSeparator());
ToolStripMenuItem exitItem = new ToolStripMenuItem("Exit");
exitItem.Click += delegate(object obj, EventArgs args) {
SendExitCommand();
};
contextMenuStrip.Items.Add(exitItem);
this.mainIcon.ContextMenuStrip = contextMenuStrip;
this.mainIcon.DoubleClick += delegate(object obj, EventArgs args) {
SendHideShowCommand();
};
this.mainIcon.Icon = EmbeddedResources.GetIcon("smallicon.ico");
}
private void HardwareRemoved(IHardware hardware) {
@@ -86,6 +108,7 @@ namespace OpenHardwareMonitor.GUI {
public void Dispose() {
foreach (SensorNotifyIcon icon in list)
icon.Dispose();
mainIcon.Dispose();
}
public void Redraw() {
@@ -105,6 +128,7 @@ namespace OpenHardwareMonitor.GUI {
return;
} else {
list.Add(new SensorNotifyIcon(this, sensor, balloonTip));
UpdateMainIconVisibilty();
Config.Set(new Identifier(sensor.Identifier, "tray").ToString(), true);
}
}
@@ -126,9 +150,41 @@ namespace OpenHardwareMonitor.GUI {
instance = icon;
if (instance != null) {
list.Remove(instance);
instance.Dispose();
UpdateMainIconVisibilty();
instance.Dispose();
}
}
public event EventHandler HideShowCommand;
public void SendHideShowCommand() {
if (HideShowCommand != null)
HideShowCommand(this, null);
}
public event EventHandler ExitCommand;
public void SendExitCommand() {
if (ExitCommand != null)
ExitCommand(this, null);
}
private void UpdateMainIconVisibilty() {
if (mainIconEnabled) {
mainIcon.Visible = list.Count == 0;
} else {
mainIcon.Visible = false;
}
}
public bool IsMainIconEnabled {
get { return mainIconEnabled; }
set {
if (mainIconEnabled != value) {
mainIconEnabled = value;
UpdateMainIconVisibilty();
}
}
}
}
}