internal override void format_after(format_cell cell) { if (formatting_ == null && light_color_ == "" && !show_diff_) // nothing to do return; if (cell.col_type != expected_type) return; // only color time column Color col = formatting_ != null ? formatting_.fg : util.transparent; if (col == util.transparent) col = cell.fg_color; var text = cell.format_text.text; if ( formatting_ != null) cell.format_text.add_part(new text_part(0, text.Length, formatting_) ); bool needs_show_diff_now = show_diff_ && cell.row_index != cell.top_row_index; if (needs_show_diff_now) { int offset = util.datetime_difference_offset( prev_text(cell), text); Color lighter_col = light_color_ != "" ? parse_color(light_color_, cell.fg_color) : util.grayer_color(col); var parts = new List<text_part>() { new text_part(0, offset) { fg = lighter_col }, new text_part(offset, text.Length - offset) { fg = col } }; cell.format_text.add_parts( parts); } else cell.format_text.add_part( new text_part(0, text.Length) { fg = col }); }
internal override void format_before_do_replace(format_cell cell) { string text = cell.format_text.text.ToLower(); var exists = name_to_picture_.Keys.FirstOrDefault(x => text.StartsWith(x)); picture_ = exists != null ? name_to_picture_[exists] : null; if ( picture_ != null) cell.format_text.replace_text(0, cell.format_text.text.Length, ""); }
internal override void format_before_do_replace(format_cell cell) { if (find_ == "" || !is_on_) { return; } if (cell.location != format_cell.location_type.view && cell.location != format_cell.location_type.smart_edit) { return; } string txt = cell.format_text.text; txt = Regex.Replace(txt, find_, format_replace_string_, RegexOptions.IgnoreCase); if (txt != cell.format_text.text) { bool needs_formatting = replace_parts_.Count > 1; if (needs_formatting) { var parts = formatted_parts(txt); txt = util.concatenate(parts.Select(x => x.prefix), ""); cell.format_text.replace_text(0, cell.format_text.text.Length, txt); // and now, apply the actual formatting apply_format(cell, parts); } else { // in this case, we don't have any formatting to do cell.format_text.replace_text(0, cell.format_text.text.Length, txt); } } }
internal override void format_before(format_cell cell) { if (cell.col_type != expected_type) return; // only color time column var time = (cell.item as filter.match).line.time; if (format_time_ != "" && time != DateTime.MinValue) cell.format_text.replace_text(0, cell.format_text.text.Length, time.ToString(format_time_)); }
internal override void format_before(format_cell cell) { var text = cell.format_text.text; if (formatting_ != null && formatting_.bg != util.transparent) { cell.format_text.bg = formatting_.bg; } }
internal override void format_after(format_cell cell) { if (row_count_ < 1) return; int per_row = cell.row_index / row_count_; if (per_row % 2 == 1) { Color dark = parse_color(alternate_color_, cell.bg_color); cell.format_text.bg = dark; } }
private string prev_text(format_cell cell) { string prev = cell.prev_text; if (cell.row_index > 0 && format_time_ != "") { var prev_item = cell.parent.item_at(cell.row_index - 1); var time = (prev_item as filter.match).line.time; if (time != DateTime.MinValue) prev = time.ToString(format_time_); } return prev; }
internal override void format_after(format_cell cell) { if (expr_ == "" || regex_ == null) return; var text = cell.format_text.text; Color col = parse_color(color_, cell.fg_color); var found = util.regex_matches(regex_, text).OrderBy(x => x.Item1).ToList(); // see if i need to replace with written in another base cell.format_text.add_parts( found.Select(x => new text_part(x.Item1, x.Item2) { fg = col }).ToList()); }
internal override void format_before_do_replace(format_cell cell) { string text = cell.format_text.text.ToLower(); var exists = name_to_picture_.Keys.FirstOrDefault(x => text.StartsWith(x)); picture_ = exists != null ? name_to_picture_[exists] : null; if (picture_ != null) { cell.format_text.replace_text(0, cell.format_text.text.Length, ""); } }
internal override void format_before(format_cell cell) { if (cell.col_type != expected_type) { return; // only color time column } var time = (cell.item as filter.match).line.time; if (format_time_ != "" && time != DateTime.MinValue) { cell.format_text.replace_text(0, cell.format_text.text.Length, time.ToString(format_time_)); } }
internal override void format_after(format_cell cell) { var text = cell.format_text.text; if ( formatting_ != null) cell.format_text.add_part(new text_part(0, text.Length, formatting_) ); bool is_sel = cell.row_index == cell.sel_index; if (is_sel && cell.is_bookmark && selection_and_bookmark_image_ != null) cell.format_text.image = selection_and_bookmark_image_; else if ( is_sel && selection_image_ != null) cell.format_text.image = selection_image_; else if (cell.is_bookmark && bookmark_image_ != null) cell.format_text.image = bookmark_image_; }
internal override void format_after(format_cell cell) { if (formatting_ == null && light_color_ == "" && !show_diff_) { // nothing to do return; } if (cell.col_type != expected_type) { return; // only color time column } Color col = formatting_ != null ? formatting_.fg : util.transparent; if (col == util.transparent) { col = cell.fg_color; } var text = cell.format_text.text; if (formatting_ != null) { cell.format_text.add_part(new text_part(0, text.Length, formatting_)); } bool needs_show_diff_now = show_diff_ && cell.row_index != cell.top_row_index; if (needs_show_diff_now) { int offset = util.datetime_difference_offset(prev_text(cell), text); Color lighter_col = light_color_ != "" ? parse_color(light_color_, cell.fg_color) : util.grayer_color(col); var parts = new List <text_part>() { new text_part(0, offset) { fg = lighter_col }, new text_part(offset, text.Length - offset) { fg = col } }; cell.format_text.add_parts(parts); } else { cell.format_text.add_part(new text_part(0, text.Length) { fg = col }); } }
internal override void format_after(format_cell cell) { if (row_count_ < 1) { return; } int per_row = cell.row_index / row_count_; if (per_row % 2 == 1) { Color dark = parse_color(alternate_color_, cell.bg_color); cell.format_text.bg = dark; } }
private string prev_text(format_cell cell) { string prev = cell.prev_text; if (cell.row_index > 0 && format_time_ != "") { var prev_item = cell.parent.item_at(cell.row_index - 1); var time = (prev_item as filter.match).line.time; if (time != DateTime.MinValue) { prev = time.ToString(format_time_); } } return(prev); }
private void apply_format(format_cell cell, List <format_part> format) { int cur_idx = 0; var apply_parts = new List <text_part>(); foreach (var part in format) { cur_idx += part.prefix.Length; if (part.format != null) { apply_parts.Add(new text_part(cur_idx, part.len, part.format)); } } cell.format_text.add_parts(apply_parts); }
internal override void format_after(format_cell cell) { if (expr_ == "" || regex_ == null) { return; } var text = cell.format_text.text; Color col = parse_color(color_, cell.fg_color); var found = util.regex_matches(regex_, text).OrderBy(x => x.Item1).ToList(); // see if i need to replace with written in another base cell.format_text.add_parts(found.Select(x => new text_part(x.Item1, x.Item2) { fg = col }).ToList()); }
private bool already_formatted(format_cell cell, int start, int len) { var text = cell.format_text.text; for (int idx = start; idx < start + len; ++idx) { var part = cell.format_text.part_at_index(idx); if (part != null) { // in this case, we consider "formatted" only if the part found is less than then whole text if (part.len < text.Length) { return(true); } } } return(false); }
internal override void get_tooltip(format_cell cell, int char_index, ref string tooltip) { if (!is_cell_type_ok(cell.col_type)) { return; } var text = cell.format_text.text; if (text == "") { return; } int start = char_index, end = char_index; while (start >= 0 && is_number_char(text[start])) { --start; } if (start < 0) { start = 0; } if (!is_number_char(text[start])) { ++start; } while (end < text.Length && is_number_char(text[end])) { ++end; } if (end > start) { string number = text.Substring(start, end - start); try { long n = to_number(number); tooltip = String.Format("D {0}\r\nH {1}\r\nO {2}\r\nB {3}", Convert.ToString(n, 10), Convert.ToString(n, 16), Convert.ToString(n, 8), Convert.ToString(n, 2)); } catch { // invalid number } } }
internal override void format_before_do_replace(format_cell cell) { // see if on view if (cell.location != format_cell.location_type.view) return; if (!show_multi_into_single_line_) return; // ... make sure we catch all lines var lines = cell.format_text.text.Replace("\r\n", "\r").Replace("\n", "\r").Split(new[] {"\r"}, StringSplitOptions.None); if (lines.Length <= 1) return; // single line var new_text = util.concatenate(lines, separator_); cell.format_text.replace_text(0, cell.format_text.text.Length, new_text); if (alternate_format_ != null || separator_format_ != null) { if ( alternate_format_ != null) alternate_format_.update_colors(cell); if ( separator_format_ != null) separator_format_.update_colors(cell); int cur_idx = 0; var line_indexes = new List<int>(); foreach (var line in lines) { line_indexes.Add(cur_idx); cur_idx += line.Length + separator_.Length; } List<text_part> parts = new List<text_part>(); for (int i = 0; i < line_indexes.Count; i++) { bool even = i % 2 == 0; if ( separator_format_ != null && i < line_indexes.Count - 1) parts.Add( new text_part(line_indexes[i] + lines[i].Length, separator_.Length, separator_format_) ); if (!even) { // odd - show in alternate if ( alternate_format_ != null) parts.Add( new text_part( line_indexes[i], lines[i].Length, alternate_format_)); } } cell.format_text.add_parts(parts); } }
internal override void format_before_do_replace(format_cell cell) { if (find_ == "" || !is_on_) return; if (cell.location != format_cell.location_type.view && cell.location != format_cell.location_type.smart_edit) return; string txt = cell.format_text.text; txt = Regex.Replace(txt, find_, format_replace_string_, RegexOptions.IgnoreCase); if (txt != cell.format_text.text) { bool needs_formatting = replace_parts_.Count > 1; if ( needs_formatting) { var parts = formatted_parts(txt); txt = util.concatenate(parts.Select(x => x.prefix), ""); cell.format_text.replace_text(0, cell.format_text.text.Length, txt); // and now, apply the actual formatting apply_format(cell, parts); } else // in this case, we don't have any formatting to do cell.format_text.replace_text(0, cell.format_text.text.Length, txt); } }
internal override void format_after(format_cell cell) { var text = cell.format_text.text; if (formatting_ != null) { cell.format_text.add_part(new text_part(0, text.Length, formatting_)); } bool is_sel = cell.row_index == cell.sel_index; if (is_sel && cell.is_bookmark && selection_and_bookmark_image_ != null) { cell.format_text.image = selection_and_bookmark_image_; } else if (is_sel && selection_image_ != null) { cell.format_text.image = selection_image_; } else if (cell.is_bookmark && bookmark_image_ != null) { cell.format_text.image = bookmark_image_; } }
internal override void format_after(format_cell cell) { if (compare_.Count < 1) { return; // nothing to compare } var text = cell.format_text.text; int before_idx = before_ != "" ? text.IndexOf(before_) : 0; if (before_idx >= 0) { before_idx += before_.Length; int after_idx = after_ != "" ? text.IndexOf(after_, before_idx) : text.Length; if (after_idx >= 0) { var number = text.Substring(before_idx, after_idx - before_idx).Trim(); double val; if (double.TryParse(number, out val)) { // found the number - at this point, do all comparisons text_part format_number = new text_part(0, 0); foreach (var comp in compare_) { bool equal = false, less = false, greater = false; try { if (is_int_) { equal = (long)val == comp.compare_int; less = (long)val < comp.compare_int; greater = (long)val > comp.compare_int; } else { equal = val == comp.compare_double; less = val < comp.compare_double; greater = val > comp.compare_double; } } catch { // this can happen only if number is longer than 'long' equal = less = greater = false; } if (equal && comp.equal != null) { format_number = format_number.merge_copy(comp.equal); } else if (less && comp.less != null) { format_number = format_number.merge_copy(comp.less); } else if (greater && comp.greater != null) { format_number = format_number.merge_copy(comp.greater); } } cell.format_text.add_part(new text_part(before_idx, after_idx - before_idx, format_number)); } } } }
internal override void format_before(format_cell cell) { var text = cell.format_text.text; if (formatting_ != null && formatting_.bg != util.transparent) cell.format_text.bg = formatting_.bg; }
internal override void format_before(format_cell cell) { if (!is_cell_type_ok(cell.col_type)) { return; } if (color_ == "" && number_base == 10 && pad_ == "" && !look_for_hex_) { // we don't need to do anything return; } // if number too big, don't do anything // also, doubles -> don't care about base var text = cell.format_text.text; Color col = parse_color(color_, cell.fg_color); if (look_for_hex_) { // ... note: we don't want the delimeters included var hex_numbers = util.regex_matches(regex_hex_, text).Where( // note: if the number is already formatted in some way, don't format it again x => double_check_is_hex(text.Substring(x.Item1, x.Item2)) && !already_formatted(cell, x.Item1, x.Item2)) .ToList(); cell.format_text.add_parts(hex_numbers.Select(x => new text_part(x.Item1, x.Item2) { fg = col }).ToList()); } /* IMPORTANT: we have the following assumption: the hexa numbers NEVER interfere with the decimal numbers. * * Here's the rationale: the decimal numbers can be transformed, while the hex numbers will NEVER be transformed. In other words, we can transform * something like "Number 255 is awesome." into "Number FF is awesome". Thus, we're replacing sub-text in a a text that also has formatting. * * Normally, that should work ok (formatted_text.replace_text), but if texts got to be imbricated one another, things could get ugly * */ var dec_numbers = util.regex_matches(regex_decimal_, text) // note: if the number is already formatted in some way, don't format it again .Where(x => !already_formatted(cell, x.Item1, x.Item2)).OrderBy(x => x.Item1).ToList(); // see if i need to replace with written in another base cell.format_text.add_parts(dec_numbers.Select(x => new text_part(x.Item1, x.Item2) { fg = col }).ToList()); int start_offset = 0; foreach (var cur_number_offset in dec_numbers) { int start = cur_number_offset.Item1 + start_offset, len = cur_number_offset.Item2; var new_number = convert_number(cell.format_text.text.Substring(start, len)); if (new_number != "") { cell.format_text.replace_text(start, len, new_number); int diff = new_number.Length - len; start_offset += diff; } } }
internal override void format_before(format_cell cell) { }
internal override void format_before_do_replace(format_cell cell) { // see if on view if (cell.location != format_cell.location_type.view) { return; } if (!show_multi_into_single_line_) { return; } // ... make sure we catch all lines var lines = cell.format_text.text.Replace("\r\n", "\r").Replace("\n", "\r").Split(new[] { "\r" }, StringSplitOptions.None); if (lines.Length <= 1) { return; // single line } var new_text = util.concatenate(lines, separator_); cell.format_text.replace_text(0, cell.format_text.text.Length, new_text); if (alternate_format_ != null || separator_format_ != null) { if (alternate_format_ != null) { alternate_format_.update_colors(cell); } if (separator_format_ != null) { separator_format_.update_colors(cell); } int cur_idx = 0; var line_indexes = new List <int>(); foreach (var line in lines) { line_indexes.Add(cur_idx); cur_idx += line.Length + separator_.Length; } List <text_part> parts = new List <text_part>(); for (int i = 0; i < line_indexes.Count; i++) { bool even = i % 2 == 0; if (separator_format_ != null && i < line_indexes.Count - 1) { parts.Add(new text_part(line_indexes[i] + lines[i].Length, separator_.Length, separator_format_)); } if (!even) { // odd - show in alternate if (alternate_format_ != null) { parts.Add(new text_part(line_indexes[i], lines[i].Length, alternate_format_)); } } } cell.format_text.add_parts(parts); } }
internal override void get_tooltip(format_cell cell, int char_index, ref string tooltip) { foreach ( var formatter in sub_) formatter.get_tooltip(cell, char_index, ref tooltip); }
internal override void format_before(format_cell cell) { if (!is_cell_type_ok(cell.col_type)) return; if (color_ == "" && number_base == 10 && pad_ == "" && !look_for_hex_) // we don't need to do anything return; // if number too big, don't do anything // also, doubles -> don't care about base var text = cell.format_text.text; Color col = parse_color(color_, cell.fg_color); if (look_for_hex_) { // ... note: we don't want the delimeters included var hex_numbers = util.regex_matches(regex_hex_, text).Where( // note: if the number is already formatted in some way, don't format it again x => double_check_is_hex(text.Substring(x.Item1, x.Item2)) && !already_formatted(cell, x.Item1, x.Item2) ) .ToList(); cell.format_text.add_parts(hex_numbers.Select(x => new text_part(x.Item1, x.Item2) {fg = col}).ToList()); } /* IMPORTANT: we have the following assumption: the hexa numbers NEVER interfere with the decimal numbers. Here's the rationale: the decimal numbers can be transformed, while the hex numbers will NEVER be transformed. In other words, we can transform something like "Number 255 is awesome." into "Number FF is awesome". Thus, we're replacing sub-text in a a text that also has formatting. Normally, that should work ok (formatted_text.replace_text), but if texts got to be imbricated one another, things could get ugly */ var dec_numbers = util.regex_matches(regex_decimal_, text) // note: if the number is already formatted in some way, don't format it again .Where(x => !already_formatted(cell, x.Item1, x.Item2)) .OrderBy(x => x.Item1).ToList(); // see if i need to replace with written in another base cell.format_text.add_parts(dec_numbers.Select(x => new text_part(x.Item1, x.Item2) {fg = col}).ToList()); int start_offset = 0; foreach (var cur_number_offset in dec_numbers) { int start = cur_number_offset.Item1 + start_offset, len = cur_number_offset.Item2; var new_number = convert_number(cell.format_text.text.Substring(start, len)); if (new_number != "") { cell.format_text.replace_text(start, len, new_number); int diff = new_number.Length - len; start_offset += diff; } } }
internal override void format_before_do_replace(format_cell cell) { foreach ( var formatter in sub_) formatter.format_before_do_replace(cell); }
internal virtual void format_after(format_cell cell) { }
private void apply_format(format_cell cell, List<format_part> format) { int cur_idx = 0; var apply_parts = new List<text_part>(); foreach (var part in format) { cur_idx += part.prefix.Length; if ( part.format != null) apply_parts.Add( new text_part(cur_idx, part.len, part.format)); } cell.format_text.add_parts(apply_parts); }
internal virtual void format_before(format_cell cell) { }
internal override void get_tooltip(format_cell cell, int char_index, ref string tooltip) { if (!is_cell_type_ok(cell.col_type)) return; var text = cell.format_text.text; if (text == "") return; int start = char_index, end = char_index; while (start >= 0 && is_number_char(text[start])) --start; if (start < 0) start = 0; if (!is_number_char(text[start])) ++start; while (end < text.Length && is_number_char(text[end])) ++end; if (end > start) { string number = text.Substring(start, end - start); try { long n = to_number(number); tooltip = String.Format("D {0}\r\nH {1}\r\nO {2}\r\nB {3}", Convert.ToString(n, 10), Convert.ToString(n, 16), Convert.ToString(n, 8), Convert.ToString(n, 2)); } catch { // invalid number } } }
internal override void format_after(format_cell cell) { foreach ( var formatter in sub_) formatter.format_after(cell); }
private bool already_formatted(format_cell cell, int start, int len) { var text = cell.format_text.text; for (int idx = start; idx < start + len; ++idx) { var part = cell.format_text.part_at_index(idx); if ( part != null) // in this case, we consider "formatted" only if the part found is less than then whole text if (part.len < text.Length) return true; } return false; }
internal override void format_after(format_cell cell) { if (compare_.Count < 1) return; // nothing to compare var text = cell.format_text.text; int before_idx = before_ != "" ? text.IndexOf(before_) : 0; if (before_idx >= 0) { before_idx += before_.Length; int after_idx = after_ != "" ? text.IndexOf(after_, before_idx) : text.Length; if (after_idx >= 0) { var number = text.Substring(before_idx, after_idx - before_idx).Trim(); double val; if (double.TryParse(number, out val)) { // found the number - at this point, do all comparisons text_part format_number = new text_part(0,0); foreach (var comp in compare_) { bool equal = false, less = false, greater = false; try { if (is_int_) { equal = (long) val == comp.compare_int; less = (long) val < comp.compare_int; greater = (long) val > comp.compare_int; } else { equal = val == comp.compare_double; less = val < comp.compare_double; greater = val > comp.compare_double; } } catch { // this can happen only if number is longer than 'long' equal = less = greater = false; } if (equal && comp.equal != null) format_number = format_number.merge_copy(comp.equal); else if (less && comp.less != null) format_number = format_number.merge_copy(comp.less); else if (greater && comp.greater != null) format_number = format_number.merge_copy(comp.greater); } cell.format_text.add_part( new text_part(before_idx, after_idx - before_idx, format_number)); } } } }
internal virtual void get_tooltip(format_cell cell, int char_index, ref string tooltip) { }
internal override void format_after(format_cell cell) { }
/* You should override this is you're replacing large parts of the text. The idea is to do this first, * because replacing large text (thtat internally contains formatted parts) can go wrong. Namely, the formatted parts might point to the wrong location. * * Example: * say I'm replacig "I have 23 lines of awesome text." with "I have plenty of awesome text". * Say the "23" part is formatted to show in red. What shall I do with this part in the replaced text? * I would end up showing "pl" characters in red - which makes no sense. */ internal virtual void format_before_do_replace(format_cell cell) { }
/* You should override this is you're replacing large parts of the text. The idea is to do this first, because replacing large text (thtat internally contains formatted parts) can go wrong. Namely, the formatted parts might point to the wrong location. Example: say I'm replacig "I have 23 lines of awesome text." with "I have plenty of awesome text". Say the "23" part is formatted to show in red. What shall I do with this part in the replaced text? I would end up showing "pl" characters in red - which makes no sense. */ internal virtual void format_before_do_replace(format_cell cell) { }