private void next_parse_mark(OutputGroup og) { string path = og.GetPath(); for (int i = current_capture_label_index + 1; i < CaptureLabels.Count; i++) { CaptureLabel cl = CaptureLabels[i]; if (cl.level == og.Level && cl.get_path() == path ) { if (current_capture_label_index >= 0 && current_capture_label_index < CaptureLabels.Count) { unmark_capture_branch(CaptureLabels[current_capture_label_index]); } mark_capture_branch(cl, og, path); current_capture_label_index = i; break; } } if (current_capture_label_index >= 0 && current_capture_label_index < CaptureLabels.Count) { NextMark.Enabled = CaptureLabels[current_capture_label_index].index_in_path < current_path_capture_count - 1; PrevMark.Enabled = CaptureLabels[current_capture_label_index].index_in_path > 0; } }
void mark_capture_branch(CaptureLabel cl, OutputGroup og, string path) { List <CaptureLabel> cls = new List <CaptureLabel>(); for (CaptureLabel c = cl; c != null; c = c.parent) { cls.Add(c); } int total_label_length = 0; for (int i = cls.Count - 1; i >= 0; i--) { CaptureLabel c = cls[i]; if (!c.visible) { continue; } c.start3 = c.start2 + total_label_length; c.end3 = c.end2 + total_label_length + c.label.Length; if (Settings.Default.PrintCaptureLabels) { print_capture_label(c); total_label_length += c.label.Length; } highlight_capture(c); } ignore_selection_changed = false; TextBox.Select(cl.start3, 0); }
/// <summary> /// selects the complete captured group within the parsed text box by double click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TextBox_DoubleClick(object sender, EventArgs e) { if (CaptureLabels == null) { return; } if (current_capture_label_index < 0 || current_capture_label_index >= CaptureLabels.Count) { SetStatus(""); return; } CaptureLabel owner_cl = null; int start = TextBox.SelectionStart; for (CaptureLabel c = CaptureLabels[current_capture_label_index]; c != null; c = c.parent) { if (!c.visible) { continue; } if (start >= c.start3 && (owner_cl == null || c.level > owner_cl.level)) { owner_cl = c; } } if (owner_cl == null) { return; } TextBox.SelectionStart = owner_cl.start3; TextBox.SelectionLength = owner_cl.end3 - owner_cl.start3; }
void highlight_capture(CaptureLabel cl) { Invoke(() => { TextBox.Select(cl.start3, cl.end3 - cl.start3); TextBox.SelectionBackColor = Settings.Default.GetFilterBackColor(cl.level); }); }
/// <summary> /// return standard path used for comparison /// </summary> /// <returns></returns> internal string get_path() { List <string> path = new List <string>(); for (CaptureLabel cl = this; cl != null; cl = cl.parent) { path.Insert(0, cl.group_name); } return(string.Join("/", path.ToArray())); }
internal void print_capture_label(CaptureLabel cl) { Invoke(() => { TextBox.Select(cl.start3, 0); TextBox.SelectedText = cl.label; TextBox.Select(cl.start3, cl.label.Length); TextBox.SelectionBackColor = Settings.Default.GetFilterBackColor(cl.level); TextBox.SelectionColor = cl.fgcolor; TextBox.SelectionFont = Settings.Default.CaptureLabelFont; }); }
internal CaptureLabel(int start, int length, int start2, int length2, int level, int match_id, int group_id, string group_name, CaptureLabel parent, bool visible, int index_in_path) { this.start = start; this.end = start + length; this.start2 = start2; this.end2 = start2 + length2; //this.start3 = this.start2; //this.end3 = this.end2; this.level = level; this.match_id = match_id; this.group_id = group_id; this.group_name = group_name; this.parent = parent; this.visible = visible; this.index_in_path = index_in_path; label = "[" + match_id.ToString() + "$" + group_id.ToString() + "]"; }
void unmark_capture_branch(CaptureLabel cl) { CaptureLabel scl = cl; for (CaptureLabel c = cl; c != null; c = c.parent) { TextBox.Select(c.start3, c.label.Length); TextBox.ReadOnly = false;//it is to avoid a bug in richtextbox. Morons from microsoft know about it since 2005 and still have not fixed it! TextBox.SelectedText = ""; TextBox.ReadOnly = true; scl = c; c.start3 = -1; c.end3 = -1; } //TextBox.SelectAll(); //TextBox.SelectionBackColor = Color.White; TextBox.Select(scl.start2, scl.end2 - scl.start2); TextBox.SelectionBackColor = Color.White; TextBox.Select(scl.start2, 0); }
internal CaptureLabel AddCaptureLabel( int start, int length, int level, int group_id, string group_name, int group_count ) { int start2 = start; int length2 = length; SourceForm.This.shift_on_positions_ignored_by_rich_text_box(ref start2, ref length2); //set parent CaptureLabel parent = null; if (level > 0) { int end2 = start2 + length2; for (int i = CaptureLabels.Count - 1; i >= 0; i--) { CaptureLabel c = CaptureLabels[i]; if (c.start2 <= start2 && c.end2 >= end2 && c.level == level - 1) { parent = c; break; } } } //set match_id int match_id = -1; if (CaptureLabels.Count > 0) { if (level - 1 == CaptureLabels[CaptureLabels.Count - 1].level) match_id = 0; else if (level == CaptureLabels[CaptureLabels.Count - 1].level && group_id - 1 == CaptureLabels[CaptureLabels.Count - 1].group_id ) match_id = CaptureLabels[CaptureLabels.Count - 1].match_id; else { for (int i = CaptureLabels.Count - 1; i >= 0; i--) { CaptureLabel c = CaptureLabels[i]; if (level == c.level && group_id == c.group_id) { match_id = c.match_id + 1; break; } } } } else match_id = 0; //index_in_path int index_in_path = 0; for (int i = CaptureLabels.Count - 1; i >= 0; i--) { CaptureLabel c = CaptureLabels[i]; if (c.level == level && c.group_id == group_id) { index_in_path = c.index_in_path + 1; break; } } CaptureLabel cl = new CaptureLabel(start, length, start2, length2, level, match_id, group_id, group_name, parent, true, index_in_path); SourceForm.This.CaptureLabels.Add(cl); return cl; }
void highlight_capture(CaptureLabel cl) { ControlRoutines.Invoke(this, () => { TextBox.Select(cl.start3, cl.end3 - cl.start3); TextBox.SelectionBackColor = Settings.Default.GetFilterBackColor(cl.level); }); }
internal void print_capture_label(CaptureLabel cl) { ControlRoutines.Invoke(this, () => { TextBox.Select(cl.start3, 0); TextBox.SelectedText = cl.label; TextBox.Select(cl.start3, cl.label.Length); TextBox.SelectionBackColor = Settings.Default.GetFilterBackColor(cl.level); TextBox.SelectionColor = cl.fgcolor; TextBox.SelectionFont = Settings.Default.CaptureLabelFont; }); }
/// <summary> /// Sets status bar text along the current cursor position in the parsed text box. /// Finds the selected capture, determines its filter tree path and constructs from them status text. /// </summary> /// <param name="start"></param> /// <param name="length"></param> void set_status_by_position(int start, int length) { if (CaptureLabels == null) { return; } if (current_capture_label_index < 0 || current_capture_label_index >= CaptureLabels.Count) { SetStatus(""); return; } int end = start + length; CaptureLabel owner_cl = null; for (CaptureLabel c = CaptureLabels[current_capture_label_index]; c != null; c = c.parent) { if (!c.visible) { continue; } if (start >= c.start3 && end <= c.end && (owner_cl == null || c.level > owner_cl.level)) { owner_cl = c; } } if (owner_cl == null) { SetStatus(""); return; } string path = null; for (CaptureLabel l = owner_cl; l != null; l = l.parent) { string name; int r; if (int.TryParse(l.group_name, out r)) { name = "$" + l.group_name; } else { name = l.group_name; } path = "/" + name + "[" + l.match_id.ToString() + "]" + path; } string text = Document.Text.Substring(owner_cl.start, owner_cl.end - owner_cl.start); if (tr != null) { tr.Abort(); } tr = new ThreadRunner(10000, this, "Stripping text of the selected capture is not completed still. Break it?"); text = (string)tr.Run(this, "set_status_by_position_2", text); SetStatus(path.Substring(1) + " - \"" + text + "\""); }
internal CaptureLabel AddCaptureLabel( int start, int length, int level, int group_id, string group_name, int group_count ) { int start2 = start; int length2 = length; SourceForm.This.shift_on_positions_ignored_by_rich_text_box(ref start2, ref length2); //set parent CaptureLabel parent = null; if (level > 0) { int end2 = start2 + length2; for (int i = CaptureLabels.Count - 1; i >= 0; i--) { CaptureLabel c = CaptureLabels[i]; if (c.start2 <= start2 && c.end2 >= end2 && c.level == level - 1) { parent = c; break; } } } //set match_id int match_id = -1; if (CaptureLabels.Count > 0) { if (level - 1 == CaptureLabels[CaptureLabels.Count - 1].level) { match_id = 0; } else if (level == CaptureLabels[CaptureLabels.Count - 1].level && group_id - 1 == CaptureLabels[CaptureLabels.Count - 1].group_id ) { match_id = CaptureLabels[CaptureLabels.Count - 1].match_id; } else { for (int i = CaptureLabels.Count - 1; i >= 0; i--) { CaptureLabel c = CaptureLabels[i]; if (level == c.level && group_id == c.group_id) { match_id = c.match_id + 1; break; } } } } else { match_id = 0; } //index_in_path int index_in_path = 0; for (int i = CaptureLabels.Count - 1; i >= 0; i--) { CaptureLabel c = CaptureLabels[i]; if (c.level == level && c.group_id == group_id) { index_in_path = c.index_in_path + 1; break; } } CaptureLabel cl = new CaptureLabel(start, length, start2, length2, level, match_id, group_id, group_name, parent, true, index_in_path); SourceForm.This.CaptureLabels.Add(cl); return(cl); }