//this is what runs at initialization public Form1() { InitializeComponent(); DataGridPreview.DataSource = null; DataGridPreview.ColumnCount = 2; DataGridPreview.Columns[0].Name = "RegEx"; DataGridPreview.Columns[1].Name = "Repacement"; DataGridPreview.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; DataGridPreview.Update(); foreach (var encoding in Encoding.GetEncodings()) { EncodingDropdown.Items.Add(encoding.Name); } try { EncodingDropdown.SelectedIndex = EncodingDropdown.FindStringExact("utf-8"); } catch { EncodingDropdown.SelectedIndex = EncodingDropdown.FindStringExact(Encoding.Default.BodyName); } }
public SettingsForm_RegExReplace(string RegexFile, string SelectedEncoding, Regex[] RegexArray, string[] ReplacementArray, bool fileLoaded, bool CaseSens, bool CompactWhite) { InitializeComponent(); foreach (var encoding in Encoding.GetEncodings()) { EncodingDropdown.Items.Add(encoding.Name); } try { EncodingDropdown.SelectedIndex = EncodingDropdown.FindStringExact(SelectedEncoding); } catch { EncodingDropdown.SelectedIndex = EncodingDropdown.FindStringExact(Encoding.Default.BodyName); } SelectedFileTextbox.Text = RegexFile; this.SelectedEncoding = SelectedEncoding; this.fileLoaded = fileLoaded; this.RegexArray = RegexArray; this.ReplacementArray = ReplacementArray; DataTable dt = new DataTable(); dt.Columns.Add("RegEx"); dt.Columns.Add("Replacement"); CompactWhitespaceCheckbox.Checked = CompactWhite; CaseSensitiveCheckbox.Checked = CaseSens; if (fileLoaded) { //Map out the input entries for (int i = 0; i < RegexArray.Length; i++) { System.Data.DataTable table = new System.Data.DataTable("RegExTable"); dt.Rows.Add(new string[] { RegexArray[i].ToString(), ReplacementArray[i] }); } DataGridPreview.DataSource = null; DataGridPreview.Columns.Clear(); DataGridPreview.Rows.Clear(); DataGridPreview.DataSource = dt; DataGridPreview.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; DataGridPreview.AutoResizeColumns(); DataGridPreview.Update(); } }
private void SetFolderButton_Click(object sender, System.EventArgs e) { SelectedFileTextbox.Text = ""; using (var dialog = new OpenFileDialog()) { dialog.Multiselect = false; dialog.CheckFileExists = true; dialog.CheckPathExists = true; dialog.ValidateNames = true; dialog.Title = "Please choose your RegEx Dictionary File"; dialog.FileName = "RegEx-Dictionary.txt"; dialog.Filter = "Text File (*.txt)|*.txt"; if (dialog.ShowDialog() == DialogResult.OK) { SelectedFileTextbox.Text = dialog.FileName; string RegexListFileRawText = ""; //Load dictionary file now try { RegexListFileRawText = File.ReadAllText(dialog.FileName, Encoding.GetEncoding(EncodingDropdown.SelectedItem.ToString())); //parse out the the dictionary file List <Regex> RegexList = new List <Regex>(); List <string> ReplacementList = new List <string>(); DataTable dt = new DataTable(); dt.Columns.Add("RegEx"); dt.Columns.Add("Replacement"); string[] EntryLines = RegexListFileRawText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); //Map out the input entries for (int i = 0; i < EntryLines.Length; i++) { System.Data.DataTable table = new System.Data.DataTable("RegExTable"); string[] EntryRow = EntryLines[i].Split(new char[] { '\t' }); dt.Rows.Add(new string[] { EntryRow[0], EntryRow[1] }); if (CaseSensitiveCheckbox.Checked) { RegexList.Add(new Regex(@EntryRow[0], RegexOptions.Compiled)); } else { RegexList.Add(new Regex(@EntryRow[0], RegexOptions.Compiled | RegexOptions.IgnoreCase)); } ReplacementList.Add(EntryRow[1]); } RegexArray = RegexList.ToArray(); ReplacementArray = ReplacementList.ToArray(); fileLoaded = true; DataGridPreview.DataSource = null; DataGridPreview.Columns.Clear(); DataGridPreview.Rows.Clear(); DataGridPreview.DataSource = dt; DataGridPreview.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; DataGridPreview.AutoResizeColumns(); DataGridPreview.Update(); MessageBox.Show("Your regular expression list has been successfully loaded.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { DataGridPreview.DataSource = null; DataGridPreview.Columns.Clear(); DataGridPreview.Rows.Clear(); DataGridPreview.ColumnCount = 2; DataGridPreview.Columns[0].Name = "RegEx"; DataGridPreview.Columns[1].Name = "Repacement"; DataGridPreview.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; DataGridPreview.Update(); SelectedFileTextbox.Text = ""; fileLoaded = false; RegexArray = new Regex[0]; ReplacementArray = new string[0]; MessageBox.Show("BUTTER is having trouble reading data from your RegEx file. Is it open in another application?", "RegEx File Problem", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } }
private void LoadDictionaryButton_Click(object sender, EventArgs e) { BGData = new BGWorkerData(); // ____ _ _____ _ _____ ____ ___ ____ _____ _ _ // | _ \ ___ __ _ __| | |_ _|____ _| |_ | ___| __ ___ _ __ ___ | _ \_ _/ ___| | ___(_) | ___ // | |_) / _ \/ _` |/ _` | | |/ _ \ \/ / __| | |_ | '__/ _ \| '_ ` _ \ | | | | | | | |_ | | |/ _ \ // | _ < __/ (_| | (_| | | | __/> <| |_ | _|| | | (_) | | | | | | _| |_| | | |___ | _| | | | __/ // |_| \_\___|\__,_|\__,_| |_|\___/_/\_\\__| |_| |_| \___/|_| |_| |_| (_)____/___\____| |_| |_|_|\___| string RegexListFileRawText = ""; openFileDialog.Title = "Please choose your TextEmend RegEx List file"; if (openFileDialog.ShowDialog() != DialogResult.Cancel) { FolderBrowser.SelectedPath = System.IO.Path.GetDirectoryName(openFileDialog.FileName); //Load dictionary file now try { Encoding SelectedEncoding = null; SelectedEncoding = Encoding.GetEncoding(EncodingDropdown.SelectedItem.ToString()); RegexListFileRawText = File.ReadAllText(openFileDialog.FileName, SelectedEncoding); } catch { MessageBox.Show("TextEmend is having trouble reading data from your RegEx list file. Is it open in another application?"); return; } } else { return; } // ____ _ _ ____ _____ ____ _ _ // | _ \ ___ _ __ _ _| | __ _| |_ ___ | _ \ ___ __ _| ____|_ __ | _ \ ___ _ __ | | __ _ ___ ___ _ __ ___ ___ _ __ | |_ ___ // | |_) / _ \| '_ \| | | | |/ _` | __/ _ \ | |_) / _ \/ _` | _| \ \/ / | |_) / _ \ '_ \| |/ _` |/ __/ _ \ '_ ` _ \ / _ \ '_ \| __/ __| // | __/ (_) | |_) | |_| | | (_| | || __/ | _ < __/ (_| | |___ > < | _ < __/ |_) | | (_| | (_| __/ | | | | | __/ | | | |_\__ \ // |_| \___/| .__/ \__,_|_|\__,_|\__\___| |_| \_\___|\__, |_____/_/\_\ |_| \_\___| .__/|_|\__,_|\___\___|_| |_| |_|\___|_| |_|\__|___/ // |_| |___/ |_| |__/ //parse out the the dictionary file List <Regex> RegexList = new List <Regex>(); List <string> ReplacementList = new List <string>(); try { DataTable dt = new DataTable(); dt.Columns.Add("RegEx"); dt.Columns.Add("Replacement"); string[] EntryLines = RegexListFileRawText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); //Map out the input entries for (int i = 0; i < EntryLines.Length; i++) { System.Data.DataTable table = new System.Data.DataTable("RegExTable"); string[] EntryRow = EntryLines[i].Split(new char[] { '\t' }); dt.Rows.Add(new string[] { EntryRow[0], EntryRow[1] }); if (CaseSensitiveCheckbox.Checked) { RegexList.Add(new Regex(@EntryRow[0], RegexOptions.Compiled)); } else { RegexList.Add(new Regex(@EntryRow[0], RegexOptions.Compiled | RegexOptions.IgnoreCase)); } ReplacementList.Add(EntryRow[1]); } BGData.RegexArray = RegexList.ToArray(); BGData.ReplacementArray = ReplacementList.ToArray(); BGData.RegExListLoaded = true; DataGridPreview.DataSource = null; DataGridPreview.Columns.Clear(); DataGridPreview.Rows.Clear(); DataGridPreview.DataSource = dt; DataGridPreview.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; DataGridPreview.AutoResizeColumns(); DataGridPreview.Update(); MessageBox.Show("Your regular expression list has been successfully loaded.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { DataGridPreview.DataSource = null; DataGridPreview.Columns.Clear(); DataGridPreview.Rows.Clear(); DataGridPreview.ColumnCount = 2; DataGridPreview.Columns[0].Name = "RegEx"; DataGridPreview.Columns[1].Name = "Repacement"; DataGridPreview.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; DataGridPreview.Update(); MessageBox.Show("TextEmend encountered an error while trying to parse out your RegEx list. Please check to make sure that it is correctly formatted, that your regular expressions are valid, and that your list file is not currently open in another application.", "Error parsing RegEx list", MessageBoxButtons.OK, MessageBoxIcon.Error); BGData = new BGWorkerData(); return; } }