示例#1
0
 /// <summary>
 /// Menu: File -> Save As Template...
 /// </summary>
 private void FileMenuSaveTemplateClick(object sender, EventArgs e)
 {
     const string title = "Save Project Template";
     const string label = "Template Name:";
     string text = Project.Title;
     using (var dialog = new UserStringForm(title, text, label, true))
     {
         if (dialog.ShowDialog() == DialogResult.OK)
         {
             string path = Path.Combine(PathHelper.ProjectTemplateDirectory,
                 String.Format("{0}.7z", dialog.UserString));
             if (File.Exists(path))
             {
                 string msg = String.Format("\"{0}\" already exists.\nOverwrite?", dialog.UserString);
                 var result = MessageBox.Show(msg,
                     "Confirm Overwrite", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                 if (result != DialogResult.Yes)
                     return;
             }
             new Thread(lamda =>
                 Compressor.CompressDirectory(Project.ProjectFolder, path, true)).Start();
         }
     }
 }
示例#2
0
 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);
                 }
             }
         }
     }
 }