diff --git a/modules/text_editor/text_editor_preview.cpp b/modules/text_editor/text_editor_preview.cpp index 74697a995..de98e1755 100644 --- a/modules/text_editor/text_editor_preview.cpp +++ b/modules/text_editor/text_editor_preview.cpp @@ -4,6 +4,7 @@ #include "core/variant.h" #include "scene/gui/box_container.h" #include "scene/gui/grid_container.h" +#include "scene/gui/label.h" #include "scene/gui/rich_text_label.h" #include "modules/regex/regex.h" @@ -194,23 +195,30 @@ void TextEditorPreview::print_html(const String &p_content) { } void TextEditorPreview::print_csv(const Array &rows) { - //TODO - /* - table_preview->set_columns(rows[0].size()); + if (rows.size() == 0) { + return; + } - for (item in rows) { - for (string in item) { - Label *label = memnew(Label); - label->set_text(str(string)); - label->set_h_size_flags(SIZE_EXPAND); - label->set_align(1); - label->set_valign(1); - table_preview->add_child(label); - } - } + Vector r0 = rows[0]; - table_preview->show(); - */ + table_preview->set_columns(r0.size()); + + for (int i = 0; i < rows.size(); ++i) { + Vector item = rows[i]; + + for (int j = 0; j < item.size(); ++j) { + String string = item[j]; + + Label *label = memnew(Label); + label->set_text(string); + label->set_h_size_flags(SIZE_EXPAND); + label->set_align(Label::ALIGN_CENTER); + label->set_valign(Label::VALIGN_CENTER); + table_preview->add_child(label); + } + } + + table_preview->show(); } void TextEditorPreview::_on_TextEditorPreview_popup_hide() { diff --git a/modules/text_editor/text_file_editor.cpp b/modules/text_editor/text_file_editor.cpp index e82970998..931a4c3c5 100644 --- a/modules/text_editor/text_file_editor.cpp +++ b/modules/text_editor/text_file_editor.cpp @@ -409,9 +409,9 @@ void TextFileEditor::csv_preview() { preview->popup(); preview->set_title(" (" + current_file_path.get_file() + ")"); int lines = current_editor->text_editor->get_line_count(); - Array rows = Array(); + Array rows; - for (int i = 0; i < lines - 1; ++i) { //i in range(0, lines-1) + for (int i = 0; i < lines; ++i) { //i in range(0, lines-1) rows.append(current_editor->text_editor->get_line(i).rsplit(",", false)); }