Debian Codegraph @

editor/debugger/debugger_editor_plugin.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* debugger_editor_plugin.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 "debugger_editor_plugin.h"
32
33 #include "core/os/keyboard.h"
34 #include "editor/debugger/editor_debugger_node.h"
35 #include "editor/debugger/editor_debugger_server.h"
36 #include "editor/debugger/editor_file_server.h"
37 #include "editor/docks/editor_dock_manager.h"
38 #include "editor/editor_node.h"
39 #include "editor/run/run_instances_dialog.h"
40 #include "editor/script/script_editor_plugin.h"
41 #include "editor/settings/editor_command_palette.h"
42 #include "editor/settings/editor_settings.h"
43 #include "scene/gui/popup_menu.h"
44
45 DebuggerEditorPlugin::DebuggerEditorPlugin(PopupMenu *p_debug_menu) {
46 EditorDebuggerServer::initialize();
47
48 ED_SHORTCUT("debugger/step_into", TTRC("Step Into"), Key::F11);
49 ED_SHORTCUT("debugger/step_over", TTRC("Step Over"), Key::F10);
50 ED_SHORTCUT("debugger/step_out", TTRC("Step Out"), KeyModifierMask::ALT | Key::F11);
51 ED_SHORTCUT("debugger/break", TTRC("Break"));
52 ED_SHORTCUT("debugger/continue", TTRC("Continue"), Key::F12);
53 ED_SHORTCUT("debugger/debug_with_external_editor", TTRC("Debug with External Editor"));
54
55 // File Server for deploy with remote filesystem.
56 file_server = memnew(EditorFileServer);
57
58 EditorDebuggerNode *debugger = memnew(EditorDebuggerNode);
59 EditorDockManager::get_singleton()->add_dock(debugger);
60
61 // Main editor debug menu.
62 debug_menu = p_debug_menu;
63 debug_menu->set_hide_on_checkable_item_selection(false);
64 debug_menu->add_check_shortcut(ED_SHORTCUT("editor/deploy_with_remote_debug", TTRC("Deploy with Remote Debug")), RUN_DEPLOY_REMOTE_DEBUG);
65 debug_menu->set_item_tooltip(-1,
66 TTRC("When this option is enabled, using one-click deploy will make the executable attempt to connect to this computer's IP so the running project can be debugged.\nThis option is intended to be used for remote debugging (typically with a mobile device).\nYou don't need to enable it to use the GDScript debugger locally."));
67 debug_menu->add_check_shortcut(ED_SHORTCUT("editor/small_deploy_with_network_fs", TTRC("Small Deploy with Network Filesystem")), RUN_FILE_SERVER);
68 debug_menu->set_item_tooltip(-1,
69 TTRC("When this option is enabled, using one-click deploy for Android will only export an executable without the project data.\nThe filesystem will be provided from the project by the editor over the network.\nOn Android, deploying will use the USB cable for faster performance. This option speeds up testing for projects with large assets."));
70 debug_menu->add_separator();
71 debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_collision_shapes", TTRC("Visible Collision Shapes")), RUN_DEBUG_COLLISIONS);
72 debug_menu->set_item_tooltip(-1,
73 TTRC("When this option is enabled, collision shapes and raycast nodes (for 2D and 3D) will be visible in the running project."));
74 debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_paths", TTRC("Visible Paths")), RUN_DEBUG_PATHS);
75 debug_menu->set_item_tooltip(-1,
76 TTRC("When this option is enabled, curve resources used by path nodes will be visible in the running project."));
77 debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_navigation", TTRC("Visible Navigation")), RUN_DEBUG_NAVIGATION);
78 debug_menu->set_item_tooltip(-1,
79 TTRC("When this option is enabled, navigation meshes, and polygons will be visible in the running project."));
80 debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_avoidance", TTRC("Visible Avoidance")), RUN_DEBUG_AVOIDANCE);
81 debug_menu->set_item_tooltip(-1,
82 TTRC("When this option is enabled, avoidance object shapes, radiuses, and velocities will be visible in the running project."));
83 debug_menu->add_separator();
84 debug_menu->add_check_shortcut(ED_SHORTCUT("editor/visible_canvas_redraw", TTRC("Debug CanvasItem Redraws")), RUN_DEBUG_CANVAS_REDRAW);
85 debug_menu->set_item_tooltip(-1,
86 TTRC("When this option is enabled, redraw requests of 2D objects will become visible (as a short flash) in the running project.\nThis is useful to troubleshoot low processor mode."));
87 debug_menu->add_separator();
88 debug_menu->add_check_shortcut(ED_SHORTCUT("editor/sync_scene_changes", TTRC("Synchronize Scene Changes")), RUN_LIVE_DEBUG);
89 debug_menu->set_item_tooltip(-1,
90 TTRC("When this option is enabled, any changes made to the scene in the editor will be replicated in the running project.\nWhen used remotely on a device, this is more efficient when the network filesystem option is enabled."));
91 debug_menu->add_check_shortcut(ED_SHORTCUT("editor/sync_script_changes", TTRC("Synchronize Script Changes")), RUN_RELOAD_SCRIPTS);
92 debug_menu->set_item_tooltip(-1,
93 TTRC("When this option is enabled, any script that is saved will be reloaded in the running project.\nWhen used remotely on a device, this is more efficient when the network filesystem option is enabled."));
94 debug_menu->add_check_shortcut(ED_SHORTCUT("editor/keep_server_open", TTRC("Keep Debug Server Open")), SERVER_KEEP_OPEN);
95 debug_menu->set_item_tooltip(-1,
96 TTRC("When this option is enabled, the editor debug server will stay open and listen for new sessions started outside of the editor itself."));
97
98 // Multi-instance, start/stop.
99 debug_menu->add_separator();
100 debug_menu->add_item(TTRC("Customize Run Instances..."), RUN_MULTIPLE_INSTANCES);
101 debug_menu->connect(SceneStringName(id_pressed), callable_mp(this, &DebuggerEditorPlugin::_menu_option));
102
103 run_instances_dialog = memnew(RunInstancesDialog);
104 EditorNode::get_singleton()->get_gui_base()->add_child(run_instances_dialog);
105 }
106
107 DebuggerEditorPlugin::~DebuggerEditorPlugin() {
108 EditorDebuggerServer::deinitialize();
109 memdelete(file_server);
110 }
111
112 void DebuggerEditorPlugin::_menu_option(int p_option) {
113 switch (p_option) {
114 case RUN_FILE_SERVER: {
115 bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_FILE_SERVER));
116
117 if (ischecked) {
118 file_server->stop();
119 set_process(false);
120 } else {
121 file_server->start();
122 set_process(true);
123 }
124
125 debug_menu->set_item_checked(debug_menu->get_item_index(RUN_FILE_SERVER), !ischecked);
126 if (!initializing) {
127 EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_file_server", !ischecked);
128 }
129
130 } break;
131 case RUN_LIVE_DEBUG: {
132 bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_LIVE_DEBUG));
133
134 debug_menu->set_item_checked(debug_menu->get_item_index(RUN_LIVE_DEBUG), !ischecked);
135 EditorDebuggerNode::get_singleton()->set_live_debugging(!ischecked);
136 if (!initializing) {
137 EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_live_debug", !ischecked);
138 }
139
140 } break;
141 case RUN_DEPLOY_REMOTE_DEBUG: {
142 bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEPLOY_REMOTE_DEBUG));
143 debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEPLOY_REMOTE_DEBUG), !ischecked);
144 if (!initializing) {
145 EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_deploy_remote_debug", !ischecked);
146 }
147
148 } break;
149 case RUN_DEBUG_COLLISIONS: {
150 bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEBUG_COLLISIONS));
151 debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_COLLISIONS), !ischecked);
152 if (!initializing) {
153 EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_collisions", !ischecked);
154 }
155
156 } break;
157 case RUN_DEBUG_PATHS: {
158 bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEBUG_PATHS));
159 debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_PATHS), !ischecked);
160 if (!initializing) {
161 EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_paths", !ischecked);
162 }
163
164 } break;
165 case RUN_DEBUG_NAVIGATION: {
166 bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEBUG_NAVIGATION));
167 debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_NAVIGATION), !ischecked);
168 if (!initializing) {
169 EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_navigation", !ischecked);
170 }
171
172 } break;
173 case RUN_DEBUG_AVOIDANCE: {
174 bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEBUG_AVOIDANCE));
175 debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_AVOIDANCE), !ischecked);
176 if (!initializing) {
177 EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_avoidance", !ischecked);
178 }
179
180 } break;
181 case RUN_DEBUG_CANVAS_REDRAW: {
182 bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_DEBUG_CANVAS_REDRAW));
183 debug_menu->set_item_checked(debug_menu->get_item_index(RUN_DEBUG_CANVAS_REDRAW), !ischecked);
184 if (!initializing) {
185 EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_canvas_redraw", !ischecked);
186 }
187
188 } break;
189 case RUN_RELOAD_SCRIPTS: {
190 bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(RUN_RELOAD_SCRIPTS));
191 debug_menu->set_item_checked(debug_menu->get_item_index(RUN_RELOAD_SCRIPTS), !ischecked);
192
193 ScriptEditor::get_singleton()->set_live_auto_reload_running_scripts(!ischecked);
194 if (!initializing) {
195 EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_reload_scripts", !ischecked);
196 }
197
198 } break;
199 case SERVER_KEEP_OPEN: {
200 bool ischecked = debug_menu->is_item_checked(debug_menu->get_item_index(SERVER_KEEP_OPEN));
201 debug_menu->set_item_checked(debug_menu->get_item_index(SERVER_KEEP_OPEN), !ischecked);
202
203 EditorDebuggerNode::get_singleton()->set_keep_open(!ischecked);
204 if (!initializing) {
205 EditorSettings::get_singleton()->set_project_metadata("debug_options", "server_keep_open", !ischecked);
206 }
207
208 } break;
209 case RUN_MULTIPLE_INSTANCES: {
210 run_instances_dialog->popup_dialog();
211
212 } break;
213 }
214 }
215
216 void DebuggerEditorPlugin::_notification(int p_what) {
217 switch (p_what) {
218 case NOTIFICATION_READY: {
219 _update_debug_options();
220 initializing = false;
221 } break;
222
223 case NOTIFICATION_PROCESS: {
224 file_server->poll();
225 } break;
226 }
227 }
228
229 void DebuggerEditorPlugin::_update_debug_options() {
230 bool check_deploy_remote = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_deploy_remote_debug", true);
231 bool check_file_server = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_file_server", false);
232 bool check_debug_collisions = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisions", false);
233 bool check_debug_paths = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_paths", false);
234 bool check_debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false);
235 bool check_debug_avoidance = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_avoidance", false);
236 bool check_debug_canvas_redraw = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_canvas_redraw", false);
237 bool check_live_debug = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_live_debug", true);
238 bool check_reload_scripts = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_reload_scripts", true);
239 bool check_server_keep_open = EditorSettings::get_singleton()->get_project_metadata("debug_options", "server_keep_open", false);
240
241 if (check_deploy_remote) {
242 _menu_option(RUN_DEPLOY_REMOTE_DEBUG);
243 }
244 if (check_file_server) {
245 _menu_option(RUN_FILE_SERVER);
246 }
247 if (check_debug_collisions) {
248 _menu_option(RUN_DEBUG_COLLISIONS);
249 }
250 if (check_debug_paths) {
251 _menu_option(RUN_DEBUG_PATHS);
252 }
253 if (check_debug_navigation) {
254 _menu_option(RUN_DEBUG_NAVIGATION);
255 }
256 if (check_debug_avoidance) {
257 _menu_option(RUN_DEBUG_AVOIDANCE);
258 }
259 if (check_debug_canvas_redraw) {
260 _menu_option(RUN_DEBUG_CANVAS_REDRAW);
261 }
262 if (check_live_debug) {
263 _menu_option(RUN_LIVE_DEBUG);
264 }
265 if (check_reload_scripts) {
266 _menu_option(RUN_RELOAD_SCRIPTS);
267 }
268 if (check_server_keep_open) {
269 _menu_option(SERVER_KEEP_OPEN);
270 }
271 }