mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-29 09:05:49 +00:00
Allow specifying environment variable modifications
* This works for local and remote invocations of programs, but is mostly useful on unix systems (Windows programs use env vars less often)
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user