-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathSetting.cs.old
173 lines (165 loc) · 5.22 KB
/
Setting.cs.old
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Collections.Generic;
using System.Windows.Media;
using System.Configuration;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace DesktopNote
{
public class Setting
{
public int SettingIndex;
private readonly Properties.Settings set;
public string Doc_Location
{
get {
return set.Doc_Location[SettingIndex];
}
set {
set.Doc_Location[SettingIndex] = value;
}
}
public string Bak_Location
{
get {
return set.Bak_Location[SettingIndex];
}
set {
set.Bak_Location[SettingIndex] = value;
}
}
public System.Windows.Size Win_Size
{
get {
return System.Windows.Size.Parse(set.Win_Size[SettingIndex]);
}
set {
set.Win_Size[SettingIndex] = value.ToString();
}
}
public System.Windows.Point Win_Pos
{
get {
return System.Windows.Point.Parse(set.Win_Pos[SettingIndex]);
}
set {
set.Win_Pos[SettingIndex] = value.ToString();
}
}
public bool AutoDock
{
get {
return bool.Parse(set.AutoDock[SettingIndex]);
}
set {
set.AutoDock[SettingIndex] = value.ToString();
}
}
public int DockedTo
{
get {
return int.Parse(set.DockedTo[SettingIndex]);
}
set {
set.DockedTo[SettingIndex] = value.ToString();
}
}
public string Font
{
get {
return set.Font[SettingIndex];
}
set {
set.Font[SettingIndex] = value;
}
}
public Color FontColor
{
get {
return (Color)ColorConverter.ConvertFromString(set.FontColor[SettingIndex]);
}
set {
set.FontColor[SettingIndex] = value.ToString();
}
}
public Color BackColor
{
get {
return (Color)ColorConverter.ConvertFromString(set.BackColor[SettingIndex]);
}
set {
set.BackColor[SettingIndex] = value.ToString();
}
}
public Color PaperColor
{
get {
return (Color)ColorConverter.ConvertFromString(set.PaperColor[SettingIndex]);
}
set {
set.PaperColor[SettingIndex] = value.ToString();
}
}
public Setting(int setidx)
{
SettingIndex = setidx;
set = Properties.Settings.Default;
}
/// <summary>
/// For now this is the same as calling Properties.Settings.Default.Save().
/// </summary>
public void Save()
{
set.Save();
}
/// <summary>
/// Reset the setting for specified index. Leave setidx default to reset current.
/// </summary>
public void Reset(int setidx = -1)
{
if (setidx == -1) setidx = SettingIndex;
foreach (SettingsPropertyValue val in set.PropertyValues) {
if (val.Name == nameof(set.Doc_Location) || val.Name == nameof(set.Bak_Location)) continue;
try {
if (val.Property.PropertyType == typeof(StringCollection)) {
var defval = XElement.Parse((string)val.Property.DefaultValue).Element("string").Value;
((StringCollection)val.PropertyValue)[setidx] = defval;
}
}
catch { }
}
}
/// <summary>
/// Do not use Properties.Settings.Default.Reset() as it will remove also the additional note entries.
/// </summary>
public void ResetAll()
{
//need to check before use
var notecount = set.Doc_Location.Count;
try {
foreach (SettingsPropertyValue val in set.PropertyValues) {
if (val.Name == nameof(set.Doc_Location) || val.Name == nameof(set.Bak_Location)) continue;
if (val.Property.PropertyType == typeof(StringCollection)) {
var defval = XElement.Parse((string)val.Property.DefaultValue).Element("string").Value;
for (int i = 0; i < notecount; i++) {
((StringCollection)val.PropertyValue)[i] = defval;
}
}
}
}
catch { }
}
public string Serialize()
{
var root = new XElement("Setting");
foreach (var info in typeof(Setting).GetProperties()) {
var ele = new XElement(info.Name, info.GetValue(this).ToString());
root.Add(ele);
}
return root.ToString(SaveOptions.DisableFormatting);
}
}
}