script_text_editor.cpp 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027
  1. /*************************************************************************/
  2. /* script_text_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #include "script_text_editor.h"
  31. #include "core/math/expression.h"
  32. #include "core/os/keyboard.h"
  33. #include "editor/debugger/editor_debugger_node.h"
  34. #include "editor/editor_command_palette.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_scale.h"
  37. #include "editor/editor_settings.h"
  38. void ConnectionInfoDialog::ok_pressed() {
  39. }
  40. void ConnectionInfoDialog::popup_connections(String p_method, Vector<Node *> p_nodes) {
  41. method->set_text(p_method);
  42. tree->clear();
  43. TreeItem *root = tree->create_item();
  44. for (int i = 0; i < p_nodes.size(); i++) {
  45. List<Connection> all_connections;
  46. p_nodes[i]->get_signals_connected_to_this(&all_connections);
  47. for (const Connection &connection : all_connections) {
  48. if (connection.callable.get_method() != p_method) {
  49. continue;
  50. }
  51. TreeItem *node_item = tree->create_item(root);
  52. node_item->set_text(0, Object::cast_to<Node>(connection.signal.get_object())->get_name());
  53. node_item->set_icon(0, EditorNode::get_singleton()->get_object_icon(connection.signal.get_object(), "Node"));
  54. node_item->set_selectable(0, false);
  55. node_item->set_editable(0, false);
  56. node_item->set_text(1, connection.signal.get_name());
  57. Control *p = Object::cast_to<Control>(get_parent());
  58. node_item->set_icon(1, p->get_theme_icon(SNAME("Slot"), SNAME("EditorIcons")));
  59. node_item->set_selectable(1, false);
  60. node_item->set_editable(1, false);
  61. node_item->set_text(2, Object::cast_to<Node>(connection.callable.get_object())->get_name());
  62. node_item->set_icon(2, EditorNode::get_singleton()->get_object_icon(connection.callable.get_object(), "Node"));
  63. node_item->set_selectable(2, false);
  64. node_item->set_editable(2, false);
  65. }
  66. }
  67. popup_centered(Size2(600, 300) * EDSCALE);
  68. }
  69. ConnectionInfoDialog::ConnectionInfoDialog() {
  70. set_title(TTR("Connections to method:"));
  71. VBoxContainer *vbc = memnew(VBoxContainer);
  72. vbc->set_anchor_and_offset(SIDE_LEFT, Control::ANCHOR_BEGIN, 8 * EDSCALE);
  73. vbc->set_anchor_and_offset(SIDE_TOP, Control::ANCHOR_BEGIN, 8 * EDSCALE);
  74. vbc->set_anchor_and_offset(SIDE_RIGHT, Control::ANCHOR_END, -8 * EDSCALE);
  75. vbc->set_anchor_and_offset(SIDE_BOTTOM, Control::ANCHOR_END, -8 * EDSCALE);
  76. add_child(vbc);
  77. method = memnew(Label);
  78. method->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  79. vbc->add_child(method);
  80. tree = memnew(Tree);
  81. tree->set_columns(3);
  82. tree->set_hide_root(true);
  83. tree->set_column_titles_visible(true);
  84. tree->set_column_title(0, TTR("Source"));
  85. tree->set_column_title(1, TTR("Signal"));
  86. tree->set_column_title(2, TTR("Target"));
  87. vbc->add_child(tree);
  88. tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  89. tree->set_allow_rmb_select(true);
  90. }
  91. ////////////////////////////////////////////////////////////////////////////////
  92. Vector<String> ScriptTextEditor::get_functions() {
  93. CodeEdit *te = code_editor->get_text_editor();
  94. String text = te->get_text();
  95. List<String> fnc;
  96. if (script->get_language()->validate(text, script->get_path(), &fnc)) {
  97. //if valid rewrite functions to latest
  98. functions.clear();
  99. for (const String &E : fnc) {
  100. functions.push_back(E);
  101. }
  102. }
  103. return functions;
  104. }
  105. void ScriptTextEditor::apply_code() {
  106. if (script.is_null()) {
  107. return;
  108. }
  109. script->set_source_code(code_editor->get_text_editor()->get_text());
  110. script->update_exports();
  111. code_editor->get_text_editor()->get_syntax_highlighter()->update_cache();
  112. }
  113. RES ScriptTextEditor::get_edited_resource() const {
  114. return script;
  115. }
  116. void ScriptTextEditor::set_edited_resource(const RES &p_res) {
  117. ERR_FAIL_COND(script.is_valid());
  118. ERR_FAIL_COND(p_res.is_null());
  119. script = p_res;
  120. code_editor->get_text_editor()->set_text(script->get_source_code());
  121. code_editor->get_text_editor()->clear_undo_history();
  122. code_editor->get_text_editor()->tag_saved_version();
  123. emit_signal(SNAME("name_changed"));
  124. code_editor->update_line_and_column();
  125. }
  126. void ScriptTextEditor::enable_editor() {
  127. if (editor_enabled) {
  128. return;
  129. }
  130. editor_enabled = true;
  131. _enable_code_editor();
  132. _validate_script();
  133. }
  134. void ScriptTextEditor::_load_theme_settings() {
  135. CodeEdit *text_edit = code_editor->get_text_editor();
  136. Color updated_marked_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color");
  137. Color updated_safe_line_number_color = EDITOR_GET("text_editor/theme/highlighting/safe_line_number_color");
  138. bool safe_line_number_color_updated = updated_safe_line_number_color != safe_line_number_color;
  139. bool marked_line_color_updated = updated_marked_line_color != marked_line_color;
  140. if (safe_line_number_color_updated || marked_line_color_updated) {
  141. safe_line_number_color = updated_safe_line_number_color;
  142. for (int i = 0; i < text_edit->get_line_count(); i++) {
  143. if (marked_line_color_updated && text_edit->get_line_background_color(i) == marked_line_color) {
  144. text_edit->set_line_background_color(i, updated_marked_line_color);
  145. }
  146. if (safe_line_number_color_updated && text_edit->get_line_gutter_item_color(i, line_number_gutter) != default_line_number_color) {
  147. text_edit->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color);
  148. }
  149. }
  150. marked_line_color = updated_marked_line_color;
  151. }
  152. theme_loaded = true;
  153. if (!script.is_null()) {
  154. _set_theme_for_script();
  155. }
  156. }
  157. void ScriptTextEditor::_set_theme_for_script() {
  158. if (!theme_loaded) {
  159. return;
  160. }
  161. CodeEdit *text_edit = code_editor->get_text_editor();
  162. text_edit->get_syntax_highlighter()->update_cache();
  163. List<String> strings;
  164. script->get_language()->get_string_delimiters(&strings);
  165. text_edit->clear_string_delimiters();
  166. for (const String &string : strings) {
  167. String beg = string.get_slice(" ", 0);
  168. String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String();
  169. if (!text_edit->has_string_delimiter(beg)) {
  170. text_edit->add_string_delimiter(beg, end, end.is_empty());
  171. }
  172. if (!end.is_empty() && !text_edit->has_auto_brace_completion_open_key(beg)) {
  173. text_edit->add_auto_brace_completion_pair(beg, end);
  174. }
  175. }
  176. List<String> comments;
  177. script->get_language()->get_comment_delimiters(&comments);
  178. text_edit->clear_comment_delimiters();
  179. for (const String &comment : comments) {
  180. String beg = comment.get_slice(" ", 0);
  181. String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String();
  182. text_edit->add_comment_delimiter(beg, end, end.is_empty());
  183. if (!end.is_empty() && !text_edit->has_auto_brace_completion_open_key(beg)) {
  184. text_edit->add_auto_brace_completion_pair(beg, end);
  185. }
  186. }
  187. }
  188. void ScriptTextEditor::_show_errors_panel(bool p_show) {
  189. errors_panel->set_visible(p_show);
  190. }
  191. void ScriptTextEditor::_show_warnings_panel(bool p_show) {
  192. warnings_panel->set_visible(p_show);
  193. }
  194. void ScriptTextEditor::_warning_clicked(Variant p_line) {
  195. if (p_line.get_type() == Variant::INT) {
  196. goto_line_centered(p_line.operator int64_t());
  197. }
  198. }
  199. void ScriptTextEditor::_error_clicked(Variant p_line) {
  200. if (p_line.get_type() == Variant::INT) {
  201. code_editor->get_text_editor()->set_caret_line(p_line.operator int64_t());
  202. }
  203. }
  204. void ScriptTextEditor::reload_text() {
  205. ERR_FAIL_COND(script.is_null());
  206. CodeEdit *te = code_editor->get_text_editor();
  207. int column = te->get_caret_column();
  208. int row = te->get_caret_line();
  209. int h = te->get_h_scroll();
  210. int v = te->get_v_scroll();
  211. te->set_text(script->get_source_code());
  212. te->set_caret_line(row);
  213. te->set_caret_column(column);
  214. te->set_h_scroll(h);
  215. te->set_v_scroll(v);
  216. te->tag_saved_version();
  217. code_editor->update_line_and_column();
  218. }
  219. void ScriptTextEditor::add_callback(const String &p_function, PackedStringArray p_args) {
  220. String code = code_editor->get_text_editor()->get_text();
  221. int pos = script->get_language()->find_function(p_function, code);
  222. if (pos == -1) {
  223. //does not exist
  224. code_editor->get_text_editor()->deselect();
  225. pos = code_editor->get_text_editor()->get_line_count() + 2;
  226. String func = script->get_language()->make_function("", p_function, p_args);
  227. //code=code+func;
  228. code_editor->get_text_editor()->set_caret_line(pos + 1);
  229. code_editor->get_text_editor()->set_caret_column(1000000); //none shall be that big
  230. code_editor->get_text_editor()->insert_text_at_caret("\n\n" + func);
  231. }
  232. code_editor->get_text_editor()->set_caret_line(pos);
  233. code_editor->get_text_editor()->set_caret_column(1);
  234. }
  235. bool ScriptTextEditor::show_members_overview() {
  236. return true;
  237. }
  238. void ScriptTextEditor::update_settings() {
  239. code_editor->get_text_editor()->set_gutter_draw(connection_gutter, EditorSettings::get_singleton()->get("text_editor/appearance/gutters/show_info_gutter"));
  240. code_editor->update_editor_settings();
  241. }
  242. bool ScriptTextEditor::is_unsaved() {
  243. const bool unsaved =
  244. code_editor->get_text_editor()->get_version() != code_editor->get_text_editor()->get_saved_version() ||
  245. script->get_path().is_empty(); // In memory.
  246. return unsaved;
  247. }
  248. Variant ScriptTextEditor::get_edit_state() {
  249. return code_editor->get_edit_state();
  250. }
  251. void ScriptTextEditor::set_edit_state(const Variant &p_state) {
  252. code_editor->set_edit_state(p_state);
  253. Dictionary state = p_state;
  254. if (state.has("syntax_highlighter")) {
  255. int idx = highlighter_menu->get_item_idx_from_text(state["syntax_highlighter"]);
  256. if (idx >= 0) {
  257. _change_syntax_highlighter(idx);
  258. }
  259. }
  260. if (editor_enabled) {
  261. ensure_focus();
  262. }
  263. }
  264. void ScriptTextEditor::_convert_case(CodeTextEditor::CaseStyle p_case) {
  265. code_editor->convert_case(p_case);
  266. }
  267. void ScriptTextEditor::trim_trailing_whitespace() {
  268. code_editor->trim_trailing_whitespace();
  269. }
  270. void ScriptTextEditor::insert_final_newline() {
  271. code_editor->insert_final_newline();
  272. }
  273. void ScriptTextEditor::convert_indent_to_spaces() {
  274. code_editor->convert_indent_to_spaces();
  275. }
  276. void ScriptTextEditor::convert_indent_to_tabs() {
  277. code_editor->convert_indent_to_tabs();
  278. }
  279. void ScriptTextEditor::tag_saved_version() {
  280. code_editor->get_text_editor()->tag_saved_version();
  281. }
  282. void ScriptTextEditor::goto_line(int p_line, bool p_with_error) {
  283. code_editor->goto_line(p_line);
  284. }
  285. void ScriptTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) {
  286. code_editor->goto_line_selection(p_line, p_begin, p_end);
  287. }
  288. void ScriptTextEditor::goto_line_centered(int p_line) {
  289. code_editor->goto_line_centered(p_line);
  290. }
  291. void ScriptTextEditor::set_executing_line(int p_line) {
  292. code_editor->set_executing_line(p_line);
  293. }
  294. void ScriptTextEditor::clear_executing_line() {
  295. code_editor->clear_executing_line();
  296. }
  297. void ScriptTextEditor::ensure_focus() {
  298. code_editor->get_text_editor()->grab_focus();
  299. }
  300. String ScriptTextEditor::get_name() {
  301. String name;
  302. name = script->get_path().get_file();
  303. if (name.is_empty()) {
  304. // This appears for newly created built-in scripts before saving the scene.
  305. name = TTR("[unsaved]");
  306. } else if (script->is_built_in()) {
  307. const String &script_name = script->get_name();
  308. if (!script_name.is_empty()) {
  309. // If the built-in script has a custom resource name defined,
  310. // display the built-in script name as follows: `ResourceName (scene_file.tscn)`
  311. name = vformat("%s (%s)", script_name, name.get_slice("::", 0));
  312. }
  313. }
  314. if (is_unsaved()) {
  315. name += "(*)";
  316. }
  317. return name;
  318. }
  319. Ref<Texture2D> ScriptTextEditor::get_theme_icon() {
  320. if (get_parent_control()) {
  321. String icon_name = script->get_class();
  322. if (script->is_built_in()) {
  323. icon_name += "Internal";
  324. }
  325. if (get_parent_control()->has_theme_icon(icon_name, SNAME("EditorIcons"))) {
  326. return get_parent_control()->get_theme_icon(icon_name, SNAME("EditorIcons"));
  327. } else if (get_parent_control()->has_theme_icon(script->get_class(), SNAME("EditorIcons"))) {
  328. return get_parent_control()->get_theme_icon(script->get_class(), SNAME("EditorIcons"));
  329. }
  330. }
  331. return Ref<Texture2D>();
  332. }
  333. void ScriptTextEditor::_validate_script() {
  334. CodeEdit *te = code_editor->get_text_editor();
  335. String text = te->get_text();
  336. List<String> fnc;
  337. warnings.clear();
  338. errors.clear();
  339. safe_lines.clear();
  340. if (!script->get_language()->validate(text, script->get_path(), &fnc, &errors, &warnings, &safe_lines)) {
  341. // TRANSLATORS: Script error pointing to a line and column number.
  342. String error_text = vformat(TTR("Error at (%d, %d):"), errors[0].line, errors[0].column) + " " + errors[0].message;
  343. code_editor->set_error(error_text);
  344. code_editor->set_error_pos(errors[0].line - 1, errors[0].column - 1);
  345. script_is_valid = false;
  346. } else {
  347. code_editor->set_error("");
  348. if (!script->is_tool()) {
  349. script->set_source_code(text);
  350. script->update_exports();
  351. te->get_syntax_highlighter()->update_cache();
  352. }
  353. functions.clear();
  354. for (const String &E : fnc) {
  355. functions.push_back(E);
  356. }
  357. script_is_valid = true;
  358. }
  359. _update_connected_methods();
  360. _update_warnings();
  361. _update_errors();
  362. emit_signal(SNAME("name_changed"));
  363. emit_signal(SNAME("edited_script_changed"));
  364. }
  365. void ScriptTextEditor::_update_warnings() {
  366. int warning_nb = warnings.size();
  367. warnings_panel->clear();
  368. bool has_connections_table = false;
  369. // Add missing connections.
  370. if (GLOBAL_GET("debug/gdscript/warnings/enable").booleanize()) {
  371. Node *base = get_tree()->get_edited_scene_root();
  372. if (base && missing_connections.size() > 0) {
  373. has_connections_table = true;
  374. warnings_panel->push_table(1);
  375. for (const Connection &connection : missing_connections) {
  376. String base_path = base->get_name();
  377. String source_path = base == connection.signal.get_object() ? base_path : base_path + "/" + base->get_path_to(Object::cast_to<Node>(connection.signal.get_object()));
  378. String target_path = base == connection.callable.get_object() ? base_path : base_path + "/" + base->get_path_to(Object::cast_to<Node>(connection.callable.get_object()));
  379. warnings_panel->push_cell();
  380. warnings_panel->push_color(warnings_panel->get_theme_color(SNAME("warning_color"), SNAME("Editor")));
  381. warnings_panel->add_text(vformat(TTR("Missing connected method '%s' for signal '%s' from node '%s' to node '%s'."), connection.callable.get_method(), connection.signal.get_name(), source_path, target_path));
  382. warnings_panel->pop(); // Color.
  383. warnings_panel->pop(); // Cell.
  384. }
  385. warnings_panel->pop(); // Table.
  386. warning_nb += missing_connections.size();
  387. }
  388. }
  389. code_editor->set_warning_count(warning_nb);
  390. if (has_connections_table) {
  391. warnings_panel->add_newline();
  392. }
  393. // Add script warnings.
  394. warnings_panel->push_table(2);
  395. for (const ScriptLanguage::Warning &w : warnings) {
  396. warnings_panel->push_cell();
  397. warnings_panel->push_meta(w.start_line - 1);
  398. warnings_panel->push_color(warnings_panel->get_theme_color(SNAME("warning_color"), SNAME("Editor")));
  399. warnings_panel->add_text(TTR("Line") + " " + itos(w.start_line));
  400. warnings_panel->add_text(" (" + w.string_code + "):");
  401. warnings_panel->pop(); // Color.
  402. warnings_panel->pop(); // Meta goto.
  403. warnings_panel->pop(); // Cell.
  404. warnings_panel->push_cell();
  405. warnings_panel->add_text(w.message);
  406. warnings_panel->pop(); // Cell.
  407. }
  408. warnings_panel->pop(); // Table.
  409. }
  410. void ScriptTextEditor::_update_errors() {
  411. code_editor->set_error_count(errors.size());
  412. errors_panel->clear();
  413. errors_panel->push_table(2);
  414. for (const ScriptLanguage::ScriptError &err : errors) {
  415. errors_panel->push_cell();
  416. errors_panel->push_meta(err.line - 1);
  417. errors_panel->push_color(warnings_panel->get_theme_color(SNAME("error_color"), SNAME("Editor")));
  418. errors_panel->add_text(TTR("Line") + " " + itos(err.line) + ":");
  419. errors_panel->pop(); // Color.
  420. errors_panel->pop(); // Meta goto.
  421. errors_panel->pop(); // Cell.
  422. errors_panel->push_cell();
  423. errors_panel->add_text(err.message);
  424. errors_panel->pop(); // Cell.
  425. }
  426. errors_panel->pop(); // Table
  427. CodeEdit *te = code_editor->get_text_editor();
  428. bool highlight_safe = EDITOR_DEF("text_editor/appearance/gutters/highlight_type_safe_lines", true);
  429. bool last_is_safe = false;
  430. for (int i = 0; i < te->get_line_count(); i++) {
  431. if (errors.is_empty()) {
  432. te->set_line_background_color(i, Color(0, 0, 0, 0));
  433. } else {
  434. for (const ScriptLanguage::ScriptError &E : errors) {
  435. bool error_line = i == E.line - 1;
  436. te->set_line_background_color(i, error_line ? marked_line_color : Color(0, 0, 0, 0));
  437. if (error_line) {
  438. break;
  439. }
  440. }
  441. }
  442. if (highlight_safe) {
  443. if (safe_lines.has(i + 1)) {
  444. te->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color);
  445. last_is_safe = true;
  446. } else if (last_is_safe && (te->is_in_comment(i) != -1 || te->get_line(i).strip_edges().is_empty())) {
  447. te->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color);
  448. } else {
  449. te->set_line_gutter_item_color(i, line_number_gutter, default_line_number_color);
  450. last_is_safe = false;
  451. }
  452. } else {
  453. te->set_line_gutter_item_color(i, 1, default_line_number_color);
  454. }
  455. }
  456. }
  457. void ScriptTextEditor::_update_bookmark_list() {
  458. bookmarks_menu->clear();
  459. bookmarks_menu->reset_size();
  460. bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
  461. bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL);
  462. bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT);
  463. bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV);
  464. Array bookmark_list = code_editor->get_text_editor()->get_bookmarked_lines();
  465. if (bookmark_list.size() == 0) {
  466. return;
  467. }
  468. bookmarks_menu->add_separator();
  469. for (int i = 0; i < bookmark_list.size(); i++) {
  470. // Strip edges to remove spaces or tabs.
  471. // Also replace any tabs by spaces, since we can't print tabs in the menu.
  472. String line = code_editor->get_text_editor()->get_line(bookmark_list[i]).replace("\t", " ").strip_edges();
  473. // Limit the size of the line if too big.
  474. if (line.length() > 50) {
  475. line = line.substr(0, 50);
  476. }
  477. bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - `" + line + "`");
  478. bookmarks_menu->set_item_metadata(bookmarks_menu->get_item_count() - 1, bookmark_list[i]);
  479. }
  480. }
  481. void ScriptTextEditor::_bookmark_item_pressed(int p_idx) {
  482. if (p_idx < 4) { // Any item before the separator.
  483. _edit_option(bookmarks_menu->get_item_id(p_idx));
  484. } else {
  485. code_editor->goto_line_centered(bookmarks_menu->get_item_metadata(p_idx));
  486. }
  487. }
  488. static Vector<Node *> _find_all_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) {
  489. Vector<Node *> nodes;
  490. if (p_current->get_owner() != p_base && p_base != p_current) {
  491. return nodes;
  492. }
  493. Ref<Script> c = p_current->get_script();
  494. if (c == p_script) {
  495. nodes.push_back(p_current);
  496. }
  497. for (int i = 0; i < p_current->get_child_count(); i++) {
  498. Vector<Node *> found = _find_all_node_for_script(p_base, p_current->get_child(i), p_script);
  499. nodes.append_array(found);
  500. }
  501. return nodes;
  502. }
  503. static Node *_find_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) {
  504. if (p_current->get_owner() != p_base && p_base != p_current) {
  505. return nullptr;
  506. }
  507. Ref<Script> c = p_current->get_script();
  508. if (c == p_script) {
  509. return p_current;
  510. }
  511. for (int i = 0; i < p_current->get_child_count(); i++) {
  512. Node *found = _find_node_for_script(p_base, p_current->get_child(i), p_script);
  513. if (found) {
  514. return found;
  515. }
  516. }
  517. return nullptr;
  518. }
  519. static void _find_changed_scripts_for_external_editor(Node *p_base, Node *p_current, Set<Ref<Script>> &r_scripts) {
  520. if (p_current->get_owner() != p_base && p_base != p_current) {
  521. return;
  522. }
  523. Ref<Script> c = p_current->get_script();
  524. if (c.is_valid()) {
  525. r_scripts.insert(c);
  526. }
  527. for (int i = 0; i < p_current->get_child_count(); i++) {
  528. _find_changed_scripts_for_external_editor(p_base, p_current->get_child(i), r_scripts);
  529. }
  530. }
  531. void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_for_script) {
  532. if (!bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) {
  533. return;
  534. }
  535. ERR_FAIL_COND(!get_tree());
  536. Set<Ref<Script>> scripts;
  537. Node *base = get_tree()->get_edited_scene_root();
  538. if (base) {
  539. _find_changed_scripts_for_external_editor(base, base, scripts);
  540. }
  541. for (Set<Ref<Script>>::Element *E = scripts.front(); E; E = E->next()) {
  542. Ref<Script> script = E->get();
  543. if (p_for_script.is_valid() && p_for_script != script) {
  544. continue;
  545. }
  546. if (script->is_built_in()) {
  547. continue; //internal script, who cares, though weird
  548. }
  549. uint64_t last_date = script->get_last_modified_time();
  550. uint64_t date = FileAccess::get_modified_time(script->get_path());
  551. if (last_date != date) {
  552. Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE);
  553. ERR_CONTINUE(!rel_script.is_valid());
  554. script->set_source_code(rel_script->get_source_code());
  555. script->set_last_modified_time(rel_script->get_last_modified_time());
  556. script->update_exports();
  557. _trigger_live_script_reload();
  558. }
  559. }
  560. }
  561. void ScriptTextEditor::_code_complete_scripts(void *p_ud, const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_force) {
  562. ScriptTextEditor *ste = (ScriptTextEditor *)p_ud;
  563. ste->_code_complete_script(p_code, r_options, r_force);
  564. }
  565. void ScriptTextEditor::_code_complete_script(const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_force) {
  566. if (color_panel->is_visible()) {
  567. return;
  568. }
  569. Node *base = get_tree()->get_edited_scene_root();
  570. if (base) {
  571. base = _find_node_for_script(base, base, script);
  572. }
  573. String hint;
  574. Error err = script->get_language()->complete_code(p_code, script->get_path(), base, r_options, r_force, hint);
  575. if (err == OK) {
  576. code_editor->get_text_editor()->set_code_hint(hint);
  577. }
  578. }
  579. void ScriptTextEditor::_update_breakpoint_list() {
  580. breakpoints_menu->clear();
  581. breakpoints_menu->reset_size();
  582. breakpoints_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_breakpoint"), DEBUG_TOGGLE_BREAKPOINT);
  583. breakpoints_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_breakpoints"), DEBUG_REMOVE_ALL_BREAKPOINTS);
  584. breakpoints_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_breakpoint"), DEBUG_GOTO_NEXT_BREAKPOINT);
  585. breakpoints_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_breakpoint"), DEBUG_GOTO_PREV_BREAKPOINT);
  586. Array breakpoint_list = code_editor->get_text_editor()->get_breakpointed_lines();
  587. if (breakpoint_list.size() == 0) {
  588. return;
  589. }
  590. breakpoints_menu->add_separator();
  591. for (int i = 0; i < breakpoint_list.size(); i++) {
  592. // Strip edges to remove spaces or tabs.
  593. // Also replace any tabs by spaces, since we can't print tabs in the menu.
  594. String line = code_editor->get_text_editor()->get_line(breakpoint_list[i]).replace("\t", " ").strip_edges();
  595. // Limit the size of the line if too big.
  596. if (line.length() > 50) {
  597. line = line.substr(0, 50);
  598. }
  599. breakpoints_menu->add_item(String::num((int)breakpoint_list[i] + 1) + " - `" + line + "`");
  600. breakpoints_menu->set_item_metadata(breakpoints_menu->get_item_count() - 1, breakpoint_list[i]);
  601. }
  602. }
  603. void ScriptTextEditor::_breakpoint_item_pressed(int p_idx) {
  604. if (p_idx < 4) { // Any item before the separator.
  605. _edit_option(breakpoints_menu->get_item_id(p_idx));
  606. } else {
  607. code_editor->goto_line(breakpoints_menu->get_item_metadata(p_idx));
  608. code_editor->get_text_editor()->call_deferred(SNAME("center_viewport_to_caret")); //Need to be deferred, because goto uses call_deferred().
  609. }
  610. }
  611. void ScriptTextEditor::_breakpoint_toggled(int p_row) {
  612. EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), p_row + 1, code_editor->get_text_editor()->is_line_breakpointed(p_row));
  613. }
  614. void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_column) {
  615. Node *base = get_tree()->get_edited_scene_root();
  616. if (base) {
  617. base = _find_node_for_script(base, base, script);
  618. }
  619. ScriptLanguage::LookupResult result;
  620. if (ScriptServer::is_global_class(p_symbol)) {
  621. EditorNode::get_singleton()->load_resource(ScriptServer::get_global_class_path(p_symbol));
  622. } else if (p_symbol.is_resource_file()) {
  623. List<String> scene_extensions;
  624. ResourceLoader::get_recognized_extensions_for_type("PackedScene", &scene_extensions);
  625. if (scene_extensions.find(p_symbol.get_extension())) {
  626. EditorNode::get_singleton()->load_scene(p_symbol);
  627. } else {
  628. EditorNode::get_singleton()->load_resource(p_symbol);
  629. }
  630. } else if (script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), p_symbol, script->get_path(), base, result) == OK) {
  631. _goto_line(p_row);
  632. switch (result.type) {
  633. case ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION: {
  634. if (result.script.is_valid()) {
  635. emit_signal(SNAME("request_open_script_at_line"), result.script, result.location - 1);
  636. } else {
  637. emit_signal(SNAME("request_save_history"));
  638. goto_line_centered(result.location - 1);
  639. }
  640. } break;
  641. case ScriptLanguage::LookupResult::RESULT_CLASS: {
  642. emit_signal(SNAME("go_to_help"), "class_name:" + result.class_name);
  643. } break;
  644. case ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT: {
  645. StringName cname = result.class_name;
  646. bool success;
  647. while (true) {
  648. ClassDB::get_integer_constant(cname, result.class_member, &success);
  649. if (success) {
  650. result.class_name = cname;
  651. cname = ClassDB::get_parent_class(cname);
  652. } else {
  653. break;
  654. }
  655. }
  656. emit_signal(SNAME("go_to_help"), "class_constant:" + result.class_name + ":" + result.class_member);
  657. } break;
  658. case ScriptLanguage::LookupResult::RESULT_CLASS_PROPERTY: {
  659. emit_signal(SNAME("go_to_help"), "class_property:" + result.class_name + ":" + result.class_member);
  660. } break;
  661. case ScriptLanguage::LookupResult::RESULT_CLASS_METHOD: {
  662. StringName cname = result.class_name;
  663. while (true) {
  664. if (ClassDB::has_method(cname, result.class_member)) {
  665. result.class_name = cname;
  666. cname = ClassDB::get_parent_class(cname);
  667. } else {
  668. break;
  669. }
  670. }
  671. emit_signal(SNAME("go_to_help"), "class_method:" + result.class_name + ":" + result.class_member);
  672. } break;
  673. case ScriptLanguage::LookupResult::RESULT_CLASS_ENUM: {
  674. StringName cname = result.class_name;
  675. StringName success;
  676. while (true) {
  677. success = ClassDB::get_integer_constant_enum(cname, result.class_member, true);
  678. if (success != StringName()) {
  679. result.class_name = cname;
  680. cname = ClassDB::get_parent_class(cname);
  681. } else {
  682. break;
  683. }
  684. }
  685. emit_signal(SNAME("go_to_help"), "class_enum:" + result.class_name + ":" + result.class_member);
  686. } break;
  687. case ScriptLanguage::LookupResult::RESULT_CLASS_TBD_GLOBALSCOPE: {
  688. emit_signal(SNAME("go_to_help"), "class_global:" + result.class_name + ":" + result.class_member);
  689. } break;
  690. }
  691. } else if (ProjectSettings::get_singleton()->has_autoload(p_symbol)) {
  692. // Check for Autoload scenes.
  693. const ProjectSettings::AutoloadInfo &info = ProjectSettings::get_singleton()->get_autoload(p_symbol);
  694. if (info.is_singleton) {
  695. EditorNode::get_singleton()->load_scene(info.path);
  696. }
  697. } else if (p_symbol.is_relative_path()) {
  698. // Every symbol other than absolute path is relative path so keep this condition at last.
  699. String path = _get_absolute_path(p_symbol);
  700. if (FileAccess::exists(path)) {
  701. List<String> scene_extensions;
  702. ResourceLoader::get_recognized_extensions_for_type("PackedScene", &scene_extensions);
  703. if (scene_extensions.find(path.get_extension())) {
  704. EditorNode::get_singleton()->load_scene(path);
  705. } else {
  706. EditorNode::get_singleton()->load_resource(path);
  707. }
  708. }
  709. }
  710. }
  711. void ScriptTextEditor::_validate_symbol(const String &p_symbol) {
  712. CodeEdit *text_edit = code_editor->get_text_editor();
  713. Node *base = get_tree()->get_edited_scene_root();
  714. if (base) {
  715. base = _find_node_for_script(base, base, script);
  716. }
  717. ScriptLanguage::LookupResult result;
  718. if (ScriptServer::is_global_class(p_symbol) || p_symbol.is_resource_file() || script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), p_symbol, script->get_path(), base, result) == OK || (ProjectSettings::get_singleton()->has_autoload(p_symbol) && ProjectSettings::get_singleton()->get_autoload(p_symbol).is_singleton)) {
  719. text_edit->set_symbol_lookup_word_as_valid(true);
  720. } else if (p_symbol.is_relative_path()) {
  721. String path = _get_absolute_path(p_symbol);
  722. if (FileAccess::exists(path)) {
  723. text_edit->set_symbol_lookup_word_as_valid(true);
  724. } else {
  725. text_edit->set_symbol_lookup_word_as_valid(false);
  726. }
  727. } else {
  728. text_edit->set_symbol_lookup_word_as_valid(false);
  729. }
  730. }
  731. String ScriptTextEditor::_get_absolute_path(const String &rel_path) {
  732. String base_path = script->get_path().get_base_dir();
  733. String path = base_path.plus_file(rel_path);
  734. return path.replace("///", "//").simplify_path();
  735. }
  736. void ScriptTextEditor::update_toggle_scripts_button() {
  737. code_editor->update_toggle_scripts_button();
  738. }
  739. void ScriptTextEditor::_update_connected_methods() {
  740. CodeEdit *text_edit = code_editor->get_text_editor();
  741. text_edit->set_gutter_width(connection_gutter, text_edit->get_line_height());
  742. for (int i = 0; i < text_edit->get_line_count(); i++) {
  743. if (text_edit->get_line_gutter_metadata(i, connection_gutter) == "") {
  744. continue;
  745. }
  746. text_edit->set_line_gutter_metadata(i, connection_gutter, "");
  747. text_edit->set_line_gutter_icon(i, connection_gutter, nullptr);
  748. text_edit->set_line_gutter_clickable(i, connection_gutter, false);
  749. }
  750. missing_connections.clear();
  751. if (!script_is_valid) {
  752. return;
  753. }
  754. Node *base = get_tree()->get_edited_scene_root();
  755. if (!base) {
  756. return;
  757. }
  758. Vector<Node *> nodes = _find_all_node_for_script(base, base, script);
  759. Set<StringName> methods_found;
  760. for (int i = 0; i < nodes.size(); i++) {
  761. List<Connection> connections;
  762. nodes[i]->get_signals_connected_to_this(&connections);
  763. for (const Connection &connection : connections) {
  764. if (!(connection.flags & CONNECT_PERSIST)) {
  765. continue;
  766. }
  767. // As deleted nodes are still accessible via the undo/redo system, check if they're still on the tree.
  768. Node *source = Object::cast_to<Node>(connection.signal.get_object());
  769. if (source && !source->is_inside_tree()) {
  770. continue;
  771. }
  772. const StringName method = connection.callable.get_method();
  773. if (methods_found.has(method)) {
  774. continue;
  775. }
  776. if (!ClassDB::has_method(script->get_instance_base_type(), method)) {
  777. int line = -1;
  778. for (int j = 0; j < functions.size(); j++) {
  779. String name = functions[j].get_slice(":", 0);
  780. if (name == method) {
  781. line = functions[j].get_slice(":", 1).to_int() - 1;
  782. text_edit->set_line_gutter_metadata(line, connection_gutter, method);
  783. text_edit->set_line_gutter_icon(line, connection_gutter, get_parent_control()->get_theme_icon(SNAME("Slot"), SNAME("EditorIcons")));
  784. text_edit->set_line_gutter_clickable(line, connection_gutter, true);
  785. methods_found.insert(method);
  786. break;
  787. }
  788. }
  789. if (line >= 0) {
  790. continue;
  791. }
  792. // There is a chance that the method is inherited from another script.
  793. bool found_inherited_function = false;
  794. Ref<Script> inherited_script = script->get_base_script();
  795. while (!inherited_script.is_null()) {
  796. if (inherited_script->has_method(method)) {
  797. found_inherited_function = true;
  798. break;
  799. }
  800. inherited_script = inherited_script->get_base_script();
  801. }
  802. if (!found_inherited_function) {
  803. missing_connections.push_back(connection);
  804. }
  805. }
  806. }
  807. }
  808. }
  809. void ScriptTextEditor::_update_gutter_indexes() {
  810. for (int i = 0; i < code_editor->get_text_editor()->get_gutter_count(); i++) {
  811. if (code_editor->get_text_editor()->get_gutter_name(i) == "connection_gutter") {
  812. connection_gutter = i;
  813. continue;
  814. }
  815. if (code_editor->get_text_editor()->get_gutter_name(i) == "line_numbers") {
  816. line_number_gutter = i;
  817. continue;
  818. }
  819. }
  820. }
  821. void ScriptTextEditor::_gutter_clicked(int p_line, int p_gutter) {
  822. if (p_gutter != connection_gutter) {
  823. return;
  824. }
  825. String method = code_editor->get_text_editor()->get_line_gutter_metadata(p_line, p_gutter);
  826. if (method.is_empty()) {
  827. return;
  828. }
  829. Node *base = get_tree()->get_edited_scene_root();
  830. if (!base) {
  831. return;
  832. }
  833. Vector<Node *> nodes = _find_all_node_for_script(base, base, script);
  834. connection_info_dialog->popup_connections(method, nodes);
  835. }
  836. void ScriptTextEditor::_edit_option(int p_op) {
  837. CodeEdit *tx = code_editor->get_text_editor();
  838. switch (p_op) {
  839. case EDIT_UNDO: {
  840. tx->undo();
  841. tx->call_deferred(SNAME("grab_focus"));
  842. } break;
  843. case EDIT_REDO: {
  844. tx->redo();
  845. tx->call_deferred(SNAME("grab_focus"));
  846. } break;
  847. case EDIT_CUT: {
  848. tx->cut();
  849. tx->call_deferred(SNAME("grab_focus"));
  850. } break;
  851. case EDIT_COPY: {
  852. tx->copy();
  853. tx->call_deferred(SNAME("grab_focus"));
  854. } break;
  855. case EDIT_PASTE: {
  856. tx->paste();
  857. tx->call_deferred(SNAME("grab_focus"));
  858. } break;
  859. case EDIT_SELECT_ALL: {
  860. tx->select_all();
  861. tx->call_deferred(SNAME("grab_focus"));
  862. } break;
  863. case EDIT_MOVE_LINE_UP: {
  864. code_editor->move_lines_up();
  865. } break;
  866. case EDIT_MOVE_LINE_DOWN: {
  867. code_editor->move_lines_down();
  868. } break;
  869. case EDIT_INDENT_LEFT: {
  870. Ref<Script> scr = script;
  871. if (scr.is_null()) {
  872. return;
  873. }
  874. tx->unindent_lines();
  875. } break;
  876. case EDIT_INDENT_RIGHT: {
  877. Ref<Script> scr = script;
  878. if (scr.is_null()) {
  879. return;
  880. }
  881. tx->indent_lines();
  882. } break;
  883. case EDIT_DELETE_LINE: {
  884. code_editor->delete_lines();
  885. } break;
  886. case EDIT_DUPLICATE_SELECTION: {
  887. code_editor->duplicate_selection();
  888. } break;
  889. case EDIT_TOGGLE_FOLD_LINE: {
  890. tx->toggle_foldable_line(tx->get_caret_line());
  891. tx->update();
  892. } break;
  893. case EDIT_FOLD_ALL_LINES: {
  894. tx->fold_all_lines();
  895. tx->update();
  896. } break;
  897. case EDIT_UNFOLD_ALL_LINES: {
  898. tx->unfold_all_lines();
  899. tx->update();
  900. } break;
  901. case EDIT_TOGGLE_COMMENT: {
  902. _edit_option_toggle_inline_comment();
  903. } break;
  904. case EDIT_COMPLETE: {
  905. tx->request_code_completion(true);
  906. } break;
  907. case EDIT_AUTO_INDENT: {
  908. String text = tx->get_text();
  909. Ref<Script> scr = script;
  910. if (scr.is_null()) {
  911. return;
  912. }
  913. tx->begin_complex_operation();
  914. int begin, end;
  915. if (tx->has_selection()) {
  916. begin = tx->get_selection_from_line();
  917. end = tx->get_selection_to_line();
  918. // ignore if the cursor is not past the first column
  919. if (tx->get_selection_to_column() == 0) {
  920. end--;
  921. }
  922. } else {
  923. begin = 0;
  924. end = tx->get_line_count() - 1;
  925. }
  926. scr->get_language()->auto_indent_code(text, begin, end);
  927. Vector<String> lines = text.split("\n");
  928. for (int i = begin; i <= end; ++i) {
  929. tx->set_line(i, lines[i]);
  930. }
  931. tx->end_complex_operation();
  932. } break;
  933. case EDIT_TRIM_TRAILING_WHITESAPCE: {
  934. trim_trailing_whitespace();
  935. } break;
  936. case EDIT_CONVERT_INDENT_TO_SPACES: {
  937. convert_indent_to_spaces();
  938. } break;
  939. case EDIT_CONVERT_INDENT_TO_TABS: {
  940. convert_indent_to_tabs();
  941. } break;
  942. case EDIT_PICK_COLOR: {
  943. color_panel->popup();
  944. } break;
  945. case EDIT_TO_UPPERCASE: {
  946. _convert_case(CodeTextEditor::UPPER);
  947. } break;
  948. case EDIT_TO_LOWERCASE: {
  949. _convert_case(CodeTextEditor::LOWER);
  950. } break;
  951. case EDIT_CAPITALIZE: {
  952. _convert_case(CodeTextEditor::CAPITALIZE);
  953. } break;
  954. case EDIT_EVALUATE: {
  955. Expression expression;
  956. Vector<String> lines = code_editor->get_text_editor()->get_selected_text().split("\n");
  957. PackedStringArray results;
  958. for (int i = 0; i < lines.size(); i++) {
  959. String line = lines[i];
  960. String whitespace = line.substr(0, line.size() - line.strip_edges(true, false).size()); //extract the whitespace at the beginning
  961. if (expression.parse(line) == OK) {
  962. Variant result = expression.execute(Array(), Variant(), false);
  963. if (expression.get_error_text().is_empty()) {
  964. results.push_back(whitespace + result.get_construct_string());
  965. } else {
  966. results.push_back(line);
  967. }
  968. } else {
  969. results.push_back(line);
  970. }
  971. }
  972. code_editor->get_text_editor()->begin_complex_operation(); //prevents creating a two-step undo
  973. code_editor->get_text_editor()->insert_text_at_caret(String("\n").join(results));
  974. code_editor->get_text_editor()->end_complex_operation();
  975. } break;
  976. case SEARCH_FIND: {
  977. code_editor->get_find_replace_bar()->popup_search();
  978. } break;
  979. case SEARCH_FIND_NEXT: {
  980. code_editor->get_find_replace_bar()->search_next();
  981. } break;
  982. case SEARCH_FIND_PREV: {
  983. code_editor->get_find_replace_bar()->search_prev();
  984. } break;
  985. case SEARCH_REPLACE: {
  986. code_editor->get_find_replace_bar()->popup_replace();
  987. } break;
  988. case SEARCH_IN_FILES: {
  989. String selected_text = code_editor->get_text_editor()->get_selected_text();
  990. // Yep, because it doesn't make sense to instance this dialog for every single script open...
  991. // So this will be delegated to the ScriptEditor.
  992. emit_signal(SNAME("search_in_files_requested"), selected_text);
  993. } break;
  994. case REPLACE_IN_FILES: {
  995. String selected_text = code_editor->get_text_editor()->get_selected_text();
  996. emit_signal(SNAME("replace_in_files_requested"), selected_text);
  997. } break;
  998. case SEARCH_LOCATE_FUNCTION: {
  999. quick_open->popup_dialog(get_functions());
  1000. quick_open->set_title(TTR("Go to Function"));
  1001. } break;
  1002. case SEARCH_GOTO_LINE: {
  1003. goto_line_dialog->popup_find_line(tx);
  1004. } break;
  1005. case BOOKMARK_TOGGLE: {
  1006. code_editor->toggle_bookmark();
  1007. } break;
  1008. case BOOKMARK_GOTO_NEXT: {
  1009. code_editor->goto_next_bookmark();
  1010. } break;
  1011. case BOOKMARK_GOTO_PREV: {
  1012. code_editor->goto_prev_bookmark();
  1013. } break;
  1014. case BOOKMARK_REMOVE_ALL: {
  1015. code_editor->remove_all_bookmarks();
  1016. } break;
  1017. case DEBUG_TOGGLE_BREAKPOINT: {
  1018. int line = tx->get_caret_line();
  1019. bool dobreak = !tx->is_line_breakpointed(line);
  1020. tx->set_line_as_breakpoint(line, dobreak);
  1021. EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), line + 1, dobreak);
  1022. } break;
  1023. case DEBUG_REMOVE_ALL_BREAKPOINTS: {
  1024. Array bpoints = tx->get_breakpointed_lines();
  1025. for (int i = 0; i < bpoints.size(); i++) {
  1026. int line = bpoints[i];
  1027. bool dobreak = !tx->is_line_breakpointed(line);
  1028. tx->set_line_as_breakpoint(line, dobreak);
  1029. EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), line + 1, dobreak);
  1030. }
  1031. } break;
  1032. case DEBUG_GOTO_NEXT_BREAKPOINT: {
  1033. Array bpoints = tx->get_breakpointed_lines();
  1034. if (bpoints.size() <= 0) {
  1035. return;
  1036. }
  1037. int line = tx->get_caret_line();
  1038. // wrap around
  1039. if (line >= (int)bpoints[bpoints.size() - 1]) {
  1040. tx->unfold_line(bpoints[0]);
  1041. tx->set_caret_line(bpoints[0]);
  1042. tx->center_viewport_to_caret();
  1043. } else {
  1044. for (int i = 0; i < bpoints.size(); i++) {
  1045. int bline = bpoints[i];
  1046. if (bline > line) {
  1047. tx->unfold_line(bline);
  1048. tx->set_caret_line(bline);
  1049. tx->center_viewport_to_caret();
  1050. return;
  1051. }
  1052. }
  1053. }
  1054. } break;
  1055. case DEBUG_GOTO_PREV_BREAKPOINT: {
  1056. Array bpoints = tx->get_breakpointed_lines();
  1057. if (bpoints.size() <= 0) {
  1058. return;
  1059. }
  1060. int line = tx->get_caret_line();
  1061. // wrap around
  1062. if (line <= (int)bpoints[0]) {
  1063. tx->unfold_line(bpoints[bpoints.size() - 1]);
  1064. tx->set_caret_line(bpoints[bpoints.size() - 1]);
  1065. tx->center_viewport_to_caret();
  1066. } else {
  1067. for (int i = bpoints.size() - 1; i >= 0; i--) {
  1068. int bline = bpoints[i];
  1069. if (bline < line) {
  1070. tx->unfold_line(bline);
  1071. tx->set_caret_line(bline);
  1072. tx->center_viewport_to_caret();
  1073. return;
  1074. }
  1075. }
  1076. }
  1077. } break;
  1078. case HELP_CONTEXTUAL: {
  1079. String text = tx->get_selected_text();
  1080. if (text.is_empty()) {
  1081. text = tx->get_word_under_caret();
  1082. }
  1083. if (!text.is_empty()) {
  1084. emit_signal(SNAME("request_help"), text);
  1085. }
  1086. } break;
  1087. case LOOKUP_SYMBOL: {
  1088. String text = tx->get_word_under_caret();
  1089. if (text.is_empty()) {
  1090. text = tx->get_selected_text();
  1091. }
  1092. if (!text.is_empty()) {
  1093. _lookup_symbol(text, tx->get_caret_line(), tx->get_caret_column());
  1094. }
  1095. } break;
  1096. }
  1097. }
  1098. void ScriptTextEditor::_edit_option_toggle_inline_comment() {
  1099. if (script.is_null()) {
  1100. return;
  1101. }
  1102. String delimiter = "#";
  1103. List<String> comment_delimiters;
  1104. script->get_language()->get_comment_delimiters(&comment_delimiters);
  1105. for (const String &script_delimiter : comment_delimiters) {
  1106. if (!script_delimiter.contains(" ")) {
  1107. delimiter = script_delimiter;
  1108. break;
  1109. }
  1110. }
  1111. code_editor->toggle_inline_comment(delimiter);
  1112. }
  1113. void ScriptTextEditor::add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {
  1114. ERR_FAIL_COND(p_highlighter.is_null());
  1115. highlighters[p_highlighter->_get_name()] = p_highlighter;
  1116. highlighter_menu->add_radio_check_item(p_highlighter->_get_name());
  1117. }
  1118. void ScriptTextEditor::set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) {
  1119. ERR_FAIL_COND(p_highlighter.is_null());
  1120. Map<String, Ref<EditorSyntaxHighlighter>>::Element *el = highlighters.front();
  1121. while (el != nullptr) {
  1122. int highlighter_index = highlighter_menu->get_item_idx_from_text(el->key());
  1123. highlighter_menu->set_item_checked(highlighter_index, el->value() == p_highlighter);
  1124. el = el->next();
  1125. }
  1126. CodeEdit *te = code_editor->get_text_editor();
  1127. p_highlighter->_set_edited_resource(script);
  1128. te->set_syntax_highlighter(p_highlighter);
  1129. }
  1130. void ScriptTextEditor::_change_syntax_highlighter(int p_idx) {
  1131. set_syntax_highlighter(highlighters[highlighter_menu->get_item_text(p_idx)]);
  1132. }
  1133. void ScriptTextEditor::_notification(int p_what) {
  1134. switch (p_what) {
  1135. case NOTIFICATION_THEME_CHANGED:
  1136. if (is_visible_in_tree()) {
  1137. _update_warnings();
  1138. _update_errors();
  1139. }
  1140. [[fallthrough]];
  1141. case NOTIFICATION_ENTER_TREE: {
  1142. code_editor->get_text_editor()->set_gutter_width(connection_gutter, code_editor->get_text_editor()->get_line_height());
  1143. } break;
  1144. default:
  1145. break;
  1146. }
  1147. }
  1148. void ScriptTextEditor::_bind_methods() {
  1149. ClassDB::bind_method("_update_connected_methods", &ScriptTextEditor::_update_connected_methods);
  1150. ClassDB::bind_method("_get_drag_data_fw", &ScriptTextEditor::get_drag_data_fw);
  1151. ClassDB::bind_method("_can_drop_data_fw", &ScriptTextEditor::can_drop_data_fw);
  1152. ClassDB::bind_method("_drop_data_fw", &ScriptTextEditor::drop_data_fw);
  1153. }
  1154. Control *ScriptTextEditor::get_edit_menu() {
  1155. return edit_hb;
  1156. }
  1157. void ScriptTextEditor::clear_edit_menu() {
  1158. memdelete(edit_hb);
  1159. }
  1160. void ScriptTextEditor::set_find_replace_bar(FindReplaceBar *p_bar) {
  1161. code_editor->set_find_replace_bar(p_bar);
  1162. }
  1163. void ScriptTextEditor::reload(bool p_soft) {
  1164. CodeEdit *te = code_editor->get_text_editor();
  1165. Ref<Script> scr = script;
  1166. if (scr.is_null()) {
  1167. return;
  1168. }
  1169. scr->set_source_code(te->get_text());
  1170. bool soft = p_soft || scr->get_instance_base_type() == "EditorPlugin"; // Always soft-reload editor plugins.
  1171. scr->get_language()->reload_tool_script(scr, soft);
  1172. }
  1173. Array ScriptTextEditor::get_breakpoints() {
  1174. return code_editor->get_text_editor()->get_breakpointed_lines();
  1175. }
  1176. void ScriptTextEditor::set_breakpoint(int p_line, bool p_enabled) {
  1177. code_editor->get_text_editor()->set_line_as_breakpoint(p_line, p_enabled);
  1178. }
  1179. void ScriptTextEditor::clear_breakpoints() {
  1180. code_editor->get_text_editor()->clear_breakpointed_lines();
  1181. }
  1182. void ScriptTextEditor::set_tooltip_request_func(const Callable &p_toolip_callback) {
  1183. Variant args[1] = { this };
  1184. const Variant *argp[] = { &args[0] };
  1185. code_editor->get_text_editor()->set_tooltip_request_func(p_toolip_callback.bind(argp, 1));
  1186. }
  1187. void ScriptTextEditor::set_debugger_active(bool p_active) {
  1188. }
  1189. Control *ScriptTextEditor::get_base_editor() const {
  1190. return code_editor->get_text_editor();
  1191. }
  1192. Variant ScriptTextEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  1193. return Variant();
  1194. }
  1195. bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  1196. Dictionary d = p_data;
  1197. if (d.has("type") &&
  1198. (String(d["type"]) == "resource" ||
  1199. String(d["type"]) == "files" ||
  1200. String(d["type"]) == "nodes" ||
  1201. String(d["type"]) == "obj_property" ||
  1202. String(d["type"]) == "files_and_dirs")) {
  1203. return true;
  1204. }
  1205. return false;
  1206. }
  1207. static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
  1208. if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) {
  1209. return nullptr;
  1210. }
  1211. Ref<Script> scr = p_current_node->get_script();
  1212. if (scr.is_valid() && scr == script) {
  1213. return p_current_node;
  1214. }
  1215. for (int i = 0; i < p_current_node->get_child_count(); i++) {
  1216. Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
  1217. if (n) {
  1218. return n;
  1219. }
  1220. }
  1221. return nullptr;
  1222. }
  1223. void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  1224. const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
  1225. Dictionary d = p_data;
  1226. CodeEdit *te = code_editor->get_text_editor();
  1227. Point2i pos = te->get_line_column_at_pos(p_point);
  1228. int row = pos.y;
  1229. int col = pos.x;
  1230. if (d.has("type") && String(d["type"]) == "resource") {
  1231. Ref<Resource> res = d["resource"];
  1232. if (!res.is_valid()) {
  1233. return;
  1234. }
  1235. if (res->get_path().is_resource_file()) {
  1236. EditorNode::get_singleton()->show_warning(TTR("Only resources from filesystem can be dropped."));
  1237. return;
  1238. }
  1239. te->set_caret_line(row);
  1240. te->set_caret_column(col);
  1241. te->insert_text_at_caret(res->get_path());
  1242. }
  1243. if (d.has("type") && (String(d["type"]) == "files" || String(d["type"]) == "files_and_dirs")) {
  1244. Array files = d["files"];
  1245. String text_to_drop;
  1246. bool preload = Input::get_singleton()->is_key_pressed(Key::CTRL);
  1247. for (int i = 0; i < files.size(); i++) {
  1248. if (i > 0) {
  1249. text_to_drop += ", ";
  1250. }
  1251. if (preload) {
  1252. text_to_drop += "preload(" + String(files[i]).c_escape().quote(quote_style) + ")";
  1253. } else {
  1254. text_to_drop += String(files[i]).c_escape().quote(quote_style);
  1255. }
  1256. }
  1257. te->set_caret_line(row);
  1258. te->set_caret_column(col);
  1259. te->insert_text_at_caret(text_to_drop);
  1260. }
  1261. if (d.has("type") && String(d["type"]) == "nodes") {
  1262. Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script);
  1263. if (!sn) {
  1264. EditorNode::get_singleton()->show_warning(vformat(TTR("Can't drop nodes because script '%s' is not used in this scene."), get_name()));
  1265. return;
  1266. }
  1267. Array nodes = d["nodes"];
  1268. String text_to_drop;
  1269. for (int i = 0; i < nodes.size(); i++) {
  1270. if (i > 0) {
  1271. text_to_drop += ",";
  1272. }
  1273. NodePath np = nodes[i];
  1274. Node *node = get_node(np);
  1275. if (!node) {
  1276. continue;
  1277. }
  1278. String path = sn->get_path_to(node);
  1279. text_to_drop += path.c_escape().quote(quote_style);
  1280. }
  1281. te->set_caret_line(row);
  1282. te->set_caret_column(col);
  1283. te->insert_text_at_caret(text_to_drop);
  1284. }
  1285. if (d.has("type") && String(d["type"]) == "obj_property") {
  1286. const String text_to_drop = String(d["property"]).c_escape().quote(quote_style);
  1287. te->set_caret_line(row);
  1288. te->set_caret_column(col);
  1289. te->insert_text_at_caret(text_to_drop);
  1290. }
  1291. }
  1292. void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
  1293. Ref<InputEventMouseButton> mb = ev;
  1294. Ref<InputEventKey> k = ev;
  1295. Point2 local_pos;
  1296. bool create_menu = false;
  1297. CodeEdit *tx = code_editor->get_text_editor();
  1298. if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
  1299. local_pos = mb->get_global_position() - tx->get_global_position();
  1300. create_menu = true;
  1301. } else if (k.is_valid() && k->is_action("ui_menu", true)) {
  1302. tx->adjust_viewport_to_caret();
  1303. local_pos = tx->get_caret_draw_pos();
  1304. create_menu = true;
  1305. }
  1306. if (create_menu) {
  1307. Point2i pos = tx->get_line_column_at_pos(local_pos);
  1308. int row = pos.y;
  1309. int col = pos.x;
  1310. tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/behavior/navigation/move_caret_on_right_click"));
  1311. if (tx->is_move_caret_on_right_click_enabled()) {
  1312. if (tx->has_selection()) {
  1313. int from_line = tx->get_selection_from_line();
  1314. int to_line = tx->get_selection_to_line();
  1315. int from_column = tx->get_selection_from_column();
  1316. int to_column = tx->get_selection_to_column();
  1317. if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) {
  1318. // Right click is outside the selected text
  1319. tx->deselect();
  1320. }
  1321. }
  1322. if (!tx->has_selection()) {
  1323. tx->set_caret_line(row, false, false);
  1324. tx->set_caret_column(col);
  1325. }
  1326. }
  1327. String word_at_pos = tx->get_word_at_pos(local_pos);
  1328. if (word_at_pos.is_empty()) {
  1329. word_at_pos = tx->get_word_under_caret();
  1330. }
  1331. if (word_at_pos.is_empty()) {
  1332. word_at_pos = tx->get_selected_text();
  1333. }
  1334. bool has_color = (word_at_pos == "Color");
  1335. bool foldable = tx->can_fold_line(row) || tx->is_line_folded(row);
  1336. bool open_docs = false;
  1337. bool goto_definition = false;
  1338. if (word_at_pos.is_resource_file()) {
  1339. open_docs = true;
  1340. } else {
  1341. Node *base = get_tree()->get_edited_scene_root();
  1342. if (base) {
  1343. base = _find_node_for_script(base, base, script);
  1344. }
  1345. ScriptLanguage::LookupResult result;
  1346. if (script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), word_at_pos, script->get_path(), base, result) == OK) {
  1347. open_docs = true;
  1348. }
  1349. }
  1350. if (has_color) {
  1351. String line = tx->get_line(row);
  1352. color_position.x = row;
  1353. color_position.y = col;
  1354. int begin = 0;
  1355. int end = 0;
  1356. bool valid = false;
  1357. for (int i = col; i < line.length(); i++) {
  1358. if (line[i] == '(') {
  1359. begin = i;
  1360. continue;
  1361. } else if (line[i] == ')') {
  1362. end = i + 1;
  1363. valid = true;
  1364. break;
  1365. }
  1366. }
  1367. if (valid) {
  1368. color_args = line.substr(begin, end - begin);
  1369. String stripped = color_args.replace(" ", "").replace("(", "").replace(")", "");
  1370. Vector<float> color = stripped.split_floats(",");
  1371. if (color.size() > 2) {
  1372. float alpha = color.size() > 3 ? color[3] : 1.0f;
  1373. color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha));
  1374. }
  1375. color_panel->set_position(get_screen_position() + local_pos);
  1376. } else {
  1377. has_color = false;
  1378. }
  1379. }
  1380. _make_context_menu(tx->has_selection(), has_color, foldable, open_docs, goto_definition, local_pos);
  1381. }
  1382. }
  1383. void ScriptTextEditor::_color_changed(const Color &p_color) {
  1384. String new_args;
  1385. if (p_color.a == 1.0f) {
  1386. new_args = String("(" + rtos(p_color.r) + ", " + rtos(p_color.g) + ", " + rtos(p_color.b) + ")");
  1387. } else {
  1388. new_args = String("(" + rtos(p_color.r) + ", " + rtos(p_color.g) + ", " + rtos(p_color.b) + ", " + rtos(p_color.a) + ")");
  1389. }
  1390. String line = code_editor->get_text_editor()->get_line(color_position.x);
  1391. String line_with_replaced_args = line.replace(color_args, new_args);
  1392. color_args = new_args;
  1393. code_editor->get_text_editor()->begin_complex_operation();
  1394. code_editor->get_text_editor()->set_line(color_position.x, line_with_replaced_args);
  1395. code_editor->get_text_editor()->end_complex_operation();
  1396. code_editor->get_text_editor()->update();
  1397. }
  1398. void ScriptTextEditor::_prepare_edit_menu() {
  1399. const CodeEdit *tx = code_editor->get_text_editor();
  1400. PopupMenu *popup = edit_menu->get_popup();
  1401. popup->set_item_disabled(popup->get_item_index(EDIT_UNDO), !tx->has_undo());
  1402. popup->set_item_disabled(popup->get_item_index(EDIT_REDO), !tx->has_redo());
  1403. }
  1404. void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos) {
  1405. context_menu->clear();
  1406. context_menu->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
  1407. context_menu->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
  1408. context_menu->add_separator();
  1409. context_menu->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
  1410. context_menu->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
  1411. context_menu->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
  1412. context_menu->add_separator();
  1413. context_menu->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
  1414. context_menu->add_separator();
  1415. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
  1416. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
  1417. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
  1418. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
  1419. if (p_selection) {
  1420. context_menu->add_separator();
  1421. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE);
  1422. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE);
  1423. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE);
  1424. }
  1425. if (p_foldable) {
  1426. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
  1427. }
  1428. if (p_color || p_open_docs || p_goto_definition) {
  1429. context_menu->add_separator();
  1430. if (p_open_docs) {
  1431. context_menu->add_item(TTR("Lookup Symbol"), LOOKUP_SYMBOL);
  1432. }
  1433. if (p_color) {
  1434. context_menu->add_item(TTR("Pick Color"), EDIT_PICK_COLOR);
  1435. }
  1436. }
  1437. const CodeEdit *tx = code_editor->get_text_editor();
  1438. context_menu->set_item_disabled(context_menu->get_item_index(EDIT_UNDO), !tx->has_undo());
  1439. context_menu->set_item_disabled(context_menu->get_item_index(EDIT_REDO), !tx->has_redo());
  1440. context_menu->set_position(get_screen_position() + p_pos);
  1441. context_menu->reset_size();
  1442. context_menu->popup();
  1443. }
  1444. void ScriptTextEditor::_enable_code_editor() {
  1445. ERR_FAIL_COND(code_editor->get_parent());
  1446. VSplitContainer *editor_box = memnew(VSplitContainer);
  1447. add_child(editor_box);
  1448. editor_box->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
  1449. editor_box->set_v_size_flags(SIZE_EXPAND_FILL);
  1450. editor_box->add_child(code_editor);
  1451. code_editor->connect("show_errors_panel", callable_mp(this, &ScriptTextEditor::_show_errors_panel));
  1452. code_editor->connect("show_warnings_panel", callable_mp(this, &ScriptTextEditor::_show_warnings_panel));
  1453. code_editor->connect("validate_script", callable_mp(this, &ScriptTextEditor::_validate_script));
  1454. code_editor->connect("load_theme_settings", callable_mp(this, &ScriptTextEditor::_load_theme_settings));
  1455. code_editor->get_text_editor()->connect("symbol_lookup", callable_mp(this, &ScriptTextEditor::_lookup_symbol));
  1456. code_editor->get_text_editor()->connect("symbol_validate", callable_mp(this, &ScriptTextEditor::_validate_symbol));
  1457. code_editor->get_text_editor()->connect("gutter_added", callable_mp(this, &ScriptTextEditor::_update_gutter_indexes));
  1458. code_editor->get_text_editor()->connect("gutter_removed", callable_mp(this, &ScriptTextEditor::_update_gutter_indexes));
  1459. code_editor->get_text_editor()->connect("gutter_clicked", callable_mp(this, &ScriptTextEditor::_gutter_clicked));
  1460. code_editor->get_text_editor()->connect("gui_input", callable_mp(this, &ScriptTextEditor::_text_edit_gui_input));
  1461. code_editor->show_toggle_scripts_button();
  1462. _update_gutter_indexes();
  1463. editor_box->add_child(warnings_panel);
  1464. warnings_panel->add_theme_font_override(
  1465. "normal_font", EditorNode::get_singleton()->get_gui_base()->get_theme_font(SNAME("main"), SNAME("EditorFonts")));
  1466. warnings_panel->add_theme_font_size_override(
  1467. "normal_font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size(SNAME("main_size"), SNAME("EditorFonts")));
  1468. warnings_panel->connect("meta_clicked", callable_mp(this, &ScriptTextEditor::_warning_clicked));
  1469. editor_box->add_child(errors_panel);
  1470. errors_panel->add_theme_font_override(
  1471. "normal_font", EditorNode::get_singleton()->get_gui_base()->get_theme_font(SNAME("main"), SNAME("EditorFonts")));
  1472. errors_panel->add_theme_font_size_override(
  1473. "normal_font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size(SNAME("main_size"), SNAME("EditorFonts")));
  1474. errors_panel->connect("meta_clicked", callable_mp(this, &ScriptTextEditor::_error_clicked));
  1475. add_child(context_menu);
  1476. context_menu->connect("id_pressed", callable_mp(this, &ScriptTextEditor::_edit_option));
  1477. add_child(color_panel);
  1478. color_picker = memnew(ColorPicker);
  1479. color_picker->set_deferred_mode(true);
  1480. color_picker->connect("color_changed", callable_mp(this, &ScriptTextEditor::_color_changed));
  1481. color_panel->add_child(color_picker);
  1482. // get default color picker mode from editor settings
  1483. int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode");
  1484. if (default_color_mode == 1) {
  1485. color_picker->set_hsv_mode(true);
  1486. } else if (default_color_mode == 2) {
  1487. color_picker->set_raw_mode(true);
  1488. }
  1489. int picker_shape = EDITOR_GET("interface/inspector/default_color_picker_shape");
  1490. color_picker->set_picker_shape((ColorPicker::PickerShapeType)picker_shape);
  1491. quick_open = memnew(ScriptEditorQuickOpen);
  1492. quick_open->connect("goto_line", callable_mp(this, &ScriptTextEditor::_goto_line));
  1493. add_child(quick_open);
  1494. goto_line_dialog = memnew(GotoLineDialog);
  1495. add_child(goto_line_dialog);
  1496. add_child(connection_info_dialog);
  1497. edit_hb->add_child(search_menu);
  1498. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND);
  1499. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT);
  1500. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV);
  1501. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE);
  1502. search_menu->get_popup()->add_separator();
  1503. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES);
  1504. search_menu->get_popup()->add_separator();
  1505. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/contextual_help"), HELP_CONTEXTUAL);
  1506. search_menu->get_popup()->connect("id_pressed", callable_mp(this, &ScriptTextEditor::_edit_option));
  1507. edit_hb->add_child(edit_menu);
  1508. edit_menu->connect("about_to_popup", callable_mp(this, &ScriptTextEditor::_prepare_edit_menu));
  1509. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
  1510. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
  1511. edit_menu->get_popup()->add_separator();
  1512. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
  1513. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
  1514. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
  1515. edit_menu->get_popup()->add_separator();
  1516. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
  1517. edit_menu->get_popup()->add_separator();
  1518. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
  1519. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
  1520. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
  1521. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
  1522. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
  1523. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
  1524. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
  1525. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_all_lines"), EDIT_FOLD_ALL_LINES);
  1526. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES);
  1527. edit_menu->get_popup()->add_separator();
  1528. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/duplicate_selection"), EDIT_DUPLICATE_SELECTION);
  1529. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_completion_query"), EDIT_COMPLETE);
  1530. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE);
  1531. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE);
  1532. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES);
  1533. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_tabs"), EDIT_CONVERT_INDENT_TO_TABS);
  1534. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/auto_indent"), EDIT_AUTO_INDENT);
  1535. edit_menu->get_popup()->connect("id_pressed", callable_mp(this, &ScriptTextEditor::_edit_option));
  1536. edit_menu->get_popup()->add_separator();
  1537. edit_menu->get_popup()->add_child(convert_case);
  1538. edit_menu->get_popup()->add_submenu_item(TTR("Convert Case"), "convert_case");
  1539. convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/convert_to_uppercase", TTR("Uppercase"), KeyModifierMask::SHIFT | Key::F4), EDIT_TO_UPPERCASE);
  1540. convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/convert_to_lowercase", TTR("Lowercase"), KeyModifierMask::SHIFT | Key::F5), EDIT_TO_LOWERCASE);
  1541. convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/capitalize", TTR("Capitalize"), KeyModifierMask::SHIFT | Key::F6), EDIT_CAPITALIZE);
  1542. convert_case->connect("id_pressed", callable_mp(this, &ScriptTextEditor::_edit_option));
  1543. edit_menu->get_popup()->add_child(highlighter_menu);
  1544. edit_menu->get_popup()->add_submenu_item(TTR("Syntax Highlighter"), "highlighter_menu");
  1545. highlighter_menu->connect("id_pressed", callable_mp(this, &ScriptTextEditor::_change_syntax_highlighter));
  1546. _load_theme_settings();
  1547. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace_in_files"), REPLACE_IN_FILES);
  1548. edit_hb->add_child(goto_menu);
  1549. goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_function"), SEARCH_LOCATE_FUNCTION);
  1550. goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE);
  1551. goto_menu->get_popup()->add_separator();
  1552. goto_menu->get_popup()->add_child(bookmarks_menu);
  1553. goto_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "Bookmarks");
  1554. _update_bookmark_list();
  1555. bookmarks_menu->connect("about_to_popup", callable_mp(this, &ScriptTextEditor::_update_bookmark_list));
  1556. bookmarks_menu->connect("index_pressed", callable_mp(this, &ScriptTextEditor::_bookmark_item_pressed));
  1557. goto_menu->get_popup()->add_child(breakpoints_menu);
  1558. goto_menu->get_popup()->add_submenu_item(TTR("Breakpoints"), "Breakpoints");
  1559. _update_breakpoint_list();
  1560. breakpoints_menu->connect("about_to_popup", callable_mp(this, &ScriptTextEditor::_update_breakpoint_list));
  1561. breakpoints_menu->connect("index_pressed", callable_mp(this, &ScriptTextEditor::_breakpoint_item_pressed));
  1562. goto_menu->get_popup()->connect("id_pressed", callable_mp(this, &ScriptTextEditor::_edit_option));
  1563. }
  1564. ScriptTextEditor::ScriptTextEditor() {
  1565. code_editor = memnew(CodeTextEditor);
  1566. code_editor->add_theme_constant_override("separation", 2);
  1567. code_editor->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
  1568. code_editor->set_code_complete_func(_code_complete_scripts, this);
  1569. code_editor->set_v_size_flags(SIZE_EXPAND_FILL);
  1570. code_editor->get_text_editor()->set_draw_breakpoints_gutter(true);
  1571. code_editor->get_text_editor()->set_draw_executing_lines_gutter(true);
  1572. code_editor->get_text_editor()->connect("breakpoint_toggled", callable_mp(this, &ScriptTextEditor::_breakpoint_toggled));
  1573. connection_gutter = 1;
  1574. code_editor->get_text_editor()->add_gutter(connection_gutter);
  1575. code_editor->get_text_editor()->set_gutter_name(connection_gutter, "connection_gutter");
  1576. code_editor->get_text_editor()->set_gutter_draw(connection_gutter, false);
  1577. code_editor->get_text_editor()->set_gutter_overwritable(connection_gutter, true);
  1578. code_editor->get_text_editor()->set_gutter_type(connection_gutter, TextEdit::GUTTER_TYPE_ICON);
  1579. warnings_panel = memnew(RichTextLabel);
  1580. warnings_panel->set_custom_minimum_size(Size2(0, 100 * EDSCALE));
  1581. warnings_panel->set_h_size_flags(SIZE_EXPAND_FILL);
  1582. warnings_panel->set_meta_underline(true);
  1583. warnings_panel->set_selection_enabled(true);
  1584. warnings_panel->set_focus_mode(FOCUS_CLICK);
  1585. warnings_panel->hide();
  1586. errors_panel = memnew(RichTextLabel);
  1587. errors_panel->set_custom_minimum_size(Size2(0, 100 * EDSCALE));
  1588. errors_panel->set_h_size_flags(SIZE_EXPAND_FILL);
  1589. errors_panel->set_meta_underline(true);
  1590. errors_panel->set_selection_enabled(true);
  1591. errors_panel->set_focus_mode(FOCUS_CLICK);
  1592. errors_panel->hide();
  1593. update_settings();
  1594. code_editor->get_text_editor()->set_code_hint_draw_below(EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line"));
  1595. code_editor->get_text_editor()->set_symbol_lookup_on_click_enabled(true);
  1596. code_editor->get_text_editor()->set_context_menu_enabled(false);
  1597. context_menu = memnew(PopupMenu);
  1598. color_panel = memnew(PopupPanel);
  1599. edit_hb = memnew(HBoxContainer);
  1600. edit_menu = memnew(MenuButton);
  1601. edit_menu->set_text(TTR("Edit"));
  1602. edit_menu->set_switch_on_hover(true);
  1603. edit_menu->set_shortcut_context(this);
  1604. convert_case = memnew(PopupMenu);
  1605. convert_case->set_name("convert_case");
  1606. highlighter_menu = memnew(PopupMenu);
  1607. highlighter_menu->set_name("highlighter_menu");
  1608. Ref<EditorPlainTextSyntaxHighlighter> plain_highlighter;
  1609. plain_highlighter.instantiate();
  1610. add_syntax_highlighter(plain_highlighter);
  1611. Ref<EditorStandardSyntaxHighlighter> highlighter;
  1612. highlighter.instantiate();
  1613. add_syntax_highlighter(highlighter);
  1614. set_syntax_highlighter(highlighter);
  1615. search_menu = memnew(MenuButton);
  1616. search_menu->set_text(TTR("Search"));
  1617. search_menu->set_switch_on_hover(true);
  1618. search_menu->set_shortcut_context(this);
  1619. goto_menu = memnew(MenuButton);
  1620. goto_menu->set_text(TTR("Go To"));
  1621. goto_menu->set_switch_on_hover(true);
  1622. goto_menu->set_shortcut_context(this);
  1623. bookmarks_menu = memnew(PopupMenu);
  1624. bookmarks_menu->set_name("Bookmarks");
  1625. breakpoints_menu = memnew(PopupMenu);
  1626. breakpoints_menu->set_name("Breakpoints");
  1627. connection_info_dialog = memnew(ConnectionInfoDialog);
  1628. code_editor->get_text_editor()->set_drag_forwarding(this);
  1629. }
  1630. ScriptTextEditor::~ScriptTextEditor() {
  1631. highlighters.clear();
  1632. if (!editor_enabled) {
  1633. memdelete(code_editor);
  1634. memdelete(warnings_panel);
  1635. memdelete(errors_panel);
  1636. memdelete(context_menu);
  1637. memdelete(color_panel);
  1638. memdelete(edit_hb);
  1639. memdelete(edit_menu);
  1640. memdelete(convert_case);
  1641. memdelete(highlighter_menu);
  1642. memdelete(search_menu);
  1643. memdelete(goto_menu);
  1644. memdelete(bookmarks_menu);
  1645. memdelete(breakpoints_menu);
  1646. memdelete(connection_info_dialog);
  1647. }
  1648. }
  1649. static ScriptEditorBase *create_editor(const RES &p_resource) {
  1650. if (Object::cast_to<Script>(*p_resource)) {
  1651. return memnew(ScriptTextEditor);
  1652. }
  1653. return nullptr;
  1654. }
  1655. void ScriptTextEditor::register_editor() {
  1656. ED_SHORTCUT("script_text_editor/move_up", TTR("Move Up"), KeyModifierMask::ALT | Key::UP);
  1657. ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KeyModifierMask::ALT | Key::DOWN);
  1658. ED_SHORTCUT("script_text_editor/delete_line", TTR("Delete Line"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::K);
  1659. // Leave these at zero, same can be accomplished with tab/shift-tab, including selection.
  1660. // The next/previous in history shortcut in this case makes a lot more sense.
  1661. ED_SHORTCUT("script_text_editor/indent_left", TTR("Indent Left"), Key::NONE);
  1662. ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), Key::NONE);
  1663. ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KeyModifierMask::CMD | Key::K);
  1664. ED_SHORTCUT("script_text_editor/toggle_fold_line", TTR("Fold/Unfold Line"), KeyModifierMask::ALT | Key::F);
  1665. ED_SHORTCUT("script_text_editor/fold_all_lines", TTR("Fold All Lines"), Key::NONE);
  1666. ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), Key::NONE);
  1667. ED_SHORTCUT("script_text_editor/duplicate_selection", TTR("Duplicate Selection"), KeyModifierMask::SHIFT | KeyModifierMask::CMD | Key::D);
  1668. ED_SHORTCUT_OVERRIDE("script_text_editor/duplicate_selection", "macos", KeyModifierMask::SHIFT | KeyModifierMask::CMD | Key::C);
  1669. ED_SHORTCUT("script_text_editor/evaluate_selection", TTR("Evaluate Selection"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::E);
  1670. ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KeyModifierMask::CMD | KeyModifierMask::ALT | Key::T);
  1671. ED_SHORTCUT("script_text_editor/convert_indent_to_spaces", TTR("Convert Indent to Spaces"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::Y);
  1672. ED_SHORTCUT("script_text_editor/convert_indent_to_tabs", TTR("Convert Indent to Tabs"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::I);
  1673. ED_SHORTCUT("script_text_editor/auto_indent", TTR("Auto Indent"), KeyModifierMask::CMD | Key::I);
  1674. ED_SHORTCUT_AND_COMMAND("script_text_editor/find", TTR("Find..."), KeyModifierMask::CMD | Key::F);
  1675. ED_SHORTCUT("script_text_editor/find_next", TTR("Find Next"), Key::F3);
  1676. ED_SHORTCUT_OVERRIDE("script_text_editor/find_next", "macos", KeyModifierMask::CMD | Key::G);
  1677. ED_SHORTCUT("script_text_editor/find_previous", TTR("Find Previous"), KeyModifierMask::SHIFT | Key::F3);
  1678. ED_SHORTCUT_OVERRIDE("script_text_editor/find_previous", "macos", KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::G);
  1679. ED_SHORTCUT_AND_COMMAND("script_text_editor/replace", TTR("Replace..."), KeyModifierMask::CMD | Key::R);
  1680. ED_SHORTCUT_OVERRIDE("script_text_editor/replace", "macos", KeyModifierMask::ALT | KeyModifierMask::CMD | Key::F);
  1681. ED_SHORTCUT("script_text_editor/find_in_files", TTR("Find in Files..."), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::F);
  1682. ED_SHORTCUT("script_text_editor/replace_in_files", TTR("Replace in Files..."), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::R);
  1683. ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KeyModifierMask::ALT | Key::F1);
  1684. ED_SHORTCUT_OVERRIDE("script_text_editor/contextual_help", "macos", KeyModifierMask::ALT | KeyModifierMask::SHIFT | Key::SPACE);
  1685. ED_SHORTCUT("script_text_editor/toggle_bookmark", TTR("Toggle Bookmark"), KeyModifierMask::CMD | KeyModifierMask::ALT | Key::B);
  1686. ED_SHORTCUT("script_text_editor/goto_next_bookmark", TTR("Go to Next Bookmark"), KeyModifierMask::CMD | Key::B);
  1687. ED_SHORTCUT("script_text_editor/goto_previous_bookmark", TTR("Go to Previous Bookmark"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::B);
  1688. ED_SHORTCUT("script_text_editor/remove_all_bookmarks", TTR("Remove All Bookmarks"), Key::NONE);
  1689. ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KeyModifierMask::ALT | KeyModifierMask::CMD | Key::F);
  1690. ED_SHORTCUT_OVERRIDE("script_text_editor/goto_function", "macos", KeyModifierMask::CTRL | KeyModifierMask::CMD | Key::J);
  1691. ED_SHORTCUT("script_text_editor/goto_line", TTR("Go to Line..."), KeyModifierMask::CMD | Key::L);
  1692. ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), Key::F9);
  1693. ED_SHORTCUT_OVERRIDE("script_text_editor/toggle_breakpoint", "macos", KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::B);
  1694. ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::F9);
  1695. ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Go to Next Breakpoint"), KeyModifierMask::CMD | Key::PERIOD);
  1696. ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Go to Previous Breakpoint"), KeyModifierMask::CMD | Key::COMMA);
  1697. ScriptEditor::register_create_script_editor_function(create_editor);
  1698. }
  1699. void ScriptTextEditor::validate() {
  1700. this->code_editor->validate_script();
  1701. }