diff options
Diffstat (limited to 'editor/script_editor_debugger.cpp')
-rw-r--r-- | editor/script_editor_debugger.cpp | 320 |
1 files changed, 190 insertions, 130 deletions
diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index 9db53fe5f5..2d4af6c63d 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -30,11 +30,13 @@ #include "script_editor_debugger.h" +#include "core/io/marshalls.h" +#include "core/project_settings.h" +#include "core/ustring.h" #include "editor_node.h" #include "editor_profiler.h" #include "editor_settings.h" #include "main/performance.h" -#include "project_settings.h" #include "property_editor.h" #include "scene/gui/dialogs.h" #include "scene/gui/label.h" @@ -47,7 +49,6 @@ #include "scene/gui/texture_button.h" #include "scene/gui/tree.h" #include "scene/resources/packed_scene.h" -#include "ustring.h" class ScriptEditorDebuggerVariables : public Object { @@ -396,7 +397,6 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da dobreak->set_disabled(false); docontinue->set_disabled(true); emit_signal("breaked", false, false, Variant()); - //tabs->set_current_tab(0); profiler->set_enabled(true); profiler->disable_seeking(); inspector->edit(NULL); @@ -429,8 +429,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da ObjectID id = ObjectID(p_data[i + 3]); it->set_text(0, p_data[i + 1]); - if (has_icon(p_data[i + 2], "EditorIcons")) - it->set_icon(0, get_icon(p_data[i + 2], "EditorIcons")); + Ref<Texture> icon = EditorNode::get_singleton()->get_class_icon(p_data[i + 2], ""); + if (icon.is_valid()) + it->set_icon(0, icon); it->set_metadata(0, id); if (id == inspected_object_id) { @@ -492,17 +493,23 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da pinfo.usage = PropertyUsageFlags(int(prop[4])); Variant var = prop[5]; - String hint_string = pinfo.hint_string; - if (hint_string.begins_with("RES:") && hint_string != "RES:") { - String path = hint_string.substr(4, hint_string.length()); - var = ResourceLoader::load(path); - } - if (is_new_object) { //don't update.. it's the same, instead refresh debugObj->prop_list.push_back(pinfo); } + if (var.get_type() == Variant::STRING) { + String str = var; + var = str.substr(4, str.length()); + + if (str.begins_with("PATH")) { + if (String(var).empty()) + var = RES(); + else + var = ResourceLoader::load(var); + } + } + debugObj->prop_values[pinfo.name] = var; } @@ -573,14 +580,10 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da PropertyHint h = PROPERTY_HINT_NONE; String hs = String(); - if (n.begins_with("*")) { - - n = n.substr(1, n.length()); + if (v.get_type() == Variant::OBJECT) { + v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id(); h = PROPERTY_HINT_OBJECT_ID; - String s = v; - s = s.replace("[", ""); - hs = s.get_slice(":", 0); - v = s.get_slice(":", 1).to_int(); + hs = "Object"; } variables->add_property("Locals/" + n, v, h, hs); @@ -596,14 +599,10 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da PropertyHint h = PROPERTY_HINT_NONE; String hs = String(); - if (n.begins_with("*")) { - - n = n.substr(1, n.length()); + if (v.get_type() == Variant::OBJECT) { + v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id(); h = PROPERTY_HINT_OBJECT_ID; - String s = v; - s = s.replace("[", ""); - hs = s.get_slice(":", 0); - v = s.get_slice(":", 1).to_int(); + hs = "Object"; } variables->add_property("Members/" + n, v, h, hs); @@ -619,14 +618,10 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da PropertyHint h = PROPERTY_HINT_NONE; String hs = String(); - if (n.begins_with("*")) { - - n = n.substr(1, n.length()); + if (v.get_type() == Variant::OBJECT) { + v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id(); h = PROPERTY_HINT_OBJECT_ID; - String s = v; - s = s.replace("[", ""); - hs = s.get_slice(":", 0); - v = s.get_slice(":", 1).to_int(); + hs = "Object"; } variables->add_property("Globals/" + n, v, h, hs); @@ -712,27 +707,65 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da bool warning = err[9]; bool e; String time = String("%d:%02d:%02d:%04d").sprintf(vals, &e); - String txt = time + " - " + (err[8].is_zero() ? String(err[7]) : String(err[8])); + String txt = err[8].is_zero() ? String(err[7]) : String(err[8]); + + TreeItem *r = error_tree->get_root(); + if (!r) { + r = error_tree->create_item(); + } - String tooltip = TTR("Type:") + String(warning ? TTR("Warning") : TTR("Error")); - tooltip += "\n" + TTR("Description:") + " " + String(err[8]); - tooltip += "\n" + TTR("Time:") + " " + time; - tooltip += "\nC " + TTR("Error:") + " " + String(err[7]); - tooltip += "\nC " + TTR("Source:") + " " + String(err[5]) + ":" + String(err[6]); - tooltip += "\nC " + TTR("Function:") + " " + String(err[4]); + TreeItem *error = error_tree->create_item(r); + error->set_collapsed(true); - error_list->add_item(txt, EditorNode::get_singleton()->get_gui_base()->get_icon(warning ? "Warning" : "Error", "EditorIcons")); - error_list->set_item_tooltip(error_list->get_item_count() - 1, tooltip); + error->set_icon(0, get_icon(warning ? "Warning" : "Error", "EditorIcons")); + error->set_text(0, time); + error->set_text_align(0, TreeItem::ALIGN_LEFT); - int scc = p_data[1]; + error->set_text(1, txt); + + String source(err[5]); + bool source_is_project_file = source.begins_with("res://"); + if (source_is_project_file) + source = source.get_file(); - Array stack; - stack.resize(scc); - for (int i = 0; i < scc; i++) { - stack[i] = p_data[2 + i]; + txt = source + ":" + String(err[6]); + String method = err[4]; + if (method.length() > 0) + txt += " @ " + method + "()"; + + TreeItem *c_info = error_tree->create_item(error); + c_info->set_text(0, "<" + TTR(source_is_project_file ? "Source" : "C Source") + ">"); + c_info->set_text(1, txt); + c_info->set_text_align(0, TreeItem::ALIGN_LEFT); + + if (source_is_project_file) { + Array meta; + meta.push_back(source); + meta.push_back(err[6]); + error->set_metadata(0, meta); + c_info->set_metadata(0, meta); } - error_list->set_item_metadata(error_list->get_item_count() - 1, stack); + int scc = p_data[1]; + + for (int i = 0; i < scc; i += 3) { + String script = p_data[2 + i]; + String method = p_data[3 + i]; + int line = p_data[4 + i]; + TreeItem *stack_trace = error_tree->create_item(error); + + Array meta; + meta.push_back(script); + meta.push_back(line); + stack_trace->set_metadata(0, meta); + + if (i == 0) { + stack_trace->set_text(0, "<" + TTR("Stack Trace") + ">"); + stack_trace->set_text_align(0, TreeItem::ALIGN_LEFT); + error->set_metadata(0, meta); + } + stack_trace->set_text(1, script.get_file() + ":" + itos(line) + " @ " + method + "()"); + } if (warning) warning_count++; @@ -970,8 +1003,8 @@ void ScriptEditorDebugger::_notification(int p_what) { //scene_tree_refresh->set_icon( get_icon("Reload","EditorIcons")); le_set->connect("pressed", this, "_live_edit_set"); le_clear->connect("pressed", this, "_live_edit_clear"); - error_list->connect("item_selected", this, "_error_selected"); - error_stack->connect("item_selected", this, "_error_stack_selected"); + error_tree->connect("item_selected", this, "_error_selected"); + error_tree->connect("item_activated", this, "_error_activated"); vmem_refresh->set_icon(get_icon("Reload", "EditorIcons")); reason->add_color_override("font_color", get_color("error_color", "Editor")); @@ -1017,19 +1050,19 @@ void ScriptEditorDebugger::_notification(int p_what) { if (error_count != last_error_count || warning_count != last_warning_count) { if (error_count == 0 && warning_count == 0) { - error_split->set_name(TTR("Errors")); + error_tree->set_name(TTR("Errors")); debugger_button->set_text(TTR("Debugger")); debugger_button->set_icon(Ref<Texture>()); - tabs->set_tab_icon(error_split->get_index(), Ref<Texture>()); + tabs->set_tab_icon(error_tree->get_index(), Ref<Texture>()); } else { - error_split->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")"); + error_tree->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")"); debugger_button->set_text(TTR("Debugger") + " (" + itos(error_count + warning_count) + ")"); if (error_count == 0) { debugger_button->set_icon(get_icon("Warning", "EditorIcons")); - tabs->set_tab_icon(error_split->get_index(), get_icon("Warning", "EditorIcons")); + tabs->set_tab_icon(error_tree->get_index(), get_icon("Warning", "EditorIcons")); } else { debugger_button->set_icon(get_icon("Error", "EditorIcons")); - tabs->set_tab_icon(error_split->get_index(), get_icon("Error", "EditorIcons")); + tabs->set_tab_icon(error_tree->get_index(), get_icon("Error", "EditorIcons")); } } last_error_count = error_count; @@ -1060,8 +1093,7 @@ void ScriptEditorDebugger::_notification(int p_what) { inspect_scene_tree->clear(); le_set->set_disabled(true); le_clear->set_disabled(false); - error_list->clear(); - error_stack->clear(); + error_tree->clear(); error_count = 0; warning_count = 0; profiler_signature.clear(); @@ -1261,9 +1293,6 @@ void ScriptEditorDebugger::stop() { EditorNode::get_singleton()->get_scene_tree_dock()->hide_remote_tree(); EditorNode::get_singleton()->get_scene_tree_dock()->hide_tab_buttons(); - Node *node = editor->get_scene_tree_dock()->get_tree_editor()->get_selected(); - editor->push_item(node); - if (hide_on_stop) { if (is_visible_in_tree()) EditorNode::get_singleton()->hide_bottom_panel(); @@ -1659,45 +1688,52 @@ void ScriptEditorDebugger::reload_scripts() { } } -void ScriptEditorDebugger::_error_selected(int p_idx) { +void ScriptEditorDebugger::_error_activated() { + TreeItem *selected = error_tree->get_selected(); - error_stack->clear(); - Array st = error_list->get_item_metadata(p_idx); - for (int i = 0; i < st.size(); i += 3) { + TreeItem *ci = selected->get_children(); + if (ci) { + selected->set_collapsed(!selected->is_collapsed()); + } +} - String script = st[i]; - String func = st[i + 1]; - int line = st[i + 2]; - Array md; - md.push_back(st[i]); - md.push_back(st[i + 1]); - md.push_back(st[i + 2]); +void ScriptEditorDebugger::_error_selected() { + TreeItem *selected = error_tree->get_selected(); - String str = func; - String tooltip_str = TTR("Function:") + " " + func; - if (script.length() > 0) { - str += " in " + script.get_file(); - tooltip_str = TTR("File:") + " " + script + "\n" + tooltip_str; - if (line > 0) { - str += ":line " + itos(line); - tooltip_str += "\n" + TTR("Line:") + " " + itos(line); - } - } + Array meta = selected->get_metadata(0); + + if (meta.size() == 0) { + return; + } + + Ref<Script> s = ResourceLoader::load(meta[0]); + emit_signal("goto_script_line", s, int(meta[1]) - 1); +} + +void ScriptEditorDebugger::_expand_errors_list() { - error_stack->add_item(str); - error_stack->set_item_metadata(error_stack->get_item_count() - 1, md); - error_stack->set_item_tooltip(error_stack->get_item_count() - 1, tooltip_str); + TreeItem *root = error_tree->get_root(); + if (!root) + return; + + TreeItem *item = root->get_children(); + while (item) { + item->set_collapsed(false); + item = item->get_next(); } } -void ScriptEditorDebugger::_error_stack_selected(int p_idx) { +void ScriptEditorDebugger::_collapse_errors_list() { - Array arr = error_stack->get_item_metadata(p_idx); - if (arr.size() != 3) + TreeItem *root = error_tree->get_root(); + if (!root) return; - Ref<Script> s = ResourceLoader::load(arr[0]); - emit_signal("goto_script_line", s, int(arr[2]) - 1); + TreeItem *item = root->get_children(); + while (item) { + item->set_collapsed(true); + item = item->get_next(); + } } void ScriptEditorDebugger::set_hide_on_stop(bool p_hide) { @@ -1754,27 +1790,24 @@ void ScriptEditorDebugger::_clear_remote_objects() { void ScriptEditorDebugger::_clear_errors_list() { - error_list->clear(); + error_tree->clear(); error_count = 0; warning_count = 0; _notification(NOTIFICATION_PROCESS); } // Right click on specific file(s) or folder(s). -void ScriptEditorDebugger::_error_list_item_rmb_selected(int p_item, const Vector2 &p_pos) { +void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) { item_menu->clear(); item_menu->set_size(Size2(1, 1)); - // Allow specific actions only on one item. - bool single_item_selected = error_list->get_selected_items().size() == 1; - - if (single_item_selected) { + if (error_tree->is_anything_selected()) { item_menu->add_icon_item(get_icon("ActionCopy", "EditorIcons"), TTR("Copy Error"), ITEM_MENU_COPY_ERROR); } if (item_menu->get_item_count() > 0) { - item_menu->set_position(error_list->get_global_position() + p_pos); + item_menu->set_position(error_tree->get_global_position() + p_pos); item_menu->popup(); } } @@ -1784,10 +1817,30 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) { switch (p_option) { case ITEM_MENU_COPY_ERROR: { - String title = error_list->get_item_text(error_list->get_current()); - String desc = error_list->get_item_tooltip(error_list->get_current()); + TreeItem *ti = error_tree->get_selected(); + while (ti->get_parent() != error_tree->get_root()) + ti = ti->get_parent(); + + String type; + + if (ti->get_icon(0) == get_icon("Warning", "EditorIcons")) { + type = "W "; + } else if (ti->get_icon(0) == get_icon("Error", "EditorIcons")) { + type = "E "; + } + + String text = ti->get_text(0) + " "; + int rpad_len = text.length(); + + text = type + text + ti->get_text(1) + "\n"; + TreeItem *ci = ti->get_children(); + while (ci) { + text += " " + ci->get_text(0).rpad(rpad_len) + ci->get_text(1) + "\n"; + ci = ci->get_next(); + } + + OS::get_singleton()->set_clipboard(text); - OS::get_singleton()->set_clipboard(title + "\n----------\n" + desc); } break; case ITEM_MENU_SAVE_REMOTE_NODE: { @@ -1826,12 +1879,14 @@ void ScriptEditorDebugger::_bind_methods() { ClassDB::bind_method(D_METHOD("_live_edit_clear"), &ScriptEditorDebugger::_live_edit_clear); ClassDB::bind_method(D_METHOD("_error_selected"), &ScriptEditorDebugger::_error_selected); - ClassDB::bind_method(D_METHOD("_error_stack_selected"), &ScriptEditorDebugger::_error_stack_selected); + ClassDB::bind_method(D_METHOD("_error_activated"), &ScriptEditorDebugger::_error_activated); + ClassDB::bind_method(D_METHOD("_expand_errors_list"), &ScriptEditorDebugger::_expand_errors_list); + ClassDB::bind_method(D_METHOD("_collapse_errors_list"), &ScriptEditorDebugger::_collapse_errors_list); ClassDB::bind_method(D_METHOD("_profiler_activate"), &ScriptEditorDebugger::_profiler_activate); ClassDB::bind_method(D_METHOD("_profiler_seeked"), &ScriptEditorDebugger::_profiler_seeked); ClassDB::bind_method(D_METHOD("_clear_errors_list"), &ScriptEditorDebugger::_clear_errors_list); - ClassDB::bind_method(D_METHOD("_error_list_item_rmb_selected"), &ScriptEditorDebugger::_error_list_item_rmb_selected); + ClassDB::bind_method(D_METHOD("_error_tree_item_rmb_selected"), &ScriptEditorDebugger::_error_tree_item_rmb_selected); ClassDB::bind_method(D_METHOD("_item_menu_id_pressed"), &ScriptEditorDebugger::_item_menu_id_pressed); ClassDB::bind_method(D_METHOD("_paused"), &ScriptEditorDebugger::_paused); @@ -1946,16 +2001,14 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { stack_dump->connect("cell_selected", this, "_stack_dump_frame_selected"); sc->add_child(stack_dump); - inspector = memnew(PropertyEditor); + inspector = memnew(EditorInspector); inspector->set_h_size_flags(SIZE_EXPAND_FILL); - inspector->hide_top_label(); - inspector->get_property_tree()->set_column_title(0, TTR("Variable")); inspector->set_enable_capitalize_paths(false); inspector->set_read_only(true); inspector->connect("object_id_selected", this, "_scene_tree_property_select_object"); sc->add_child(inspector); - server = TCP_Server::create_ref(); + server.instance(); pending_in_queue = 0; @@ -1967,44 +2020,52 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { } { //errors - - error_split = memnew(HSplitContainer); VBoxContainer *errvb = memnew(VBoxContainer); + errvb->set_name(TTR("Errors")); + HBoxContainer *errhb = memnew(HBoxContainer); - errvb->set_h_size_flags(SIZE_EXPAND_FILL); - Label *velb = memnew(Label(TTR("Errors:"))); - velb->set_h_size_flags(SIZE_EXPAND_FILL); - errhb->add_child(velb); + errvb->add_child(errhb); + + Button *expand_all = memnew(Button); + expand_all->set_text(TTR("Expand All")); + expand_all->connect("pressed", this, "_expand_errors_list"); + errhb->add_child(expand_all); + + Button *collapse_all = memnew(Button); + collapse_all->set_text(TTR("Collapse All")); + collapse_all->connect("pressed", this, "_collapse_errors_list"); + errhb->add_child(collapse_all); + + Control *space = memnew(Control); + space->set_h_size_flags(SIZE_EXPAND_FILL); + errhb->add_child(space); clearbutton = memnew(Button); clearbutton->set_text(TTR("Clear")); + clearbutton->set_h_size_flags(0); clearbutton->connect("pressed", this, "_clear_errors_list"); errhb->add_child(clearbutton); - errvb->add_child(errhb); - error_list = memnew(ItemList); - error_list->set_v_size_flags(SIZE_EXPAND_FILL); - error_list->set_h_size_flags(SIZE_EXPAND_FILL); - error_list->connect("item_rmb_selected", this, "_error_list_item_rmb_selected"); - error_list->set_allow_rmb_select(true); - error_list->set_autoscroll_to_bottom(true); + error_tree = memnew(Tree); + error_tree->set_columns(2); - item_menu = memnew(PopupMenu); - item_menu->connect("id_pressed", this, "_item_menu_id_pressed"); - error_list->add_child(item_menu); + error_tree->set_column_expand(0, false); + error_tree->set_column_min_width(0, 140); - errvb->add_child(error_list); + error_tree->set_column_expand(1, true); - error_split->add_child(errvb); + error_tree->set_select_mode(Tree::SELECT_ROW); + error_tree->set_hide_root(true); + error_tree->set_v_size_flags(SIZE_EXPAND_FILL); + error_tree->set_allow_rmb_select(true); + error_tree->connect("item_rmb_selected", this, "_error_tree_item_rmb_selected"); + errvb->add_child(error_tree); - errvb = memnew(VBoxContainer); - errvb->set_h_size_flags(SIZE_EXPAND_FILL); - error_stack = memnew(ItemList); - errvb->add_margin_child(TTR("Stack Trace (if applicable):"), error_stack, true); - error_split->add_child(errvb); + item_menu = memnew(PopupMenu); + item_menu->connect("id_pressed", this, "_item_menu_id_pressed"); + error_tree->add_child(item_menu); - error_split->set_name(TTR("Errors")); - tabs->add_child(error_split); + tabs->add_child(errvb); } { // remote scene tree @@ -2180,7 +2241,6 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { ScriptEditorDebugger::~ScriptEditorDebugger() { - //inspector->edit(NULL); memdelete(variables); ppeer->set_stream_peer(Ref<StreamPeer>()); |