private void btnSaveTemplate_Click(object sender, EventArgs e) { SaveAs save = new SaveAs(); if (save.ShowDialog() == DialogResult.Cancel || String.IsNullOrEmpty(save.TemplateName.Trim())) { return; } string templateName = save.TemplateName.Trim(); RegexTemplate dupe = this.regexTemplates.Where(t => t.Name.ToLower().Trim() == templateName.ToLower()).FirstOrDefault(); if (!String.IsNullOrEmpty(dupe.Name)) { if (MessageBox.Show($"A template with the name \"{save.TemplateName}\" already exists.{Environment.NewLine}Do you really want to override the existing template?", "Overwrite template", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes) { return; } this.regexTemplates.Remove(dupe); } List <RegularExpressionEditor> toSave = this.regexEditors.OrderBy(x => x.Index).Where(x => x.UserEnabled).ToList(); this.regexTemplates.Add(new RegexTemplate() { Name = templateName, Options = this.regexOptions(), Search = toSave.Select(x => x.Expression).ToArray(), Replace = toSave.Select(x => x.Replacement).ToArray() }); this.serializeTemplates(); }
private void lbTemplates_MouseDoubleClick(object sender, MouseEventArgs e) { if (lbTemplates.SelectedItem == null) { return; } RegexTemplate template = (RegexTemplate)lbTemplates.SelectedItem; while (template.Search.Length - this.regexEditors.Count > 0) { this.createEditor(); } while (this.regexEditors.Count > template.Search.Length) { this.removeEditor(); } RegularExpressionEditor[] orderedEditors = this.regexEditors.OrderBy(x => x.Index).ToArray(); for (int i = 0; i < template.Search.Length; i++) { orderedEditors[i].Expression = template.Search[i]; orderedEditors[i].Replacement = template.Replace[i]; orderedEditors[i].UserEnabled = true; } cbRxOCultureInvariant.Checked = ((template.Options & RegexOptions.CultureInvariant) != 0); cbRxOECMAScript.Checked = ((template.Options & RegexOptions.ECMAScript) != 0); cbRxOExplicitCapture.Checked = ((template.Options & RegexOptions.ExplicitCapture) != 0); cbRxOIgnoreCase.Checked = ((template.Options & RegexOptions.IgnoreCase) != 0); cbRxOIgnorePatternWhitespace.Checked = ((template.Options & RegexOptions.IgnorePatternWhitespace) != 0); cbRxORightToLeft.Checked = ((template.Options & RegexOptions.RightToLeft) != 0); if ((template.Options & RegexOptions.Singleline) != 0) { rbRxOLSingleline.Checked = true; } else { rbRxOLMultiline.Checked = true; } }