1.1 --- a/GUI/MainForm.cs Thu Feb 11 13:22:17 2010 +0000
1.2 +++ b/GUI/MainForm.cs Fri Feb 12 00:36:56 2010 +0000
1.3 @@ -56,6 +56,8 @@
1.4 private IDictionary<ISensor, Color> sensorPlotColors =
1.5 new Dictionary<ISensor, Color>();
1.6 private Color[] plotColorPalette;
1.7 + private SensorSystemTray sensorSystemTray;
1.8 + private NotifyIcon notifyIcon;
1.9
1.10 public MainForm() {
1.11 InitializeComponent();
1.12 @@ -98,6 +100,14 @@
1.13
1.14 treeModel.Nodes.Add(root);
1.15 treeView.Model = treeModel;
1.16 +
1.17 + notifyIcon = new NotifyIcon();
1.18 + notifyIcon.ContextMenuStrip = this.notifyContextMenuStrip;
1.19 + notifyIcon.Icon = EmbeddedResources.GetIcon("smallicon.ico");
1.20 + notifyIcon.Text = "Open Hardware Monitor";
1.21 + notifyIcon.DoubleClick += new EventHandler(this.restoreClick);
1.22 +
1.23 + sensorSystemTray = new SensorSystemTray(computer);
1.24
1.25 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
1.26 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
1.27 @@ -218,6 +228,7 @@
1.28
1.29 treeView.Invalidate();
1.30 plotPanel.Invalidate();
1.31 + sensorSystemTray.Redraw();
1.32 }
1.33
1.34 private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
1.35 @@ -242,6 +253,9 @@
1.36 Config.Set("mainForm.Width", Width);
1.37 Config.Set("mainForm.Height", Height);
1.38 }
1.39 +
1.40 + sensorSystemTray.Dispose();
1.41 + notifyIcon.Dispose();
1.42
1.43 computer.Close();
1.44 }
1.45 @@ -287,7 +301,27 @@
1.46 NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
1.47 if (info.Control == null) {
1.48 columnsContextMenuStrip.Show(treeView, m.X, m.Y);
1.49 - }
1.50 + } else {
1.51 + SensorNode node = info.Node.Tag as SensorNode;
1.52 + if (node != null && node.Sensor != null) {
1.53 +
1.54 + sensorContextMenuStrip.Items.Clear();
1.55 + if (sensorSystemTray.Contains(node.Sensor)) {
1.56 + ToolStripMenuItem item = new ToolStripMenuItem("Remove From Tray");
1.57 + item.Click += delegate(object obj, EventArgs args) {
1.58 + sensorSystemTray.Remove(node.Sensor);
1.59 + };
1.60 + sensorContextMenuStrip.Items.Add(item);
1.61 + } else {
1.62 + ToolStripMenuItem item = new ToolStripMenuItem("Add To Tray");
1.63 + item.Click += delegate(object obj, EventArgs args) {
1.64 + sensorSystemTray.Add(node.Sensor);
1.65 + };
1.66 + sensorContextMenuStrip.Items.Add(item);
1.67 + }
1.68 + sensorContextMenuStrip.Show(treeView, m.X, m.Y);
1.69 + }
1.70 + }
1.71 }
1.72
1.73 private void saveReportToolStripMenuItem_Click(object sender, EventArgs e) {
1.74 @@ -338,5 +372,17 @@
1.75 ToggleSysTray();
1.76 }
1.77
1.78 + private void removeToolStripMenuItem_Click(object sender, EventArgs e) {
1.79 + ToolStripMenuItem item = sender as ToolStripMenuItem;
1.80 + if (item == null)
1.81 + return;
1.82 +
1.83 + ISensor sensor = item.Owner.Tag as ISensor;
1.84 + if (sensor == null)
1.85 + return;
1.86 +
1.87 + sensorSystemTray.Remove(sensor);
1.88 + }
1.89 +
1.90 }
1.91 }