forked from openhardwaremonitor/openhardwaremonitor
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUserOption.cs
67 lines (57 loc) · 1.73 KB
/
UserOption.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
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 <[email protected]>
*/
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;
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 event EventHandler Changed {
add {
changed += value;
if (changed != null)
changed(this, null);
}
remove {
changed -= value;
}
}
}
}