public DictionaryEditor(PatternDictionary dict) : this() { Dict = dict; chkEnable.Checked = dict.Enable; chkRegex.Checked = dict.Regex; chkIgnoreCase.Checked = dict.IgnoreCase; BindingList <Pair> pairs = new BindingList <Pair>(); foreach (var kv in dict.Entries) { pairs.Add(new Pair() { Key = kv.Key, Value = kv.Value, Parent = pairs, IsRegex = dict.Regex, }); } pairs.AddingNew += (s, a) => { a.NewObject = new Pair() { Key = "", Value = "", Parent = pairs, IsRegex = dict.Regex, }; }; dataGridView1.DataSource = pairs; }
private void fromClipboardToolStripMenuItem_Click(object sender, EventArgs e) { var text = Clipboard.GetText(); var lines = Regex.Split(text, @"\r?\n|\r"); var entries = lines .Select(x => x.Split("\t"[0])) .Where(x => x.Length >= 2) .GroupBy(x => x[0]) .Select(x => x.First()) .ToDictionary(x => x[0], x => x[1]) ; if (entries.Count == 0) { MessageBox.Show("Not supported format."); return; } var sb = new StringBuilder(); foreach (var kv in entries.Take(Math.Min(lines.Length, 5))) { sb.AppendLine($"{kv.Key}\t{kv.Value}"); } if (entries.Count > 5) { sb.AppendLine("..."); } if (MessageBox.Show(sb.ToString(), "Preview", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } var dict = new PatternDictionary { Enable = true, Entries = entries, }; saveFileDialog1.InitialDirectory = DictionaryFolder; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { dict.Path = saveFileDialog1.FileName; dict.Name = Path.GetFileNameWithoutExtension(saveFileDialog1.FileName); AddDictionary(dict); } using var frm = new DictionaryEditor(dict); var result = frm.ShowDialog(); if (result == DialogResult.OK) { Dictionaries.Remove(dict); Dictionaries.Add(frm.Dict); } }
private void AddDictionary(PatternDictionary dict) { Dictionaries.Add(dict); var tsmi = new ToolStripMenuItem(dict.Name + "...") { Tag = dict.Path, }; tsmi.Click += tsmiDictionary_Click; tsmiDictionaries.DropDownItems.Add(tsmi); }
public object Clone() { var dict = new PatternDictionary() { Enable = Enable, Regex = Regex, IgnoreCase = IgnoreCase, Priority = Priority, Entries = Entries, Name = Name, Path = Path, }; return(dict); }