public TransformUI() { InitializeComponent(); m_caps = new List <KeyValuePair <string, string> >(); // Add/Update m_btn_add.ToolTip(m_tt, "Adds a new transform, or updates an existing transform"); m_btn_add.Click += (s, a) => { if (!CommitEnabled) { return; } RaiseCommitEvent(); }; // Match help m_btn_regex_help.ToolTip(m_tt, "Displays a quick help guide for the Match field"); m_btn_regex_help.Click += (s, a) => { MatchFieldHelpUI.Show(); }; // Toggle equivalent regex m_btn_show_eqv_regex.ToolTip(m_tt, "Toggle the visibility of the equivalent regular expression field"); m_btn_show_eqv_regex.Click += (s, a) => { m_panel_eqv_regex.Visible = !m_panel_eqv_regex.Visible; UpdateUI(); }; // Match (tooltip set in UpdateUI()) m_edit_match.TextChanged += (s, a) => { if (!((TextBox)s).Modified) { return; } Pattern.Expr = m_edit_match.Text; Touched = true; UpdateUI(); }; // Match - Substring m_radio_substring.ToolTip(m_tt, "Match any occurrence of the pattern as a substring"); m_radio_substring.Click += (s, a) => { if (m_radio_substring.Checked) { Pattern.PatnType = EPattern.Substring; } UpdateUI(); }; // Match - Wildcard m_radio_wildcard.ToolTip(m_tt, "Match using wildcards, where '*' matches any number of characters and '?' matches any single character"); m_radio_wildcard.Click += (s, a) => { if (m_radio_wildcard.Checked) { Pattern.PatnType = EPattern.Wildcard; } UpdateUI(); }; // Match - Regex m_radio_regex.ToolTip(m_tt, "Match using a regular expression"); m_radio_regex.Click += (s, a) => { if (m_radio_regex.Checked) { Pattern.PatnType = EPattern.RegularExpression; } UpdateUI(); }; // Match - Ignore case m_check_ignore_case.ToolTip(m_tt, "Enable to have the template ignore case when matching"); m_check_ignore_case.Click += (s, a) => { Pattern.IgnoreCase = m_check_ignore_case.Checked; Touched = true; UpdateUI(); }; // Match - compiled regex m_edit_eqv_regex.ToolTip(m_tt, "The regular expression that the Match field is converted into.\r\nVisible here for reference and diagnostic purposes"); // Replace (tooltip set in UpdateUI()) m_edit_replace.TextChanged += (s, a) => { if (!((TextBox)s).Modified) { return; } Pattern.Replace = m_edit_replace.Text; Touched = true; UpdateUI(); }; var subs = new BindingSource { DataSource = Transform.Substitutors.Select(x => new TransSubWrapper(x)), AllowNew = false }; // Substitutions m_grid_subs.VirtualMode = true; m_grid_subs.AutoGenerateColumns = false; m_grid_subs.Columns.Add(new DataGridViewTextBoxColumn { Name = ColumnNames.Tag, HeaderText = "Tag", FillWeight = 11.5f, ReadOnly = true, ToolTipText = "The identifier of the capture group" }); m_grid_subs.Columns.Add(new DataGridViewTextBoxColumn { Name = ColumnNames.Value, HeaderText = "Value", FillWeight = 37.6f, ReadOnly = true, ToolTipText = "The value of the capture group when applied to the current line of text in the text area" }); m_grid_subs.Columns.Add(new DataGridViewComboBoxColumn { Name = ColumnNames.Type, HeaderText = "Transform", FillWeight = 25.8f, DataSource = subs, FlatStyle = FlatStyle.Flat, ToolTipText = "The type of text transform to apply to this capture group" }); m_grid_subs.Columns.Add(new DataGridViewImageColumn { Name = ColumnNames.Cfg, HeaderText = "", FillWeight = 5.0f, ImageLayout = DataGridViewImageCellLayout.Zoom, ToolTipText = "Displays a pencil icon if the text transform can be configured.\r\nClicking will display the configuration dialog" }); m_grid_subs.DataError += (s, a) => {}; //Debug.Assert(false, "Data error in subs grid: {0}".Fmt(a.Exception.MessageFull())); m_grid_subs.CurrentCellDirtyStateChanged += (s, a) => m_grid_subs.CommitEdit(DataGridViewDataErrorContexts.Commit); m_grid_subs.CellValueNeeded += CellValueNeeded; m_grid_subs.CellValuePushed += CellValuePushed; m_grid_subs.CellPainting += CellPainting; m_grid_subs.CellClick += CellClick; m_grid_subs.CellDoubleClick += CellDoubleClick; // Test text m_edit_test.ToolTip(m_tt, "Enter text here on which to test your pattern."); m_edit_test.Text = PatternUI.DefaultTestText; m_edit_test.TextChanged += (s, a) => { UpdateUI(); }; int last_selected_line = -1; m_edit_test.SelectionChanged += (s, a) => { if (MouseButtons != MouseButtons.None || ModifierKeys != Keys.None) { return; } var idx = m_edit_test.GetLineFromCharIndex(m_edit_test.SelectionStart); if (last_selected_line != idx) { last_selected_line = idx; } else { return; } UpdateUI(); }; // Result text m_edit_result.ToolTip(m_tt, "Shows the result of applying the transform to the text in the test area above\r\n" + "Transforms only replace the portion of the input text that they match.\r\n" + "If you are trying to replace the whole line, your pattern needs to match the whole line"); }
/// <summary>Creates a Pattern edit control.</summary> public PatternUI() { InitializeComponent(); Touched = false; // Image list m_il.ImageSize = new Size(28, 28); m_il.ColorDepth = ColorDepth.Depth32Bit; m_il.Images.Add("add", Resources.edit_add); m_il.Images.Add("save", Resources.edit_save); // Pattern // Tool tip set in UpdateUI m_edit_match.TextChanged += (s, a) => { if (!((TextBox)s).Modified) { return; } Pattern.Expr = m_edit_match.Text; Touched = true; UpdateUI(); }; m_edit_match.KeyDown += (s, a) => { a.Handled = a.KeyCode == Keys.Enter; if (a.Handled) { m_btn_add.PerformClick(); } }; // Regex help m_btn_regex_help.ToolTip(m_tt, "Displays a quick help guide for regular expressions"); m_btn_regex_help.Click += (s, a) => { RegexHelpUI.Show(); }; // Add/Update m_btn_add.ToolTip(m_tt, "Adds a new pattern, or updates an existing pattern"); m_btn_add.Click += (s, a) => { if (!CommitEnabled) { return; } RaiseCommitEvent(); }; // Substring m_radio_substring.ToolTip(m_tt, "Match any occurrence of the pattern as a substring"); m_radio_substring.Click += (s, a) => { if (m_radio_substring.Checked) { Pattern.PatnType = EPattern.Substring; } UpdateUI(); }; // Wildcard m_radio_wildcard.ToolTip(m_tt, "Match using wildcards, where '*' matches any number of characters and '?' matches any single character"); m_radio_wildcard.Click += (s, a) => { if (m_radio_wildcard.Checked) { Pattern.PatnType = EPattern.Wildcard; } UpdateUI(); }; // Regex m_radio_regex.ToolTip(m_tt, "Match using a regular expression"); m_radio_regex.Click += (s, a) => { if (m_radio_regex.Checked) { Pattern.PatnType = EPattern.RegularExpression; } UpdateUI(); }; // Ignore case m_check_ignore_case.ToolTip(m_tt, "Enable to have the pattern ignore case when matching"); m_check_ignore_case.CheckedChanged += (s, a) => { Pattern.IgnoreCase = m_check_ignore_case.Checked; Touched = true; UpdateUI(); }; // Whole line m_check_whole_line.ToolTip(m_tt, "If checked, the entire line must match the pattern for it to be considered a match"); m_check_whole_line.CheckedChanged += (s, a) => { Pattern.WholeLine = m_check_whole_line.Checked; Touched = true; UpdateUI(); }; // Invert m_check_invert.ToolTip(m_tt, "Invert the match result. e.g the pattern 'a' matches anything without the letter 'a' when this option is checked"); m_check_invert.CheckedChanged += (s, a) => { Pattern.Invert = m_check_invert.Checked; Touched = true; UpdateUI(); }; // Test text m_edit_test.ToolTip(m_tt, "An area for testing your pattern.\r\nAdd any text you like here"); m_edit_test.Text = DefaultTestText; m_edit_test.TextChanged += (s, a) => { if (!((RichTextBox)s).Modified) { return; } UpdateUI(); }; int last_selected_line = -1; m_edit_test.SelectionChanged += (s, a) => { if (m_edit_test.SelectionLength != 0) { return; } var idx = m_edit_test.GetLineFromCharIndex(m_edit_test.SelectionStart); if (last_selected_line != idx) { last_selected_line = idx; } else { return; } UpdateUI(); }; // Groups m_grid_grps.AutoGenerateColumns = false; m_grid_grps.Columns.Add(new DataGridViewTextBoxColumn { Name = "Tag", HeaderText = "Tag", FillWeight = 1, DataPropertyName = "Key", ToolTipText = "The names of the capture groups identified in the match pattern" }); m_grid_grps.Columns.Add(new DataGridViewTextBoxColumn { Name = "Value", HeaderText = "Value", FillWeight = 2, DataPropertyName = "Value", ToolTipText = "The values of the capture groups based on the test text and the match pattern" }); m_grid_grps.DataError += (s, a) => Debug.Assert(false, $"Data error in groups grid: {a.Exception.MessageFull()}"); }