Code style #125
This commit is contained in:
+54
-57
@@ -1,67 +1,64 @@
|
||||
/*
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org>
|
||||
|
||||
*/
|
||||
// Mozilla Public License 2.0
|
||||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors
|
||||
// All Rights Reserved
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using OpenHardwareMonitor.Utilities;
|
||||
|
||||
namespace OpenHardwareMonitor.GUI {
|
||||
public class UserOption {
|
||||
private string name;
|
||||
private bool value;
|
||||
private MenuItem menuItem;
|
||||
private event EventHandler changed;
|
||||
private PersistentSettings settings;
|
||||
namespace OpenHardwareMonitor.GUI
|
||||
{
|
||||
public class UserOption
|
||||
{
|
||||
private readonly string _name;
|
||||
private bool _value;
|
||||
private readonly MenuItem _menuItem;
|
||||
private event EventHandler _changed;
|
||||
private readonly PersistentSettings _settings;
|
||||
|
||||
public UserOption(string name, bool value,
|
||||
MenuItem menuItem, PersistentSettings settings) {
|
||||
|
||||
this.settings = settings;
|
||||
this.name = name;
|
||||
if (name != null)
|
||||
this.value = settings.GetValue(name, value);
|
||||
else
|
||||
this.value = value;
|
||||
this.menuItem = menuItem;
|
||||
this.menuItem.Checked = this.value;
|
||||
this.menuItem.Click += new EventHandler(menuItem_Click);
|
||||
}
|
||||
|
||||
private void menuItem_Click(object sender, EventArgs e) {
|
||||
this.Value = !this.Value;
|
||||
}
|
||||
|
||||
public bool Value {
|
||||
get { return value; }
|
||||
set {
|
||||
if (this.value != value) {
|
||||
this.value = value;
|
||||
if (this.name != null)
|
||||
settings.SetValue(name, value);
|
||||
this.menuItem.Checked = value;
|
||||
if (changed != null)
|
||||
changed(this, null);
|
||||
public UserOption(string name, bool value, MenuItem menuItem, PersistentSettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
_name = name;
|
||||
_value = name != null ? settings.GetValue(name, value) : value;
|
||||
_menuItem = menuItem;
|
||||
_menuItem.Checked = _value;
|
||||
_menuItem.Click += MenuItem_Click;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler Changed {
|
||||
add {
|
||||
changed += value;
|
||||
if (changed != null)
|
||||
changed(this, null);
|
||||
}
|
||||
remove {
|
||||
changed -= value;
|
||||
}
|
||||
private void MenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Value = !Value;
|
||||
}
|
||||
|
||||
public bool Value
|
||||
{
|
||||
get { return _value; }
|
||||
set
|
||||
{
|
||||
if (_value != value)
|
||||
{
|
||||
_value = value;
|
||||
if (_name != null)
|
||||
_settings.SetValue(_name, value);
|
||||
_menuItem.Checked = value;
|
||||
_changed?.Invoke(this, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler Changed
|
||||
{
|
||||
add
|
||||
{
|
||||
_changed += value;
|
||||
_changed?.Invoke(this, null);
|
||||
}
|
||||
remove
|
||||
{
|
||||
_changed -= value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user