GUI/UserOption.cs
author moel.mich
Wed, 04 Aug 2010 20:27:05 +0000
changeset 162 2129ccee0bd1
child 165 813d8bc3192f
permissions -rw-r--r--
Added an ISA bus mutex.
moel@156
     1
/*
moel@156
     2
  
moel@156
     3
  Version: MPL 1.1/GPL 2.0/LGPL 2.1
moel@156
     4
moel@156
     5
  The contents of this file are subject to the Mozilla Public License Version
moel@156
     6
  1.1 (the "License"); you may not use this file except in compliance with
moel@156
     7
  the License. You may obtain a copy of the License at
moel@156
     8
 
moel@156
     9
  http://www.mozilla.org/MPL/
moel@156
    10
moel@156
    11
  Software distributed under the License is distributed on an "AS IS" basis,
moel@156
    12
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
moel@156
    13
  for the specific language governing rights and limitations under the License.
moel@156
    14
moel@156
    15
  The Original Code is the Open Hardware Monitor code.
moel@156
    16
moel@156
    17
  The Initial Developer of the Original Code is 
moel@156
    18
  Michael Möller <m.moeller@gmx.ch>.
moel@156
    19
  Portions created by the Initial Developer are Copyright (C) 2009-2010
moel@156
    20
  the Initial Developer. All Rights Reserved.
moel@156
    21
moel@156
    22
  Contributor(s):
moel@156
    23
moel@156
    24
  Alternatively, the contents of this file may be used under the terms of
moel@156
    25
  either the GNU General Public License Version 2 or later (the "GPL"), or
moel@156
    26
  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
moel@156
    27
  in which case the provisions of the GPL or the LGPL are applicable instead
moel@156
    28
  of those above. If you wish to allow use of your version of this file only
moel@156
    29
  under the terms of either the GPL or the LGPL, and not to allow others to
moel@156
    30
  use your version of this file under the terms of the MPL, indicate your
moel@156
    31
  decision by deleting the provisions above and replace them with the notice
moel@156
    32
  and other provisions required by the GPL or the LGPL. If you do not delete
moel@156
    33
  the provisions above, a recipient may use your version of this file under
moel@156
    34
  the terms of any one of the MPL, the GPL or the LGPL.
moel@156
    35
 
moel@156
    36
*/
moel@156
    37
moel@156
    38
using System;
moel@156
    39
using System.Collections.Generic;
moel@156
    40
using System.Windows.Forms;
moel@156
    41
using OpenHardwareMonitor.Utilities;
moel@156
    42
moel@156
    43
namespace OpenHardwareMonitor.GUI {
moel@156
    44
  public class UserOption {
moel@156
    45
    private string name;
moel@156
    46
    private bool value;
moel@156
    47
    private MenuItem menuItem;
moel@156
    48
    private event EventHandler changed;
moel@156
    49
moel@156
    50
    public UserOption(string name, bool value,
moel@156
    51
      MenuItem menuItem) {
moel@156
    52
moel@156
    53
      this.name = name;
moel@156
    54
      if (name != null)
moel@156
    55
        this.value = Config.Get(name, value);
moel@156
    56
      else
moel@156
    57
        this.value = value;
moel@156
    58
      this.menuItem = menuItem;
moel@156
    59
      this.menuItem.Checked = this.value;
moel@156
    60
      this.menuItem.Click += new EventHandler(menuItem_Click);
moel@156
    61
    }
moel@156
    62
moel@156
    63
    private void menuItem_Click(object sender, EventArgs e) {
moel@156
    64
      this.Value = !this.Value;
moel@156
    65
    }    
moel@156
    66
moel@156
    67
    public bool Value {
moel@156
    68
      get { return value; }
moel@156
    69
      set {
moel@156
    70
        if (this.value != value) {
moel@156
    71
          this.value = value;
moel@156
    72
          if (this.name != null)
moel@156
    73
            Config.Set(name, value);
moel@156
    74
          this.menuItem.Checked = value;
moel@156
    75
          if (changed != null)
moel@156
    76
            changed(this, null);
moel@156
    77
        }
moel@156
    78
      }
moel@156
    79
    }
moel@156
    80
moel@156
    81
    public event EventHandler Changed {
moel@156
    82
      add {
moel@156
    83
        changed += value;
moel@156
    84
        if (changed != null)
moel@156
    85
          changed(this, null);
moel@156
    86
      }
moel@156
    87
      remove {
moel@156
    88
        changed -= value;
moel@156
    89
      }
moel@156
    90
    }
moel@156
    91
  }
moel@156
    92
}