// note: it's possible to create a valid formatter, and have an error. Like, when the syntax is partially right // In that case, I will just use what is valid private static column_formatter_base create_formatter(string name, string syntax, ref string error) { error = ""; column_formatter_base result = null; switch (name) { case "cell": result = new cell(); break; case "format": result = new column_formatters.format(); break; case "picture": result = new picture(); break; case "stack_trace": case "stack-trace": result = new stack_trace(); break; case "xml": result = new xml(); break; default: error = "Invalid formatter name: " + name; break; } // load_syntax if (result != null) { try { result.load_syntax(new settings_as_string(syntax), ref error); } catch (Exception e) { logger.Error("can't load formatter " + e.Message); error = "Cannot load " + name + ". Invalid syntax"; } } return(result); }
public formatted_text_cache(log_view parent, column_formatter_base.format_cell.location_type location) { parent_ = parent; location_ = location; }
public void update_colors(column_formatter_base.format_cell cell) { if (modify_fg != modify_color_type.same) fg = modify_fg == modify_color_type.darker ? util.darker_color(cell.fg_color) : util.grayer_color(cell.fg_color); if (modify_bg != modify_color_type.same) bg = modify_bg == modify_color_type.darker ? util.darker_color(cell.bg_color) : util.grayer_color(cell.bg_color); }
// returns the overrides, sorted by index in the string to print public column_formatter_base.format_cell override_print(log_view parent, string text, int col_idx, column_formatter_base.format_cell.location_type location) { int row_idx = parent.item_index(this); int top_row_idx = parent.top_row_idx; string prev_text = ""; if (row_idx > 0) prev_text = log_view_cell.cell_value(parent.item_at(row_idx - 1), col_idx); int sel_index = parent.sel_row_idx_ui_thread; bool is_bokmark = parent.has_bookmark(line_idx); var cell = new column_formatter_base.format_cell(this, parent, col_idx, log_view_cell.cell_idx_to_type(col_idx), new formatted_text(text), row_idx, top_row_idx, sel_index, is_bokmark, prev_text, location); parent.formatter.format_before(cell); var print = override_print_from_all_places(parent, cell.format_text.text, col_idx); cell.format_text.add_parts( print); parent.formatter.format_after(cell); return cell; }
// IMPORTANT: here, when doing preview, we don't show any results from find/find-as-you-type/running filters private formatted_text override_print(match_item i, string text, int col_idx, column_formatter_base.format_cell.location_type location) { int row_idx = list_.IndexOf(i); Debug.Assert(row_idx >= 0); int top_row_idx = top_idx(); string prev_text = ""; if (row_idx > 0) prev_text = log_view_cell.cell_value( list_.GetItem(row_idx - 1).RowObject as match_item , col_idx); int sel_index = parent_.sel_row_idx_ui_thread; bool is_bokmark = parent_.has_bookmark(i.line_idx); var cell = new column_formatter_base.format_cell(i, parent_, col_idx, log_view_cell.cell_idx_to_type(col_idx), new formatted_text(text), row_idx, top_row_idx, sel_index, is_bokmark, prev_text, location); formatter_.format_before(cell); formatter_.format_after(cell); return cell.format_text; }
internal string get_tooltip(column_formatter_base.format_cell cell, int char_index) { string tooltip = ""; foreach ( var format in formatters_) if (needs_apply_formatter(format, cell)) format.the_formatter.get_tooltip(cell, char_index, ref tooltip); return tooltip; }
internal void format_after(column_formatter_base.format_cell cell) { // each formatter is called once "before" the filters // then, it's called again "after" the filters // // this way, I can modify the text before (when dealing with numbers and such) foreach ( var format in formatters_) if (needs_apply_formatter(format, cell)) { format.the_formatter.format_after(cell); switch (format.the_formatter.align) { case column_formatter_base.align_type.left: cell.format_text.align = HorizontalAlignment.Left; break; case column_formatter_base.align_type.center: cell.format_text.align = HorizontalAlignment.Center; break; case column_formatter_base.align_type.right: cell.format_text.align = HorizontalAlignment.Right; break; case column_formatter_base.align_type.none: break; default: Debug.Assert(false); break; } } foreach ( var format in formatters_) if (needs_apply_formatter(format, cell)) if (format.the_formatter.get_image() != null) { cell.format_text.image = format.the_formatter.get_image(); break; } cell.format_text.update_parts(); }
internal void format_before(column_formatter_base.format_cell cell) { // each formatter is called once "before" the filters // then, it's called again "after" the filters // // this way, I can modify the text before (when dealing with numbers and such) foreach ( var format in formatters_) if ( needs_apply_formatter(format, cell)) format.the_formatter.format_before_do_replace(cell); foreach ( var format in formatters_) if ( needs_apply_formatter(format, cell)) format.the_formatter.format_before(cell); }
private bool needs_apply_formatter(formatter format, column_formatter_base.format_cell cell) { if (format.column_type == "all") return true; var aliases = cell.parent.filter.log.aliases; var cell_type = aliases.to_info_type(format.column_type); if (cell_type != info_type.max) return cell.col_type == cell_type; // in this case, we don't know what column the formater is to be applied to return false; }