forked from baldurk/renderdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironmentEditor.cs
More file actions
213 lines (176 loc) · 6.5 KB
/
Copy pathEnvironmentEditor.cs
File metadata and controls
213 lines (176 loc) · 6.5 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using renderdoc;
namespace renderdocui.Windows.Dialogs
{
public partial class EnvironmentEditor : Form
{
public EnvironmentEditor()
{
InitializeComponent();
pendSeparator.Items.AddRange(new object[] {
EnvironmentSeparator.Platform.Str(),
EnvironmentSeparator.SemiColon.Str(),
EnvironmentSeparator.Colon.Str(),
EnvironmentSeparator.None.Str()
});
}
private void EnvironmentEditor_Load(object sender, EventArgs e)
{
pendSeparator.SelectedIndex = (int)EnvironmentSeparator.Platform;
setType.Checked = true;
varName.Select();
varName_TextChanged(varName, new EventArgs());
variables.NodesSelection.Clear();
}
private int ExistingIndex()
{
int i=0;
foreach (var n in variables.Nodes)
{
if ((string)n[0] == varName.Text)
return i;
i++;
}
return -1;
}
private void modification_CheckedChanged(object sender, EventArgs e)
{
pendSeparator.Enabled = !setType.Checked;
}
private void varName_TextChanged(object sender, EventArgs e)
{
int idx = ExistingIndex();
if (idx >= 0)
{
addUpdate.Text = "Update";
delete.Enabled = true;
variables.NodesSelection.Clear();
variables.NodesSelection.Add(variables.Nodes[idx]);
}
else
{
addUpdate.Text = "Add";
delete.Enabled = false;
addUpdate.Enabled = (varName.Text.Trim() != "");
}
}
private void varField_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\n' || e.KeyChar == '\r')
{
addUpdate.PerformClick();
}
}
private void variables_AfterSelect(object sender, TreeViewEventArgs e)
{
if (variables.SelectedNode != null)
{
EnvironmentModification mod = variables.SelectedNode.Tag as EnvironmentModification;
if (mod != null)
{
varName.Text = mod.variable;
varValue.Text = mod.value;
pendSeparator.SelectedIndex = (int)mod.separator;
if (mod.type == EnvironmentModificationType.Set)
setType.PerformClick();
else if (mod.type == EnvironmentModificationType.Append)
appendType.PerformClick();
else if (mod.type == EnvironmentModificationType.Prepend)
prependType.PerformClick();
}
}
}
private void delete_Click(object sender, EventArgs e)
{
if (variables.SelectedNode != null)
{
variables.BeginUpdate();
variables.Nodes.Remove(variables.SelectedNode);
variables.EndUpdate();
variables.NodesSelection.Clear();
string text = varName.Text;
varName.Text = "";
varName.Text = text;
}
}
private void addUpdate_Click(object sender, EventArgs e)
{
EnvironmentModification mod = new EnvironmentModification();
mod.variable = varName.Text;
mod.value = varValue.Text;
mod.separator = (EnvironmentSeparator)pendSeparator.SelectedIndex;
if (appendType.Checked)
mod.type = EnvironmentModificationType.Append;
else if (prependType.Checked)
mod.type = EnvironmentModificationType.Prepend;
else
mod.type = EnvironmentModificationType.Set;
AddModification(mod, false);
varName.Text = "";
varName.Text = mod.variable;
}
public void AddModification(EnvironmentModification mod, bool silent)
{
TreelistView.Node node = new TreelistView.Node();
int idx = ExistingIndex();
if (idx >= 0)
node = variables.Nodes[idx];
if (mod.variable.Trim() == "")
{
if(!silent)
MessageBox.Show("Environment variable cannot be just whitespace", "Invalid variable", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
variables.BeginUpdate();
if (idx < 0)
variables.Nodes.Add(node);
node.SetData(new object[] { mod.variable, mod.GetTypeString(), mod.value });
node.Tag = mod;
variables.EndUpdate();
variables.NodesSelection.Clear();
variables.NodesSelection.Add(node);
varName.AutoCompleteCustomSource.Clear();
for (int i = 0; i < variables.Nodes.Count; i++)
varName.AutoCompleteCustomSource.Add((string)variables.Nodes[i][0]);
}
public EnvironmentModification[] Modifications
{
get
{
EnvironmentModification[] ret = new EnvironmentModification[variables.Nodes.Count];
for(int i=0; i < variables.Nodes.Count; i++)
ret[i] = variables.Nodes[i].Tag as EnvironmentModification;
return ret;
}
}
private void EnvironmentEditor_FormClosing(object sender, FormClosingEventArgs e)
{
int idx = ExistingIndex();
if(idx >= 0)
return;
DialogResult res = MessageBox.Show(
"You did not add the variable modification you were editing. Add it now?",
"Variable not added", MessageBoxButtons.YesNoCancel);
if (res == DialogResult.Yes)
{
addUpdate_Click(addUpdate, new EventArgs());
}
else if (res == DialogResult.Cancel)
{
e.Cancel = true;
}
}
private void variables_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete && delete.Enabled)
delete.PerformClick();
}
}
}