script_text_editor.cpp 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034
  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-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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_node.h"
  35. #include "editor/editor_scale.h"
  36. #include "editor/editor_settings.h"
  37. void ConnectionInfoDialog::ok_pressed() {
  38. }
  39. void ConnectionInfoDialog::popup_connections(String p_method, Vector<Node *> p_nodes) {
  40. method->set_text(p_method);
  41. tree->clear();
  42. TreeItem *root = tree->create_item();
  43. for (int i = 0; i < p_nodes.size(); i++) {
  44. List<Connection> all_connections;
  45. p_nodes[i]->get_signals_connected_to_this(&all_connections);
  46. for (List<Connection>::Element *E = all_connections.front(); E; E = E->next()) {
  47. Connection connection = E->get();
  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. node_item->set_icon(1, get_parent_control()->get_icon("Slot", "EditorIcons"));
  58. node_item->set_selectable(1, false);
  59. node_item->set_editable(1, false);
  60. node_item->set_text(2, Object::cast_to<Node>(connection.callable.get_object())->get_name());
  61. node_item->set_icon(2, EditorNode::get_singleton()->get_object_icon(connection.callable.get_object(), "Node"));
  62. node_item->set_selectable(2, false);
  63. node_item->set_editable(2, false);
  64. }
  65. }
  66. popup_centered(Size2(600, 300) * EDSCALE);
  67. }
  68. ConnectionInfoDialog::ConnectionInfoDialog() {
  69. set_title(TTR("Connections to method:"));
  70. VBoxContainer *vbc = memnew(VBoxContainer);
  71. vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE);
  72. vbc->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 8 * EDSCALE);
  73. vbc->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -8 * EDSCALE);
  74. vbc->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -8 * EDSCALE);
  75. add_child(vbc);
  76. method = memnew(Label);
  77. method->set_align(Label::ALIGN_CENTER);
  78. vbc->add_child(method);
  79. tree = memnew(Tree);
  80. tree->set_columns(3);
  81. tree->set_hide_root(true);
  82. tree->set_column_titles_visible(true);
  83. tree->set_column_title(0, TTR("Source"));
  84. tree->set_column_title(1, TTR("Signal"));
  85. tree->set_column_title(2, TTR("Target"));
  86. vbc->add_child(tree);
  87. tree->set_v_size_flags(SIZE_EXPAND_FILL);
  88. tree->set_allow_rmb_select(true);
  89. }
  90. ////////////////////////////////////////////////////////////////////////////////
  91. Vector<String> ScriptTextEditor::get_functions() {
  92. String errortxt;
  93. int line = -1, col;
  94. TextEdit *te = code_editor->get_text_edit();
  95. String text = te->get_text();
  96. List<String> fnc;
  97. if (script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc)) {
  98. //if valid rewrite functions to latest
  99. functions.clear();
  100. for (List<String>::Element *E = fnc.front(); E; E = E->next()) {
  101. functions.push_back(E->get());
  102. }
  103. }
  104. return functions;
  105. }
  106. void ScriptTextEditor::apply_code() {
  107. if (script.is_null())
  108. return;
  109. script->set_source_code(code_editor->get_text_edit()->get_text());
  110. script->update_exports();
  111. _update_member_keywords();
  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_null());
  118. script = p_res;
  119. _set_theme_for_script();
  120. code_editor->get_text_edit()->set_text(script->get_source_code());
  121. code_editor->get_text_edit()->clear_undo_history();
  122. code_editor->get_text_edit()->tag_saved_version();
  123. emit_signal("name_changed");
  124. code_editor->update_line_and_column();
  125. _validate_script();
  126. }
  127. void ScriptTextEditor::_update_member_keywords() {
  128. member_keywords.clear();
  129. code_editor->get_text_edit()->clear_member_keywords();
  130. Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
  131. StringName instance_base = script->get_instance_base_type();
  132. if (instance_base == StringName())
  133. return;
  134. List<PropertyInfo> plist;
  135. ClassDB::get_property_list(instance_base, &plist);
  136. for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
  137. String name = E->get().name;
  138. if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP)
  139. continue;
  140. if (name.find("/") != -1)
  141. continue;
  142. code_editor->get_text_edit()->add_member_keyword(name, member_variable_color);
  143. }
  144. List<String> clist;
  145. ClassDB::get_integer_constant_list(instance_base, &clist);
  146. for (List<String>::Element *E = clist.front(); E; E = E->next()) {
  147. code_editor->get_text_edit()->add_member_keyword(E->get(), member_variable_color);
  148. }
  149. }
  150. void ScriptTextEditor::_load_theme_settings() {
  151. TextEdit *text_edit = code_editor->get_text_edit();
  152. text_edit->clear_colors();
  153. Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
  154. Color completion_background_color = EDITOR_GET("text_editor/highlighting/completion_background_color");
  155. Color completion_selected_color = EDITOR_GET("text_editor/highlighting/completion_selected_color");
  156. Color completion_existing_color = EDITOR_GET("text_editor/highlighting/completion_existing_color");
  157. Color completion_scroll_color = EDITOR_GET("text_editor/highlighting/completion_scroll_color");
  158. Color completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color");
  159. Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
  160. Color line_number_color = EDITOR_GET("text_editor/highlighting/line_number_color");
  161. Color safe_line_number_color = EDITOR_GET("text_editor/highlighting/safe_line_number_color");
  162. Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color");
  163. Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color");
  164. Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color");
  165. Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color");
  166. Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color");
  167. Color current_line_color = EDITOR_GET("text_editor/highlighting/current_line_color");
  168. Color line_length_guideline_color = EDITOR_GET("text_editor/highlighting/line_length_guideline_color");
  169. Color word_highlighted_color = EDITOR_GET("text_editor/highlighting/word_highlighted_color");
  170. Color number_color = EDITOR_GET("text_editor/highlighting/number_color");
  171. Color function_color = EDITOR_GET("text_editor/highlighting/function_color");
  172. Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
  173. Color mark_color = EDITOR_GET("text_editor/highlighting/mark_color");
  174. Color bookmark_color = EDITOR_GET("text_editor/highlighting/bookmark_color");
  175. Color breakpoint_color = EDITOR_GET("text_editor/highlighting/breakpoint_color");
  176. Color executing_line_color = EDITOR_GET("text_editor/highlighting/executing_line_color");
  177. Color code_folding_color = EDITOR_GET("text_editor/highlighting/code_folding_color");
  178. Color search_result_color = EDITOR_GET("text_editor/highlighting/search_result_color");
  179. Color search_result_border_color = EDITOR_GET("text_editor/highlighting/search_result_border_color");
  180. Color symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color");
  181. Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
  182. Color basetype_color = EDITOR_GET("text_editor/highlighting/base_type_color");
  183. Color type_color = EDITOR_GET("text_editor/highlighting/engine_type_color");
  184. Color usertype_color = EDITOR_GET("text_editor/highlighting/user_type_color");
  185. Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color");
  186. Color string_color = EDITOR_GET("text_editor/highlighting/string_color");
  187. text_edit->add_color_override("background_color", background_color);
  188. text_edit->add_color_override("completion_background_color", completion_background_color);
  189. text_edit->add_color_override("completion_selected_color", completion_selected_color);
  190. text_edit->add_color_override("completion_existing_color", completion_existing_color);
  191. text_edit->add_color_override("completion_scroll_color", completion_scroll_color);
  192. text_edit->add_color_override("completion_font_color", completion_font_color);
  193. text_edit->add_color_override("font_color", text_color);
  194. text_edit->add_color_override("line_number_color", line_number_color);
  195. text_edit->add_color_override("safe_line_number_color", safe_line_number_color);
  196. text_edit->add_color_override("caret_color", caret_color);
  197. text_edit->add_color_override("caret_background_color", caret_background_color);
  198. text_edit->add_color_override("font_color_selected", text_selected_color);
  199. text_edit->add_color_override("selection_color", selection_color);
  200. text_edit->add_color_override("brace_mismatch_color", brace_mismatch_color);
  201. text_edit->add_color_override("current_line_color", current_line_color);
  202. text_edit->add_color_override("line_length_guideline_color", line_length_guideline_color);
  203. text_edit->add_color_override("word_highlighted_color", word_highlighted_color);
  204. text_edit->add_color_override("number_color", number_color);
  205. text_edit->add_color_override("function_color", function_color);
  206. text_edit->add_color_override("member_variable_color", member_variable_color);
  207. text_edit->add_color_override("bookmark_color", bookmark_color);
  208. text_edit->add_color_override("breakpoint_color", breakpoint_color);
  209. text_edit->add_color_override("executing_line_color", executing_line_color);
  210. text_edit->add_color_override("mark_color", mark_color);
  211. text_edit->add_color_override("code_folding_color", code_folding_color);
  212. text_edit->add_color_override("search_result_color", search_result_color);
  213. text_edit->add_color_override("search_result_border_color", search_result_border_color);
  214. text_edit->add_color_override("symbol_color", symbol_color);
  215. text_edit->add_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 6));
  216. colors_cache.symbol_color = symbol_color;
  217. colors_cache.keyword_color = keyword_color;
  218. colors_cache.basetype_color = basetype_color;
  219. colors_cache.type_color = type_color;
  220. colors_cache.usertype_color = usertype_color;
  221. colors_cache.comment_color = comment_color;
  222. colors_cache.string_color = string_color;
  223. theme_loaded = true;
  224. if (!script.is_null())
  225. _set_theme_for_script();
  226. }
  227. void ScriptTextEditor::_set_theme_for_script() {
  228. if (!theme_loaded)
  229. return;
  230. TextEdit *text_edit = code_editor->get_text_edit();
  231. List<String> keywords;
  232. script->get_language()->get_reserved_words(&keywords);
  233. for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
  234. text_edit->add_keyword_color(E->get(), colors_cache.keyword_color);
  235. }
  236. //colorize core types
  237. const Color basetype_color = colors_cache.basetype_color;
  238. text_edit->add_keyword_color("String", basetype_color);
  239. text_edit->add_keyword_color("Vector2", basetype_color);
  240. text_edit->add_keyword_color("Rect2", basetype_color);
  241. text_edit->add_keyword_color("Transform2D", basetype_color);
  242. text_edit->add_keyword_color("Vector3", basetype_color);
  243. text_edit->add_keyword_color("AABB", basetype_color);
  244. text_edit->add_keyword_color("Basis", basetype_color);
  245. text_edit->add_keyword_color("Plane", basetype_color);
  246. text_edit->add_keyword_color("Transform", basetype_color);
  247. text_edit->add_keyword_color("Quat", basetype_color);
  248. text_edit->add_keyword_color("Color", basetype_color);
  249. text_edit->add_keyword_color("Object", basetype_color);
  250. text_edit->add_keyword_color("NodePath", basetype_color);
  251. text_edit->add_keyword_color("RID", basetype_color);
  252. text_edit->add_keyword_color("Dictionary", basetype_color);
  253. text_edit->add_keyword_color("Array", basetype_color);
  254. text_edit->add_keyword_color("PackedByteArray", basetype_color);
  255. text_edit->add_keyword_color("PackedIntArray", basetype_color);
  256. text_edit->add_keyword_color("PackedRealArray", basetype_color);
  257. text_edit->add_keyword_color("PackedStringArray", basetype_color);
  258. text_edit->add_keyword_color("PackedVector2Array", basetype_color);
  259. text_edit->add_keyword_color("PackedVector3Array", basetype_color);
  260. text_edit->add_keyword_color("PackedColorArray", basetype_color);
  261. //colorize engine types
  262. List<StringName> types;
  263. ClassDB::get_class_list(&types);
  264. for (List<StringName>::Element *E = types.front(); E; E = E->next()) {
  265. String n = E->get();
  266. if (n.begins_with("_"))
  267. n = n.substr(1, n.length());
  268. text_edit->add_keyword_color(n, colors_cache.type_color);
  269. }
  270. _update_member_keywords();
  271. //colorize user types
  272. List<StringName> global_classes;
  273. ScriptServer::get_global_class_list(&global_classes);
  274. for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
  275. text_edit->add_keyword_color(E->get(), colors_cache.usertype_color);
  276. }
  277. //colorize singleton autoloads (as types, just as engine singletons are)
  278. List<PropertyInfo> props;
  279. ProjectSettings::get_singleton()->get_property_list(&props);
  280. for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
  281. String s = E->get().name;
  282. if (!s.begins_with("autoload/")) {
  283. continue;
  284. }
  285. String path = ProjectSettings::get_singleton()->get(s);
  286. if (path.begins_with("*")) {
  287. text_edit->add_keyword_color(s.get_slice("/", 1), colors_cache.usertype_color);
  288. }
  289. }
  290. //colorize comments
  291. List<String> comments;
  292. script->get_language()->get_comment_delimiters(&comments);
  293. for (List<String>::Element *E = comments.front(); E; E = E->next()) {
  294. String comment = E->get();
  295. String beg = comment.get_slice(" ", 0);
  296. String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String();
  297. text_edit->add_color_region(beg, end, colors_cache.comment_color, end == "");
  298. }
  299. //colorize strings
  300. List<String> strings;
  301. script->get_language()->get_string_delimiters(&strings);
  302. for (List<String>::Element *E = strings.front(); E; E = E->next()) {
  303. String string = E->get();
  304. String beg = string.get_slice(" ", 0);
  305. String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String();
  306. text_edit->add_color_region(beg, end, colors_cache.string_color, end == "");
  307. }
  308. }
  309. void ScriptTextEditor::_show_warnings_panel(bool p_show) {
  310. warnings_panel->set_visible(p_show);
  311. }
  312. void ScriptTextEditor::_error_pressed() {
  313. code_editor->goto_error();
  314. }
  315. void ScriptTextEditor::_warning_clicked(Variant p_line) {
  316. if (p_line.get_type() == Variant::INT) {
  317. code_editor->get_text_edit()->cursor_set_line(p_line.operator int64_t());
  318. } else if (p_line.get_type() == Variant::DICTIONARY) {
  319. Dictionary meta = p_line.operator Dictionary();
  320. code_editor->get_text_edit()->insert_at("# warning-ignore:" + meta["code"].operator String(), meta["line"].operator int64_t() - 1);
  321. _validate_script();
  322. }
  323. }
  324. void ScriptTextEditor::reload_text() {
  325. ERR_FAIL_COND(script.is_null());
  326. TextEdit *te = code_editor->get_text_edit();
  327. int column = te->cursor_get_column();
  328. int row = te->cursor_get_line();
  329. int h = te->get_h_scroll();
  330. int v = te->get_v_scroll();
  331. te->set_text(script->get_source_code());
  332. te->cursor_set_line(row);
  333. te->cursor_set_column(column);
  334. te->set_h_scroll(h);
  335. te->set_v_scroll(v);
  336. te->tag_saved_version();
  337. code_editor->update_line_and_column();
  338. }
  339. void ScriptTextEditor::_notification(int p_what) {
  340. switch (p_what) {
  341. case NOTIFICATION_READY:
  342. _load_theme_settings();
  343. break;
  344. }
  345. }
  346. void ScriptTextEditor::add_callback(const String &p_function, PackedStringArray p_args) {
  347. String code = code_editor->get_text_edit()->get_text();
  348. int pos = script->get_language()->find_function(p_function, code);
  349. if (pos == -1) {
  350. //does not exist
  351. code_editor->get_text_edit()->deselect();
  352. pos = code_editor->get_text_edit()->get_line_count() + 2;
  353. String func = script->get_language()->make_function("", p_function, p_args);
  354. //code=code+func;
  355. code_editor->get_text_edit()->cursor_set_line(pos + 1);
  356. code_editor->get_text_edit()->cursor_set_column(1000000); //none shall be that big
  357. code_editor->get_text_edit()->insert_text_at_cursor("\n\n" + func);
  358. }
  359. code_editor->get_text_edit()->cursor_set_line(pos);
  360. code_editor->get_text_edit()->cursor_set_column(1);
  361. }
  362. bool ScriptTextEditor::show_members_overview() {
  363. return true;
  364. }
  365. void ScriptTextEditor::update_settings() {
  366. code_editor->update_editor_settings();
  367. }
  368. bool ScriptTextEditor::is_unsaved() {
  369. return code_editor->get_text_edit()->get_version() != code_editor->get_text_edit()->get_saved_version();
  370. }
  371. Variant ScriptTextEditor::get_edit_state() {
  372. return code_editor->get_edit_state();
  373. }
  374. void ScriptTextEditor::set_edit_state(const Variant &p_state) {
  375. code_editor->set_edit_state(p_state);
  376. Dictionary state = p_state;
  377. if (state.has("syntax_highlighter")) {
  378. int idx = highlighter_menu->get_item_idx_from_text(state["syntax_highlighter"]);
  379. if (idx >= 0) {
  380. _change_syntax_highlighter(idx);
  381. }
  382. }
  383. }
  384. void ScriptTextEditor::_convert_case(CodeTextEditor::CaseStyle p_case) {
  385. code_editor->convert_case(p_case);
  386. }
  387. void ScriptTextEditor::trim_trailing_whitespace() {
  388. code_editor->trim_trailing_whitespace();
  389. }
  390. void ScriptTextEditor::insert_final_newline() {
  391. code_editor->insert_final_newline();
  392. }
  393. void ScriptTextEditor::convert_indent_to_spaces() {
  394. code_editor->convert_indent_to_spaces();
  395. }
  396. void ScriptTextEditor::convert_indent_to_tabs() {
  397. code_editor->convert_indent_to_tabs();
  398. }
  399. void ScriptTextEditor::tag_saved_version() {
  400. code_editor->get_text_edit()->tag_saved_version();
  401. }
  402. void ScriptTextEditor::goto_line(int p_line, bool p_with_error) {
  403. code_editor->goto_line(p_line);
  404. }
  405. void ScriptTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) {
  406. code_editor->goto_line_selection(p_line, p_begin, p_end);
  407. }
  408. void ScriptTextEditor::goto_line_centered(int p_line) {
  409. code_editor->goto_line_centered(p_line);
  410. }
  411. void ScriptTextEditor::set_executing_line(int p_line) {
  412. code_editor->set_executing_line(p_line);
  413. }
  414. void ScriptTextEditor::clear_executing_line() {
  415. code_editor->clear_executing_line();
  416. }
  417. void ScriptTextEditor::ensure_focus() {
  418. code_editor->get_text_edit()->grab_focus();
  419. }
  420. String ScriptTextEditor::get_name() {
  421. String name;
  422. if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) {
  423. name = script->get_path().get_file();
  424. if (is_unsaved()) {
  425. name += "(*)";
  426. }
  427. } else if (script->get_name() != "")
  428. name = script->get_name();
  429. else
  430. name = script->get_class() + "(" + itos(script->get_instance_id()) + ")";
  431. return name;
  432. }
  433. Ref<Texture2D> ScriptTextEditor::get_icon() {
  434. if (get_parent_control() && get_parent_control()->has_icon(script->get_class(), "EditorIcons")) {
  435. return get_parent_control()->get_icon(script->get_class(), "EditorIcons");
  436. }
  437. return Ref<Texture2D>();
  438. }
  439. void ScriptTextEditor::_validate_script() {
  440. String errortxt;
  441. int line = -1, col;
  442. TextEdit *te = code_editor->get_text_edit();
  443. String text = te->get_text();
  444. List<String> fnc;
  445. Set<int> safe_lines;
  446. List<ScriptLanguage::Warning> warnings;
  447. if (!script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc, &warnings, &safe_lines)) {
  448. String error_text = "error(" + itos(line) + "," + itos(col) + "): " + errortxt;
  449. code_editor->set_error(error_text);
  450. code_editor->set_error_pos(line - 1, col - 1);
  451. script_is_valid = false;
  452. } else {
  453. code_editor->set_error("");
  454. line = -1;
  455. if (!script->is_tool()) {
  456. script->set_source_code(text);
  457. script->update_exports();
  458. _update_member_keywords();
  459. }
  460. functions.clear();
  461. for (List<String>::Element *E = fnc.front(); E; E = E->next()) {
  462. functions.push_back(E->get());
  463. }
  464. script_is_valid = true;
  465. }
  466. _update_connected_methods();
  467. int warning_nb = warnings.size();
  468. warnings_panel->clear();
  469. // Add missing connections.
  470. if (GLOBAL_GET("debug/gdscript/warnings/enable").booleanize()) {
  471. Node *base = get_tree()->get_edited_scene_root();
  472. if (base && missing_connections.size() > 0) {
  473. warnings_panel->push_table(1);
  474. for (List<Connection>::Element *E = missing_connections.front(); E; E = E->next()) {
  475. Connection connection = E->get();
  476. String base_path = base->get_name();
  477. String source_path = base == connection.signal.get_object() ? base_path : base_path + "/" + base->get_path_to(Object::cast_to<Node>(connection.signal.get_object()));
  478. String target_path = base == connection.callable.get_object() ? base_path : base_path + "/" + base->get_path_to(Object::cast_to<Node>(connection.callable.get_object()));
  479. warnings_panel->push_cell();
  480. warnings_panel->push_color(warnings_panel->get_color("warning_color", "Editor"));
  481. 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));
  482. warnings_panel->pop(); // Color.
  483. warnings_panel->pop(); // Cell.
  484. }
  485. warnings_panel->pop(); // Table.
  486. warning_nb += missing_connections.size();
  487. }
  488. }
  489. code_editor->set_warning_nb(warning_nb);
  490. // Add script warnings.
  491. warnings_panel->push_table(3);
  492. for (List<ScriptLanguage::Warning>::Element *E = warnings.front(); E; E = E->next()) {
  493. ScriptLanguage::Warning w = E->get();
  494. warnings_panel->push_cell();
  495. warnings_panel->push_meta(w.line - 1);
  496. warnings_panel->push_color(warnings_panel->get_color("warning_color", "Editor"));
  497. warnings_panel->add_text(TTR("Line") + " " + itos(w.line));
  498. warnings_panel->add_text(" (" + w.string_code + "):");
  499. warnings_panel->pop(); // Color.
  500. warnings_panel->pop(); // Meta goto.
  501. warnings_panel->pop(); // Cell.
  502. warnings_panel->push_cell();
  503. warnings_panel->add_text(w.message);
  504. warnings_panel->pop(); // Cell.
  505. Dictionary ignore_meta;
  506. ignore_meta["line"] = w.line;
  507. ignore_meta["code"] = w.string_code.to_lower();
  508. warnings_panel->push_cell();
  509. warnings_panel->push_meta(ignore_meta);
  510. warnings_panel->add_text(TTR("(ignore)"));
  511. warnings_panel->pop(); // Meta ignore.
  512. warnings_panel->pop(); // Cell.
  513. }
  514. warnings_panel->pop(); // Table.
  515. line--;
  516. bool highlight_safe = EDITOR_DEF("text_editor/highlighting/highlight_type_safe_lines", true);
  517. bool last_is_safe = false;
  518. for (int i = 0; i < te->get_line_count(); i++) {
  519. te->set_line_as_marked(i, line == i);
  520. if (highlight_safe) {
  521. if (safe_lines.has(i + 1)) {
  522. te->set_line_as_safe(i, true);
  523. last_is_safe = true;
  524. } else if (last_is_safe && (te->is_line_comment(i) || te->get_line(i).strip_edges().empty())) {
  525. te->set_line_as_safe(i, true);
  526. } else {
  527. te->set_line_as_safe(i, false);
  528. last_is_safe = false;
  529. }
  530. } else {
  531. te->set_line_as_safe(i, false);
  532. }
  533. }
  534. emit_signal("name_changed");
  535. emit_signal("edited_script_changed");
  536. }
  537. void ScriptTextEditor::_update_bookmark_list() {
  538. bookmarks_menu->clear();
  539. bookmarks_menu->set_size(Size2(1, 1));
  540. bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
  541. bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL);
  542. bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT);
  543. bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV);
  544. Array bookmark_list = code_editor->get_text_edit()->get_bookmarks_array();
  545. if (bookmark_list.size() == 0) {
  546. return;
  547. }
  548. bookmarks_menu->add_separator();
  549. for (int i = 0; i < bookmark_list.size(); i++) {
  550. // Strip edges to remove spaces or tabs.
  551. // Also replace any tabs by spaces, since we can't print tabs in the menu.
  552. String line = code_editor->get_text_edit()->get_line(bookmark_list[i]).replace("\t", " ").strip_edges();
  553. // Limit the size of the line if too big.
  554. if (line.length() > 50) {
  555. line = line.substr(0, 50);
  556. }
  557. bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - `" + line + "`");
  558. bookmarks_menu->set_item_metadata(bookmarks_menu->get_item_count() - 1, bookmark_list[i]);
  559. }
  560. }
  561. void ScriptTextEditor::_bookmark_item_pressed(int p_idx) {
  562. if (p_idx < 4) { // Any item before the separator.
  563. _edit_option(bookmarks_menu->get_item_id(p_idx));
  564. } else {
  565. code_editor->goto_line(bookmarks_menu->get_item_metadata(p_idx));
  566. code_editor->get_text_edit()->call_deferred("center_viewport_to_cursor"); //Need to be deferred, because goto uses call_deferred().
  567. }
  568. }
  569. static Vector<Node *> _find_all_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) {
  570. Vector<Node *> nodes;
  571. if (p_current->get_owner() != p_base && p_base != p_current) {
  572. return nodes;
  573. }
  574. Ref<Script> c = p_current->get_script();
  575. if (c == p_script) {
  576. nodes.push_back(p_current);
  577. }
  578. for (int i = 0; i < p_current->get_child_count(); i++) {
  579. Vector<Node *> found = _find_all_node_for_script(p_base, p_current->get_child(i), p_script);
  580. nodes.append_array(found);
  581. }
  582. return nodes;
  583. }
  584. static Node *_find_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) {
  585. if (p_current->get_owner() != p_base && p_base != p_current)
  586. return NULL;
  587. Ref<Script> c = p_current->get_script();
  588. if (c == p_script)
  589. return p_current;
  590. for (int i = 0; i < p_current->get_child_count(); i++) {
  591. Node *found = _find_node_for_script(p_base, p_current->get_child(i), p_script);
  592. if (found)
  593. return found;
  594. }
  595. return NULL;
  596. }
  597. static void _find_changed_scripts_for_external_editor(Node *p_base, Node *p_current, Set<Ref<Script> > &r_scripts) {
  598. if (p_current->get_owner() != p_base && p_base != p_current)
  599. return;
  600. Ref<Script> c = p_current->get_script();
  601. if (c.is_valid())
  602. r_scripts.insert(c);
  603. for (int i = 0; i < p_current->get_child_count(); i++) {
  604. _find_changed_scripts_for_external_editor(p_base, p_current->get_child(i), r_scripts);
  605. }
  606. }
  607. void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_for_script) {
  608. if (!bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")))
  609. return;
  610. ERR_FAIL_COND(!get_tree());
  611. Set<Ref<Script> > scripts;
  612. Node *base = get_tree()->get_edited_scene_root();
  613. if (base) {
  614. _find_changed_scripts_for_external_editor(base, base, scripts);
  615. }
  616. for (Set<Ref<Script> >::Element *E = scripts.front(); E; E = E->next()) {
  617. Ref<Script> script = E->get();
  618. if (p_for_script.is_valid() && p_for_script != script)
  619. continue;
  620. if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) {
  621. continue; //internal script, who cares, though weird
  622. }
  623. uint64_t last_date = script->get_last_modified_time();
  624. uint64_t date = FileAccess::get_modified_time(script->get_path());
  625. if (last_date != date) {
  626. Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true);
  627. ERR_CONTINUE(!rel_script.is_valid());
  628. script->set_source_code(rel_script->get_source_code());
  629. script->set_last_modified_time(rel_script->get_last_modified_time());
  630. script->update_exports();
  631. }
  632. }
  633. }
  634. void ScriptTextEditor::_code_complete_scripts(void *p_ud, const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_force) {
  635. ScriptTextEditor *ste = (ScriptTextEditor *)p_ud;
  636. ste->_code_complete_script(p_code, r_options, r_force);
  637. }
  638. void ScriptTextEditor::_code_complete_script(const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_force) {
  639. if (color_panel->is_visible_in_tree()) return;
  640. Node *base = get_tree()->get_edited_scene_root();
  641. if (base) {
  642. base = _find_node_for_script(base, base, script);
  643. }
  644. String hint;
  645. Error err = script->get_language()->complete_code(p_code, script->get_path(), base, r_options, r_force, hint);
  646. if (err == OK) {
  647. code_editor->get_text_edit()->set_code_hint(hint);
  648. }
  649. }
  650. void ScriptTextEditor::_update_breakpoint_list() {
  651. breakpoints_menu->clear();
  652. breakpoints_menu->set_size(Size2(1, 1));
  653. breakpoints_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_breakpoint"), DEBUG_TOGGLE_BREAKPOINT);
  654. breakpoints_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_breakpoints"), DEBUG_REMOVE_ALL_BREAKPOINTS);
  655. breakpoints_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_breakpoint"), DEBUG_GOTO_NEXT_BREAKPOINT);
  656. breakpoints_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_breakpoint"), DEBUG_GOTO_PREV_BREAKPOINT);
  657. Array breakpoint_list = code_editor->get_text_edit()->get_breakpoints_array();
  658. if (breakpoint_list.size() == 0) {
  659. return;
  660. }
  661. breakpoints_menu->add_separator();
  662. for (int i = 0; i < breakpoint_list.size(); i++) {
  663. // Strip edges to remove spaces or tabs.
  664. // Also replace any tabs by spaces, since we can't print tabs in the menu.
  665. String line = code_editor->get_text_edit()->get_line(breakpoint_list[i]).replace("\t", " ").strip_edges();
  666. // Limit the size of the line if too big.
  667. if (line.length() > 50) {
  668. line = line.substr(0, 50);
  669. }
  670. breakpoints_menu->add_item(String::num((int)breakpoint_list[i] + 1) + " - `" + line + "`");
  671. breakpoints_menu->set_item_metadata(breakpoints_menu->get_item_count() - 1, breakpoint_list[i]);
  672. }
  673. }
  674. void ScriptTextEditor::_breakpoint_item_pressed(int p_idx) {
  675. if (p_idx < 4) { // Any item before the separator.
  676. _edit_option(breakpoints_menu->get_item_id(p_idx));
  677. } else {
  678. code_editor->goto_line(breakpoints_menu->get_item_metadata(p_idx));
  679. code_editor->get_text_edit()->call_deferred("center_viewport_to_cursor"); //Need to be deferred, because goto uses call_deferred().
  680. }
  681. }
  682. void ScriptTextEditor::_breakpoint_toggled(int p_row) {
  683. EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), p_row + 1, code_editor->get_text_edit()->is_line_set_as_breakpoint(p_row));
  684. }
  685. void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_column) {
  686. Node *base = get_tree()->get_edited_scene_root();
  687. if (base) {
  688. base = _find_node_for_script(base, base, script);
  689. }
  690. ScriptLanguage::LookupResult result;
  691. if (ScriptServer::is_global_class(p_symbol)) {
  692. EditorNode::get_singleton()->load_resource(ScriptServer::get_global_class_path(p_symbol));
  693. } else if (p_symbol.is_resource_file()) {
  694. List<String> scene_extensions;
  695. ResourceLoader::get_recognized_extensions_for_type("PackedScene", &scene_extensions);
  696. if (scene_extensions.find(p_symbol.get_extension())) {
  697. EditorNode::get_singleton()->load_scene(p_symbol);
  698. } else {
  699. EditorNode::get_singleton()->load_resource(p_symbol);
  700. }
  701. } else if (script->get_language()->lookup_code(code_editor->get_text_edit()->get_text_for_lookup_completion(), p_symbol, script->get_path(), base, result) == OK) {
  702. _goto_line(p_row);
  703. result.class_name = result.class_name.trim_prefix("_");
  704. switch (result.type) {
  705. case ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION: {
  706. if (result.script.is_valid()) {
  707. emit_signal("request_open_script_at_line", result.script, result.location - 1);
  708. } else {
  709. emit_signal("request_save_history");
  710. _goto_line(result.location - 1);
  711. }
  712. } break;
  713. case ScriptLanguage::LookupResult::RESULT_CLASS: {
  714. emit_signal("go_to_help", "class_name:" + result.class_name);
  715. } break;
  716. case ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT: {
  717. StringName cname = result.class_name;
  718. bool success;
  719. while (true) {
  720. ClassDB::get_integer_constant(cname, result.class_member, &success);
  721. if (success) {
  722. result.class_name = cname;
  723. cname = ClassDB::get_parent_class(cname);
  724. } else {
  725. break;
  726. }
  727. }
  728. emit_signal("go_to_help", "class_constant:" + result.class_name + ":" + result.class_member);
  729. } break;
  730. case ScriptLanguage::LookupResult::RESULT_CLASS_PROPERTY: {
  731. emit_signal("go_to_help", "class_property:" + result.class_name + ":" + result.class_member);
  732. } break;
  733. case ScriptLanguage::LookupResult::RESULT_CLASS_METHOD: {
  734. StringName cname = result.class_name;
  735. while (true) {
  736. if (ClassDB::has_method(cname, result.class_member)) {
  737. result.class_name = cname;
  738. cname = ClassDB::get_parent_class(cname);
  739. } else {
  740. break;
  741. }
  742. }
  743. emit_signal("go_to_help", "class_method:" + result.class_name + ":" + result.class_member);
  744. } break;
  745. case ScriptLanguage::LookupResult::RESULT_CLASS_ENUM: {
  746. StringName cname = result.class_name;
  747. StringName success;
  748. while (true) {
  749. success = ClassDB::get_integer_constant_enum(cname, result.class_member, true);
  750. if (success != StringName()) {
  751. result.class_name = cname;
  752. cname = ClassDB::get_parent_class(cname);
  753. } else {
  754. break;
  755. }
  756. }
  757. emit_signal("go_to_help", "class_enum:" + result.class_name + ":" + result.class_member);
  758. } break;
  759. case ScriptLanguage::LookupResult::RESULT_CLASS_TBD_GLOBALSCOPE: {
  760. emit_signal("go_to_help", "class_global:" + result.class_name + ":" + result.class_member);
  761. } break;
  762. }
  763. }
  764. }
  765. void ScriptTextEditor::update_toggle_scripts_button() {
  766. if (code_editor != NULL) {
  767. code_editor->update_toggle_scripts_button();
  768. }
  769. }
  770. void ScriptTextEditor::_update_connected_methods() {
  771. TextEdit *text_edit = code_editor->get_text_edit();
  772. text_edit->clear_info_icons();
  773. missing_connections.clear();
  774. if (!script_is_valid) {
  775. return;
  776. }
  777. Node *base = get_tree()->get_edited_scene_root();
  778. if (!base) {
  779. return;
  780. }
  781. Vector<Node *> nodes = _find_all_node_for_script(base, base, script);
  782. Set<StringName> methods_found;
  783. for (int i = 0; i < nodes.size(); i++) {
  784. List<Connection> connections;
  785. nodes[i]->get_signals_connected_to_this(&connections);
  786. for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
  787. Connection connection = E->get();
  788. if (!(connection.flags & CONNECT_PERSIST)) {
  789. continue;
  790. }
  791. // As deleted nodes are still accessible via the undo/redo system, check if they're still on the tree.
  792. Node *source = Object::cast_to<Node>(connection.signal.get_object());
  793. if (source && !source->is_inside_tree()) {
  794. continue;
  795. }
  796. if (methods_found.has(connection.callable.get_method())) {
  797. continue;
  798. }
  799. if (!ClassDB::has_method(script->get_instance_base_type(), connection.callable.get_method())) {
  800. int line = -1;
  801. for (int j = 0; j < functions.size(); j++) {
  802. String name = functions[j].get_slice(":", 0);
  803. if (name == connection.callable.get_method()) {
  804. line = functions[j].get_slice(":", 1).to_int();
  805. text_edit->set_line_info_icon(line - 1, get_parent_control()->get_icon("Slot", "EditorIcons"), connection.callable.get_method());
  806. methods_found.insert(connection.callable.get_method());
  807. break;
  808. }
  809. }
  810. if (line >= 0) {
  811. continue;
  812. }
  813. // There is a chance that the method is inherited from another script.
  814. bool found_inherited_function = false;
  815. Ref<Script> inherited_script = script->get_base_script();
  816. while (!inherited_script.is_null()) {
  817. if (inherited_script->has_method(connection.callable.get_method())) {
  818. found_inherited_function = true;
  819. break;
  820. }
  821. inherited_script = inherited_script->get_base_script();
  822. }
  823. if (!found_inherited_function) {
  824. missing_connections.push_back(connection);
  825. }
  826. }
  827. }
  828. }
  829. }
  830. void ScriptTextEditor::_lookup_connections(int p_row, String p_method) {
  831. Node *base = get_tree()->get_edited_scene_root();
  832. if (!base) {
  833. return;
  834. }
  835. Vector<Node *> nodes = _find_all_node_for_script(base, base, script);
  836. connection_info_dialog->popup_connections(p_method, nodes);
  837. }
  838. void ScriptTextEditor::_edit_option(int p_op) {
  839. TextEdit *tx = code_editor->get_text_edit();
  840. switch (p_op) {
  841. case EDIT_UNDO: {
  842. tx->undo();
  843. tx->call_deferred("grab_focus");
  844. } break;
  845. case EDIT_REDO: {
  846. tx->redo();
  847. tx->call_deferred("grab_focus");
  848. } break;
  849. case EDIT_CUT: {
  850. tx->cut();
  851. tx->call_deferred("grab_focus");
  852. } break;
  853. case EDIT_COPY: {
  854. tx->copy();
  855. tx->call_deferred("grab_focus");
  856. } break;
  857. case EDIT_PASTE: {
  858. tx->paste();
  859. tx->call_deferred("grab_focus");
  860. } break;
  861. case EDIT_SELECT_ALL: {
  862. tx->select_all();
  863. tx->call_deferred("grab_focus");
  864. } break;
  865. case EDIT_MOVE_LINE_UP: {
  866. code_editor->move_lines_up();
  867. } break;
  868. case EDIT_MOVE_LINE_DOWN: {
  869. code_editor->move_lines_down();
  870. } break;
  871. case EDIT_INDENT_LEFT: {
  872. Ref<Script> scr = script;
  873. if (scr.is_null())
  874. return;
  875. tx->indent_left();
  876. } break;
  877. case EDIT_INDENT_RIGHT: {
  878. Ref<Script> scr = script;
  879. if (scr.is_null())
  880. return;
  881. tx->indent_right();
  882. } break;
  883. case EDIT_DELETE_LINE: {
  884. code_editor->delete_lines();
  885. } break;
  886. case EDIT_CLONE_DOWN: {
  887. code_editor->clone_lines_down();
  888. } break;
  889. case EDIT_TOGGLE_FOLD_LINE: {
  890. tx->toggle_fold_line(tx->cursor_get_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->unhide_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->query_code_comple();
  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. tx->begin_complex_operation();
  913. int begin, end;
  914. if (tx->is_selection_active()) {
  915. begin = tx->get_selection_from_line();
  916. end = tx->get_selection_to_line();
  917. // ignore if the cursor is not past the first column
  918. if (tx->get_selection_to_column() == 0) {
  919. end--;
  920. }
  921. } else {
  922. begin = 0;
  923. end = tx->get_line_count() - 1;
  924. }
  925. scr->get_language()->auto_indent_code(text, begin, end);
  926. Vector<String> lines = text.split("\n");
  927. for (int i = begin; i <= end; ++i) {
  928. tx->set_line(i, lines[i]);
  929. }
  930. tx->end_complex_operation();
  931. } break;
  932. case EDIT_TRIM_TRAILING_WHITESAPCE: {
  933. trim_trailing_whitespace();
  934. } break;
  935. case EDIT_CONVERT_INDENT_TO_SPACES: {
  936. convert_indent_to_spaces();
  937. } break;
  938. case EDIT_CONVERT_INDENT_TO_TABS: {
  939. convert_indent_to_tabs();
  940. } break;
  941. case EDIT_PICK_COLOR: {
  942. color_panel->popup();
  943. } break;
  944. case EDIT_TO_UPPERCASE: {
  945. _convert_case(CodeTextEditor::UPPER);
  946. } break;
  947. case EDIT_TO_LOWERCASE: {
  948. _convert_case(CodeTextEditor::LOWER);
  949. } break;
  950. case EDIT_CAPITALIZE: {
  951. _convert_case(CodeTextEditor::CAPITALIZE);
  952. } break;
  953. case EDIT_EVALUATE: {
  954. Expression expression;
  955. Vector<String> lines = code_editor->get_text_edit()->get_selection_text().split("\n");
  956. PackedStringArray results;
  957. for (int i = 0; i < lines.size(); i++) {
  958. String line = lines[i];
  959. String whitespace = line.substr(0, line.size() - line.strip_edges(true, false).size()); //extract the whitespace at the beginning
  960. if (expression.parse(line) == OK) {
  961. Variant result = expression.execute(Array(), Variant(), false);
  962. if (expression.get_error_text() == "") {
  963. results.push_back(whitespace + result.get_construct_string());
  964. } else {
  965. results.push_back(line);
  966. }
  967. } else {
  968. results.push_back(line);
  969. }
  970. }
  971. code_editor->get_text_edit()->begin_complex_operation(); //prevents creating a two-step undo
  972. code_editor->get_text_edit()->insert_text_at_cursor(String("\n").join(results));
  973. code_editor->get_text_edit()->end_complex_operation();
  974. } break;
  975. case SEARCH_FIND: {
  976. code_editor->get_find_replace_bar()->popup_search();
  977. } break;
  978. case SEARCH_FIND_NEXT: {
  979. code_editor->get_find_replace_bar()->search_next();
  980. } break;
  981. case SEARCH_FIND_PREV: {
  982. code_editor->get_find_replace_bar()->search_prev();
  983. } break;
  984. case SEARCH_REPLACE: {
  985. code_editor->get_find_replace_bar()->popup_replace();
  986. } break;
  987. case SEARCH_IN_FILES: {
  988. String selected_text = code_editor->get_text_edit()->get_selection_text();
  989. // Yep, because it doesn't make sense to instance this dialog for every single script open...
  990. // So this will be delegated to the ScriptEditor.
  991. emit_signal("search_in_files_requested", selected_text);
  992. } break;
  993. case REPLACE_IN_FILES: {
  994. String selected_text = code_editor->get_text_edit()->get_selection_text();
  995. emit_signal("replace_in_files_requested", selected_text);
  996. } break;
  997. case SEARCH_LOCATE_FUNCTION: {
  998. quick_open->popup_dialog(get_functions());
  999. quick_open->set_title(TTR("Go to Function"));
  1000. } break;
  1001. case SEARCH_GOTO_LINE: {
  1002. goto_line_dialog->popup_find_line(tx);
  1003. } break;
  1004. case BOOKMARK_TOGGLE: {
  1005. code_editor->toggle_bookmark();
  1006. } break;
  1007. case BOOKMARK_GOTO_NEXT: {
  1008. code_editor->goto_next_bookmark();
  1009. } break;
  1010. case BOOKMARK_GOTO_PREV: {
  1011. code_editor->goto_prev_bookmark();
  1012. } break;
  1013. case BOOKMARK_REMOVE_ALL: {
  1014. code_editor->remove_all_bookmarks();
  1015. } break;
  1016. case DEBUG_TOGGLE_BREAKPOINT: {
  1017. int line = tx->cursor_get_line();
  1018. bool dobreak = !tx->is_line_set_as_breakpoint(line);
  1019. tx->set_line_as_breakpoint(line, dobreak);
  1020. EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), line + 1, dobreak);
  1021. } break;
  1022. case DEBUG_REMOVE_ALL_BREAKPOINTS: {
  1023. List<int> bpoints;
  1024. tx->get_breakpoints(&bpoints);
  1025. for (List<int>::Element *E = bpoints.front(); E; E = E->next()) {
  1026. int line = E->get();
  1027. bool dobreak = !tx->is_line_set_as_breakpoint(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. List<int> bpoints;
  1034. tx->get_breakpoints(&bpoints);
  1035. if (bpoints.size() <= 0) {
  1036. return;
  1037. }
  1038. int line = tx->cursor_get_line();
  1039. // wrap around
  1040. if (line >= bpoints[bpoints.size() - 1]) {
  1041. tx->unfold_line(bpoints[0]);
  1042. tx->cursor_set_line(bpoints[0]);
  1043. tx->center_viewport_to_cursor();
  1044. } else {
  1045. for (List<int>::Element *E = bpoints.front(); E; E = E->next()) {
  1046. int bline = E->get();
  1047. if (bline > line) {
  1048. tx->unfold_line(bline);
  1049. tx->cursor_set_line(bline);
  1050. tx->center_viewport_to_cursor();
  1051. return;
  1052. }
  1053. }
  1054. }
  1055. } break;
  1056. case DEBUG_GOTO_PREV_BREAKPOINT: {
  1057. List<int> bpoints;
  1058. tx->get_breakpoints(&bpoints);
  1059. if (bpoints.size() <= 0) {
  1060. return;
  1061. }
  1062. int line = tx->cursor_get_line();
  1063. // wrap around
  1064. if (line <= bpoints[0]) {
  1065. tx->unfold_line(bpoints[bpoints.size() - 1]);
  1066. tx->cursor_set_line(bpoints[bpoints.size() - 1]);
  1067. tx->center_viewport_to_cursor();
  1068. } else {
  1069. for (List<int>::Element *E = bpoints.back(); E; E = E->prev()) {
  1070. int bline = E->get();
  1071. if (bline < line) {
  1072. tx->unfold_line(bline);
  1073. tx->cursor_set_line(bline);
  1074. tx->center_viewport_to_cursor();
  1075. return;
  1076. }
  1077. }
  1078. }
  1079. } break;
  1080. case HELP_CONTEXTUAL: {
  1081. String text = tx->get_selection_text();
  1082. if (text == "")
  1083. text = tx->get_word_under_cursor();
  1084. if (text != "") {
  1085. emit_signal("request_help", text);
  1086. }
  1087. } break;
  1088. case LOOKUP_SYMBOL: {
  1089. String text = tx->get_word_under_cursor();
  1090. if (text == "")
  1091. text = tx->get_selection_text();
  1092. if (text != "") {
  1093. _lookup_symbol(text, tx->cursor_get_line(), tx->cursor_get_column());
  1094. }
  1095. } break;
  1096. }
  1097. }
  1098. void ScriptTextEditor::_edit_option_toggle_inline_comment() {
  1099. if (script.is_null())
  1100. return;
  1101. String delimiter = "#";
  1102. List<String> comment_delimiters;
  1103. script->get_language()->get_comment_delimiters(&comment_delimiters);
  1104. for (List<String>::Element *E = comment_delimiters.front(); E; E = E->next()) {
  1105. String script_delimiter = E->get();
  1106. if (script_delimiter.find(" ") == -1) {
  1107. delimiter = script_delimiter;
  1108. break;
  1109. }
  1110. }
  1111. code_editor->toggle_inline_comment(delimiter);
  1112. }
  1113. void ScriptTextEditor::add_syntax_highlighter(SyntaxHighlighter *p_highlighter) {
  1114. highlighters[p_highlighter->get_name()] = p_highlighter;
  1115. highlighter_menu->add_radio_check_item(p_highlighter->get_name());
  1116. }
  1117. void ScriptTextEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter) {
  1118. TextEdit *te = code_editor->get_text_edit();
  1119. te->_set_syntax_highlighting(p_highlighter);
  1120. if (p_highlighter != NULL)
  1121. highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(p_highlighter->get_name()), true);
  1122. else
  1123. highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(TTR("Standard")), true);
  1124. }
  1125. void ScriptTextEditor::_change_syntax_highlighter(int p_idx) {
  1126. Map<String, SyntaxHighlighter *>::Element *el = highlighters.front();
  1127. while (el != NULL) {
  1128. highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(el->key()), false);
  1129. el = el->next();
  1130. }
  1131. // highlighter_menu->set_item_checked(p_idx, true);
  1132. set_syntax_highlighter(highlighters[highlighter_menu->get_item_text(p_idx)]);
  1133. }
  1134. void ScriptTextEditor::_bind_methods() {
  1135. ClassDB::bind_method("_validate_script", &ScriptTextEditor::_validate_script);
  1136. ClassDB::bind_method("_update_bookmark_list", &ScriptTextEditor::_update_bookmark_list);
  1137. ClassDB::bind_method("_bookmark_item_pressed", &ScriptTextEditor::_bookmark_item_pressed);
  1138. ClassDB::bind_method("_load_theme_settings", &ScriptTextEditor::_load_theme_settings);
  1139. ClassDB::bind_method("_update_breakpoint_list", &ScriptTextEditor::_update_breakpoint_list);
  1140. ClassDB::bind_method("_breakpoint_item_pressed", &ScriptTextEditor::_breakpoint_item_pressed);
  1141. ClassDB::bind_method("_breakpoint_toggled", &ScriptTextEditor::_breakpoint_toggled);
  1142. ClassDB::bind_method("_lookup_connections", &ScriptTextEditor::_lookup_connections);
  1143. ClassDB::bind_method("_update_connected_methods", &ScriptTextEditor::_update_connected_methods);
  1144. ClassDB::bind_method("_change_syntax_highlighter", &ScriptTextEditor::_change_syntax_highlighter);
  1145. ClassDB::bind_method("_edit_option", &ScriptTextEditor::_edit_option);
  1146. ClassDB::bind_method("_goto_line", &ScriptTextEditor::_goto_line);
  1147. ClassDB::bind_method("_lookup_symbol", &ScriptTextEditor::_lookup_symbol);
  1148. ClassDB::bind_method("_text_edit_gui_input", &ScriptTextEditor::_text_edit_gui_input);
  1149. ClassDB::bind_method("_show_warnings_panel", &ScriptTextEditor::_show_warnings_panel);
  1150. ClassDB::bind_method("_error_pressed", &ScriptTextEditor::_error_pressed);
  1151. ClassDB::bind_method("_warning_clicked", &ScriptTextEditor::_warning_clicked);
  1152. ClassDB::bind_method("_color_changed", &ScriptTextEditor::_color_changed);
  1153. ClassDB::bind_method("get_drag_data_fw", &ScriptTextEditor::get_drag_data_fw);
  1154. ClassDB::bind_method("can_drop_data_fw", &ScriptTextEditor::can_drop_data_fw);
  1155. ClassDB::bind_method("drop_data_fw", &ScriptTextEditor::drop_data_fw);
  1156. }
  1157. Control *ScriptTextEditor::get_edit_menu() {
  1158. return edit_hb;
  1159. }
  1160. void ScriptTextEditor::clear_edit_menu() {
  1161. memdelete(edit_hb);
  1162. }
  1163. void ScriptTextEditor::reload(bool p_soft) {
  1164. TextEdit *te = code_editor->get_text_edit();
  1165. Ref<Script> scr = script;
  1166. if (scr.is_null())
  1167. return;
  1168. scr->set_source_code(te->get_text());
  1169. bool soft = p_soft || scr->get_instance_base_type() == "EditorPlugin"; //always soft-reload editor plugins
  1170. scr->get_language()->reload_tool_script(scr, soft);
  1171. }
  1172. void ScriptTextEditor::get_breakpoints(List<int> *p_breakpoints) {
  1173. code_editor->get_text_edit()->get_breakpoints(p_breakpoints);
  1174. }
  1175. void ScriptTextEditor::set_tooltip_request_func(String p_method, Object *p_obj) {
  1176. code_editor->get_text_edit()->set_tooltip_request_func(p_obj, p_method, this);
  1177. }
  1178. void ScriptTextEditor::set_debugger_active(bool p_active) {
  1179. }
  1180. Variant ScriptTextEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  1181. return Variant();
  1182. }
  1183. bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  1184. Dictionary d = p_data;
  1185. if (d.has("type") && (String(d["type"]) == "resource" ||
  1186. String(d["type"]) == "files" ||
  1187. String(d["type"]) == "nodes" ||
  1188. String(d["type"]) == "files_and_dirs")) {
  1189. return true;
  1190. }
  1191. return false;
  1192. }
  1193. static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
  1194. if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
  1195. return NULL;
  1196. Ref<Script> scr = p_current_node->get_script();
  1197. if (scr.is_valid() && scr == script)
  1198. return p_current_node;
  1199. for (int i = 0; i < p_current_node->get_child_count(); i++) {
  1200. Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
  1201. if (n)
  1202. return n;
  1203. }
  1204. return NULL;
  1205. }
  1206. void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  1207. Dictionary d = p_data;
  1208. TextEdit *te = code_editor->get_text_edit();
  1209. int row, col;
  1210. te->_get_mouse_pos(p_point, row, col);
  1211. if (d.has("type") && String(d["type"]) == "resource") {
  1212. Ref<Resource> res = d["resource"];
  1213. if (!res.is_valid()) {
  1214. return;
  1215. }
  1216. if (res->get_path().is_resource_file()) {
  1217. EditorNode::get_singleton()->show_warning(TTR("Only resources from filesystem can be dropped."));
  1218. return;
  1219. }
  1220. te->cursor_set_line(row);
  1221. te->cursor_set_column(col);
  1222. te->insert_text_at_cursor(res->get_path());
  1223. }
  1224. if (d.has("type") && (String(d["type"]) == "files" || String(d["type"]) == "files_and_dirs")) {
  1225. Array files = d["files"];
  1226. String text_to_drop;
  1227. for (int i = 0; i < files.size(); i++) {
  1228. if (i > 0)
  1229. text_to_drop += ",";
  1230. text_to_drop += "\"" + String(files[i]).c_escape() + "\"";
  1231. }
  1232. te->cursor_set_line(row);
  1233. te->cursor_set_column(col);
  1234. te->insert_text_at_cursor(text_to_drop);
  1235. }
  1236. if (d.has("type") && String(d["type"]) == "nodes") {
  1237. Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script);
  1238. if (!sn) {
  1239. EditorNode::get_singleton()->show_warning(vformat(TTR("Can't drop nodes because script '%s' is not used in this scene."), get_name()));
  1240. return;
  1241. }
  1242. Array nodes = d["nodes"];
  1243. String text_to_drop;
  1244. for (int i = 0; i < nodes.size(); i++) {
  1245. if (i > 0)
  1246. text_to_drop += ",";
  1247. NodePath np = nodes[i];
  1248. Node *node = get_node(np);
  1249. if (!node) {
  1250. continue;
  1251. }
  1252. String path = sn->get_path_to(node);
  1253. text_to_drop += "\"" + path.c_escape() + "\"";
  1254. }
  1255. te->cursor_set_line(row);
  1256. te->cursor_set_column(col);
  1257. te->insert_text_at_cursor(text_to_drop);
  1258. }
  1259. }
  1260. void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
  1261. Ref<InputEventMouseButton> mb = ev;
  1262. Ref<InputEventKey> k = ev;
  1263. Point2 local_pos;
  1264. bool create_menu = false;
  1265. TextEdit *tx = code_editor->get_text_edit();
  1266. if (mb.is_valid() && mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
  1267. local_pos = mb->get_global_position() - tx->get_global_position();
  1268. create_menu = true;
  1269. } else if (k.is_valid() && k->get_scancode() == KEY_MENU) {
  1270. local_pos = tx->_get_cursor_pixel_pos();
  1271. create_menu = true;
  1272. }
  1273. if (create_menu) {
  1274. int col, row;
  1275. tx->_get_mouse_pos(local_pos, row, col);
  1276. tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret"));
  1277. if (tx->is_right_click_moving_caret()) {
  1278. if (tx->is_selection_active()) {
  1279. int from_line = tx->get_selection_from_line();
  1280. int to_line = tx->get_selection_to_line();
  1281. int from_column = tx->get_selection_from_column();
  1282. int to_column = tx->get_selection_to_column();
  1283. if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) {
  1284. // Right click is outside the selected text
  1285. tx->deselect();
  1286. }
  1287. }
  1288. if (!tx->is_selection_active()) {
  1289. tx->cursor_set_line(row, true, false);
  1290. tx->cursor_set_column(col);
  1291. }
  1292. }
  1293. String word_at_pos = tx->get_word_at_pos(local_pos);
  1294. if (word_at_pos == "")
  1295. word_at_pos = tx->get_word_under_cursor();
  1296. if (word_at_pos == "")
  1297. word_at_pos = tx->get_selection_text();
  1298. bool has_color = (word_at_pos == "Color");
  1299. bool foldable = tx->can_fold(row) || tx->is_folded(row);
  1300. bool open_docs = false;
  1301. bool goto_definition = false;
  1302. if (word_at_pos.is_resource_file()) {
  1303. open_docs = true;
  1304. } else {
  1305. Node *base = get_tree()->get_edited_scene_root();
  1306. if (base) {
  1307. base = _find_node_for_script(base, base, script);
  1308. }
  1309. ScriptLanguage::LookupResult result;
  1310. if (script->get_language()->lookup_code(code_editor->get_text_edit()->get_text_for_lookup_completion(), word_at_pos, script->get_path(), base, result) == OK) {
  1311. open_docs = true;
  1312. }
  1313. }
  1314. if (has_color) {
  1315. String line = tx->get_line(row);
  1316. color_position.x = row;
  1317. color_position.y = col;
  1318. int begin = 0;
  1319. int end = 0;
  1320. bool valid = false;
  1321. for (int i = col; i < line.length(); i++) {
  1322. if (line[i] == '(') {
  1323. begin = i;
  1324. continue;
  1325. } else if (line[i] == ')') {
  1326. end = i + 1;
  1327. valid = true;
  1328. break;
  1329. }
  1330. }
  1331. if (valid) {
  1332. color_args = line.substr(begin, end - begin);
  1333. String stripped = color_args.replace(" ", "").replace("(", "").replace(")", "");
  1334. Vector<float> color = stripped.split_floats(",");
  1335. if (color.size() > 2) {
  1336. float alpha = color.size() > 3 ? color[3] : 1.0f;
  1337. color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha));
  1338. }
  1339. color_panel->set_position(get_global_transform().xform(local_pos));
  1340. } else {
  1341. has_color = false;
  1342. }
  1343. }
  1344. _make_context_menu(tx->is_selection_active(), has_color, foldable, open_docs, goto_definition, local_pos);
  1345. }
  1346. }
  1347. void ScriptTextEditor::_color_changed(const Color &p_color) {
  1348. String new_args;
  1349. if (p_color.a == 1.0f) {
  1350. new_args = String("(" + rtos(p_color.r) + ", " + rtos(p_color.g) + ", " + rtos(p_color.b) + ")");
  1351. } else {
  1352. new_args = String("(" + rtos(p_color.r) + ", " + rtos(p_color.g) + ", " + rtos(p_color.b) + ", " + rtos(p_color.a) + ")");
  1353. }
  1354. String line = code_editor->get_text_edit()->get_line(color_position.x);
  1355. int color_args_pos = line.find(color_args, color_position.y);
  1356. String line_with_replaced_args = line;
  1357. line_with_replaced_args.erase(color_args_pos, color_args.length());
  1358. line_with_replaced_args = line_with_replaced_args.insert(color_args_pos, new_args);
  1359. color_args = new_args;
  1360. code_editor->get_text_edit()->begin_complex_operation();
  1361. code_editor->get_text_edit()->set_line(color_position.x, line_with_replaced_args);
  1362. code_editor->get_text_edit()->end_complex_operation();
  1363. code_editor->get_text_edit()->update();
  1364. }
  1365. 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) {
  1366. context_menu->clear();
  1367. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
  1368. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
  1369. context_menu->add_separator();
  1370. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
  1371. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
  1372. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
  1373. context_menu->add_separator();
  1374. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
  1375. context_menu->add_separator();
  1376. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
  1377. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
  1378. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
  1379. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
  1380. if (p_selection) {
  1381. context_menu->add_separator();
  1382. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE);
  1383. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE);
  1384. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE);
  1385. }
  1386. if (p_foldable)
  1387. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
  1388. if (p_color || p_open_docs || p_goto_definition) {
  1389. context_menu->add_separator();
  1390. if (p_open_docs)
  1391. context_menu->add_item(TTR("Lookup Symbol"), LOOKUP_SYMBOL);
  1392. if (p_color)
  1393. context_menu->add_item(TTR("Pick Color"), EDIT_PICK_COLOR);
  1394. }
  1395. context_menu->set_position(get_global_transform().xform(p_pos));
  1396. context_menu->set_size(Vector2(1, 1));
  1397. context_menu->popup();
  1398. }
  1399. ScriptTextEditor::ScriptTextEditor() {
  1400. theme_loaded = false;
  1401. script_is_valid = false;
  1402. VSplitContainer *editor_box = memnew(VSplitContainer);
  1403. add_child(editor_box);
  1404. editor_box->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  1405. editor_box->set_v_size_flags(SIZE_EXPAND_FILL);
  1406. code_editor = memnew(CodeTextEditor);
  1407. editor_box->add_child(code_editor);
  1408. code_editor->add_constant_override("separation", 2);
  1409. code_editor->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  1410. code_editor->connect_compat("validate_script", this, "_validate_script");
  1411. code_editor->connect_compat("load_theme_settings", this, "_load_theme_settings");
  1412. code_editor->set_code_complete_func(_code_complete_scripts, this);
  1413. code_editor->get_text_edit()->connect_compat("breakpoint_toggled", this, "_breakpoint_toggled");
  1414. code_editor->get_text_edit()->connect_compat("symbol_lookup", this, "_lookup_symbol");
  1415. code_editor->get_text_edit()->connect_compat("info_clicked", this, "_lookup_connections");
  1416. code_editor->set_v_size_flags(SIZE_EXPAND_FILL);
  1417. code_editor->show_toggle_scripts_button();
  1418. warnings_panel = memnew(RichTextLabel);
  1419. editor_box->add_child(warnings_panel);
  1420. warnings_panel->set_custom_minimum_size(Size2(0, 100 * EDSCALE));
  1421. warnings_panel->set_h_size_flags(SIZE_EXPAND_FILL);
  1422. warnings_panel->set_meta_underline(true);
  1423. warnings_panel->set_selection_enabled(true);
  1424. warnings_panel->set_focus_mode(FOCUS_CLICK);
  1425. warnings_panel->hide();
  1426. code_editor->connect_compat("error_pressed", this, "_error_pressed");
  1427. code_editor->connect_compat("show_warnings_panel", this, "_show_warnings_panel");
  1428. warnings_panel->connect_compat("meta_clicked", this, "_warning_clicked");
  1429. update_settings();
  1430. code_editor->get_text_edit()->set_callhint_settings(
  1431. EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line"),
  1432. EditorSettings::get_singleton()->get("text_editor/completion/callhint_tooltip_offset"));
  1433. code_editor->get_text_edit()->set_select_identifiers_on_hover(true);
  1434. code_editor->get_text_edit()->set_context_menu_enabled(false);
  1435. code_editor->get_text_edit()->connect_compat("gui_input", this, "_text_edit_gui_input");
  1436. context_menu = memnew(PopupMenu);
  1437. add_child(context_menu);
  1438. context_menu->connect_compat("id_pressed", this, "_edit_option");
  1439. context_menu->set_hide_on_window_lose_focus(true);
  1440. color_panel = memnew(PopupPanel);
  1441. add_child(color_panel);
  1442. color_picker = memnew(ColorPicker);
  1443. color_picker->set_deferred_mode(true);
  1444. color_panel->add_child(color_picker);
  1445. color_picker->connect_compat("color_changed", this, "_color_changed");
  1446. // get default color picker mode from editor settings
  1447. int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode");
  1448. if (default_color_mode == 1)
  1449. color_picker->set_hsv_mode(true);
  1450. else if (default_color_mode == 2)
  1451. color_picker->set_raw_mode(true);
  1452. edit_hb = memnew(HBoxContainer);
  1453. edit_menu = memnew(MenuButton);
  1454. edit_menu->set_text(TTR("Edit"));
  1455. edit_menu->set_switch_on_hover(true);
  1456. edit_menu->get_popup()->set_hide_on_window_lose_focus(true);
  1457. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
  1458. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
  1459. edit_menu->get_popup()->add_separator();
  1460. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
  1461. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
  1462. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
  1463. edit_menu->get_popup()->add_separator();
  1464. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
  1465. edit_menu->get_popup()->add_separator();
  1466. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
  1467. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
  1468. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
  1469. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
  1470. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
  1471. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
  1472. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
  1473. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_all_lines"), EDIT_FOLD_ALL_LINES);
  1474. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES);
  1475. edit_menu->get_popup()->add_separator();
  1476. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
  1477. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE);
  1478. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE);
  1479. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE);
  1480. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES);
  1481. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_tabs"), EDIT_CONVERT_INDENT_TO_TABS);
  1482. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/auto_indent"), EDIT_AUTO_INDENT);
  1483. edit_menu->get_popup()->connect_compat("id_pressed", this, "_edit_option");
  1484. edit_menu->get_popup()->add_separator();
  1485. PopupMenu *convert_case = memnew(PopupMenu);
  1486. convert_case->set_name("convert_case");
  1487. edit_menu->get_popup()->add_child(convert_case);
  1488. edit_menu->get_popup()->add_submenu_item(TTR("Convert Case"), "convert_case");
  1489. convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/convert_to_uppercase", TTR("Uppercase"), KEY_MASK_SHIFT | KEY_F4), EDIT_TO_UPPERCASE);
  1490. convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/convert_to_lowercase", TTR("Lowercase"), KEY_MASK_SHIFT | KEY_F5), EDIT_TO_LOWERCASE);
  1491. convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/capitalize", TTR("Capitalize"), KEY_MASK_SHIFT | KEY_F6), EDIT_CAPITALIZE);
  1492. convert_case->connect_compat("id_pressed", this, "_edit_option");
  1493. highlighters[TTR("Standard")] = NULL;
  1494. highlighter_menu = memnew(PopupMenu);
  1495. highlighter_menu->set_name("highlighter_menu");
  1496. edit_menu->get_popup()->add_child(highlighter_menu);
  1497. edit_menu->get_popup()->add_submenu_item(TTR("Syntax Highlighter"), "highlighter_menu");
  1498. highlighter_menu->add_radio_check_item(TTR("Standard"));
  1499. highlighter_menu->connect_compat("id_pressed", this, "_change_syntax_highlighter");
  1500. search_menu = memnew(MenuButton);
  1501. edit_hb->add_child(search_menu);
  1502. search_menu->set_text(TTR("Search"));
  1503. search_menu->set_switch_on_hover(true);
  1504. search_menu->get_popup()->set_hide_on_window_lose_focus(true);
  1505. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND);
  1506. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT);
  1507. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV);
  1508. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE);
  1509. search_menu->get_popup()->add_separator();
  1510. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES);
  1511. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace_in_files"), REPLACE_IN_FILES);
  1512. search_menu->get_popup()->add_separator();
  1513. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/contextual_help"), HELP_CONTEXTUAL);
  1514. search_menu->get_popup()->connect_compat("id_pressed", this, "_edit_option");
  1515. edit_hb->add_child(edit_menu);
  1516. MenuButton *goto_menu = memnew(MenuButton);
  1517. edit_hb->add_child(goto_menu);
  1518. goto_menu->set_text(TTR("Go To"));
  1519. goto_menu->set_switch_on_hover(true);
  1520. goto_menu->get_popup()->connect_compat("id_pressed", this, "_edit_option");
  1521. goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_function"), SEARCH_LOCATE_FUNCTION);
  1522. goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE);
  1523. goto_menu->get_popup()->add_separator();
  1524. bookmarks_menu = memnew(PopupMenu);
  1525. bookmarks_menu->set_name("Bookmarks");
  1526. goto_menu->get_popup()->add_child(bookmarks_menu);
  1527. goto_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "Bookmarks");
  1528. _update_bookmark_list();
  1529. bookmarks_menu->connect_compat("about_to_show", this, "_update_bookmark_list");
  1530. bookmarks_menu->connect_compat("index_pressed", this, "_bookmark_item_pressed");
  1531. breakpoints_menu = memnew(PopupMenu);
  1532. breakpoints_menu->set_name("Breakpoints");
  1533. goto_menu->get_popup()->add_child(breakpoints_menu);
  1534. goto_menu->get_popup()->add_submenu_item(TTR("Breakpoints"), "Breakpoints");
  1535. _update_breakpoint_list();
  1536. breakpoints_menu->connect_compat("about_to_show", this, "_update_breakpoint_list");
  1537. breakpoints_menu->connect_compat("index_pressed", this, "_breakpoint_item_pressed");
  1538. quick_open = memnew(ScriptEditorQuickOpen);
  1539. add_child(quick_open);
  1540. quick_open->connect_compat("goto_line", this, "_goto_line");
  1541. goto_line_dialog = memnew(GotoLineDialog);
  1542. add_child(goto_line_dialog);
  1543. connection_info_dialog = memnew(ConnectionInfoDialog);
  1544. add_child(connection_info_dialog);
  1545. code_editor->get_text_edit()->set_drag_forwarding(this);
  1546. }
  1547. ScriptTextEditor::~ScriptTextEditor() {
  1548. for (const Map<String, SyntaxHighlighter *>::Element *E = highlighters.front(); E; E = E->next()) {
  1549. if (E->get() != NULL) {
  1550. memdelete(E->get());
  1551. }
  1552. }
  1553. highlighters.clear();
  1554. }
  1555. static ScriptEditorBase *create_editor(const RES &p_resource) {
  1556. if (Object::cast_to<Script>(*p_resource)) {
  1557. return memnew(ScriptTextEditor);
  1558. }
  1559. return NULL;
  1560. }
  1561. void ScriptTextEditor::register_editor() {
  1562. ED_SHORTCUT("script_text_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z);
  1563. ED_SHORTCUT("script_text_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y);
  1564. ED_SHORTCUT("script_text_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X);
  1565. ED_SHORTCUT("script_text_editor/copy", TTR("Copy"), KEY_MASK_CMD | KEY_C);
  1566. ED_SHORTCUT("script_text_editor/paste", TTR("Paste"), KEY_MASK_CMD | KEY_V);
  1567. ED_SHORTCUT("script_text_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A);
  1568. ED_SHORTCUT("script_text_editor/move_up", TTR("Move Up"), KEY_MASK_ALT | KEY_UP);
  1569. ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KEY_MASK_ALT | KEY_DOWN);
  1570. ED_SHORTCUT("script_text_editor/delete_line", TTR("Delete Line"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_K);
  1571. // Leave these at zero, same can be accomplished with tab/shift-tab, including selection.
  1572. // The next/previous in history shortcut in this case makes a lot more sense.
  1573. ED_SHORTCUT("script_text_editor/indent_left", TTR("Indent Left"), 0);
  1574. ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), 0);
  1575. ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KEY_MASK_CMD | KEY_K);
  1576. ED_SHORTCUT("script_text_editor/toggle_fold_line", TTR("Fold/Unfold Line"), KEY_MASK_ALT | KEY_F);
  1577. ED_SHORTCUT("script_text_editor/fold_all_lines", TTR("Fold All Lines"), 0);
  1578. ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), 0);
  1579. #ifdef OSX_ENABLED
  1580. ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_C);
  1581. ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CTRL | KEY_SPACE);
  1582. #else
  1583. ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD | KEY_D);
  1584. ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD | KEY_SPACE);
  1585. #endif
  1586. ED_SHORTCUT("script_text_editor/evaluate_selection", TTR("Evaluate Selection"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_E);
  1587. ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_T);
  1588. ED_SHORTCUT("script_text_editor/convert_indent_to_spaces", TTR("Convert Indent to Spaces"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_Y);
  1589. ED_SHORTCUT("script_text_editor/convert_indent_to_tabs", TTR("Convert Indent to Tabs"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_I);
  1590. ED_SHORTCUT("script_text_editor/auto_indent", TTR("Auto Indent"), KEY_MASK_CMD | KEY_I);
  1591. ED_SHORTCUT("script_text_editor/find", TTR("Find..."), KEY_MASK_CMD | KEY_F);
  1592. #ifdef OSX_ENABLED
  1593. ED_SHORTCUT("script_text_editor/find_next", TTR("Find Next"), KEY_MASK_CMD | KEY_G);
  1594. ED_SHORTCUT("script_text_editor/find_previous", TTR("Find Previous"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_G);
  1595. ED_SHORTCUT("script_text_editor/replace", TTR("Replace..."), KEY_MASK_ALT | KEY_MASK_CMD | KEY_F);
  1596. #else
  1597. ED_SHORTCUT("script_text_editor/find_next", TTR("Find Next"), KEY_F3);
  1598. ED_SHORTCUT("script_text_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT | KEY_F3);
  1599. ED_SHORTCUT("script_text_editor/replace", TTR("Replace..."), KEY_MASK_CMD | KEY_R);
  1600. #endif
  1601. ED_SHORTCUT("script_text_editor/find_in_files", TTR("Find in Files..."), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F);
  1602. ED_SHORTCUT("script_text_editor/replace_in_files", TTR("Replace in Files..."), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_R);
  1603. #ifdef OSX_ENABLED
  1604. ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_MASK_SHIFT | KEY_SPACE);
  1605. #else
  1606. ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_F1);
  1607. #endif
  1608. ED_SHORTCUT("script_text_editor/toggle_bookmark", TTR("Toggle Bookmark"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_B);
  1609. ED_SHORTCUT("script_text_editor/goto_next_bookmark", TTR("Go to Next Bookmark"), KEY_MASK_CMD | KEY_B);
  1610. ED_SHORTCUT("script_text_editor/goto_previous_bookmark", TTR("Go to Previous Bookmark"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B);
  1611. ED_SHORTCUT("script_text_editor/remove_all_bookmarks", TTR("Remove All Bookmarks"), 0);
  1612. #ifdef OSX_ENABLED
  1613. ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_CTRL | KEY_MASK_CMD | KEY_J);
  1614. #else
  1615. ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_ALT | KEY_MASK_CMD | KEY_F);
  1616. #endif
  1617. ED_SHORTCUT("script_text_editor/goto_line", TTR("Go to Line..."), KEY_MASK_CMD | KEY_L);
  1618. #ifdef OSX_ENABLED
  1619. ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B);
  1620. #else
  1621. ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9);
  1622. #endif
  1623. ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F9);
  1624. ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Go to Next Breakpoint"), KEY_MASK_CMD | KEY_PERIOD);
  1625. ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Go to Previous Breakpoint"), KEY_MASK_CMD | KEY_COMMA);
  1626. ScriptEditor::register_create_script_editor_function(create_editor);
  1627. }
  1628. void ScriptTextEditor::validate() {
  1629. this->code_editor->validate_script();
  1630. }