-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFormMain.cs
More file actions
272 lines (232 loc) · 9.19 KB
/
Copy pathFormMain.cs
File metadata and controls
272 lines (232 loc) · 9.19 KB
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
using CachedProgramsList.Data;
using CachedProgramsList.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CachedProgramsList
{
public partial class FormMain : Form
{
private Entries dataEntries;
public FormMain()
{
InitializeComponent();
DoubleBufferedControl(datagEntries, true);
dataEntries = new Entries((DataGridViewRow)datagEntries.Rows[0].Clone());
dataEntries.EntryAmountUpdate += dataEntries_EntryAmountUpdate;
dataEntries.WorkEnded += DataEntries_WorkEnded;
comboFilterOptions.SelectedIndex = 0;
}
private void DataEntries_WorkEnded(object sender, int e)
{
lbEntryAmount.Text = $"Found {e} entries.";
}
private void dataEntries_EntryAmountUpdate(object sender, int e)
{
lbEntryAmount.Text = $"{e} entries...";
}
private void DoubleBufferedControl(DataGridView dgv, bool setting)
{
Type dgvType = dgv.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, setting, null);
}
#region logging and filtering
private async void btCancelFilter_Click(object sender, EventArgs e)
{
btCancelFilter.Enabled = false;
btLog.Enabled = true;
datagEntries.Rows.Clear();
List<DataGridViewRow> entries = await Task.Run(() =>
{
return dataEntries.getEntries(false);
});
await addRows(entries);
}
private async void btLog_Click(object sender, EventArgs e)
{
btLog.Enabled = false;
picWorking.Visible = true;
datagEntries.Rows.Clear();
List<DataGridViewRow> entries = await Task.Run(() =>
{
return dataEntries.getEntries();
});
await addRows(entries);
btLog.Enabled = true;
picWorking.Visible = false;
}
private void txtFilter_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
btFilter.PerformClick();
e.SuppressKeyPress = true;
}
}
private async void btFilter_Click(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(txtFilter.Text))
{
btCancelFilter.Enabled = true;
btLog.Enabled = false;
datagEntries.Rows.Clear();
List<DataGridViewRow> entries = await Task.Run(() =>
{
return dataEntries.filterEntries(txtFilter.Text, comboFilterOptions.Text);
});
await addRows(entries);
}
}
private async Task addRows(List<DataGridViewRow> rows)
{
foreach (DataGridViewRow row in rows)
{
await Task.Run(() =>
{
Invoke((MethodInvoker)delegate
{
datagEntries.Rows.Add(row);
});
});
}
}
#endregion
#region menu strip
#region native
//https://stackoverflow.com/questions/1936682/how-do-i-display-a-files-properties-dialog-from-c
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SHELLEXECUTEINFO
{
public int cbSize;
public uint fMask;
public IntPtr hwnd;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpVerb;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpFile;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpParameters;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpDirectory;
public int nShow;
public IntPtr hInstApp;
public IntPtr lpIDList;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpClass;
public IntPtr hkeyClass;
public uint dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}
private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;
public static bool ShowFileProperties(string Filename)
{
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
info.lpVerb = "properties";
info.lpFile = Filename;
info.nShow = SW_SHOW;
info.fMask = SEE_MASK_INVOKEIDLIST;
return ShellExecuteEx(ref info);
}
#endregion
private string clickFolder, clickExec;
private void datagEntries_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex == 4 && e.RowIndex != -1 && e.Button == MouseButtons.Right)
{
DataGridViewCell c = (sender as DataGridView)[e.ColumnIndex, e.RowIndex];
if (!c.Selected && c.Value != null)
{
DataGridViewCell cExists = (sender as DataGridView)[1, e.RowIndex];
bool flag = (bool)cExists.Value;
openFileToolStripMenuItem.Enabled = flag;
moreInfoToolStripMenuItem.Enabled = flag;
clickExec = (string)c.Value;
int index = clickExec.LastIndexOf(@"\");
clickFolder = clickExec.Substring(0, index);
c.DataGridView.ClearSelection();
c.DataGridView.CurrentCell = c;
c.Selected = true;
var relativeMousePosition = datagEntries.PointToClient(Cursor.Position);
csmPath.Show(datagEntries, relativeMousePosition);
}
}
}
private void openPathToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Directory.Exists(clickFolder))
{
Process.Start(clickFolder);
}
else
{
MessageBox.Show("Directory doesn't exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start(clickExec);
}
private void moreInfoToolStripMenuItem_Click(object sender, EventArgs e)
{
ShowFileProperties(clickExec);
}
#endregion
#region theming
private string theme = "dark";
private void btTheme_Click(object sender, EventArgs e)
{
if (theme == "dark")
{
btTheme.BackgroundImage = Resources.dark;
lightTheme();
theme = "light";
}
else
{
btTheme.BackgroundImage = Resources.light;
darkTheme();
theme = "dark";
}
}
private void lightTheme()
{
BackColor = Color.FromArgb(235, 235, 235);
lbEntryAmount.ForeColor = Color.FromArgb(15, 15, 15);
datagEntries.BackgroundColor = Color.FromArgb(230, 230, 230);
datagEntries.GridColor = Color.FromArgb(150, 150, 150);
datagEntries.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(225, 225, 225);
datagEntries.ColumnHeadersDefaultCellStyle.ForeColor = Color.FromArgb(15, 15, 15);
datagEntries.DefaultCellStyle.BackColor = Color.FromArgb(215, 215, 215);
datagEntries.DefaultCellStyle.ForeColor = Color.FromArgb(15, 15, 15);
datagEntries.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(208, 208, 208);
datagEntries.AlternatingRowsDefaultCellStyle.ForeColor = Color.FromArgb(15, 15, 15);
}
private void darkTheme()
{
BackColor = Color.FromArgb(20, 20, 20);
lbEntryAmount.ForeColor = Color.FromArgb(240, 240, 240);
datagEntries.BackgroundColor = Color.FromArgb(25, 25, 25);
datagEntries.GridColor = Color.FromArgb(105, 105, 105);
datagEntries.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(30, 30, 30);
datagEntries.ColumnHeadersDefaultCellStyle.ForeColor = Color.FromArgb(240, 240, 240);
datagEntries.DefaultCellStyle.BackColor = Color.FromArgb(40, 40, 40);
datagEntries.DefaultCellStyle.ForeColor = Color.FromArgb(240, 240, 240);
datagEntries.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(47, 47, 47);
datagEntries.AlternatingRowsDefaultCellStyle.ForeColor = Color.FromArgb(240, 240, 240);
}
#endregion
}
}