private void buttonTemplate_Click(object sender, EventArgs e)
{
int index = this.listBoxScripts.SelectedIndex;
if (index >= 0)
{
string t = (this.listBoxScripts.SelectedItem as Script).Title;
using (var dialog =
new UserStringForm("Save as Template", t, "Template Name:", true))
{
dialog.Location = this.listBoxScripts.PointToClient(MousePosition);
if (dialog.ShowDialog(this) == DialogResult.OK)
{
string text = this._scripts[index].Text;
string filename = Path.Combine(PathHelper.ScriptTemplateDirectory,
String.Format("{0}.rb", dialog.UserString));
if (File.Exists(filename) &&
MessageBox.Show("Template already exists.\n\nOverwrite?",
"Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK)
{
return;
}
try { File.WriteAllText(filename, text); }
catch
{
MessageBox.Show("Failed to save template.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}