script_text_editor.cpp 74 KB

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