script_text_editor.cpp 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631
  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-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 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/os/keyboard.h"
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_settings.h"
  34. #include "editor/script_editor_debugger.h"
  35. Vector<String> ScriptTextEditor::get_functions() {
  36. String errortxt;
  37. int line = -1, col;
  38. TextEdit *te = code_editor->get_text_edit();
  39. String text = te->get_text();
  40. List<String> fnc;
  41. if (script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc)) {
  42. //if valid rewrite functions to latest
  43. functions.clear();
  44. for (List<String>::Element *E = fnc.front(); E; E = E->next()) {
  45. functions.push_back(E->get());
  46. }
  47. }
  48. return functions;
  49. }
  50. void ScriptTextEditor::apply_code() {
  51. if (script.is_null())
  52. return;
  53. script->set_source_code(code_editor->get_text_edit()->get_text());
  54. script->update_exports();
  55. _update_member_keywords();
  56. }
  57. RES ScriptTextEditor::get_edited_resource() const {
  58. return script;
  59. }
  60. void ScriptTextEditor::set_edited_resource(const RES &p_res) {
  61. ERR_FAIL_COND(!script.is_null());
  62. script = p_res;
  63. _set_theme_for_script();
  64. code_editor->get_text_edit()->set_text(script->get_source_code());
  65. code_editor->get_text_edit()->clear_undo_history();
  66. code_editor->get_text_edit()->tag_saved_version();
  67. emit_signal("name_changed");
  68. code_editor->update_line_and_column();
  69. }
  70. void ScriptTextEditor::_update_member_keywords() {
  71. member_keywords.clear();
  72. code_editor->get_text_edit()->clear_member_keywords();
  73. Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
  74. StringName instance_base = script->get_instance_base_type();
  75. if (instance_base == StringName())
  76. return;
  77. List<PropertyInfo> plist;
  78. ClassDB::get_property_list(instance_base, &plist);
  79. for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
  80. String name = E->get().name;
  81. if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP)
  82. continue;
  83. if (name.find("/") != -1)
  84. continue;
  85. code_editor->get_text_edit()->add_member_keyword(name, member_variable_color);
  86. }
  87. List<String> clist;
  88. ClassDB::get_integer_constant_list(instance_base, &clist);
  89. for (List<String>::Element *E = clist.front(); E; E = E->next()) {
  90. code_editor->get_text_edit()->add_member_keyword(E->get(), member_variable_color);
  91. }
  92. }
  93. void ScriptTextEditor::_load_theme_settings() {
  94. TextEdit *text_edit = code_editor->get_text_edit();
  95. text_edit->clear_colors();
  96. Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
  97. Color completion_background_color = EDITOR_GET("text_editor/highlighting/completion_background_color");
  98. Color completion_selected_color = EDITOR_GET("text_editor/highlighting/completion_selected_color");
  99. Color completion_existing_color = EDITOR_GET("text_editor/highlighting/completion_existing_color");
  100. Color completion_scroll_color = EDITOR_GET("text_editor/highlighting/completion_scroll_color");
  101. Color completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color");
  102. Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
  103. Color line_number_color = EDITOR_GET("text_editor/highlighting/line_number_color");
  104. Color safe_line_number_color = EDITOR_GET("text_editor/highlighting/safe_line_number_color");
  105. Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color");
  106. Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color");
  107. Color indent_guide_color = EDITOR_GET("text_editor/highlighting/indent_guide_color");
  108. Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color");
  109. Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color");
  110. Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color");
  111. Color current_line_color = EDITOR_GET("text_editor/highlighting/current_line_color");
  112. Color line_length_guideline_color = EDITOR_GET("text_editor/highlighting/line_length_guideline_color");
  113. Color word_highlighted_color = EDITOR_GET("text_editor/highlighting/word_highlighted_color");
  114. Color number_color = EDITOR_GET("text_editor/highlighting/number_color");
  115. Color function_color = EDITOR_GET("text_editor/highlighting/function_color");
  116. Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
  117. Color mark_color = EDITOR_GET("text_editor/highlighting/mark_color");
  118. Color breakpoint_color = EDITOR_GET("text_editor/highlighting/breakpoint_color");
  119. Color code_folding_color = EDITOR_GET("text_editor/highlighting/code_folding_color");
  120. Color search_result_color = EDITOR_GET("text_editor/highlighting/search_result_color");
  121. Color search_result_border_color = EDITOR_GET("text_editor/highlighting/search_result_border_color");
  122. Color symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color");
  123. Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
  124. Color basetype_color = EDITOR_GET("text_editor/highlighting/base_type_color");
  125. Color type_color = EDITOR_GET("text_editor/highlighting/engine_type_color");
  126. Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color");
  127. Color string_color = EDITOR_GET("text_editor/highlighting/string_color");
  128. text_edit->add_color_override("background_color", background_color);
  129. text_edit->add_color_override("completion_background_color", completion_background_color);
  130. text_edit->add_color_override("completion_selected_color", completion_selected_color);
  131. text_edit->add_color_override("completion_existing_color", completion_existing_color);
  132. text_edit->add_color_override("completion_scroll_color", completion_scroll_color);
  133. text_edit->add_color_override("completion_font_color", completion_font_color);
  134. text_edit->add_color_override("font_color", text_color);
  135. text_edit->add_color_override("line_number_color", line_number_color);
  136. text_edit->add_color_override("safe_line_number_color", safe_line_number_color);
  137. text_edit->add_color_override("caret_color", caret_color);
  138. text_edit->add_color_override("caret_background_color", caret_background_color);
  139. text_edit->add_color_override("indent_guide_color", indent_guide_color);
  140. text_edit->add_color_override("font_selected_color", text_selected_color);
  141. text_edit->add_color_override("selection_color", selection_color);
  142. text_edit->add_color_override("brace_mismatch_color", brace_mismatch_color);
  143. text_edit->add_color_override("current_line_color", current_line_color);
  144. text_edit->add_color_override("line_length_guideline_color", line_length_guideline_color);
  145. text_edit->add_color_override("word_highlighted_color", word_highlighted_color);
  146. text_edit->add_color_override("number_color", number_color);
  147. text_edit->add_color_override("function_color", function_color);
  148. text_edit->add_color_override("member_variable_color", member_variable_color);
  149. text_edit->add_color_override("breakpoint_color", breakpoint_color);
  150. text_edit->add_color_override("mark_color", mark_color);
  151. text_edit->add_color_override("code_folding_color", code_folding_color);
  152. text_edit->add_color_override("search_result_color", search_result_color);
  153. text_edit->add_color_override("search_result_border_color", search_result_border_color);
  154. text_edit->add_color_override("symbol_color", symbol_color);
  155. text_edit->add_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 6));
  156. colors_cache.symbol_color = symbol_color;
  157. colors_cache.keyword_color = keyword_color;
  158. colors_cache.basetype_color = basetype_color;
  159. colors_cache.type_color = type_color;
  160. colors_cache.comment_color = comment_color;
  161. colors_cache.string_color = string_color;
  162. theme_loaded = true;
  163. if (!script.is_null())
  164. _set_theme_for_script();
  165. }
  166. void ScriptTextEditor::_set_theme_for_script() {
  167. if (!theme_loaded)
  168. return;
  169. TextEdit *text_edit = code_editor->get_text_edit();
  170. List<String> keywords;
  171. script->get_language()->get_reserved_words(&keywords);
  172. for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
  173. text_edit->add_keyword_color(E->get(), colors_cache.keyword_color);
  174. }
  175. //colorize core types
  176. const Color basetype_color = colors_cache.basetype_color;
  177. text_edit->add_keyword_color("String", basetype_color);
  178. text_edit->add_keyword_color("Vector2", basetype_color);
  179. text_edit->add_keyword_color("Rect2", basetype_color);
  180. text_edit->add_keyword_color("Transform2D", basetype_color);
  181. text_edit->add_keyword_color("Vector3", basetype_color);
  182. text_edit->add_keyword_color("AABB", basetype_color);
  183. text_edit->add_keyword_color("Basis", basetype_color);
  184. text_edit->add_keyword_color("Plane", basetype_color);
  185. text_edit->add_keyword_color("Transform", basetype_color);
  186. text_edit->add_keyword_color("Quat", basetype_color);
  187. text_edit->add_keyword_color("Color", basetype_color);
  188. text_edit->add_keyword_color("Object", basetype_color);
  189. text_edit->add_keyword_color("NodePath", basetype_color);
  190. text_edit->add_keyword_color("RID", basetype_color);
  191. text_edit->add_keyword_color("Dictionary", basetype_color);
  192. text_edit->add_keyword_color("Array", basetype_color);
  193. text_edit->add_keyword_color("PoolByteArray", basetype_color);
  194. text_edit->add_keyword_color("PoolIntArray", basetype_color);
  195. text_edit->add_keyword_color("PoolRealArray", basetype_color);
  196. text_edit->add_keyword_color("PoolStringArray", basetype_color);
  197. text_edit->add_keyword_color("PoolVector2Array", basetype_color);
  198. text_edit->add_keyword_color("PoolVector3Array", basetype_color);
  199. text_edit->add_keyword_color("PoolColorArray", basetype_color);
  200. //colorize engine types
  201. List<StringName> types;
  202. ClassDB::get_class_list(&types);
  203. for (List<StringName>::Element *E = types.front(); E; E = E->next()) {
  204. String n = E->get();
  205. if (n.begins_with("_"))
  206. n = n.substr(1, n.length());
  207. text_edit->add_keyword_color(n, colors_cache.type_color);
  208. }
  209. _update_member_keywords();
  210. //colorize comments
  211. List<String> comments;
  212. script->get_language()->get_comment_delimiters(&comments);
  213. for (List<String>::Element *E = comments.front(); E; E = E->next()) {
  214. String comment = E->get();
  215. String beg = comment.get_slice(" ", 0);
  216. String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String();
  217. text_edit->add_color_region(beg, end, colors_cache.comment_color, end == "");
  218. }
  219. //colorize strings
  220. List<String> strings;
  221. script->get_language()->get_string_delimiters(&strings);
  222. for (List<String>::Element *E = strings.front(); E; E = E->next()) {
  223. String string = E->get();
  224. String beg = string.get_slice(" ", 0);
  225. String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String();
  226. text_edit->add_color_region(beg, end, colors_cache.string_color, end == "");
  227. }
  228. }
  229. void ScriptTextEditor::_toggle_warning_pannel(const Ref<InputEvent> &p_event) {
  230. Ref<InputEventMouseButton> mb = p_event;
  231. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  232. warnings_panel->set_visible(!warnings_panel->is_visible());
  233. }
  234. }
  235. void ScriptTextEditor::_warning_clicked(Variant p_line) {
  236. if (p_line.get_type() == Variant::INT) {
  237. code_editor->get_text_edit()->cursor_set_line(p_line.operator int64_t());
  238. } else if (p_line.get_type() == Variant::DICTIONARY) {
  239. Dictionary meta = p_line.operator Dictionary();
  240. code_editor->get_text_edit()->insert_at("#warning-ignore:" + meta["code"].operator String(), meta["line"].operator int64_t() - 1);
  241. _validate_script();
  242. }
  243. }
  244. void ScriptTextEditor::reload_text() {
  245. ERR_FAIL_COND(script.is_null());
  246. TextEdit *te = code_editor->get_text_edit();
  247. int column = te->cursor_get_column();
  248. int row = te->cursor_get_line();
  249. int h = te->get_h_scroll();
  250. int v = te->get_v_scroll();
  251. te->set_text(script->get_source_code());
  252. te->clear_undo_history();
  253. te->cursor_set_line(row);
  254. te->cursor_set_column(column);
  255. te->set_h_scroll(h);
  256. te->set_v_scroll(v);
  257. te->tag_saved_version();
  258. code_editor->update_line_and_column();
  259. }
  260. void ScriptTextEditor::_notification(int p_what) {
  261. switch (p_what) {
  262. case NOTIFICATION_READY:
  263. _load_theme_settings();
  264. _change_syntax_highlighter(EditorSettings::get_singleton()->get_project_metadata("script_text_editor", "syntax_highlighter", 0));
  265. break;
  266. }
  267. }
  268. void ScriptTextEditor::add_callback(const String &p_function, PoolStringArray p_args) {
  269. String code = code_editor->get_text_edit()->get_text();
  270. int pos = script->get_language()->find_function(p_function, code);
  271. if (pos == -1) {
  272. //does not exist
  273. code_editor->get_text_edit()->deselect();
  274. pos = code_editor->get_text_edit()->get_line_count() + 2;
  275. String func = script->get_language()->make_function("", p_function, p_args);
  276. //code=code+func;
  277. code_editor->get_text_edit()->cursor_set_line(pos + 1);
  278. code_editor->get_text_edit()->cursor_set_column(1000000); //none shall be that big
  279. code_editor->get_text_edit()->insert_text_at_cursor("\n\n" + func);
  280. }
  281. code_editor->get_text_edit()->cursor_set_line(pos);
  282. code_editor->get_text_edit()->cursor_set_column(1);
  283. }
  284. bool ScriptTextEditor::show_members_overview() {
  285. return true;
  286. }
  287. void ScriptTextEditor::update_settings() {
  288. code_editor->update_editor_settings();
  289. }
  290. bool ScriptTextEditor::is_unsaved() {
  291. return code_editor->get_text_edit()->get_version() != code_editor->get_text_edit()->get_saved_version();
  292. }
  293. Variant ScriptTextEditor::get_edit_state() {
  294. return code_editor->get_edit_state();
  295. }
  296. void ScriptTextEditor::set_edit_state(const Variant &p_state) {
  297. code_editor->set_edit_state(p_state);
  298. }
  299. void ScriptTextEditor::_convert_case(CodeTextEditor::CaseStyle p_case) {
  300. code_editor->convert_case(p_case);
  301. }
  302. void ScriptTextEditor::trim_trailing_whitespace() {
  303. code_editor->trim_trailing_whitespace();
  304. }
  305. void ScriptTextEditor::convert_indent_to_spaces() {
  306. code_editor->convert_indent_to_spaces();
  307. }
  308. void ScriptTextEditor::convert_indent_to_tabs() {
  309. code_editor->convert_indent_to_tabs();
  310. }
  311. void ScriptTextEditor::tag_saved_version() {
  312. code_editor->get_text_edit()->tag_saved_version();
  313. }
  314. void ScriptTextEditor::goto_line(int p_line, bool p_with_error) {
  315. code_editor->goto_line(p_line);
  316. }
  317. void ScriptTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) {
  318. code_editor->goto_line_selection(p_line, p_begin, p_end);
  319. }
  320. void ScriptTextEditor::ensure_focus() {
  321. code_editor->get_text_edit()->grab_focus();
  322. }
  323. String ScriptTextEditor::get_name() {
  324. String name;
  325. if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) {
  326. name = script->get_path().get_file();
  327. if (is_unsaved()) {
  328. name += "(*)";
  329. }
  330. } else if (script->get_name() != "")
  331. name = script->get_name();
  332. else
  333. name = script->get_class() + "(" + itos(script->get_instance_id()) + ")";
  334. return name;
  335. }
  336. Ref<Texture> ScriptTextEditor::get_icon() {
  337. if (get_parent_control() && get_parent_control()->has_icon(script->get_class(), "EditorIcons")) {
  338. return get_parent_control()->get_icon(script->get_class(), "EditorIcons");
  339. }
  340. return Ref<Texture>();
  341. }
  342. void ScriptTextEditor::_validate_script() {
  343. String errortxt;
  344. int line = -1, col;
  345. TextEdit *te = code_editor->get_text_edit();
  346. String text = te->get_text();
  347. List<String> fnc;
  348. Set<int> safe_lines;
  349. List<ScriptLanguage::Warning> warnings;
  350. if (!script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc, &warnings, &safe_lines)) {
  351. String error_text = "error(" + itos(line) + "," + itos(col) + "): " + errortxt;
  352. code_editor->set_error(error_text);
  353. code_editor->set_error_pos(line - 1, col - 1);
  354. } else {
  355. code_editor->set_error("");
  356. line = -1;
  357. if (!script->is_tool()) {
  358. script->set_source_code(text);
  359. script->update_exports();
  360. _update_member_keywords();
  361. //script->reload(); //will update all the variables in property editors
  362. }
  363. functions.clear();
  364. for (List<String>::Element *E = fnc.front(); E; E = E->next()) {
  365. functions.push_back(E->get());
  366. }
  367. }
  368. code_editor->get_warning_count_label()->set_text(itos(warnings.size()));
  369. warnings_panel->clear();
  370. warnings_panel->push_table(3);
  371. for (List<ScriptLanguage::Warning>::Element *E = warnings.front(); E; E = E->next()) {
  372. ScriptLanguage::Warning w = E->get();
  373. warnings_panel->push_cell();
  374. warnings_panel->push_meta(w.line - 1);
  375. warnings_panel->push_color(warnings_panel->get_color("warning_color", "Editor"));
  376. warnings_panel->add_text(TTR("Line") + " " + itos(w.line));
  377. warnings_panel->add_text(" (" + w.string_code + "):");
  378. warnings_panel->pop(); // Color
  379. warnings_panel->pop(); // Meta goto
  380. warnings_panel->pop(); // Cell
  381. warnings_panel->push_cell();
  382. warnings_panel->add_text(w.message);
  383. warnings_panel->pop(); // Cell
  384. Dictionary ignore_meta;
  385. ignore_meta["line"] = w.line;
  386. ignore_meta["code"] = w.string_code.to_lower();
  387. warnings_panel->push_cell();
  388. warnings_panel->push_meta(ignore_meta);
  389. warnings_panel->add_text(TTR("(ignore)"));
  390. warnings_panel->pop(); // Meta ignore
  391. warnings_panel->pop(); // Cell
  392. //warnings_panel->add_newline();
  393. }
  394. warnings_panel->pop(); // Table
  395. line--;
  396. bool highlight_safe = EDITOR_DEF("text_editor/highlighting/highlight_type_safe_lines", true);
  397. bool last_is_safe = false;
  398. for (int i = 0; i < te->get_line_count(); i++) {
  399. te->set_line_as_marked(i, line == i);
  400. if (highlight_safe) {
  401. if (safe_lines.has(i + 1)) {
  402. te->set_line_as_safe(i, true);
  403. last_is_safe = true;
  404. } else if (last_is_safe && (te->is_line_comment(i) || te->get_line(i).strip_edges().empty())) {
  405. te->set_line_as_safe(i, true);
  406. } else {
  407. te->set_line_as_safe(i, false);
  408. last_is_safe = false;
  409. }
  410. } else {
  411. te->set_line_as_safe(i, false);
  412. }
  413. }
  414. emit_signal("name_changed");
  415. emit_signal("edited_script_changed");
  416. }
  417. static Node *_find_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) {
  418. if (p_current->get_owner() != p_base && p_base != p_current)
  419. return NULL;
  420. Ref<Script> c = p_current->get_script();
  421. if (c == p_script)
  422. return p_current;
  423. for (int i = 0; i < p_current->get_child_count(); i++) {
  424. Node *found = _find_node_for_script(p_base, p_current->get_child(i), p_script);
  425. if (found)
  426. return found;
  427. }
  428. return NULL;
  429. }
  430. static void _find_changed_scripts_for_external_editor(Node *p_base, Node *p_current, Set<Ref<Script> > &r_scripts) {
  431. if (p_current->get_owner() != p_base && p_base != p_current)
  432. return;
  433. Ref<Script> c = p_current->get_script();
  434. if (c.is_valid())
  435. r_scripts.insert(c);
  436. for (int i = 0; i < p_current->get_child_count(); i++) {
  437. _find_changed_scripts_for_external_editor(p_base, p_current->get_child(i), r_scripts);
  438. }
  439. }
  440. void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_for_script) {
  441. if (!bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")))
  442. return;
  443. ERR_FAIL_COND(!get_tree());
  444. Set<Ref<Script> > scripts;
  445. Node *base = get_tree()->get_edited_scene_root();
  446. if (base) {
  447. _find_changed_scripts_for_external_editor(base, base, scripts);
  448. }
  449. for (Set<Ref<Script> >::Element *E = scripts.front(); E; E = E->next()) {
  450. Ref<Script> script = E->get();
  451. if (p_for_script.is_valid() && p_for_script != script)
  452. continue;
  453. if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) {
  454. continue; //internal script, who cares, though weird
  455. }
  456. uint64_t last_date = script->get_last_modified_time();
  457. uint64_t date = FileAccess::get_modified_time(script->get_path());
  458. if (last_date != date) {
  459. Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true);
  460. ERR_CONTINUE(!rel_script.is_valid());
  461. script->set_source_code(rel_script->get_source_code());
  462. script->set_last_modified_time(rel_script->get_last_modified_time());
  463. script->update_exports();
  464. }
  465. }
  466. }
  467. void ScriptTextEditor::_code_complete_scripts(void *p_ud, const String &p_code, List<String> *r_options, bool &r_force) {
  468. ScriptTextEditor *ste = (ScriptTextEditor *)p_ud;
  469. ste->_code_complete_script(p_code, r_options, r_force);
  470. }
  471. void ScriptTextEditor::_code_complete_script(const String &p_code, List<String> *r_options, bool &r_force) {
  472. if (color_panel->is_visible_in_tree()) return;
  473. Node *base = get_tree()->get_edited_scene_root();
  474. if (base) {
  475. base = _find_node_for_script(base, base, script);
  476. }
  477. String hint;
  478. Error err = script->get_language()->complete_code(p_code, script->get_path().get_base_dir(), base, r_options, r_force, hint);
  479. if (err == OK && hint != "") {
  480. code_editor->get_text_edit()->set_code_hint(hint);
  481. }
  482. }
  483. void ScriptTextEditor::_breakpoint_toggled(int p_row) {
  484. 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));
  485. }
  486. void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_column) {
  487. Node *base = get_tree()->get_edited_scene_root();
  488. if (base) {
  489. base = _find_node_for_script(base, base, script);
  490. }
  491. ScriptLanguage::LookupResult result;
  492. if (p_symbol.is_resource_file()) {
  493. List<String> scene_extensions;
  494. ResourceLoader::get_recognized_extensions_for_type("PackedScene", &scene_extensions);
  495. if (scene_extensions.find(p_symbol.get_extension())) {
  496. EditorNode::get_singleton()->load_scene(p_symbol);
  497. } else {
  498. EditorNode::get_singleton()->load_resource(p_symbol);
  499. }
  500. } else if (script->get_language()->lookup_code(code_editor->get_text_edit()->get_text_for_lookup_completion(), p_symbol, script->get_path().get_base_dir(), base, result) == OK) {
  501. _goto_line(p_row);
  502. result.class_name = result.class_name.trim_prefix("_");
  503. switch (result.type) {
  504. case ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION: {
  505. if (result.script.is_valid()) {
  506. emit_signal("request_open_script_at_line", result.script, result.location - 1);
  507. } else {
  508. emit_signal("request_save_history");
  509. _goto_line(result.location - 1);
  510. }
  511. } break;
  512. case ScriptLanguage::LookupResult::RESULT_CLASS: {
  513. emit_signal("go_to_help", "class_name:" + result.class_name);
  514. } break;
  515. case ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT: {
  516. StringName cname = result.class_name;
  517. bool success;
  518. while (true) {
  519. ClassDB::get_integer_constant(cname, result.class_member, &success);
  520. if (success) {
  521. result.class_name = cname;
  522. cname = ClassDB::get_parent_class(cname);
  523. } else {
  524. break;
  525. }
  526. }
  527. emit_signal("go_to_help", "class_constant:" + result.class_name + ":" + result.class_member);
  528. } break;
  529. case ScriptLanguage::LookupResult::RESULT_CLASS_PROPERTY: {
  530. emit_signal("go_to_help", "class_property:" + result.class_name + ":" + result.class_member);
  531. } break;
  532. case ScriptLanguage::LookupResult::RESULT_CLASS_METHOD: {
  533. StringName cname = result.class_name;
  534. while (true) {
  535. if (ClassDB::has_method(cname, result.class_member)) {
  536. result.class_name = cname;
  537. cname = ClassDB::get_parent_class(cname);
  538. } else {
  539. break;
  540. }
  541. }
  542. emit_signal("go_to_help", "class_method:" + result.class_name + ":" + result.class_member);
  543. } break;
  544. case ScriptLanguage::LookupResult::RESULT_CLASS_ENUM: {
  545. StringName cname = result.class_name;
  546. StringName success;
  547. while (true) {
  548. success = ClassDB::get_integer_constant_enum(cname, result.class_member, true);
  549. if (success != StringName()) {
  550. result.class_name = cname;
  551. cname = ClassDB::get_parent_class(cname);
  552. } else {
  553. break;
  554. }
  555. }
  556. emit_signal("go_to_help", "class_enum:" + result.class_name + ":" + result.class_member);
  557. } break;
  558. case ScriptLanguage::LookupResult::RESULT_CLASS_TBD_GLOBALSCOPE: {
  559. emit_signal("go_to_help", "class_global:" + result.class_name + ":" + result.class_member);
  560. } break;
  561. }
  562. }
  563. }
  564. void ScriptTextEditor::_edit_option(int p_op) {
  565. TextEdit *tx = code_editor->get_text_edit();
  566. switch (p_op) {
  567. case EDIT_UNDO: {
  568. tx->undo();
  569. tx->call_deferred("grab_focus");
  570. } break;
  571. case EDIT_REDO: {
  572. tx->redo();
  573. tx->call_deferred("grab_focus");
  574. } break;
  575. case EDIT_CUT: {
  576. tx->cut();
  577. tx->call_deferred("grab_focus");
  578. } break;
  579. case EDIT_COPY: {
  580. tx->copy();
  581. tx->call_deferred("grab_focus");
  582. } break;
  583. case EDIT_PASTE: {
  584. tx->paste();
  585. tx->call_deferred("grab_focus");
  586. } break;
  587. case EDIT_SELECT_ALL: {
  588. tx->select_all();
  589. tx->call_deferred("grab_focus");
  590. } break;
  591. case EDIT_MOVE_LINE_UP: {
  592. code_editor->move_lines_up();
  593. } break;
  594. case EDIT_MOVE_LINE_DOWN: {
  595. code_editor->move_lines_down();
  596. } break;
  597. case EDIT_INDENT_LEFT: {
  598. Ref<Script> scr = script;
  599. if (scr.is_null())
  600. return;
  601. tx->indent_left();
  602. } break;
  603. case EDIT_INDENT_RIGHT: {
  604. Ref<Script> scr = script;
  605. if (scr.is_null())
  606. return;
  607. tx->indent_right();
  608. } break;
  609. case EDIT_DELETE_LINE: {
  610. code_editor->delete_lines();
  611. } break;
  612. case EDIT_CLONE_DOWN: {
  613. code_editor->clone_lines_down();
  614. } break;
  615. case EDIT_TOGGLE_FOLD_LINE: {
  616. tx->toggle_fold_line(tx->cursor_get_line());
  617. tx->update();
  618. } break;
  619. case EDIT_FOLD_ALL_LINES: {
  620. tx->fold_all_lines();
  621. tx->update();
  622. } break;
  623. case EDIT_UNFOLD_ALL_LINES: {
  624. tx->unhide_all_lines();
  625. tx->update();
  626. } break;
  627. case EDIT_TOGGLE_COMMENT: {
  628. Ref<Script> scr = script;
  629. if (scr.is_null())
  630. return;
  631. String delimiter = "#";
  632. List<String> comment_delimiters;
  633. scr->get_language()->get_comment_delimiters(&comment_delimiters);
  634. for (List<String>::Element *E = comment_delimiters.front(); E; E = E->next()) {
  635. String script_delimiter = E->get();
  636. if (script_delimiter.find(" ") == -1) {
  637. delimiter = script_delimiter;
  638. break;
  639. }
  640. }
  641. tx->begin_complex_operation();
  642. if (tx->is_selection_active()) {
  643. int begin = tx->get_selection_from_line();
  644. int end = tx->get_selection_to_line();
  645. // End of selection ends on the first column of the last line, ignore it.
  646. if (tx->get_selection_to_column() == 0)
  647. end -= 1;
  648. int col_to = tx->get_selection_to_column();
  649. int cursor_pos = tx->cursor_get_column();
  650. // Check if all lines in the selected block are commented
  651. bool is_commented = true;
  652. for (int i = begin; i <= end; i++) {
  653. if (!tx->get_line(i).begins_with(delimiter)) {
  654. is_commented = false;
  655. break;
  656. }
  657. }
  658. for (int i = begin; i <= end; i++) {
  659. String line_text = tx->get_line(i);
  660. if (line_text.strip_edges().empty()) {
  661. line_text = delimiter;
  662. } else {
  663. if (is_commented) {
  664. line_text = line_text.substr(delimiter.length(), line_text.length());
  665. } else {
  666. line_text = delimiter + line_text;
  667. }
  668. }
  669. tx->set_line(i, line_text);
  670. }
  671. // Adjust selection & cursor position.
  672. int offset = is_commented ? -1 : 1;
  673. int col_from = tx->get_selection_from_column() > 0 ? tx->get_selection_from_column() + offset : 0;
  674. if (is_commented && tx->cursor_get_column() == tx->get_line(tx->cursor_get_line()).length() + 1)
  675. cursor_pos += 1;
  676. if (tx->get_selection_to_column() != 0 && col_to != tx->get_line(tx->get_selection_to_line()).length() + 1)
  677. col_to += offset;
  678. if (tx->cursor_get_column() != 0)
  679. cursor_pos += offset;
  680. tx->select(begin, col_from, tx->get_selection_to_line(), col_to);
  681. tx->cursor_set_column(cursor_pos);
  682. } else {
  683. int begin = tx->cursor_get_line();
  684. String line_text = tx->get_line(begin);
  685. int col = tx->cursor_get_column();
  686. if (line_text.begins_with(delimiter)) {
  687. line_text = line_text.substr(delimiter.length(), line_text.length());
  688. col -= 1;
  689. } else {
  690. line_text = delimiter + line_text;
  691. col += 1;
  692. }
  693. tx->set_line(begin, line_text);
  694. tx->cursor_set_column(col);
  695. }
  696. tx->end_complex_operation();
  697. tx->update();
  698. } break;
  699. case EDIT_COMPLETE: {
  700. tx->query_code_comple();
  701. } break;
  702. case EDIT_AUTO_INDENT: {
  703. String text = tx->get_text();
  704. Ref<Script> scr = script;
  705. if (scr.is_null())
  706. return;
  707. tx->begin_complex_operation();
  708. int begin, end;
  709. if (tx->is_selection_active()) {
  710. begin = tx->get_selection_from_line();
  711. end = tx->get_selection_to_line();
  712. // ignore if the cursor is not past the first column
  713. if (tx->get_selection_to_column() == 0) {
  714. end--;
  715. }
  716. } else {
  717. begin = 0;
  718. end = tx->get_line_count() - 1;
  719. }
  720. scr->get_language()->auto_indent_code(text, begin, end);
  721. Vector<String> lines = text.split("\n");
  722. for (int i = begin; i <= end; ++i) {
  723. tx->set_line(i, lines[i]);
  724. }
  725. tx->end_complex_operation();
  726. } break;
  727. case EDIT_TRIM_TRAILING_WHITESAPCE: {
  728. trim_trailing_whitespace();
  729. } break;
  730. case EDIT_CONVERT_INDENT_TO_SPACES: {
  731. convert_indent_to_spaces();
  732. } break;
  733. case EDIT_CONVERT_INDENT_TO_TABS: {
  734. convert_indent_to_tabs();
  735. } break;
  736. case EDIT_PICK_COLOR: {
  737. color_panel->popup();
  738. } break;
  739. case EDIT_TO_UPPERCASE: {
  740. _convert_case(CodeTextEditor::UPPER);
  741. } break;
  742. case EDIT_TO_LOWERCASE: {
  743. _convert_case(CodeTextEditor::LOWER);
  744. } break;
  745. case EDIT_CAPITALIZE: {
  746. _convert_case(CodeTextEditor::CAPITALIZE);
  747. } break;
  748. case SEARCH_FIND: {
  749. code_editor->get_find_replace_bar()->popup_search();
  750. } break;
  751. case SEARCH_FIND_NEXT: {
  752. code_editor->get_find_replace_bar()->search_next();
  753. } break;
  754. case SEARCH_FIND_PREV: {
  755. code_editor->get_find_replace_bar()->search_prev();
  756. } break;
  757. case SEARCH_REPLACE: {
  758. code_editor->get_find_replace_bar()->popup_replace();
  759. } break;
  760. case SEARCH_IN_FILES: {
  761. String selected_text = code_editor->get_text_edit()->get_selection_text();
  762. // Yep, because it doesn't make sense to instance this dialog for every single script open...
  763. // So this will be delegated to the ScriptEditor
  764. emit_signal("search_in_files_requested", selected_text);
  765. } break;
  766. case SEARCH_LOCATE_FUNCTION: {
  767. quick_open->popup_dialog(get_functions());
  768. quick_open->set_title(TTR("Go to Function"));
  769. } break;
  770. case SEARCH_GOTO_LINE: {
  771. goto_line_dialog->popup_find_line(tx);
  772. } break;
  773. case DEBUG_TOGGLE_BREAKPOINT: {
  774. int line = tx->cursor_get_line();
  775. bool dobreak = !tx->is_line_set_as_breakpoint(line);
  776. tx->set_line_as_breakpoint(line, dobreak);
  777. ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(script->get_path(), line + 1, dobreak);
  778. } break;
  779. case DEBUG_REMOVE_ALL_BREAKPOINTS: {
  780. List<int> bpoints;
  781. tx->get_breakpoints(&bpoints);
  782. for (List<int>::Element *E = bpoints.front(); E; E = E->next()) {
  783. int line = E->get();
  784. bool dobreak = !tx->is_line_set_as_breakpoint(line);
  785. tx->set_line_as_breakpoint(line, dobreak);
  786. ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(script->get_path(), line + 1, dobreak);
  787. }
  788. }
  789. case DEBUG_GOTO_NEXT_BREAKPOINT: {
  790. List<int> bpoints;
  791. tx->get_breakpoints(&bpoints);
  792. if (bpoints.size() <= 0) {
  793. return;
  794. }
  795. int line = tx->cursor_get_line();
  796. // wrap around
  797. if (line >= bpoints[bpoints.size() - 1]) {
  798. tx->unfold_line(bpoints[0]);
  799. tx->cursor_set_line(bpoints[0]);
  800. } else {
  801. for (List<int>::Element *E = bpoints.front(); E; E = E->next()) {
  802. int bline = E->get();
  803. if (bline > line) {
  804. tx->unfold_line(bline);
  805. tx->cursor_set_line(bline);
  806. return;
  807. }
  808. }
  809. }
  810. } break;
  811. case DEBUG_GOTO_PREV_BREAKPOINT: {
  812. List<int> bpoints;
  813. tx->get_breakpoints(&bpoints);
  814. if (bpoints.size() <= 0) {
  815. return;
  816. }
  817. int line = tx->cursor_get_line();
  818. // wrap around
  819. if (line <= bpoints[0]) {
  820. tx->unfold_line(bpoints[bpoints.size() - 1]);
  821. tx->cursor_set_line(bpoints[bpoints.size() - 1]);
  822. } else {
  823. for (List<int>::Element *E = bpoints.back(); E; E = E->prev()) {
  824. int bline = E->get();
  825. if (bline < line) {
  826. tx->unfold_line(bline);
  827. tx->cursor_set_line(bline);
  828. return;
  829. }
  830. }
  831. }
  832. } break;
  833. case HELP_CONTEXTUAL: {
  834. String text = tx->get_selection_text();
  835. if (text == "")
  836. text = tx->get_word_under_cursor();
  837. if (text != "") {
  838. emit_signal("request_help", text);
  839. }
  840. } break;
  841. case LOOKUP_SYMBOL: {
  842. String text = tx->get_word_under_cursor();
  843. if (text == "")
  844. text = tx->get_selection_text();
  845. if (text != "") {
  846. _lookup_symbol(text, tx->cursor_get_line(), tx->cursor_get_column());
  847. }
  848. } break;
  849. }
  850. }
  851. void ScriptTextEditor::add_syntax_highlighter(SyntaxHighlighter *p_highlighter) {
  852. highlighters[p_highlighter->get_name()] = p_highlighter;
  853. highlighter_menu->add_radio_check_item(p_highlighter->get_name());
  854. }
  855. void ScriptTextEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter) {
  856. TextEdit *te = code_editor->get_text_edit();
  857. te->_set_syntax_highlighting(p_highlighter);
  858. if (p_highlighter != NULL)
  859. highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(p_highlighter->get_name()), true);
  860. else
  861. highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(TTR("Standard")), true);
  862. }
  863. void ScriptTextEditor::_change_syntax_highlighter(int p_idx) {
  864. Map<String, SyntaxHighlighter *>::Element *el = highlighters.front();
  865. while (el != NULL) {
  866. highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(el->key()), false);
  867. el = el->next();
  868. }
  869. // highlighter_menu->set_item_checked(p_idx, true);
  870. set_syntax_highlighter(highlighters[highlighter_menu->get_item_text(p_idx)]);
  871. EditorSettings::get_singleton()->set_project_metadata("script_text_editor", "syntax_highlighter", p_idx);
  872. }
  873. void ScriptTextEditor::_bind_methods() {
  874. ClassDB::bind_method("_validate_script", &ScriptTextEditor::_validate_script);
  875. ClassDB::bind_method("_load_theme_settings", &ScriptTextEditor::_load_theme_settings);
  876. ClassDB::bind_method("_breakpoint_toggled", &ScriptTextEditor::_breakpoint_toggled);
  877. ClassDB::bind_method("_change_syntax_highlighter", &ScriptTextEditor::_change_syntax_highlighter);
  878. ClassDB::bind_method("_edit_option", &ScriptTextEditor::_edit_option);
  879. ClassDB::bind_method("_goto_line", &ScriptTextEditor::_goto_line);
  880. ClassDB::bind_method("_lookup_symbol", &ScriptTextEditor::_lookup_symbol);
  881. ClassDB::bind_method("_text_edit_gui_input", &ScriptTextEditor::_text_edit_gui_input);
  882. ClassDB::bind_method("_toggle_warning_pannel", &ScriptTextEditor::_toggle_warning_pannel);
  883. ClassDB::bind_method("_warning_clicked", &ScriptTextEditor::_warning_clicked);
  884. ClassDB::bind_method("_color_changed", &ScriptTextEditor::_color_changed);
  885. ClassDB::bind_method("get_drag_data_fw", &ScriptTextEditor::get_drag_data_fw);
  886. ClassDB::bind_method("can_drop_data_fw", &ScriptTextEditor::can_drop_data_fw);
  887. ClassDB::bind_method("drop_data_fw", &ScriptTextEditor::drop_data_fw);
  888. }
  889. Control *ScriptTextEditor::get_edit_menu() {
  890. return edit_hb;
  891. }
  892. void ScriptTextEditor::clear_edit_menu() {
  893. memdelete(edit_hb);
  894. }
  895. void ScriptTextEditor::reload(bool p_soft) {
  896. TextEdit *te = code_editor->get_text_edit();
  897. Ref<Script> scr = script;
  898. if (scr.is_null())
  899. return;
  900. scr->set_source_code(te->get_text());
  901. bool soft = p_soft || scr->get_instance_base_type() == "EditorPlugin"; //always soft-reload editor plugins
  902. scr->get_language()->reload_tool_script(scr, soft);
  903. }
  904. void ScriptTextEditor::get_breakpoints(List<int> *p_breakpoints) {
  905. code_editor->get_text_edit()->get_breakpoints(p_breakpoints);
  906. }
  907. void ScriptTextEditor::set_tooltip_request_func(String p_method, Object *p_obj) {
  908. code_editor->get_text_edit()->set_tooltip_request_func(p_obj, p_method, this);
  909. }
  910. void ScriptTextEditor::set_debugger_active(bool p_active) {
  911. }
  912. Variant ScriptTextEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  913. return Variant();
  914. }
  915. bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  916. Dictionary d = p_data;
  917. if (d.has("type") && (String(d["type"]) == "resource" ||
  918. String(d["type"]) == "files" ||
  919. String(d["type"]) == "nodes")) {
  920. return true;
  921. }
  922. return false;
  923. }
  924. #ifdef TOOLS_ENABLED
  925. static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
  926. if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
  927. return NULL;
  928. Ref<Script> scr = p_current_node->get_script();
  929. if (scr.is_valid() && scr == script)
  930. return p_current_node;
  931. for (int i = 0; i < p_current_node->get_child_count(); i++) {
  932. Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
  933. if (n)
  934. return n;
  935. }
  936. return NULL;
  937. }
  938. #else
  939. static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
  940. return NULL;
  941. }
  942. #endif
  943. void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  944. Dictionary d = p_data;
  945. TextEdit *te = code_editor->get_text_edit();
  946. int row, col;
  947. te->_get_mouse_pos(p_point, row, col);
  948. if (d.has("type") && String(d["type"]) == "resource") {
  949. Ref<Resource> res = d["resource"];
  950. if (!res.is_valid()) {
  951. return;
  952. }
  953. if (res->get_path().is_resource_file()) {
  954. EditorNode::get_singleton()->show_warning(TTR("Only resources from filesystem can be dropped."));
  955. return;
  956. }
  957. te->cursor_set_line(row);
  958. te->cursor_set_column(col);
  959. te->insert_text_at_cursor(res->get_path());
  960. }
  961. if (d.has("type") && String(d["type"]) == "files") {
  962. Array files = d["files"];
  963. String text_to_drop;
  964. for (int i = 0; i < files.size(); i++) {
  965. if (i > 0)
  966. text_to_drop += ",";
  967. text_to_drop += "\"" + String(files[i]).c_escape() + "\"";
  968. }
  969. te->cursor_set_line(row);
  970. te->cursor_set_column(col);
  971. te->insert_text_at_cursor(text_to_drop);
  972. }
  973. if (d.has("type") && String(d["type"]) == "nodes") {
  974. Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script);
  975. if (!sn) {
  976. EditorNode::get_singleton()->show_warning("Can't drop nodes because script '" + get_name() + "' is not used in this scene.");
  977. return;
  978. }
  979. Array nodes = d["nodes"];
  980. String text_to_drop;
  981. for (int i = 0; i < nodes.size(); i++) {
  982. if (i > 0)
  983. text_to_drop += ",";
  984. NodePath np = nodes[i];
  985. Node *node = get_node(np);
  986. if (!node) {
  987. continue;
  988. }
  989. String path = sn->get_path_to(node);
  990. text_to_drop += "\"" + path.c_escape() + "\"";
  991. }
  992. te->cursor_set_line(row);
  993. te->cursor_set_column(col);
  994. te->insert_text_at_cursor(text_to_drop);
  995. }
  996. }
  997. void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
  998. Ref<InputEventMouseButton> mb = ev;
  999. if (mb.is_valid()) {
  1000. if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
  1001. int col, row;
  1002. TextEdit *tx = code_editor->get_text_edit();
  1003. tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col);
  1004. Vector2 mpos = mb->get_global_position() - tx->get_global_position();
  1005. tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret"));
  1006. if (tx->is_right_click_moving_caret()) {
  1007. if (tx->is_selection_active()) {
  1008. int from_line = tx->get_selection_from_line();
  1009. int to_line = tx->get_selection_to_line();
  1010. int from_column = tx->get_selection_from_column();
  1011. int to_column = tx->get_selection_to_column();
  1012. if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) {
  1013. // Right click is outside the selected text
  1014. tx->deselect();
  1015. }
  1016. }
  1017. if (!tx->is_selection_active()) {
  1018. tx->cursor_set_line(row, true, false);
  1019. tx->cursor_set_column(col);
  1020. }
  1021. }
  1022. String word_at_mouse = tx->get_word_at_pos(mpos);
  1023. if (word_at_mouse == "")
  1024. word_at_mouse = tx->get_word_under_cursor();
  1025. if (word_at_mouse == "")
  1026. word_at_mouse = tx->get_selection_text();
  1027. bool has_color = (word_at_mouse == "Color");
  1028. bool foldable = tx->can_fold(row) || tx->is_folded(row);
  1029. bool open_docs = false;
  1030. bool goto_definition = false;
  1031. if (word_at_mouse.is_resource_file()) {
  1032. open_docs = true;
  1033. } else {
  1034. Node *base = get_tree()->get_edited_scene_root();
  1035. if (base) {
  1036. base = _find_node_for_script(base, base, script);
  1037. }
  1038. ScriptLanguage::LookupResult result;
  1039. if (script->get_language()->lookup_code(code_editor->get_text_edit()->get_text_for_lookup_completion(), word_at_mouse, script->get_path().get_base_dir(), base, result) == OK) {
  1040. open_docs = true;
  1041. }
  1042. }
  1043. if (has_color) {
  1044. String line = tx->get_line(row);
  1045. color_line = row;
  1046. int begin = 0;
  1047. int end = 0;
  1048. bool valid = false;
  1049. for (int i = col; i < line.length(); i++) {
  1050. if (line[i] == '(') {
  1051. begin = i;
  1052. continue;
  1053. } else if (line[i] == ')') {
  1054. end = i + 1;
  1055. valid = true;
  1056. break;
  1057. }
  1058. }
  1059. if (valid) {
  1060. color_args = line.substr(begin, end - begin);
  1061. String stripped = color_args.replace(" ", "").replace("(", "").replace(")", "");
  1062. Vector<float> color = stripped.split_floats(",");
  1063. if (color.size() > 2) {
  1064. float alpha = color.size() > 3 ? color[3] : 1.0f;
  1065. color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha));
  1066. }
  1067. color_panel->set_position(get_global_transform().xform(get_local_mouse_position()));
  1068. } else {
  1069. has_color = false;
  1070. }
  1071. }
  1072. _make_context_menu(tx->is_selection_active(), has_color, foldable, open_docs, goto_definition);
  1073. }
  1074. }
  1075. }
  1076. void ScriptTextEditor::_color_changed(const Color &p_color) {
  1077. String new_args;
  1078. if (p_color.a == 1.0f) {
  1079. new_args = String("(" + rtos(p_color.r) + ", " + rtos(p_color.g) + ", " + rtos(p_color.b) + ")");
  1080. } else {
  1081. new_args = String("(" + rtos(p_color.r) + ", " + rtos(p_color.g) + ", " + rtos(p_color.b) + ", " + rtos(p_color.a) + ")");
  1082. }
  1083. String line = code_editor->get_text_edit()->get_line(color_line);
  1084. String new_line = line.replace(color_args, new_args);
  1085. color_args = new_args;
  1086. code_editor->get_text_edit()->set_line(color_line, new_line);
  1087. }
  1088. void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition) {
  1089. context_menu->clear();
  1090. if (p_selection) {
  1091. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
  1092. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
  1093. }
  1094. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
  1095. context_menu->add_separator();
  1096. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
  1097. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
  1098. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
  1099. context_menu->add_separator();
  1100. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
  1101. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
  1102. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
  1103. if (p_selection) {
  1104. context_menu->add_separator();
  1105. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE);
  1106. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE);
  1107. }
  1108. if (p_foldable)
  1109. context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
  1110. if (p_color || p_open_docs || p_goto_definition) {
  1111. context_menu->add_separator();
  1112. if (p_open_docs)
  1113. context_menu->add_item(TTR("Lookup Symbol"), LOOKUP_SYMBOL);
  1114. if (p_color)
  1115. context_menu->add_item(TTR("Pick Color"), EDIT_PICK_COLOR);
  1116. }
  1117. context_menu->set_position(get_global_transform().xform(get_local_mouse_position()));
  1118. context_menu->set_size(Vector2(1, 1));
  1119. context_menu->popup();
  1120. }
  1121. ScriptTextEditor::ScriptTextEditor() {
  1122. theme_loaded = false;
  1123. VSplitContainer *editor_box = memnew(VSplitContainer);
  1124. add_child(editor_box);
  1125. editor_box->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  1126. editor_box->set_v_size_flags(SIZE_EXPAND_FILL);
  1127. code_editor = memnew(CodeTextEditor);
  1128. editor_box->add_child(code_editor);
  1129. code_editor->add_constant_override("separation", 0);
  1130. code_editor->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  1131. code_editor->connect("validate_script", this, "_validate_script");
  1132. code_editor->connect("load_theme_settings", this, "_load_theme_settings");
  1133. code_editor->set_code_complete_func(_code_complete_scripts, this);
  1134. code_editor->get_text_edit()->connect("breakpoint_toggled", this, "_breakpoint_toggled");
  1135. code_editor->get_text_edit()->connect("symbol_lookup", this, "_lookup_symbol");
  1136. code_editor->set_v_size_flags(SIZE_EXPAND_FILL);
  1137. warnings_panel = memnew(RichTextLabel);
  1138. editor_box->add_child(warnings_panel);
  1139. warnings_panel->set_custom_minimum_size(Size2(0, 100 * EDSCALE));
  1140. warnings_panel->set_h_size_flags(SIZE_EXPAND_FILL);
  1141. warnings_panel->set_meta_underline(true);
  1142. warnings_panel->set_selection_enabled(true);
  1143. warnings_panel->set_focus_mode(FOCUS_CLICK);
  1144. warnings_panel->hide();
  1145. code_editor->get_warning_label()->connect("gui_input", this, "_toggle_warning_pannel");
  1146. code_editor->get_warning_count_label()->connect("gui_input", this, "_toggle_warning_pannel");
  1147. warnings_panel->connect("meta_clicked", this, "_warning_clicked");
  1148. update_settings();
  1149. code_editor->get_text_edit()->set_callhint_settings(
  1150. EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line"),
  1151. EditorSettings::get_singleton()->get("text_editor/completion/callhint_tooltip_offset"));
  1152. code_editor->get_text_edit()->set_select_identifiers_on_hover(true);
  1153. code_editor->get_text_edit()->set_context_menu_enabled(false);
  1154. code_editor->get_text_edit()->connect("gui_input", this, "_text_edit_gui_input");
  1155. context_menu = memnew(PopupMenu);
  1156. add_child(context_menu);
  1157. context_menu->connect("id_pressed", this, "_edit_option");
  1158. context_menu->set_hide_on_window_lose_focus(true);
  1159. color_panel = memnew(PopupPanel);
  1160. add_child(color_panel);
  1161. color_picker = memnew(ColorPicker);
  1162. color_panel->add_child(color_picker);
  1163. color_picker->connect("color_changed", this, "_color_changed");
  1164. edit_hb = memnew(HBoxContainer);
  1165. edit_menu = memnew(MenuButton);
  1166. edit_menu->set_text(TTR("Edit"));
  1167. edit_menu->set_switch_on_hover(true);
  1168. edit_menu->get_popup()->set_hide_on_window_lose_focus(true);
  1169. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
  1170. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
  1171. edit_menu->get_popup()->add_separator();
  1172. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
  1173. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
  1174. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
  1175. edit_menu->get_popup()->add_separator();
  1176. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
  1177. edit_menu->get_popup()->add_separator();
  1178. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
  1179. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
  1180. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
  1181. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
  1182. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
  1183. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
  1184. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
  1185. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_all_lines"), EDIT_FOLD_ALL_LINES);
  1186. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES);
  1187. edit_menu->get_popup()->add_separator();
  1188. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
  1189. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE);
  1190. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE);
  1191. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES);
  1192. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_tabs"), EDIT_CONVERT_INDENT_TO_TABS);
  1193. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/auto_indent"), EDIT_AUTO_INDENT);
  1194. edit_menu->get_popup()->connect("id_pressed", this, "_edit_option");
  1195. edit_menu->get_popup()->add_separator();
  1196. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_breakpoint"), DEBUG_TOGGLE_BREAKPOINT);
  1197. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_breakpoints"), DEBUG_REMOVE_ALL_BREAKPOINTS);
  1198. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_breakpoint"), DEBUG_GOTO_NEXT_BREAKPOINT);
  1199. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_breakpoint"), DEBUG_GOTO_PREV_BREAKPOINT);
  1200. edit_menu->get_popup()->add_separator();
  1201. PopupMenu *convert_case = memnew(PopupMenu);
  1202. convert_case->set_name("convert_case");
  1203. edit_menu->get_popup()->add_child(convert_case);
  1204. edit_menu->get_popup()->add_submenu_item(TTR("Convert Case"), "convert_case");
  1205. convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/convert_to_uppercase", TTR("Uppercase"), KEY_MASK_SHIFT | KEY_F4), EDIT_TO_UPPERCASE);
  1206. convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/convert_to_lowercase", TTR("Lowercase"), KEY_MASK_SHIFT | KEY_F5), EDIT_TO_LOWERCASE);
  1207. convert_case->add_shortcut(ED_SHORTCUT("script_text_editor/capitalize", TTR("Capitalize"), KEY_MASK_SHIFT | KEY_F6), EDIT_CAPITALIZE);
  1208. convert_case->connect("id_pressed", this, "_edit_option");
  1209. highlighters[TTR("Standard")] = NULL;
  1210. highlighter_menu = memnew(PopupMenu);
  1211. highlighter_menu->set_name("highlighter_menu");
  1212. edit_menu->get_popup()->add_child(highlighter_menu);
  1213. edit_menu->get_popup()->add_submenu_item(TTR("Syntax Highlighter"), "highlighter_menu");
  1214. highlighter_menu->add_radio_check_item(TTR("Standard"));
  1215. highlighter_menu->connect("id_pressed", this, "_change_syntax_highlighter");
  1216. search_menu = memnew(MenuButton);
  1217. edit_hb->add_child(search_menu);
  1218. search_menu->set_text(TTR("Search"));
  1219. search_menu->set_switch_on_hover(true);
  1220. search_menu->get_popup()->set_hide_on_window_lose_focus(true);
  1221. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND);
  1222. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT);
  1223. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV);
  1224. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE);
  1225. search_menu->get_popup()->add_separator();
  1226. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES);
  1227. search_menu->get_popup()->add_separator();
  1228. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_function"), SEARCH_LOCATE_FUNCTION);
  1229. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE);
  1230. search_menu->get_popup()->add_separator();
  1231. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/contextual_help"), HELP_CONTEXTUAL);
  1232. search_menu->get_popup()->connect("id_pressed", this, "_edit_option");
  1233. edit_hb->add_child(edit_menu);
  1234. quick_open = memnew(ScriptEditorQuickOpen);
  1235. add_child(quick_open);
  1236. quick_open->connect("goto_line", this, "_goto_line");
  1237. goto_line_dialog = memnew(GotoLineDialog);
  1238. add_child(goto_line_dialog);
  1239. code_editor->get_text_edit()->set_drag_forwarding(this);
  1240. }
  1241. static ScriptEditorBase *create_editor(const RES &p_resource) {
  1242. if (Object::cast_to<Script>(*p_resource)) {
  1243. return memnew(ScriptTextEditor);
  1244. }
  1245. return NULL;
  1246. }
  1247. void ScriptTextEditor::register_editor() {
  1248. ED_SHORTCUT("script_text_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z);
  1249. ED_SHORTCUT("script_text_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y);
  1250. ED_SHORTCUT("script_text_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X);
  1251. ED_SHORTCUT("script_text_editor/copy", TTR("Copy"), KEY_MASK_CMD | KEY_C);
  1252. ED_SHORTCUT("script_text_editor/paste", TTR("Paste"), KEY_MASK_CMD | KEY_V);
  1253. ED_SHORTCUT("script_text_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A);
  1254. ED_SHORTCUT("script_text_editor/move_up", TTR("Move Up"), KEY_MASK_ALT | KEY_UP);
  1255. ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KEY_MASK_ALT | KEY_DOWN);
  1256. ED_SHORTCUT("script_text_editor/delete_line", TTR("Delete Line"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_K);
  1257. //leave these at zero, same can be accomplished with tab/shift-tab, including selection
  1258. //the next/previous in history shortcut in this case makes a lot more sene.
  1259. ED_SHORTCUT("script_text_editor/indent_left", TTR("Indent Left"), 0);
  1260. ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), 0);
  1261. ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KEY_MASK_CMD | KEY_K);
  1262. ED_SHORTCUT("script_text_editor/toggle_fold_line", TTR("Fold/Unfold Line"), KEY_MASK_ALT | KEY_F);
  1263. ED_SHORTCUT("script_text_editor/fold_all_lines", TTR("Fold All Lines"), 0);
  1264. ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), 0);
  1265. #ifdef OSX_ENABLED
  1266. ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_C);
  1267. ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CTRL | KEY_SPACE);
  1268. #else
  1269. ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD | KEY_B);
  1270. ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD | KEY_SPACE);
  1271. #endif
  1272. ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_T);
  1273. ED_SHORTCUT("script_text_editor/convert_indent_to_spaces", TTR("Convert Indent to Spaces"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_Y);
  1274. ED_SHORTCUT("script_text_editor/convert_indent_to_tabs", TTR("Convert Indent to Tabs"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_I);
  1275. ED_SHORTCUT("script_text_editor/auto_indent", TTR("Auto Indent"), KEY_MASK_CMD | KEY_I);
  1276. #ifdef OSX_ENABLED
  1277. ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B);
  1278. #else
  1279. ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9);
  1280. #endif
  1281. ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F9);
  1282. ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Go to Next Breakpoint"), KEY_MASK_CMD | KEY_PERIOD);
  1283. ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Go to Previous Breakpoint"), KEY_MASK_CMD | KEY_COMMA);
  1284. ED_SHORTCUT("script_text_editor/find", TTR("Find..."), KEY_MASK_CMD | KEY_F);
  1285. #ifdef OSX_ENABLED
  1286. ED_SHORTCUT("script_text_editor/find_next", TTR("Find Next"), KEY_MASK_CMD | KEY_G);
  1287. ED_SHORTCUT("script_text_editor/find_previous", TTR("Find Previous"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_G);
  1288. ED_SHORTCUT("script_text_editor/replace", TTR("Replace..."), KEY_MASK_ALT | KEY_MASK_CMD | KEY_F);
  1289. #else
  1290. ED_SHORTCUT("script_text_editor/find_next", TTR("Find Next"), KEY_F3);
  1291. ED_SHORTCUT("script_text_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT | KEY_F3);
  1292. ED_SHORTCUT("script_text_editor/replace", TTR("Replace..."), KEY_MASK_CMD | KEY_R);
  1293. #endif
  1294. ED_SHORTCUT("script_text_editor/find_in_files", TTR("Find in Files..."), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F);
  1295. #ifdef OSX_ENABLED
  1296. ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_CTRL | KEY_MASK_CMD | KEY_J);
  1297. #else
  1298. ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_ALT | KEY_MASK_CMD | KEY_F);
  1299. #endif
  1300. ED_SHORTCUT("script_text_editor/goto_line", TTR("Go to Line..."), KEY_MASK_CMD | KEY_L);
  1301. #ifdef OSX_ENABLED
  1302. ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_MASK_SHIFT | KEY_SPACE);
  1303. #else
  1304. ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_SHIFT | KEY_F1);
  1305. #endif
  1306. ScriptEditor::register_create_script_editor_function(create_editor);
  1307. }