moel@156: /* moel@156: moel@156: Version: MPL 1.1/GPL 2.0/LGPL 2.1 moel@156: moel@156: The contents of this file are subject to the Mozilla Public License Version moel@156: 1.1 (the "License"); you may not use this file except in compliance with moel@156: the License. You may obtain a copy of the License at moel@156: moel@156: http://www.mozilla.org/MPL/ moel@156: moel@156: Software distributed under the License is distributed on an "AS IS" basis, moel@156: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License moel@156: for the specific language governing rights and limitations under the License. moel@156: moel@156: The Original Code is the Open Hardware Monitor code. moel@156: moel@156: The Initial Developer of the Original Code is moel@156: Michael Möller . moel@156: Portions created by the Initial Developer are Copyright (C) 2009-2010 moel@156: the Initial Developer. All Rights Reserved. moel@156: moel@156: Contributor(s): moel@156: moel@156: Alternatively, the contents of this file may be used under the terms of moel@156: either the GNU General Public License Version 2 or later (the "GPL"), or moel@156: the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), moel@156: in which case the provisions of the GPL or the LGPL are applicable instead moel@156: of those above. If you wish to allow use of your version of this file only moel@156: under the terms of either the GPL or the LGPL, and not to allow others to moel@156: use your version of this file under the terms of the MPL, indicate your moel@156: decision by deleting the provisions above and replace them with the notice moel@156: and other provisions required by the GPL or the LGPL. If you do not delete moel@156: the provisions above, a recipient may use your version of this file under moel@156: the terms of any one of the MPL, the GPL or the LGPL. moel@156: moel@156: */ moel@156: moel@156: using System; moel@156: using System.Collections.Generic; moel@156: using System.Windows.Forms; moel@156: using OpenHardwareMonitor.Utilities; moel@156: moel@156: namespace OpenHardwareMonitor.GUI { moel@156: public class UserOption { moel@156: private string name; moel@156: private bool value; moel@156: private MenuItem menuItem; moel@156: private event EventHandler changed; moel@165: private PersistentSettings settings; moel@156: moel@156: public UserOption(string name, bool value, moel@165: MenuItem menuItem, PersistentSettings settings) { moel@156: moel@165: this.settings = settings; moel@156: this.name = name; moel@156: if (name != null) moel@165: this.value = settings.Get(name, value); moel@156: else moel@156: this.value = value; moel@156: this.menuItem = menuItem; moel@156: this.menuItem.Checked = this.value; moel@156: this.menuItem.Click += new EventHandler(menuItem_Click); moel@156: } moel@156: moel@156: private void menuItem_Click(object sender, EventArgs e) { moel@156: this.Value = !this.Value; moel@156: } moel@156: moel@156: public bool Value { moel@156: get { return value; } moel@156: set { moel@156: if (this.value != value) { moel@156: this.value = value; moel@156: if (this.name != null) moel@165: settings.Set(name, value); moel@156: this.menuItem.Checked = value; moel@156: if (changed != null) moel@156: changed(this, null); moel@156: } moel@156: } moel@156: } moel@156: moel@156: public event EventHandler Changed { moel@156: add { moel@156: changed += value; moel@156: if (changed != null) moel@156: changed(this, null); moel@156: } moel@156: remove { moel@156: changed -= value; moel@156: } moel@156: } moel@156: } moel@156: }