-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ColumnEditor.cs
304 lines (278 loc) · 12.6 KB
/
ColumnEditor.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
using DownloadManager.NativeMethods;
using static DownloadManager.CurrentDownloads;
using static DownloadManager.Logging;
namespace DownloadManager
{
public partial class ColumnEditor : Form
{
CurrentDownloads downloads;
public ColumnEditor(CurrentDownloads downloads)
{
InitializeComponent();
this.downloads = downloads;
DesktopWindowManager.SetImmersiveDarkMode(this.Handle, true);
DesktopWindowManager.EnableMicaIfSupported(this.Handle);
DesktopWindowManager.ExtendFrameIntoClientArea(this.Handle);
foreach (string item in Settings.Default.currentDownloadsShownColumns)
{
Application.DoEvents();
switch (item)
{
case "0":
showList.Items.Add("File Name");
break;
case "1":
showList.Items.Add("Progress");
break;
case "2":
showList.Items.Add("Speed");
break;
case "3":
showList.Items.Add("URL");
break;
case "4":
showList.Items.Add("Received");
break;
case "5":
showList.Items.Add("Size");
break;
default:
// Invalid column
Logging.Log(LogLevel.Error, "Found invalid column while creating list of shown columns!");
showList.Items.Add("<unknown>");
break;
}
}
foreach (string item in Settings.Default.currentDownloadsHiddenColumns)
{
Application.DoEvents();
if (Settings.Default.currentDownloadsShownColumns.Contains(item))
{
Logging.Log(LogLevel.Warning, "Duplicate column found in shown columns while making list of hidden columns. The item will be removed.");
Settings.Default.currentDownloadsHiddenColumns.Remove(item);
Settings.Default.Save();
break;
}
switch (item)
{
case "0":
hideList.Items.Add("File Name");
break;
case "1":
hideList.Items.Add("Progress");
break;
case "2":
hideList.Items.Add("Speed");
break;
case "3":
hideList.Items.Add("URL");
break;
case "4":
hideList.Items.Add("Received");
break;
case "5":
hideList.Items.Add("Size");
break;
default:
// Invalid column
Logging.Log(LogLevel.Error, "Found invalid column while creating list of shown columns!");
hideList.Items.Add("<unknown>");
break;
}
}
}
private void doneButton_Click(object sender, EventArgs e)
{
// Create list of shown columns
Settings.Default.currentDownloadsShownColumns.Clear();
List<Column> shownColumns = new List<Column>();
foreach (string item in showList.Items)
{
switch (item)
{
case "File Name":
shownColumns.Add(Column.fileName);
Settings.Default.currentDownloadsShownColumns.Add(((int)Column.fileName).ToString());
break;
case "Progress":
shownColumns.Add(Column.progress);
Settings.Default.currentDownloadsShownColumns.Add(((int)Column.progress).ToString());
break;
case "Speed":
shownColumns.Add(Column.speed);
Settings.Default.currentDownloadsShownColumns.Add(((int)Column.speed).ToString());
break;
case "URL":
shownColumns.Add(Column.url);
Settings.Default.currentDownloadsShownColumns.Add(((int)Column.url).ToString());
break;
case "Received":
shownColumns.Add(Column.received);
Settings.Default.currentDownloadsShownColumns.Add(((int)Column.received).ToString());
break;
case "Size":
shownColumns.Add(Column.size);
Settings.Default.currentDownloadsShownColumns.Add(((int)Column.size).ToString());
break;
default:
// Invalid column
Logging.Log(LogLevel.Warning, "Found invalid column while creating list of shown columns! The item will be ignored.");
break;
}
}
Settings.Default.currentDownloadsHiddenColumns.Clear();
List<Column> hiddenColumns = new List<Column>();
foreach (string item in hideList.Items)
{
switch (item)
{
case "File Name":
hiddenColumns.Add(Column.fileName);
Settings.Default.currentDownloadsHiddenColumns.Add(((int)Column.fileName).ToString());
break;
case "Progress":
hiddenColumns.Add(Column.progress);
Settings.Default.currentDownloadsHiddenColumns.Add(((int)Column.progress).ToString());
break;
case "Speed":
hiddenColumns.Add(Column.speed);
Settings.Default.currentDownloadsHiddenColumns.Add(((int)Column.speed).ToString());
break;
case "URL":
hiddenColumns.Add(Column.url);
Settings.Default.currentDownloadsHiddenColumns.Add(((int)Column.url).ToString());
break;
case "Received":
hiddenColumns.Add(Column.received);
Settings.Default.currentDownloadsHiddenColumns.Add(((int)Column.received).ToString());
break;
case "Size":
hiddenColumns.Add(Column.size);
Settings.Default.currentDownloadsHiddenColumns.Add(((int)Column.size).ToString());
break;
default:
// Invalid column
Logging.Log(LogLevel.Warning, "Found invalid column while creating list of hidden columns! The item will be ignored.");
break;
}
}
Settings.Default.Save();
downloads.HideColumns(hiddenColumns, shownColumns);
this.Close();
}
private void showButton_Click(object sender, EventArgs e)
{
// Move item to shown list
if (hideList.SelectedIndex == -1)
{
// Do nothing
return;
}
showList.Items.Add(hideList.Items[hideList.SelectedIndex]);
hideList.Items.RemoveAt(hideList.SelectedIndex);
}
private void hideButton_Click(object sender, EventArgs e)
{
// Hide item to hide list
if (showList.SelectedIndex == -1)
{
// Do nothing
return;
}
hideList.Items.Add(showList.Items[showList.SelectedIndex]);
showList.Items.RemoveAt(showList.SelectedIndex);
}
private void resetButton_Click(object sender, EventArgs e)
{
DialogResult result = new DarkMessageBox("Are you sure you want to reset your column preferences?\nThis should only be used if new columns added in an update are not showing or you are experiencing issues with hiding/showing columns.", "Reset Column Preferences?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, false).ShowDialog();
if (result == DialogResult.Yes)
{
DownloadForm._instance.SetupColumnPrefs();
showList.Items.Clear();
hideList.Items.Clear();
List<Column> shownColumns = new List<Column>();
List<Column> hiddenColumns = new List<Column>();
foreach (string item in Settings.Default.currentDownloadsShownColumns)
{
Application.DoEvents();
switch (item)
{
case "0":
showList.Items.Add("File Name");
shownColumns.Add(Column.fileName);
break;
case "1":
showList.Items.Add("Progress");
shownColumns.Add(Column.progress);
break;
case "2":
showList.Items.Add("Speed");
shownColumns.Add(Column.speed);
break;
case "3":
showList.Items.Add("URL");
shownColumns.Add(Column.url);
break;
case "4":
showList.Items.Add("Received");
shownColumns.Add(Column.received);
break;
case "5":
showList.Items.Add("Size");
shownColumns.Add(Column.size);
break;
default:
// Invalid column
Logging.Log(LogLevel.Error, "Found invalid column while creating list of shown columns!");
showList.Items.Add("<unknown>");
break;
}
}
foreach (string item in Settings.Default.currentDownloadsHiddenColumns)
{
Application.DoEvents();
if (Settings.Default.currentDownloadsShownColumns.Contains(item))
{
Logging.Log(LogLevel.Warning, "Duplicate column found in shown columns while making list of hidden columns. The item will be removed.");
Settings.Default.currentDownloadsHiddenColumns.Remove(item);
Settings.Default.Save();
break;
}
switch (item)
{
case "0":
hideList.Items.Add("File Name");
hiddenColumns.Add(Column.fileName);
break;
case "1":
hideList.Items.Add("Progress");
hiddenColumns.Add(Column.progress);
break;
case "2":
hideList.Items.Add("Speed");
hiddenColumns.Add(Column.speed);
break;
case "3":
hideList.Items.Add("URL");
hiddenColumns.Add(Column.url);
break;
case "4":
hideList.Items.Add("Received");
hiddenColumns.Add(Column.received);
break;
case "5":
hideList.Items.Add("Size");
hiddenColumns.Add(Column.size);
break;
default:
// Invalid column
Logging.Log(LogLevel.Error, "Found invalid column while creating list of shown columns!");
hideList.Items.Add("<unknown>");
break;
}
}
downloads.HideColumns(hiddenColumns, shownColumns);
}
}
}
}