-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskDlgControlDesigner.cs
More file actions
188 lines (167 loc) · 6.71 KB
/
Copy pathTaskDlgControlDesigner.cs
File metadata and controls
188 lines (167 loc) · 6.71 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
namespace Windows_Dialog_Box_Generator
{
public partial class TaskDlgControlDesigner : Form
{
public List<TaskDialogControl> TaskDlgControls = [];
public TaskDlgControlDesigner()
{
InitializeComponent();
}
public TaskDlgControlDesigner(IEnumerable<TaskDialogControl> controls)
{
InitializeComponent();
TaskDlgControls = [.. controls];
RefreshList();
}
private void RefreshList()
{
listView1.Items.Clear();
listView1.BeginUpdate();
imgList.Images.Clear();
imgList.Images.Add(Properties.Resources.icon_button);
imgList.Images.Add(Properties.Resources.icon_button_uacshield);
imgList.Images.Add(Properties.Resources.icon_cmdlink);
imgList.Images.Add(Properties.Resources.icon_check);
imgList.Images.Add(Properties.Resources.icon_radio);
foreach (TaskDialogControl control in TaskDlgControls)
{
listView1.Items.Add(new ListViewItem
{
Text = control switch // TaskDialogControl doesn't have a Text property, we have to check types instead
{
TaskDialogButton b => b.Text,
TaskDialogRadioButton r => r.Text,
TaskDialogVerificationCheckBox v => v.Text,
_ => string.Empty
},
ImageIndex = control switch
{
TaskDialogCommandLinkButton c => 2,
TaskDialogButton b => b.ShowShieldIcon ? 1 : 0,
TaskDialogRadioButton r => 4,
TaskDialogVerificationCheckBox v => 3,
_ => -1 // -1 = no icon, this is the default
},
Tag = control,
SubItems =
{
new ListViewItem.ListViewSubItem
{
Text = control switch
{
TaskDialogButton b => b.Enabled.ToString(),
TaskDialogRadioButton r => r.Enabled.ToString(),
// A TaskDialogVerificationCheckBox doesn't have Enabled
_ => string.Empty
}
},
new ListViewItem.ListViewSubItem
{
Text = control switch
{
TaskDialogButton b => string.Empty,
TaskDialogRadioButton r => r.Checked.ToString(),
TaskDialogVerificationCheckBox v => v.Checked.ToString(),
_ => string.Empty
}
}
}
});
}
listView1.EndUpdate();
}
private void button3_Click(object sender, EventArgs e)
{
var dlg = new TaskDlgControlDesigner_ButtonMakeDlg();
var result = dlg.ShowDialog();
if (result == DialogResult.OK)
{
TaskDialogButton button;
if (dlg.radioButton1.Checked)
{
button = dlg.comboBox1.SelectedIndex switch
{
0 => TaskDialogButton.Abort,
1 => TaskDialogButton.Cancel,
2 => TaskDialogButton.Close,
3 => TaskDialogButton.Continue,
4 => TaskDialogButton.Help,
5 => TaskDialogButton.Ignore,
6 => TaskDialogButton.No,
7 => TaskDialogButton.OK,
8 => TaskDialogButton.Retry,
9 => TaskDialogButton.TryAgain,
10 => TaskDialogButton.Yes,
_ => new TaskDialogButton("(Error)")
};
button.AllowCloseDialog = dlg.checkBox3.Checked;
button.Enabled = dlg.checkBox2.Checked;
button.ShowShieldIcon = dlg.checkBox1.Checked;
}
else
{
if (dlg.radioButton3.Checked)
{
button = new TaskDialogButton(dlg.textBox1.Text, dlg.checkBox2.Checked, dlg.checkBox3.Checked)
{
ShowShieldIcon = dlg.checkBox1.Checked
};
}
else
{
button = new TaskDialogCommandLinkButton(dlg.textBox2.Text, dlg.textBox3.Text, dlg.checkBox2.Checked, dlg.checkBox3.Checked)
{
ShowShieldIcon = dlg.checkBox1.Checked
};
}
}
if (button != null)
{
TaskDlgControls.Add(button);
RefreshList();
}
}
}
private void button6_Click(object sender, EventArgs e)
{
foreach (ListViewItem lvi in listView1.SelectedItems)
{
if (lvi.Tag is TaskDialogControl c)
{
TaskDlgControls.Remove(c);
}
}
button6.Enabled = false;
RefreshList();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
button6.Enabled = listView1.SelectedItems.Count > 0;
}
private void button4_Click(object sender, EventArgs e)
{
var dlg = new TaskDlgControlDesigner_RadioMakeDlg();
// Smart checking: if a radio button already exists and is checked, uncheck this one
// otherwise, check it
foreach (TaskDialogRadioButton rb in TaskDlgControls.OfType<TaskDialogRadioButton>())
{
if (rb.Checked)
{
dlg.checkBox1.Checked = false;
break;
}
}
var result = dlg.ShowDialog();
if (result == DialogResult.OK)
{
TaskDlgControls.Add(new TaskDialogRadioButton
{
Text = dlg.textBox1.Text,
Checked = dlg.checkBox1.Checked,
Enabled = dlg.checkBox2.Checked
});
RefreshList();
}
}
}
}