GUI/UserOption.cs
author StephaneLenclud
Sun, 03 Feb 2013 18:01:50 +0100
branchMiniDisplay
changeset 433 090259cfd699
parent 166 fa9dfbfc4145
permissions -rw-r--r--
Adding SoundGraphDisplay and SensorFrontView classes.
They were respectively based on SystemTray and SensorNotifyIcon.
SoundGraphDisplay is now able to load iMONDisplay.dll providing it lives on your PATH.
Adding option to sensor context menu for adding it into FrontView.
moel@156
     1
/*
moel@156
     2
 
moel@344
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@344
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@344
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@156
     6
 
moel@344
     7
  Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344
     8
	
moel@156
     9
*/
moel@156
    10
moel@156
    11
using System;
moel@156
    12
using System.Collections.Generic;
moel@156
    13
using System.Windows.Forms;
moel@156
    14
using OpenHardwareMonitor.Utilities;
moel@156
    15
moel@156
    16
namespace OpenHardwareMonitor.GUI {
moel@156
    17
  public class UserOption {
moel@156
    18
    private string name;
moel@156
    19
    private bool value;
moel@156
    20
    private MenuItem menuItem;
moel@156
    21
    private event EventHandler changed;
moel@165
    22
    private PersistentSettings settings;
moel@156
    23
moel@156
    24
    public UserOption(string name, bool value,
moel@165
    25
      MenuItem menuItem, PersistentSettings settings) {
moel@156
    26
moel@165
    27
      this.settings = settings;
moel@156
    28
      this.name = name;
moel@156
    29
      if (name != null)
moel@166
    30
        this.value = settings.GetValue(name, value);
moel@156
    31
      else
moel@156
    32
        this.value = value;
moel@156
    33
      this.menuItem = menuItem;
moel@156
    34
      this.menuItem.Checked = this.value;
moel@156
    35
      this.menuItem.Click += new EventHandler(menuItem_Click);
moel@156
    36
    }
moel@156
    37
moel@156
    38
    private void menuItem_Click(object sender, EventArgs e) {
moel@156
    39
      this.Value = !this.Value;
moel@156
    40
    }    
moel@156
    41
moel@156
    42
    public bool Value {
moel@156
    43
      get { return value; }
moel@156
    44
      set {
moel@156
    45
        if (this.value != value) {
moel@156
    46
          this.value = value;
moel@156
    47
          if (this.name != null)
moel@166
    48
            settings.SetValue(name, value);
moel@156
    49
          this.menuItem.Checked = value;
moel@156
    50
          if (changed != null)
moel@156
    51
            changed(this, null);
moel@156
    52
        }
moel@156
    53
      }
moel@156
    54
    }
moel@156
    55
moel@156
    56
    public event EventHandler Changed {
moel@156
    57
      add {
moel@156
    58
        changed += value;
moel@156
    59
        if (changed != null)
moel@156
    60
          changed(this, null);
moel@156
    61
      }
moel@156
    62
      remove {
moel@156
    63
        changed -= value;
moel@156
    64
      }
moel@156
    65
    }
moel@156
    66
  }
moel@156
    67
}