| 1 | /**************************************************************************/ |
| 2 | /* editor_debugger_node.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "editor_debugger_node.h" |
| 32 | |
| 33 | #include "core/object/undo_redo.h" |
| 34 | #include "editor/debugger/editor_debugger_plugin.h" |
| 35 | #include "editor/debugger/editor_debugger_tree.h" |
| 36 | #include "editor/debugger/script_editor_debugger.h" |
| 37 | #include "editor/docks/editor_dock_manager.h" |
| 38 | #include "editor/docks/inspector_dock.h" |
| 39 | #include "editor/docks/scene_tree_dock.h" |
| 40 | #include "editor/editor_log.h" |
| 41 | #include "editor/editor_node.h" |
| 42 | #include "editor/editor_string_names.h" |
| 43 | #include "editor/editor_undo_redo_manager.h" |
| 44 | #include "editor/run/editor_run_bar.h" |
| 45 | #include "editor/script/script_editor_plugin.h" |
| 46 | #include "editor/settings/editor_command_palette.h" |
| 47 | #include "editor/settings/editor_settings.h" |
| 48 | #include "editor/themes/editor_theme_manager.h" |
| 49 | #include "scene/gui/menu_button.h" |
| 50 | #include "scene/gui/tab_container.h" |
| 51 | #include "scene/resources/packed_scene.h" |
| 52 | |
| 53 | template <typename Func> |
| 54 | void _for_all(TabContainer *p_node, const Func &p_func) { |
| 55 | for (int i = 0; i < p_node->get_tab_count(); i++) { |
| 56 | ScriptEditorDebugger *dbg = Object::cast_to<ScriptEditorDebugger>(p_node->get_tab_control(i)); |
| 57 | ERR_FAIL_NULL(dbg); |
| 58 | p_func(dbg); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | EditorDebuggerNode *EditorDebuggerNode::singleton = nullptr; |
| 63 | |
| 64 | EditorDebuggerNode::EditorDebuggerNode() { |
| 65 | set_name(TTRC("Debugger")); |
| 66 | set_icon_name("Debug"); |
| 67 | set_layout_key("Debugger"); |
| 68 | set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_debugger_bottom_panel", TTRC("Toggle Debugger Dock"), KeyModifierMask::ALT | Key::D)); |
| 69 | set_default_slot(EditorDock::DOCK_SLOT_BOTTOM); |
| 70 | set_available_layouts(EditorDock::DOCK_LAYOUT_HORIZONTAL); |
| 71 | set_global(false); |
| 72 | set_transient(true); |
| 73 | |
| 74 | _update_margins(); |
| 75 | |
| 76 | if (!singleton) { |
| 77 | singleton = this; |
| 78 | } |
| 79 | |
| 80 | tabs = memnew(TabContainer); |
| 81 | tabs->set_tabs_visible(false); |
| 82 | tabs->connect("tab_changed", callable_mp(this, &EditorDebuggerNode::_debugger_changed)); |
| 83 | add_child(tabs); |
| 84 | |
| 85 | Ref<StyleBoxEmpty> empty; |
| 86 | empty.instantiate(); |
| 87 | tabs->add_theme_style_override(SceneStringName(panel), empty); |
| 88 | |
| 89 | auto_switch_remote_scene_tree = EDITOR_GET("debugger/auto_switch_to_remote_scene_tree"); |
| 90 | _add_debugger(); |
| 91 | |
| 92 | // Remote scene tree |
| 93 | remote_scene_tree = memnew(EditorDebuggerTree); |
| 94 | remote_scene_tree->connect("objects_selected", callable_mp(this, &EditorDebuggerNode::_remote_objects_requested)); |
| 95 | remote_scene_tree->connect("selection_cleared", callable_mp(this, &EditorDebuggerNode::_remote_selection_cleared)); |
| 96 | remote_scene_tree->connect("save_node", callable_mp(this, &EditorDebuggerNode::_save_node_requested)); |
| 97 | remote_scene_tree->connect("button_clicked", callable_mp(this, &EditorDebuggerNode::_remote_tree_button_pressed)); |
| 98 | SceneTreeDock::get_singleton()->add_remote_tree_editor(remote_scene_tree); |
| 99 | SceneTreeDock::get_singleton()->connect("remote_tree_selected", callable_mp(this, &EditorDebuggerNode::request_remote_tree)); |
| 100 | |
| 101 | remote_scene_tree_timeout = EDITOR_GET("debugger/remote_scene_tree_refresh_interval"); |
| 102 | inspect_edited_object_timeout = EDITOR_GET("debugger/remote_inspect_refresh_interval"); |
| 103 | |
| 104 | if (Engine::get_singleton()->is_recovery_mode_hint()) { |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | EditorRunBar::get_singleton()->get_pause_button()->connect(SceneStringName(pressed), callable_mp(this, &EditorDebuggerNode::_paused)); |
| 109 | } |
| 110 | |
| 111 | ScriptEditorDebugger *EditorDebuggerNode::_add_debugger() { |
| 112 | ScriptEditorDebugger *node = memnew(ScriptEditorDebugger); |
| 113 | |
| 114 | int id = tabs->get_tab_count(); |
| 115 | node->connect("stop_requested", callable_mp(this, &EditorDebuggerNode::_debugger_wants_stop).bind(id)); |
| 116 | node->connect("stopped", callable_mp(this, &EditorDebuggerNode::_debugger_stopped).bind(id)); |
| 117 | node->connect("stack_frame_selected", callable_mp(this, &EditorDebuggerNode::_stack_frame_selected).bind(id)); |
| 118 | node->connect("error_selected", callable_mp(this, &EditorDebuggerNode::_error_selected).bind(id)); |
| 119 | node->connect("breakpoint_selected", callable_mp(this, &EditorDebuggerNode::_error_selected).bind(id)); |
| 120 | node->connect("clear_execution", callable_mp(this, &EditorDebuggerNode::_clear_execution)); |
| 121 | node->connect("breaked", callable_mp(this, &EditorDebuggerNode::_breaked).bind(id)); |
| 122 | node->connect("debug_data", callable_mp(this, &EditorDebuggerNode::_debug_data).bind(id)); |
| 123 | node->connect("remote_tree_select_requested", callable_mp(this, &EditorDebuggerNode::_remote_tree_select_requested).bind(id)); |
| 124 | node->connect("remote_tree_clear_selection_requested", callable_mp(this, &EditorDebuggerNode::_remote_tree_clear_selection_requested).bind(id)); |
| 125 | node->connect("remote_tree_updated", callable_mp(this, &EditorDebuggerNode::_remote_tree_updated).bind(id)); |
| 126 | node->connect("remote_objects_updated", callable_mp(this, &EditorDebuggerNode::_remote_objects_updated).bind(id)); |
| 127 | node->connect("remote_object_property_updated", callable_mp(this, &EditorDebuggerNode::_remote_object_property_updated).bind(id)); |
| 128 | node->connect("remote_objects_requested", callable_mp(this, &EditorDebuggerNode::_remote_objects_requested).bind(id)); |
| 129 | node->connect("set_breakpoint", callable_mp(this, &EditorDebuggerNode::_breakpoint_set_in_tree).bind(id)); |
| 130 | node->connect("clear_breakpoints", callable_mp(this, &EditorDebuggerNode::_breakpoints_cleared_in_tree).bind(id)); |
| 131 | node->connect("errors_cleared", callable_mp(this, &EditorDebuggerNode::_update_errors)); |
| 132 | |
| 133 | if (tabs->get_tab_count() > 0) { |
| 134 | get_debugger(0)->clear_style(); |
| 135 | } |
| 136 | |
| 137 | tabs->add_child(node); |
| 138 | |
| 139 | node->set_name(vformat(TTR("Session %d"), tabs->get_tab_count())); |
| 140 | if (tabs->get_tab_count() > 1) { |
| 141 | node->clear_style(); |
| 142 | tabs->set_tabs_visible(true); |
| 143 | tabs->add_theme_style_override(SceneStringName(panel), EditorNode::get_singleton()->get_editor_theme()->get_stylebox(SNAME("DebuggerPanel"), EditorStringName(EditorStyles))); |
| 144 | } |
| 145 | |
| 146 | if (!debugger_plugins.is_empty()) { |
| 147 | for (Ref<EditorDebuggerPlugin> plugin : debugger_plugins) { |
| 148 | plugin->create_session(node); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return node; |
| 153 | } |
| 154 | |
| 155 | void EditorDebuggerNode::_stack_frame_selected(int p_debugger) { |
| 156 | const ScriptEditorDebugger *dbg = get_debugger(p_debugger); |
| 157 | ERR_FAIL_NULL(dbg); |
| 158 | if (dbg != get_current_debugger()) { |
| 159 | return; |
| 160 | } |
| 161 | _text_editor_stack_goto(dbg); |
| 162 | } |
| 163 | |
| 164 | void EditorDebuggerNode::_error_selected(const String &p_file, int p_line, int p_debugger) { |
| 165 | if (!p_file.is_resource_file() && !ResourceCache::has(p_file)) { |
| 166 | // If it's a built-in script, make sure the scene is opened first. |
| 167 | EditorNode::get_singleton()->load_scene(p_file.get_slice("::", 0)); |
| 168 | } |
| 169 | Ref<Script> s = ResourceLoader::load(p_file); |
| 170 | emit_signal(SNAME("goto_script_line"), s, p_line - 1); |
| 171 | } |
| 172 | |
| 173 | void EditorDebuggerNode::_text_editor_stack_goto(const ScriptEditorDebugger *p_debugger) { |
| 174 | String file = p_debugger->get_stack_script_file(); |
| 175 | if (file.is_empty()) { |
| 176 | return; |
| 177 | } |
| 178 | if (file.is_resource_file()) { |
| 179 | stack_script = ResourceLoader::load(file); |
| 180 | } else { |
| 181 | // If the script is built-in, it can be opened only if the scene is loaded in memory. |
| 182 | int i = file.find("::"); |
| 183 | int j = file.rfind_char('(', i); |
| 184 | if (j > -1) { // If the script is named, the string is "name (file)", so we need to extract the path. |
| 185 | file = file.substr(j + 1, file.find_char(')', i) - j - 1); |
| 186 | } |
| 187 | Ref<PackedScene> ps = ResourceLoader::load(file.get_slice("::", 0)); |
| 188 | stack_script = ResourceLoader::load(file); |
| 189 | } |
| 190 | const int line = p_debugger->get_stack_script_line() - 1; |
| 191 | emit_signal(SNAME("goto_script_line"), stack_script, line); |
| 192 | emit_signal(SNAME("set_execution"), stack_script, line); |
| 193 | stack_script.unref(); // Why?!? |
| 194 | } |
| 195 | |
| 196 | void EditorDebuggerNode::_text_editor_stack_clear(const ScriptEditorDebugger *p_debugger) { |
| 197 | String file = p_debugger->get_stack_script_file(); |
| 198 | if (file.is_empty()) { |
| 199 | return; |
| 200 | } |
| 201 | if (file.is_resource_file()) { |
| 202 | stack_script = ResourceLoader::load(file); |
| 203 | } else { |
| 204 | // If the script is built-in, it can be opened only if the scene is loaded in memory. |
| 205 | int i = file.find("::"); |
| 206 | int j = file.rfind_char('(', i); |
| 207 | if (j > -1) { // If the script is named, the string is "name (file)", so we need to extract the path. |
| 208 | file = file.substr(j + 1, file.find_char(')', i) - j - 1); |
| 209 | } |
| 210 | Ref<PackedScene> ps = ResourceLoader::load(file.get_slice("::", 0)); |
| 211 | stack_script = ResourceLoader::load(file); |
| 212 | } |
| 213 | emit_signal(SNAME("clear_execution"), stack_script); |
| 214 | stack_script.unref(); // Why?!? |
| 215 | } |
| 216 | |
| 217 | void EditorDebuggerNode::_bind_methods() { |
| 218 | // LiveDebug. |
| 219 | ClassDB::bind_method("live_debug_create_node", &EditorDebuggerNode::live_debug_create_node); |
| 220 | ClassDB::bind_method("live_debug_instantiate_node", &EditorDebuggerNode::live_debug_instantiate_node); |
| 221 | ClassDB::bind_method("live_debug_remove_node", &EditorDebuggerNode::live_debug_remove_node); |
| 222 | ClassDB::bind_method("live_debug_remove_and_keep_node", &EditorDebuggerNode::live_debug_remove_and_keep_node); |
| 223 | ClassDB::bind_method("live_debug_restore_node", &EditorDebuggerNode::live_debug_restore_node); |
| 224 | ClassDB::bind_method("live_debug_duplicate_node", &EditorDebuggerNode::live_debug_duplicate_node); |
| 225 | ClassDB::bind_method("live_debug_reparent_node", &EditorDebuggerNode::live_debug_reparent_node); |
| 226 | |
| 227 | ADD_SIGNAL(MethodInfo("goto_script_line")); |
| 228 | ADD_SIGNAL(MethodInfo("set_execution", PropertyInfo("script"), PropertyInfo(Variant::INT, "line"))); |
| 229 | ADD_SIGNAL(MethodInfo("clear_execution", PropertyInfo("script"))); |
| 230 | ADD_SIGNAL(MethodInfo("breaked", PropertyInfo(Variant::BOOL, "reallydid"), PropertyInfo(Variant::BOOL, "can_debug"))); |
| 231 | ADD_SIGNAL(MethodInfo("breakpoint_toggled", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "line"), PropertyInfo(Variant::BOOL, "enabled"))); |
| 232 | ADD_SIGNAL(MethodInfo("breakpoint_set_in_tree", PropertyInfo("script"), PropertyInfo(Variant::INT, "line"), PropertyInfo(Variant::BOOL, "enabled"), PropertyInfo(Variant::INT, "debugger"))); |
| 233 | ADD_SIGNAL(MethodInfo("breakpoints_cleared_in_tree", PropertyInfo(Variant::INT, "debugger"))); |
| 234 | } |
| 235 | |
| 236 | void EditorDebuggerNode::register_undo_redo(UndoRedo *p_undo_redo) { |
| 237 | p_undo_redo->set_method_notify_callback(_methods_changed, this); |
| 238 | p_undo_redo->set_property_notify_callback(_properties_changed, this); |
| 239 | } |
| 240 | |
| 241 | ScriptEditorDebugger *EditorDebuggerNode::get_debugger(int p_id) const { |
| 242 | return Object::cast_to<ScriptEditorDebugger>(tabs->get_tab_control(p_id)); |
| 243 | } |
| 244 | |
| 245 | ScriptEditorDebugger *EditorDebuggerNode::get_previous_debugger() const { |
| 246 | return Object::cast_to<ScriptEditorDebugger>(tabs->get_tab_control(tabs->get_previous_tab())); |
| 247 | } |
| 248 | |
| 249 | ScriptEditorDebugger *EditorDebuggerNode::get_current_debugger() const { |
| 250 | return Object::cast_to<ScriptEditorDebugger>(tabs->get_tab_control(tabs->get_current_tab())); |
| 251 | } |
| 252 | |
| 253 | ScriptEditorDebugger *EditorDebuggerNode::get_default_debugger() const { |
| 254 | return Object::cast_to<ScriptEditorDebugger>(tabs->get_tab_control(0)); |
| 255 | } |
| 256 | |
| 257 | String EditorDebuggerNode::get_server_uri() const { |
| 258 | return server.is_valid() ? server->get_uri() : ""; |
| 259 | } |
| 260 | |
| 261 | void EditorDebuggerNode::set_keep_open(bool p_keep_open) { |
| 262 | keep_open = p_keep_open; |
| 263 | if (keep_open) { |
| 264 | if (server.is_null() || !server->is_active()) { |
| 265 | start(); |
| 266 | } |
| 267 | } else { |
| 268 | bool found = false; |
| 269 | _for_all(tabs, [&](ScriptEditorDebugger *p_debugger) { |
| 270 | if (p_debugger->is_session_active()) { |
| 271 | found = true; |
| 272 | } |
| 273 | }); |
| 274 | if (!found) { |
| 275 | stop(); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | Error EditorDebuggerNode::start(const String &p_uri) { |
| 281 | if (Engine::get_singleton()->is_recovery_mode_hint()) { |
| 282 | return ERR_UNAVAILABLE; |
| 283 | } |
| 284 | |
| 285 | ERR_FAIL_COND_V(!p_uri.contains("://"), ERR_INVALID_PARAMETER); |
| 286 | if (keep_open && current_uri == p_uri && server.is_valid()) { |
| 287 | return OK; |
| 288 | } |
| 289 | stop(true); |
| 290 | current_uri = p_uri; |
| 291 | |
| 292 | server = Ref<EditorDebuggerServer>(EditorDebuggerServer::create(p_uri.substr(0, p_uri.find("://") + 3))); |
| 293 | const Error err = server->start(p_uri); |
| 294 | if (err != OK) { |
| 295 | return err; |
| 296 | } |
| 297 | set_process(true); |
| 298 | EditorNode::get_log()->add_message("--- Debugging process started ---", EditorLog::MSG_TYPE_EDITOR); |
| 299 | return OK; |
| 300 | } |
| 301 | |
| 302 | void EditorDebuggerNode::stop(bool p_force) { |
| 303 | if (keep_open && !p_force) { |
| 304 | return; |
| 305 | } |
| 306 | |
| 307 | remote_scene_tree_wait = false; |
| 308 | inspect_edited_object_wait = false; |
| 309 | |
| 310 | current_uri.clear(); |
| 311 | if (server.is_valid()) { |
| 312 | server->stop(); |
| 313 | EditorNode::get_log()->add_message("--- Debugging process stopped ---", EditorLog::MSG_TYPE_EDITOR); |
| 314 | |
| 315 | if (EditorRunBar::get_singleton()->is_movie_maker_enabled()) { |
| 316 | // Request attention in case the user was doing something else when movie recording is finished. |
| 317 | DisplayServer::get_singleton()->window_request_attention(); |
| 318 | } |
| 319 | |
| 320 | server.unref(); |
| 321 | } |
| 322 | |
| 323 | // Also close all debugging sessions. |
| 324 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 325 | if (dbg->is_session_active()) { |
| 326 | dbg->_stop_and_notify(); |
| 327 | } |
| 328 | }); |
| 329 | _break_state_changed(); |
| 330 | breakpoints.clear(); |
| 331 | EditorUndoRedoManager::get_singleton()->clear_history(EditorUndoRedoManager::REMOTE_HISTORY, false); |
| 332 | set_process(false); |
| 333 | } |
| 334 | |
| 335 | void EditorDebuggerNode::_notification(int p_what) { |
| 336 | switch (p_what) { |
| 337 | case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { |
| 338 | if (!EditorThemeManager::is_generated_theme_outdated()) { |
| 339 | return; |
| 340 | } |
| 341 | |
| 342 | if (tabs->get_tab_count() > 1) { |
| 343 | tabs->add_theme_style_override(SceneStringName(panel), EditorNode::get_singleton()->get_editor_theme()->get_stylebox(SNAME("DebuggerPanel"), EditorStringName(EditorStyles))); |
| 344 | } |
| 345 | _update_margins(); |
| 346 | |
| 347 | remote_scene_tree->update_icon_max_width(); |
| 348 | } break; |
| 349 | |
| 350 | case NOTIFICATION_READY: { |
| 351 | _update_debug_options(); |
| 352 | initializing = false; |
| 353 | } break; |
| 354 | |
| 355 | case NOTIFICATION_PROCESS: { |
| 356 | if (server.is_null()) { |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | if (!server->is_active()) { |
| 361 | stop(); |
| 362 | return; |
| 363 | } |
| 364 | server->poll(); |
| 365 | |
| 366 | _update_errors(); |
| 367 | |
| 368 | // Remote scene tree update. |
| 369 | if (!remote_scene_tree_wait) { |
| 370 | remote_scene_tree_timeout -= get_process_delta_time(); |
| 371 | if (remote_scene_tree_timeout < 0) { |
| 372 | remote_scene_tree_timeout = EDITOR_GET("debugger/remote_scene_tree_refresh_interval"); |
| 373 | |
| 374 | if (remote_scene_tree->is_visible_in_tree()) { |
| 375 | remote_scene_tree_wait = true; |
| 376 | get_current_debugger()->request_remote_tree(); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | // Remote inspector update. |
| 382 | if (!inspect_edited_object_wait) { |
| 383 | inspect_edited_object_timeout -= get_process_delta_time(); |
| 384 | if (inspect_edited_object_timeout < 0) { |
| 385 | inspect_edited_object_timeout = EDITOR_GET("debugger/remote_inspect_refresh_interval"); |
| 386 | |
| 387 | if (EditorDebuggerRemoteObjects *robjs = Object::cast_to<EditorDebuggerRemoteObjects>(InspectorDock::get_inspector_singleton()->get_edited_object())) { |
| 388 | inspect_edited_object_wait = true; |
| 389 | get_current_debugger()->request_remote_objects(robjs->remote_object_ids, false); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | // Take connections. |
| 395 | if (server->is_connection_available()) { |
| 396 | ScriptEditorDebugger *debugger = nullptr; |
| 397 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 398 | if (debugger || dbg->is_session_active()) { |
| 399 | return; |
| 400 | } |
| 401 | debugger = dbg; |
| 402 | }); |
| 403 | if (debugger == nullptr) { |
| 404 | if (tabs->get_tab_count() <= 4) { // Max 4 debugging sessions active. |
| 405 | debugger = _add_debugger(); |
| 406 | } else { |
| 407 | // We already have too many sessions, disconnecting new clients to prevent them from hanging. |
| 408 | server->take_connection()->close(); |
| 409 | return; // Can't add, stop here. |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | EditorRunBar::get_singleton()->get_pause_button()->set_disabled(false); |
| 414 | // Switch to remote tree view if so desired. |
| 415 | remote_scene_tree->set_new_session(); |
| 416 | auto_switch_remote_scene_tree = EDITOR_GET("debugger/auto_switch_to_remote_scene_tree"); |
| 417 | if (auto_switch_remote_scene_tree) { |
| 418 | SceneTreeDock::get_singleton()->show_remote_tree(); |
| 419 | } |
| 420 | // Good to go. |
| 421 | SceneTreeDock::get_singleton()->show_tab_buttons(); |
| 422 | debugger->set_editor_remote_tree(remote_scene_tree); |
| 423 | debugger->start(server->take_connection()); |
| 424 | // Send breakpoints. |
| 425 | for (const KeyValue<Breakpoint, bool> &E : breakpoints) { |
| 426 | const Breakpoint &bp = E.key; |
| 427 | debugger->set_breakpoint(bp.source, bp.line, E.value); |
| 428 | } // Will arrive too late, how does the regular run work? |
| 429 | |
| 430 | debugger->update_live_edit_root(); |
| 431 | } |
| 432 | } break; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | void EditorDebuggerNode::_update_errors() { |
| 437 | int error_count = 0; |
| 438 | int warning_count = 0; |
| 439 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 440 | error_count += dbg->get_error_count(); |
| 441 | warning_count += dbg->get_warning_count(); |
| 442 | }); |
| 443 | |
| 444 | if (error_count != last_error_count || warning_count != last_warning_count) { |
| 445 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 446 | dbg->update_tabs(); |
| 447 | }); |
| 448 | |
| 449 | last_error_count = error_count; |
| 450 | last_warning_count = warning_count; |
| 451 | |
| 452 | if (error_count == 0 && warning_count == 0) { |
| 453 | set_title(""); |
| 454 | set_dock_icon(Ref<Texture2D>()); |
| 455 | set_title_color(Color(0, 0, 0, 0)); |
| 456 | set_force_show_icon(false); |
| 457 | } else { |
| 458 | set_title(TTR("Debugger") + " (" + itos(error_count + warning_count) + ")"); |
| 459 | if (error_count >= 1 && warning_count >= 1) { |
| 460 | set_dock_icon(get_editor_theme_icon(SNAME("ErrorWarning"))); |
| 461 | // Use error color to represent the highest level of severity reported. |
| 462 | set_title_color(get_theme_color(SNAME("error_color"), EditorStringName(Editor))); |
| 463 | } else if (error_count >= 1) { |
| 464 | set_dock_icon(get_editor_theme_icon(SNAME("Error"))); |
| 465 | set_title_color(get_theme_color(SNAME("error_color"), EditorStringName(Editor))); |
| 466 | } else { |
| 467 | set_dock_icon(get_editor_theme_icon(SNAME("Warning"))); |
| 468 | set_title_color(get_theme_color(SNAME("warning_color"), EditorStringName(Editor))); |
| 469 | } |
| 470 | set_force_show_icon(true); |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | void EditorDebuggerNode::_update_margins() { |
| 476 | Ref<StyleBox> bottom_panel_margins = EditorNode::get_singleton()->get_editor_theme()->get_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)); |
| 477 | add_theme_constant_override("margin_top", -bottom_panel_margins->get_margin(SIDE_TOP)); |
| 478 | add_theme_constant_override("margin_left", -bottom_panel_margins->get_margin(SIDE_LEFT)); |
| 479 | add_theme_constant_override("margin_right", -bottom_panel_margins->get_margin(SIDE_RIGHT)); |
| 480 | add_theme_constant_override("margin_bottom", -bottom_panel_margins->get_margin(SIDE_BOTTOM)); |
| 481 | } |
| 482 | |
| 483 | void EditorDebuggerNode::_debugger_stopped(int p_id) { |
| 484 | ScriptEditorDebugger *dbg = get_debugger(p_id); |
| 485 | ERR_FAIL_NULL(dbg); |
| 486 | |
| 487 | bool found = false; |
| 488 | _for_all(tabs, [&](ScriptEditorDebugger *p_debugger) { |
| 489 | if (p_debugger->is_session_active()) { |
| 490 | found = true; |
| 491 | } |
| 492 | }); |
| 493 | if (!found) { |
| 494 | EditorRunBar::get_singleton()->get_pause_button()->set_pressed(false); |
| 495 | EditorRunBar::get_singleton()->get_pause_button()->set_disabled(true); |
| 496 | SceneTreeDock *dock = SceneTreeDock::get_singleton(); |
| 497 | if (dock->is_inside_tree()) { |
| 498 | dock->hide_remote_tree(); |
| 499 | dock->hide_tab_buttons(); |
| 500 | } |
| 501 | EditorNode::get_singleton()->notify_all_debug_sessions_exited(); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | void EditorDebuggerNode::_debugger_wants_stop(int p_id) { |
| 506 | // Ask editor to kill PID. |
| 507 | if (int pid = get_debugger(p_id)->get_remote_pid()) { |
| 508 | callable_mp(EditorNode::get_singleton(), &EditorNode::stop_child_process).call_deferred(pid); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | void EditorDebuggerNode::_debugger_changed(int p_tab) { |
| 513 | remote_scene_tree_wait = false; |
| 514 | inspect_edited_object_wait = false; |
| 515 | |
| 516 | if (Object *robjs = InspectorDock::get_inspector_singleton()->get_edited_object()) { |
| 517 | if (Object::cast_to<EditorDebuggerRemoteObjects>(robjs)) { |
| 518 | // Clear inspected object, you can only inspect objects in selected debugger. |
| 519 | // Hopefully, in the future, we will have one inspector per debugger. |
| 520 | EditorNode::get_singleton()->push_item(nullptr); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | if (ScriptEditorDebugger *prev_debug = get_previous_debugger()) { |
| 525 | prev_debug->clear_inspector(); |
| 526 | _text_editor_stack_clear(prev_debug); |
| 527 | } |
| 528 | if (remote_scene_tree->is_visible_in_tree()) { |
| 529 | get_current_debugger()->request_remote_tree(); |
| 530 | } |
| 531 | if (get_current_debugger()->is_breaked()) { |
| 532 | _text_editor_stack_goto(get_current_debugger()); |
| 533 | } |
| 534 | |
| 535 | _break_state_changed(); |
| 536 | } |
| 537 | |
| 538 | void EditorDebuggerNode::_debug_data(const String &p_msg, const Array &p_data, int p_debugger) { |
| 539 | if (p_debugger != tabs->get_current_tab()) { |
| 540 | return; |
| 541 | } |
| 542 | |
| 543 | if (p_msg == "scene:scene_tree") { |
| 544 | remote_scene_tree_wait = false; |
| 545 | } else if (p_msg == "scene:inspect_objects") { |
| 546 | inspect_edited_object_wait = false; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | void EditorDebuggerNode::set_script_debug_button(MenuButton *p_button) { |
| 551 | script_menu = p_button; |
| 552 | script_menu->set_text(TTRC("Debug")); |
| 553 | script_menu->set_switch_on_hover(true); |
| 554 | PopupMenu *p = script_menu->get_popup(); |
| 555 | p->add_shortcut(ED_GET_SHORTCUT("debugger/step_into"), DEBUG_STEP); |
| 556 | p->add_shortcut(ED_GET_SHORTCUT("debugger/step_over"), DEBUG_NEXT); |
| 557 | p->add_separator(); |
| 558 | p->add_shortcut(ED_GET_SHORTCUT("debugger/break"), DEBUG_BREAK); |
| 559 | p->add_shortcut(ED_GET_SHORTCUT("debugger/continue"), DEBUG_CONTINUE); |
| 560 | p->add_separator(); |
| 561 | p->add_check_shortcut(ED_GET_SHORTCUT("debugger/debug_with_external_editor"), DEBUG_WITH_EXTERNAL_EDITOR); |
| 562 | p->connect(SceneStringName(id_pressed), callable_mp(this, &EditorDebuggerNode::_menu_option)); |
| 563 | |
| 564 | _break_state_changed(); |
| 565 | script_menu->show(); |
| 566 | } |
| 567 | |
| 568 | void EditorDebuggerNode::_break_state_changed() { |
| 569 | const bool breaked = get_current_debugger()->is_breaked(); |
| 570 | const bool can_debug = get_current_debugger()->is_debuggable(); |
| 571 | if (breaked) { // Show debugger. |
| 572 | EditorDockManager::get_singleton()->focus_dock(this); |
| 573 | } |
| 574 | |
| 575 | // Update script menu. |
| 576 | if (!script_menu) { |
| 577 | return; |
| 578 | } |
| 579 | PopupMenu *p = script_menu->get_popup(); |
| 580 | p->set_item_disabled(p->get_item_index(DEBUG_NEXT), !(breaked && can_debug)); |
| 581 | p->set_item_disabled(p->get_item_index(DEBUG_STEP), !(breaked && can_debug)); |
| 582 | p->set_item_disabled(p->get_item_index(DEBUG_BREAK), breaked); |
| 583 | p->set_item_disabled(p->get_item_index(DEBUG_CONTINUE), !breaked); |
| 584 | } |
| 585 | |
| 586 | void EditorDebuggerNode::_menu_option(int p_id) { |
| 587 | switch (p_id) { |
| 588 | case DEBUG_NEXT: { |
| 589 | debug_next(); |
| 590 | } break; |
| 591 | case DEBUG_STEP: { |
| 592 | debug_step(); |
| 593 | } break; |
| 594 | case DEBUG_BREAK: { |
| 595 | debug_break(); |
| 596 | } break; |
| 597 | case DEBUG_CONTINUE: { |
| 598 | debug_continue(); |
| 599 | } break; |
| 600 | case DEBUG_WITH_EXTERNAL_EDITOR: { |
| 601 | bool ischecked = script_menu->get_popup()->is_item_checked(script_menu->get_popup()->get_item_index(DEBUG_WITH_EXTERNAL_EDITOR)); |
| 602 | debug_with_external_editor = !ischecked; |
| 603 | script_menu->get_popup()->set_item_checked(script_menu->get_popup()->get_item_index(DEBUG_WITH_EXTERNAL_EDITOR), !ischecked); |
| 604 | if (!initializing) { |
| 605 | EditorSettings::get_singleton()->set_project_metadata("debug_options", "debug_with_external_editor", !ischecked); |
| 606 | } |
| 607 | } break; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | void EditorDebuggerNode::_update_debug_options() { |
| 612 | if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "debug_with_external_editor", false).operator bool()) { |
| 613 | _menu_option(DEBUG_WITH_EXTERNAL_EDITOR); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | void EditorDebuggerNode::_paused() { |
| 618 | const bool paused = EditorRunBar::get_singleton()->get_pause_button()->is_pressed(); |
| 619 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 620 | if (paused && !dbg->is_breaked()) { |
| 621 | dbg->debug_break(); |
| 622 | } else if (!paused && dbg->is_breaked()) { |
| 623 | dbg->debug_continue(); |
| 624 | } |
| 625 | }); |
| 626 | } |
| 627 | |
| 628 | void EditorDebuggerNode::_breaked(bool p_breaked, bool p_can_debug, const String &p_message, bool p_has_stackdump, int p_debugger) { |
| 629 | if (get_current_debugger() != get_debugger(p_debugger)) { |
| 630 | if (!p_breaked) { |
| 631 | return; |
| 632 | } |
| 633 | tabs->set_current_tab(p_debugger); |
| 634 | } |
| 635 | _break_state_changed(); |
| 636 | EditorRunBar::get_singleton()->get_pause_button()->set_pressed(p_breaked); |
| 637 | emit_signal(SNAME("breaked"), p_breaked, p_can_debug); |
| 638 | } |
| 639 | |
| 640 | bool EditorDebuggerNode::is_skip_breakpoints() const { |
| 641 | return get_current_debugger()->is_skip_breakpoints(); |
| 642 | } |
| 643 | |
| 644 | bool EditorDebuggerNode::is_ignore_error_breaks() const { |
| 645 | return get_default_debugger()->is_ignore_error_breaks(); |
| 646 | } |
| 647 | |
| 648 | void EditorDebuggerNode::set_breakpoint(const String &p_path, int p_line, bool p_enabled) { |
| 649 | breakpoints[Breakpoint(p_path, p_line)] = p_enabled; |
| 650 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 651 | dbg->set_breakpoint(p_path, p_line, p_enabled); |
| 652 | }); |
| 653 | |
| 654 | emit_signal(SNAME("breakpoint_toggled"), p_path, p_line, p_enabled); |
| 655 | } |
| 656 | |
| 657 | void EditorDebuggerNode::set_breakpoints(const String &p_path, const Array &p_lines) { |
| 658 | for (int i = 0; i < p_lines.size(); i++) { |
| 659 | set_breakpoint(p_path, p_lines[i], true); |
| 660 | } |
| 661 | |
| 662 | for (const KeyValue<Breakpoint, bool> &E : breakpoints) { |
| 663 | Breakpoint b = E.key; |
| 664 | if (b.source == p_path && !p_lines.has(b.line)) { |
| 665 | set_breakpoint(p_path, b.line, false); |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | void EditorDebuggerNode::reload_all_scripts() { |
| 671 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 672 | dbg->reload_all_scripts(); |
| 673 | }); |
| 674 | } |
| 675 | |
| 676 | void EditorDebuggerNode::reload_scripts(const Vector<String> &p_script_paths) { |
| 677 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 678 | dbg->reload_scripts(p_script_paths); |
| 679 | }); |
| 680 | } |
| 681 | |
| 682 | void EditorDebuggerNode::debug_next() { |
| 683 | get_current_debugger()->debug_next(); |
| 684 | } |
| 685 | |
| 686 | void EditorDebuggerNode::debug_step() { |
| 687 | get_current_debugger()->debug_step(); |
| 688 | } |
| 689 | |
| 690 | void EditorDebuggerNode::debug_break() { |
| 691 | get_current_debugger()->debug_break(); |
| 692 | } |
| 693 | |
| 694 | void EditorDebuggerNode::debug_continue() { |
| 695 | get_current_debugger()->debug_continue(); |
| 696 | } |
| 697 | |
| 698 | String EditorDebuggerNode::get_var_value(const String &p_var) const { |
| 699 | return get_current_debugger()->get_var_value(p_var); |
| 700 | } |
| 701 | |
| 702 | // LiveEdit/Inspector |
| 703 | void EditorDebuggerNode::request_remote_tree() { |
| 704 | get_current_debugger()->request_remote_tree(); |
| 705 | } |
| 706 | |
| 707 | void EditorDebuggerNode::set_remote_selection(const TypedArray<int64_t> &p_ids) { |
| 708 | stop_waiting_inspection(); |
| 709 | get_current_debugger()->request_remote_objects(p_ids); |
| 710 | } |
| 711 | |
| 712 | void EditorDebuggerNode::clear_remote_tree_selection() { |
| 713 | remote_scene_tree->clear_selection(); |
| 714 | get_current_debugger()->clear_inspector(remote_scene_tree_clear_msg); |
| 715 | } |
| 716 | |
| 717 | void EditorDebuggerNode::stop_waiting_inspection() { |
| 718 | inspect_edited_object_timeout = EDITOR_GET("debugger/remote_inspect_refresh_interval"); |
| 719 | inspect_edited_object_wait = false; |
| 720 | } |
| 721 | |
| 722 | bool EditorDebuggerNode::match_remote_selection(const TypedArray<uint64_t> &p_ids) const { |
| 723 | return p_ids == remote_scene_tree->get_selection(); |
| 724 | } |
| 725 | |
| 726 | void EditorDebuggerNode::_remote_tree_select_requested(const TypedArray<int64_t> &p_ids, int p_debugger) { |
| 727 | if (p_debugger == tabs->get_current_tab()) { |
| 728 | remote_scene_tree->select_nodes(p_ids); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | void EditorDebuggerNode::_remote_tree_clear_selection_requested(int p_debugger) { |
| 733 | if (p_debugger != tabs->get_current_tab()) { |
| 734 | return; |
| 735 | } |
| 736 | remote_scene_tree->clear_selection(); |
| 737 | remote_scene_tree_clear_msg = false; |
| 738 | get_current_debugger()->clear_inspector(false); |
| 739 | remote_scene_tree_clear_msg = true; |
| 740 | } |
| 741 | |
| 742 | void EditorDebuggerNode::_remote_tree_updated(int p_debugger) { |
| 743 | if (p_debugger != tabs->get_current_tab()) { |
| 744 | return; |
| 745 | } |
| 746 | remote_scene_tree->clear(); |
| 747 | remote_scene_tree->update_scene_tree(get_current_debugger()->get_remote_tree(), p_debugger); |
| 748 | } |
| 749 | |
| 750 | void EditorDebuggerNode::_remote_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button) { |
| 751 | if (p_button != MouseButton::LEFT) { |
| 752 | return; |
| 753 | } |
| 754 | |
| 755 | TreeItem *item = Object::cast_to<TreeItem>(p_item); |
| 756 | ERR_FAIL_NULL(item); |
| 757 | |
| 758 | if (p_id == EditorDebuggerTree::BUTTON_SUBSCENE) { |
| 759 | remote_scene_tree->emit_signal(SNAME("open"), item->get_meta("scene_file_path")); |
| 760 | } else if (p_id == EditorDebuggerTree::BUTTON_VISIBILITY) { |
| 761 | ObjectID obj_id = item->get_metadata(0); |
| 762 | ERR_FAIL_COND(obj_id.is_null()); |
| 763 | get_current_debugger()->update_remote_object(obj_id, "visible", !item->get_meta("visible")); |
| 764 | get_current_debugger()->request_remote_tree(); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | void EditorDebuggerNode::_remote_objects_updated(EditorDebuggerRemoteObjects *p_objs, int p_debugger) { |
| 769 | if (p_debugger == tabs->get_current_tab() && p_objs != InspectorDock::get_inspector_singleton()->get_edited_object()) { |
| 770 | EditorNode::get_singleton()->push_item(p_objs); |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | void EditorDebuggerNode::_remote_object_property_updated(ObjectID p_id, const String &p_property, int p_debugger) { |
| 775 | if (p_debugger != tabs->get_current_tab()) { |
| 776 | return; |
| 777 | } |
| 778 | |
| 779 | Object *obj = InspectorDock::get_inspector_singleton()->get_edited_object(); |
| 780 | if (obj && obj->get_instance_id() == p_id) { |
| 781 | InspectorDock::get_inspector_singleton()->update_property(p_property); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | void EditorDebuggerNode::_remote_objects_requested(const TypedArray<uint64_t> &p_ids, int p_debugger) { |
| 786 | if (p_debugger != tabs->get_current_tab()) { |
| 787 | return; |
| 788 | } |
| 789 | stop_waiting_inspection(); |
| 790 | get_current_debugger()->request_remote_objects(p_ids); |
| 791 | } |
| 792 | |
| 793 | void EditorDebuggerNode::_remote_selection_cleared(int p_debugger) { |
| 794 | if (p_debugger != tabs->get_current_tab()) { |
| 795 | return; |
| 796 | } |
| 797 | stop_waiting_inspection(); |
| 798 | get_current_debugger()->clear_inspector(); |
| 799 | } |
| 800 | |
| 801 | void EditorDebuggerNode::_save_node_requested(ObjectID p_id, const String &p_file, int p_debugger) { |
| 802 | if (p_debugger != tabs->get_current_tab()) { |
| 803 | return; |
| 804 | } |
| 805 | get_current_debugger()->save_node(p_id, p_file); |
| 806 | } |
| 807 | |
| 808 | void EditorDebuggerNode::_breakpoint_set_in_tree(Ref<RefCounted> p_script, int p_line, bool p_enabled, int p_debugger) { |
| 809 | if (p_debugger != tabs->get_current_tab()) { |
| 810 | return; |
| 811 | } |
| 812 | |
| 813 | emit_signal(SNAME("breakpoint_set_in_tree"), p_script, p_line, p_enabled); |
| 814 | } |
| 815 | |
| 816 | void EditorDebuggerNode::_breakpoints_cleared_in_tree(int p_debugger) { |
| 817 | if (p_debugger != tabs->get_current_tab()) { |
| 818 | return; |
| 819 | } |
| 820 | |
| 821 | emit_signal(SNAME("breakpoints_cleared_in_tree")); |
| 822 | } |
| 823 | |
| 824 | // Remote inspector/edit. |
| 825 | void EditorDebuggerNode::_methods_changed(void *p_ud, Object *p_base, const StringName &p_name, const Variant **p_args, int p_argcount) { |
| 826 | if (!singleton) { |
| 827 | return; |
| 828 | } |
| 829 | _for_all(singleton->tabs, [&](ScriptEditorDebugger *dbg) { |
| 830 | dbg->_method_changed(p_base, p_name, p_args, p_argcount); |
| 831 | }); |
| 832 | } |
| 833 | |
| 834 | void EditorDebuggerNode::_properties_changed(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value) { |
| 835 | if (!singleton) { |
| 836 | return; |
| 837 | } |
| 838 | _for_all(singleton->tabs, [&](ScriptEditorDebugger *dbg) { |
| 839 | dbg->_property_changed(p_base, p_property, p_value); |
| 840 | }); |
| 841 | } |
| 842 | |
| 843 | // LiveDebug |
| 844 | void EditorDebuggerNode::set_live_debugging(bool p_enabled) { |
| 845 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 846 | dbg->set_live_debugging(p_enabled); |
| 847 | }); |
| 848 | } |
| 849 | |
| 850 | void EditorDebuggerNode::update_live_edit_root() { |
| 851 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 852 | dbg->update_live_edit_root(); |
| 853 | }); |
| 854 | } |
| 855 | |
| 856 | void EditorDebuggerNode::live_debug_create_node(const NodePath &p_parent, const String &p_type, const String &p_name) { |
| 857 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 858 | dbg->live_debug_create_node(p_parent, p_type, p_name); |
| 859 | }); |
| 860 | } |
| 861 | |
| 862 | void EditorDebuggerNode::live_debug_instantiate_node(const NodePath &p_parent, const String &p_path, const String &p_name) { |
| 863 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 864 | dbg->live_debug_instantiate_node(p_parent, p_path, p_name); |
| 865 | }); |
| 866 | } |
| 867 | |
| 868 | void EditorDebuggerNode::live_debug_remove_node(const NodePath &p_at) { |
| 869 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 870 | dbg->live_debug_remove_node(p_at); |
| 871 | }); |
| 872 | } |
| 873 | |
| 874 | void EditorDebuggerNode::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) { |
| 875 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 876 | dbg->live_debug_remove_and_keep_node(p_at, p_keep_id); |
| 877 | }); |
| 878 | } |
| 879 | |
| 880 | void EditorDebuggerNode::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) { |
| 881 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 882 | dbg->live_debug_restore_node(p_id, p_at, p_at_pos); |
| 883 | }); |
| 884 | } |
| 885 | |
| 886 | void EditorDebuggerNode::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) { |
| 887 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 888 | dbg->live_debug_duplicate_node(p_at, p_new_name); |
| 889 | }); |
| 890 | } |
| 891 | |
| 892 | void EditorDebuggerNode::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) { |
| 893 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 894 | dbg->live_debug_reparent_node(p_at, p_new_place, p_new_name, p_at_pos); |
| 895 | }); |
| 896 | } |
| 897 | |
| 898 | void EditorDebuggerNode::set_debug_mute_audio(bool p_mute) { |
| 899 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 900 | dbg->set_debug_mute_audio(p_mute); |
| 901 | }); |
| 902 | debug_mute_audio = p_mute; |
| 903 | } |
| 904 | |
| 905 | bool EditorDebuggerNode::get_debug_mute_audio() const { |
| 906 | return debug_mute_audio; |
| 907 | } |
| 908 | |
| 909 | void EditorDebuggerNode::set_camera_override(CameraOverride p_override) { |
| 910 | _for_all(tabs, [&](ScriptEditorDebugger *dbg) { |
| 911 | dbg->set_camera_override(p_override); |
| 912 | }); |
| 913 | camera_override = p_override; |
| 914 | } |
| 915 | |
| 916 | EditorDebuggerNode::CameraOverride EditorDebuggerNode::get_camera_override() { |
| 917 | return camera_override; |
| 918 | } |
| 919 | |
| 920 | void EditorDebuggerNode::add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin) { |
| 921 | ERR_FAIL_COND_MSG(p_plugin.is_null(), "Debugger plugin is null."); |
| 922 | ERR_FAIL_COND_MSG(debugger_plugins.has(p_plugin), "Debugger plugin already exists."); |
| 923 | debugger_plugins.insert(p_plugin); |
| 924 | |
| 925 | Ref<EditorDebuggerPlugin> plugin = p_plugin; |
| 926 | for (int i = 0; get_debugger(i); i++) { |
| 927 | plugin->create_session(get_debugger(i)); |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | void EditorDebuggerNode::remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin) { |
| 932 | ERR_FAIL_COND_MSG(p_plugin.is_null(), "Debugger plugin is null."); |
| 933 | ERR_FAIL_COND_MSG(!debugger_plugins.has(p_plugin), "Debugger plugin doesn't exists."); |
| 934 | debugger_plugins.erase(p_plugin); |
| 935 | Ref<EditorDebuggerPlugin>(p_plugin)->clear(); |
| 936 | } |
| 937 | |
| 938 | bool EditorDebuggerNode::plugins_capture(ScriptEditorDebugger *p_debugger, const String &p_message, const Array &p_data) { |
| 939 | int session_index = tabs->get_tab_idx_from_control(p_debugger); |
| 940 | ERR_FAIL_COND_V(session_index < 0, false); |
| 941 | int colon_index = p_message.find_char(':'); |
| 942 | ERR_FAIL_COND_V_MSG(colon_index < 1, false, "Invalid message received."); |
| 943 | |
| 944 | const String cap = p_message.substr(0, colon_index); |
| 945 | bool parsed = false; |
| 946 | for (Ref<EditorDebuggerPlugin> plugin : debugger_plugins) { |
| 947 | if (plugin->has_capture(cap)) { |
| 948 | parsed |= plugin->capture(p_message, p_data, session_index); |
| 949 | } |
| 950 | } |
| 951 | return parsed; |
| 952 | } |