-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormFlagsWatcher.cs
101 lines (83 loc) · 3 KB
/
FormFlagsWatcher.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
using EDTracking;
using System;
using System.Windows.Forms;
namespace SRVTracker
{
public partial class FormFlagsWatcher : Form
{
string[] _flagNames;
System.Array _flagValues;
long _currentFlags = 0;
public FormFlagsWatcher()
{
InitializeComponent();
Type flagsType = typeof(StatusFlags);
_flagNames = flagsType.GetEnumNames();
_flagValues = flagsType.GetEnumValues();
InitFlagsList();
}
private void InitFlagsList()
{
listViewCurrentFlags.Items.Clear();
listViewCurrentFlags.BeginUpdate();
for (int i = 0; i < _flagNames.Length; i++)
listViewCurrentFlags.Items.Add(new ListViewItem(_flagNames[i]));
listViewCurrentFlags.EndUpdate();
}
private bool isFlagSet(int flagIndex)
{
return ((_currentFlags & (long)_flagValues.GetValue(flagIndex)) == (long)_flagValues.GetValue(flagIndex));
}
private bool isFlagSet(int flagIndex, long flags)
{
return ((flags & (long)_flagValues.GetValue(flagIndex)) == (long)_flagValues.GetValue(flagIndex));
}
public void UpdateFlags(long flags)
{
listBoxStatusHistory.Items.Insert(0,_currentFlags);
_currentFlags = flags;
if (listBoxStatusHistory.SelectedIndex > -1)
return; // We're not looking at current flags
Action action = new Action(() =>
{
for (int i = 0; i < _flagNames.Length; i++)
listViewCurrentFlags.Items[i].Checked = isFlagSet(i);
});
if (listViewCurrentFlags.InvokeRequired)
listViewCurrentFlags.Invoke(action);
else
action();
}
private void buttonClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void listBoxStatusHistory_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBoxStatusHistory.SelectedIndex < 0)
return;
long flags = (long)listBoxStatusHistory.SelectedItem;
Action action = new Action(() =>
{
for (int i = 0; i < _flagNames.Length; i++)
listViewCurrentFlags.Items[i].Checked = isFlagSet(i, flags);
});
if (listViewCurrentFlags.InvokeRequired)
listViewCurrentFlags.Invoke(action);
else
action();
}
private void buttonShowCurrent_Click(object sender, EventArgs e)
{
listBoxStatusHistory.SelectedIndex = -1;
}
private void textBoxFlags_TextChanged(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(textBoxFlags.Text))
return;
long flags = Convert.ToInt32(textBoxFlags.Text);
if (flags>0)
UpdateFlags(flags);
}
}
}