moel@156: /* moel@156: moel@344: This Source Code Form is subject to the terms of the Mozilla Public moel@344: License, v. 2.0. If a copy of the MPL was not distributed with this moel@344: file, You can obtain one at http://mozilla.org/MPL/2.0/. moel@156: moel@344: Copyright (C) 2009-2010 Michael Möller moel@344: 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@166: this.value = settings.GetValue(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@166: settings.SetValue(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: }