script_text_editor.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. /*************************************************************************/
  2. /* script_text_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "script_text_editor.h"
  30. #include "tools/editor/editor_settings.h"
  31. #include "os/keyboard.h"
  32. #include "tools/editor/script_editor_debugger.h"
  33. Vector<String> ScriptTextEditor::get_functions() {
  34. String errortxt;
  35. int line=-1,col;
  36. TextEdit *te=code_editor->get_text_edit();
  37. String text = te->get_text();
  38. List<String> fnc;
  39. if (script->get_language()->validate(text,line,col,errortxt,script->get_path(),&fnc)) {
  40. //if valid rewrite functions to latest
  41. functions.clear();
  42. for (List<String>::Element *E=fnc.front();E;E=E->next()) {
  43. functions.push_back(E->get());
  44. }
  45. }
  46. return functions;
  47. }
  48. void ScriptTextEditor::apply_code() {
  49. if (script.is_null())
  50. return;
  51. // print_line("applying code");
  52. script->set_source_code(code_editor->get_text_edit()->get_text());
  53. script->update_exports();
  54. }
  55. Ref<Script> ScriptTextEditor::get_edited_script() const {
  56. return script;
  57. }
  58. bool ScriptTextEditor::goto_method(const String& p_method) {
  59. Vector<String> functions = get_functions();
  60. String method_search = p_method + ":";
  61. for (int i=0;i<functions.size();i++) {
  62. String function=functions[i];
  63. if (function.begins_with(method_search)) {
  64. int line=function.get_slice(":",1).to_int();
  65. goto_line(line-1);
  66. return true;
  67. }
  68. }
  69. return false;
  70. }
  71. void ScriptTextEditor::_load_theme_settings() {
  72. TextEdit *text_edit = code_editor->get_text_edit();
  73. text_edit->clear_colors();
  74. /* keyword color */
  75. text_edit->set_custom_bg_color(EDITOR_DEF("text_editor/background_color",Color(0,0,0,0)));
  76. text_edit->add_color_override("completion_background_color", EDITOR_DEF("text_editor/completion_background_color", Color(0,0,0,0)));
  77. text_edit->add_color_override("completion_selected_color", EDITOR_DEF("text_editor/completion_selected_color", Color::html("434244")));
  78. text_edit->add_color_override("completion_existing_color", EDITOR_DEF("text_editor/completion_existing_color", Color::html("21dfdfdf")));
  79. text_edit->add_color_override("completion_scroll_color", EDITOR_DEF("text_editor/completion_scroll_color", Color::html("ffffff")));
  80. text_edit->add_color_override("completion_font_color", EDITOR_DEF("text_editor/completion_font_color", Color::html("aaaaaa")));
  81. text_edit->add_color_override("font_color",EDITOR_DEF("text_editor/text_color",Color(0,0,0)));
  82. text_edit->add_color_override("line_number_color",EDITOR_DEF("text_editor/line_number_color",Color(0,0,0)));
  83. text_edit->add_color_override("caret_color",EDITOR_DEF("text_editor/caret_color",Color(0,0,0)));
  84. text_edit->add_color_override("caret_background_color",EDITOR_DEF("text_editor/caret_background_color",Color(0,0,0)));
  85. text_edit->add_color_override("font_selected_color",EDITOR_DEF("text_editor/text_selected_color",Color(1,1,1)));
  86. text_edit->add_color_override("selection_color",EDITOR_DEF("text_editor/selection_color",Color(0.2,0.2,1)));
  87. text_edit->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/brace_mismatch_color",Color(1,0.2,0.2)));
  88. text_edit->add_color_override("current_line_color",EDITOR_DEF("text_editor/current_line_color",Color(0.3,0.5,0.8,0.15)));
  89. text_edit->add_color_override("word_highlighted_color",EDITOR_DEF("text_editor/word_highlighted_color",Color(0.8,0.9,0.9,0.15)));
  90. text_edit->add_color_override("number_color",EDITOR_DEF("text_editor/number_color",Color(0.9,0.6,0.0,2)));
  91. text_edit->add_color_override("function_color",EDITOR_DEF("text_editor/function_color",Color(0.4,0.6,0.8)));
  92. text_edit->add_color_override("member_variable_color",EDITOR_DEF("text_editor/member_variable_color",Color(0.9,0.3,0.3)));
  93. text_edit->add_color_override("mark_color", EDITOR_DEF("text_editor/mark_color", Color(1.0,0.4,0.4,0.4)));
  94. text_edit->add_color_override("breakpoint_color", EDITOR_DEF("text_editor/breakpoint_color", Color(0.8,0.8,0.4,0.2)));
  95. text_edit->add_color_override("search_result_color",EDITOR_DEF("text_editor/search_result_color",Color(0.05,0.25,0.05,1)));
  96. text_edit->add_color_override("search_result_border_color",EDITOR_DEF("text_editor/search_result_border_color",Color(0.1,0.45,0.1,1)));
  97. text_edit->add_constant_override("line_spacing", EDITOR_DEF("text_editor/line_spacing",4));
  98. Color keyword_color= EDITOR_DEF("text_editor/keyword_color",Color(0.5,0.0,0.2));
  99. List<String> keywords;
  100. script->get_language()->get_reserved_words(&keywords);
  101. for(List<String>::Element *E=keywords.front();E;E=E->next()) {
  102. text_edit->add_keyword_color(E->get(),keyword_color);
  103. }
  104. //colorize core types
  105. Color basetype_color= EDITOR_DEF("text_editor/base_type_color",Color(0.3,0.3,0.0));
  106. text_edit->add_keyword_color("Vector2",basetype_color);
  107. text_edit->add_keyword_color("Vector3",basetype_color);
  108. text_edit->add_keyword_color("Plane",basetype_color);
  109. text_edit->add_keyword_color("Quat",basetype_color);
  110. text_edit->add_keyword_color("AABB",basetype_color);
  111. text_edit->add_keyword_color("Matrix3",basetype_color);
  112. text_edit->add_keyword_color("Transform",basetype_color);
  113. text_edit->add_keyword_color("Color",basetype_color);
  114. text_edit->add_keyword_color("Image",basetype_color);
  115. text_edit->add_keyword_color("InputEvent",basetype_color);
  116. text_edit->add_keyword_color("Rect2",basetype_color);
  117. text_edit->add_keyword_color("NodePath",basetype_color);
  118. //colorize engine types
  119. Color type_color= EDITOR_DEF("text_editor/engine_type_color",Color(0.0,0.2,0.4));
  120. List<StringName> types;
  121. ObjectTypeDB::get_type_list(&types);
  122. for(List<StringName>::Element *E=types.front();E;E=E->next()) {
  123. String n = E->get();
  124. if (n.begins_with("_"))
  125. n = n.substr(1, n.length());
  126. text_edit->add_keyword_color(n,type_color);
  127. }
  128. //colorize comments
  129. Color comment_color = EDITOR_DEF("text_editor/comment_color",Color::hex(0x797e7eff));
  130. List<String> comments;
  131. script->get_language()->get_comment_delimiters(&comments);
  132. for(List<String>::Element *E=comments.front();E;E=E->next()) {
  133. String comment = E->get();
  134. String beg = comment.get_slice(" ",0);
  135. String end = comment.get_slice_count(" ")>1?comment.get_slice(" ",1):String();
  136. text_edit->add_color_region(beg,end,comment_color,end=="");
  137. }
  138. //colorize strings
  139. Color string_color = EDITOR_DEF("text_editor/string_color",Color::hex(0x6b6f00ff));
  140. List<String> strings;
  141. script->get_language()->get_string_delimiters(&strings);
  142. for (List<String>::Element *E=strings.front();E;E=E->next()) {
  143. String string = E->get();
  144. String beg = string.get_slice(" ",0);
  145. String end = string.get_slice_count(" ")>1?string.get_slice(" ",1):String();
  146. text_edit->add_color_region(beg,end,string_color,end=="");
  147. }
  148. //colorize symbols
  149. Color symbol_color= EDITOR_DEF("text_editor/symbol_color",Color::hex(0x005291ff));
  150. text_edit->set_symbol_color(symbol_color);
  151. }
  152. void ScriptTextEditor::reload_text() {
  153. ERR_FAIL_COND(script.is_null()) ;
  154. TextEdit *te = code_editor->get_text_edit();
  155. int column = te->cursor_get_column();
  156. int row = te->cursor_get_line();
  157. int h = te->get_h_scroll();
  158. int v = te->get_v_scroll();
  159. te->set_text(script->get_source_code());
  160. te->clear_undo_history();
  161. te->cursor_set_line(row);
  162. te->cursor_set_column(column);
  163. te->set_h_scroll(h);
  164. te->set_v_scroll(v);
  165. te->tag_saved_version();
  166. code_editor->update_line_and_column();
  167. }
  168. void ScriptTextEditor::_notification(int p_what) {
  169. if (p_what==NOTIFICATION_READY) {
  170. //emit_signal("name_changed");
  171. }
  172. }
  173. void ScriptTextEditor::add_callback(const String& p_function,StringArray p_args) {
  174. String code = code_editor->get_text_edit()->get_text();
  175. int pos = script->get_language()->find_function(p_function,code);
  176. if (pos==-1) {
  177. //does not exist
  178. code_editor->get_text_edit()->deselect();
  179. pos=code_editor->get_text_edit()->get_line_count()+2;
  180. String func = script->get_language()->make_function("",p_function,p_args);
  181. //code=code+func;
  182. code_editor->get_text_edit()->cursor_set_line(pos+1);
  183. code_editor->get_text_edit()->cursor_set_column(1000000); //none shall be that big
  184. code_editor->get_text_edit()->insert_text_at_cursor("\n\n"+func);
  185. }
  186. code_editor->get_text_edit()->cursor_set_line(pos);
  187. code_editor->get_text_edit()->cursor_set_column(1);
  188. }
  189. void ScriptTextEditor::update_settings() {
  190. code_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/auto_brace_complete"));
  191. code_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/scroll_past_end_of_file"));
  192. code_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/tab_size"));
  193. code_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/draw_tabs"));
  194. code_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/show_line_numbers"));
  195. code_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/syntax_highlighting"));
  196. code_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlight_all_occurrences"));
  197. code_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/caret_blink"));
  198. code_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/caret_blink_speed"));
  199. code_editor->get_text_edit()->set_draw_breakpoint_gutter(EditorSettings::get_singleton()->get("text_editor/show_breakpoint_gutter"));
  200. code_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/block_caret"));
  201. }
  202. bool ScriptTextEditor::is_unsaved() {
  203. return code_editor->get_text_edit()->get_version()!=code_editor->get_text_edit()->get_saved_version();
  204. }
  205. Variant ScriptTextEditor::get_edit_state() {
  206. Dictionary state;
  207. state["scroll_pos"]=code_editor->get_text_edit()->get_v_scroll();
  208. state["column"]=code_editor->get_text_edit()->cursor_get_column();
  209. state["row"]=code_editor->get_text_edit()->cursor_get_line();
  210. return state;
  211. }
  212. void ScriptTextEditor::trim_trailing_whitespace() {
  213. TextEdit *tx = code_editor->get_text_edit();
  214. bool trimed_whitespace = false;
  215. for (int i = 0; i < tx->get_line_count(); i++) {
  216. String line = tx->get_line(i);
  217. if (line.ends_with(" ") || line.ends_with("\t")) {
  218. if (!trimed_whitespace) {
  219. tx->begin_complex_operation();
  220. trimed_whitespace = true;
  221. }
  222. int end = 0;
  223. for (int j = line.length() - 1; j > -1; j--) {
  224. if (line[j] != ' ' && line[j] != '\t') {
  225. end = j+1;
  226. break;
  227. }
  228. }
  229. tx->set_line(i, line.substr(0, end));
  230. }
  231. }
  232. if (trimed_whitespace) {
  233. tx->end_complex_operation();
  234. tx->update();
  235. }
  236. }
  237. void ScriptTextEditor::tag_saved_version() {
  238. code_editor->get_text_edit()->tag_saved_version();
  239. }
  240. void ScriptTextEditor::goto_line(int p_line) {
  241. code_editor->get_text_edit()->cursor_set_line(p_line);
  242. }
  243. void ScriptTextEditor::ensure_focus() {
  244. code_editor->get_text_edit()->grab_focus();
  245. }
  246. void ScriptTextEditor::set_edit_state(const Variant& p_state) {
  247. Dictionary state=p_state;
  248. code_editor->get_text_edit()->set_v_scroll(state["scroll_pos"]);
  249. code_editor->get_text_edit()->cursor_set_column( state["column"]);
  250. code_editor->get_text_edit()->cursor_set_line( state["row"] );
  251. code_editor->get_text_edit()->grab_focus();
  252. //int scroll_pos;
  253. //int cursor_column;
  254. //int cursor_row;
  255. }
  256. String ScriptTextEditor::get_name() {
  257. String name;
  258. if (script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) {
  259. name=script->get_path().get_file();
  260. if (is_unsaved()) {
  261. name+="(*)";
  262. }
  263. } else if (script->get_name()!="")
  264. name=script->get_name();
  265. else
  266. name=script->get_type()+"("+itos(script->get_instance_ID())+")";
  267. return name;
  268. }
  269. Ref<Texture> ScriptTextEditor::get_icon() {
  270. if (get_parent_control() && get_parent_control()->has_icon(script->get_type(),"EditorIcons")) {
  271. return get_parent_control()->get_icon(script->get_type(),"EditorIcons");
  272. }
  273. return Ref<Texture>();
  274. }
  275. void ScriptTextEditor::set_edited_script(const Ref<Script>& p_script) {
  276. ERR_FAIL_COND(!script.is_null());
  277. script=p_script;
  278. _load_theme_settings();
  279. code_editor->get_text_edit()->set_text(script->get_source_code());
  280. code_editor->get_text_edit()->clear_undo_history();
  281. code_editor->get_text_edit()->tag_saved_version();
  282. emit_signal("name_changed");
  283. code_editor->update_line_and_column();
  284. }
  285. void ScriptTextEditor::_validate_script() {
  286. String errortxt;
  287. int line=-1,col;
  288. TextEdit *te=code_editor->get_text_edit();
  289. String text = te->get_text();
  290. List<String> fnc;
  291. if (!script->get_language()->validate(text,line,col,errortxt,script->get_path(),&fnc)) {
  292. String error_text="error("+itos(line)+","+itos(col)+"): "+errortxt;
  293. code_editor->set_error(error_text);
  294. } else {
  295. code_editor->set_error("");
  296. line=-1;
  297. if (!script->is_tool()) {
  298. script->set_source_code(text);
  299. script->update_exports();
  300. //script->reload(); //will update all the variables in property editors
  301. }
  302. functions.clear();
  303. for (List<String>::Element *E=fnc.front();E;E=E->next()) {
  304. functions.push_back(E->get());
  305. }
  306. }
  307. line--;
  308. for(int i=0;i<te->get_line_count();i++) {
  309. te->set_line_as_marked(i,line==i);
  310. }
  311. emit_signal("name_changed");
  312. }
  313. static Node* _find_node_for_script(Node* p_base, Node*p_current, const Ref<Script>& p_script) {
  314. if (p_current->get_owner()!=p_base && p_base!=p_current)
  315. return NULL;
  316. Ref<Script> c = p_current->get_script();
  317. if (c==p_script)
  318. return p_current;
  319. for(int i=0;i<p_current->get_child_count();i++) {
  320. Node *found = _find_node_for_script(p_base,p_current->get_child(i),p_script);
  321. if (found)
  322. return found;
  323. }
  324. return NULL;
  325. }
  326. static void _find_changed_scripts_for_external_editor(Node* p_base, Node*p_current, Set<Ref<Script> > &r_scripts) {
  327. if (p_current->get_owner()!=p_base && p_base!=p_current)
  328. return;
  329. Ref<Script> c = p_current->get_script();
  330. if (c.is_valid())
  331. r_scripts.insert(c);
  332. for(int i=0;i<p_current->get_child_count();i++) {
  333. _find_changed_scripts_for_external_editor(p_base,p_current->get_child(i),r_scripts);
  334. }
  335. }
  336. void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_for_script) {
  337. if (!bool(EditorSettings::get_singleton()->get("external_editor/use_external_editor")))
  338. return;
  339. Set<Ref<Script> > scripts;
  340. Node *base = get_tree()->get_edited_scene_root();
  341. if (base) {
  342. _find_changed_scripts_for_external_editor(base,base,scripts);
  343. }
  344. for (Set<Ref<Script> >::Element *E=scripts.front();E;E=E->next()) {
  345. Ref<Script> script = E->get();
  346. if (p_for_script.is_valid() && p_for_script!=script)
  347. continue;
  348. if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1) {
  349. continue; //internal script, who cares, though weird
  350. }
  351. uint64_t last_date = script->get_last_modified_time();
  352. uint64_t date = FileAccess::get_modified_time(script->get_path());
  353. if (last_date!=date) {
  354. Ref<Script> rel_script = ResourceLoader::load(script->get_path(),script->get_type(),true);
  355. ERR_CONTINUE(!rel_script.is_valid());
  356. script->set_source_code( rel_script->get_source_code() );
  357. script->set_last_modified_time( rel_script->get_last_modified_time() );
  358. script->update_exports();
  359. }
  360. }
  361. }
  362. void ScriptTextEditor::_code_complete_scripts(void* p_ud,const String& p_code, List<String>* r_options) {
  363. ScriptTextEditor *ste = (ScriptTextEditor *)p_ud;
  364. ste->_code_complete_script(p_code,r_options);
  365. }
  366. void ScriptTextEditor::_code_complete_script(const String& p_code, List<String>* r_options) {
  367. Node *base = get_tree()->get_edited_scene_root();
  368. if (base) {
  369. base = _find_node_for_script(base,base,script);
  370. }
  371. String hint;
  372. Error err = script->get_language()->complete_code(p_code,script->get_path().get_base_dir(),base,r_options,hint);
  373. if (hint!="") {
  374. code_editor->get_text_edit()->set_code_hint(hint);
  375. }
  376. }
  377. void ScriptTextEditor::_breakpoint_toggled(int p_row) {
  378. 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));
  379. }
  380. static void swap_lines(TextEdit *tx, int line1, int line2)
  381. {
  382. String tmp = tx->get_line(line1);
  383. String tmp2 = tx->get_line(line2);
  384. tx->set_line(line2, tmp);
  385. tx->set_line(line1, tmp2);
  386. tx->cursor_set_line(line2);
  387. }
  388. void ScriptTextEditor::_edit_option(int p_op) {
  389. switch(p_op) {
  390. case EDIT_UNDO: {
  391. code_editor->get_text_edit()->undo();
  392. code_editor->get_text_edit()->call_deferred("grab_focus");
  393. } break;
  394. case EDIT_REDO: {
  395. code_editor->get_text_edit()->redo();
  396. code_editor->get_text_edit()->call_deferred("grab_focus");
  397. } break;
  398. case EDIT_CUT: {
  399. code_editor->get_text_edit()->cut();
  400. code_editor->get_text_edit()->call_deferred("grab_focus");
  401. } break;
  402. case EDIT_COPY: {
  403. code_editor->get_text_edit()->copy();
  404. code_editor->get_text_edit()->call_deferred("grab_focus");
  405. } break;
  406. case EDIT_PASTE: {
  407. code_editor->get_text_edit()->paste();
  408. code_editor->get_text_edit()->call_deferred("grab_focus");
  409. } break;
  410. case EDIT_SELECT_ALL: {
  411. code_editor->get_text_edit()->select_all();
  412. code_editor->get_text_edit()->call_deferred("grab_focus");
  413. } break;
  414. case EDIT_MOVE_LINE_UP: {
  415. TextEdit *tx = code_editor->get_text_edit();
  416. Ref<Script> scr = script;
  417. if (scr.is_null())
  418. return;
  419. tx->begin_complex_operation();
  420. if (tx->is_selection_active())
  421. {
  422. int from_line = tx->get_selection_from_line();
  423. int from_col = tx->get_selection_from_column();
  424. int to_line = tx->get_selection_to_line();
  425. int to_column = tx->get_selection_to_column();
  426. for (int i = from_line; i <= to_line; i++)
  427. {
  428. int line_id = i;
  429. int next_id = i - 1;
  430. if (line_id == 0 || next_id < 0)
  431. return;
  432. swap_lines(tx, line_id, next_id);
  433. }
  434. int from_line_up = from_line > 0 ? from_line-1 : from_line;
  435. int to_line_up = to_line > 0 ? to_line-1 : to_line;
  436. tx->select(from_line_up, from_col, to_line_up, to_column);
  437. }
  438. else
  439. {
  440. int line_id = tx->cursor_get_line();
  441. int next_id = line_id - 1;
  442. if (line_id == 0 || next_id < 0)
  443. return;
  444. swap_lines(tx, line_id, next_id);
  445. }
  446. tx->end_complex_operation();
  447. tx->update();
  448. } break;
  449. case EDIT_MOVE_LINE_DOWN: {
  450. TextEdit *tx = code_editor->get_text_edit();
  451. Ref<Script> scr = get_edited_script();
  452. if (scr.is_null())
  453. return;
  454. tx->begin_complex_operation();
  455. if (tx->is_selection_active())
  456. {
  457. int from_line = tx->get_selection_from_line();
  458. int from_col = tx->get_selection_from_column();
  459. int to_line = tx->get_selection_to_line();
  460. int to_column = tx->get_selection_to_column();
  461. for (int i = to_line; i >= from_line; i--)
  462. {
  463. int line_id = i;
  464. int next_id = i + 1;
  465. if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count())
  466. return;
  467. swap_lines(tx, line_id, next_id);
  468. }
  469. int from_line_down = from_line < tx->get_line_count() ? from_line+1 : from_line;
  470. int to_line_down = to_line < tx->get_line_count() ? to_line+1 : to_line;
  471. tx->select(from_line_down, from_col, to_line_down, to_column);
  472. }
  473. else
  474. {
  475. int line_id = tx->cursor_get_line();
  476. int next_id = line_id + 1;
  477. if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count())
  478. return;
  479. swap_lines(tx, line_id, next_id);
  480. }
  481. tx->end_complex_operation();
  482. tx->update();
  483. } break;
  484. case EDIT_INDENT_LEFT: {
  485. TextEdit *tx = code_editor->get_text_edit();
  486. Ref<Script> scr = get_edited_script();
  487. if (scr.is_null())
  488. return;
  489. tx->begin_complex_operation();
  490. if (tx->is_selection_active())
  491. {
  492. tx->indent_selection_left();
  493. }
  494. else
  495. {
  496. int begin = tx->cursor_get_line();
  497. String line_text = tx->get_line(begin);
  498. // begins with tab
  499. if (line_text.begins_with("\t"))
  500. {
  501. line_text = line_text.substr(1, line_text.length());
  502. tx->set_line(begin, line_text);
  503. }
  504. // begins with 4 spaces
  505. else if (line_text.begins_with(" "))
  506. {
  507. line_text = line_text.substr(4, line_text.length());
  508. tx->set_line(begin, line_text);
  509. }
  510. }
  511. tx->end_complex_operation();
  512. tx->update();
  513. //tx->deselect();
  514. } break;
  515. case EDIT_INDENT_RIGHT: {
  516. TextEdit *tx = code_editor->get_text_edit();
  517. Ref<Script> scr = get_edited_script();
  518. if (scr.is_null())
  519. return;
  520. tx->begin_complex_operation();
  521. if (tx->is_selection_active())
  522. {
  523. tx->indent_selection_right();
  524. }
  525. else
  526. {
  527. int begin = tx->cursor_get_line();
  528. String line_text = tx->get_line(begin);
  529. line_text = '\t' + line_text;
  530. tx->set_line(begin, line_text);
  531. }
  532. tx->end_complex_operation();
  533. tx->update();
  534. //tx->deselect();
  535. } break;
  536. case EDIT_CLONE_DOWN: {
  537. TextEdit *tx = code_editor->get_text_edit();
  538. Ref<Script> scr = get_edited_script();
  539. if (scr.is_null())
  540. return;
  541. int from_line = tx->cursor_get_line();
  542. int to_line = tx->cursor_get_line();
  543. int column = tx->cursor_get_column();
  544. if (tx->is_selection_active()) {
  545. from_line = tx->get_selection_from_line();
  546. to_line = tx->get_selection_to_line();
  547. column = tx->cursor_get_column();
  548. }
  549. int next_line = to_line + 1;
  550. tx->begin_complex_operation();
  551. for (int i = from_line; i <= to_line; i++) {
  552. if (i >= tx->get_line_count() - 1) {
  553. tx->set_line(i, tx->get_line(i) + "\n");
  554. }
  555. String line_clone = tx->get_line(i);
  556. tx->insert_at(line_clone, next_line);
  557. next_line++;
  558. }
  559. tx->cursor_set_column(column);
  560. if (tx->is_selection_active()) {
  561. tx->select(to_line + 1, tx->get_selection_from_column(), next_line - 1, tx->get_selection_to_column());
  562. }
  563. tx->end_complex_operation();
  564. tx->update();
  565. } break;
  566. case EDIT_TOGGLE_COMMENT: {
  567. TextEdit *tx = code_editor->get_text_edit();
  568. Ref<Script> scr = get_edited_script();
  569. if (scr.is_null())
  570. return;
  571. tx->begin_complex_operation();
  572. if (tx->is_selection_active())
  573. {
  574. int begin = tx->get_selection_from_line();
  575. int end = tx->get_selection_to_line();
  576. // End of selection ends on the first column of the last line, ignore it.
  577. if(tx->get_selection_to_column() == 0)
  578. end -= 1;
  579. for (int i = begin; i <= end; i++)
  580. {
  581. String line_text = tx->get_line(i);
  582. if (line_text.begins_with("#"))
  583. line_text = line_text.substr(1, line_text.length());
  584. else
  585. line_text = "#" + line_text;
  586. tx->set_line(i, line_text);
  587. }
  588. }
  589. else
  590. {
  591. int begin = tx->cursor_get_line();
  592. String line_text = tx->get_line(begin);
  593. if (line_text.begins_with("#"))
  594. line_text = line_text.substr(1, line_text.length());
  595. else
  596. line_text = "#" + line_text;
  597. tx->set_line(begin, line_text);
  598. }
  599. tx->end_complex_operation();
  600. tx->update();
  601. //tx->deselect();
  602. } break;
  603. case EDIT_COMPLETE: {
  604. code_editor->get_text_edit()->query_code_comple();
  605. } break;
  606. case EDIT_AUTO_INDENT: {
  607. TextEdit *te = code_editor->get_text_edit();
  608. String text = te->get_text();
  609. Ref<Script> scr = get_edited_script();
  610. if (scr.is_null())
  611. return;
  612. int begin,end;
  613. if (te->is_selection_active()) {
  614. begin=te->get_selection_from_line();
  615. end=te->get_selection_to_line();
  616. } else {
  617. begin=0;
  618. end=te->get_line_count()-1;
  619. }
  620. scr->get_language()->auto_indent_code(text,begin,end);
  621. te->set_text(text);
  622. } break;
  623. case EDIT_TRIM_TRAILING_WHITESAPCE: {
  624. trim_trailing_whitespace();
  625. } break;
  626. case SEARCH_FIND: {
  627. code_editor->get_find_replace_bar()->popup_search();
  628. } break;
  629. case SEARCH_FIND_NEXT: {
  630. code_editor->get_find_replace_bar()->search_next();
  631. } break;
  632. case SEARCH_FIND_PREV: {
  633. code_editor->get_find_replace_bar()->search_prev();
  634. } break;
  635. case SEARCH_REPLACE: {
  636. code_editor->get_find_replace_bar()->popup_replace();
  637. } break;
  638. case SEARCH_LOCATE_FUNCTION: {
  639. quick_open->popup(get_functions());
  640. } break;
  641. case SEARCH_GOTO_LINE: {
  642. goto_line_dialog->popup_find_line(code_editor->get_text_edit());
  643. } break;
  644. case DEBUG_TOGGLE_BREAKPOINT: {
  645. int line=code_editor->get_text_edit()->cursor_get_line();
  646. bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line);
  647. code_editor->get_text_edit()->set_line_as_breakpoint(line,dobreak);
  648. ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(),line+1,dobreak);
  649. } break;
  650. case DEBUG_REMOVE_ALL_BREAKPOINTS: {
  651. List<int> bpoints;
  652. code_editor->get_text_edit()->get_breakpoints(&bpoints);
  653. for(List<int>::Element *E=bpoints.front();E;E=E->next()) {
  654. int line = E->get();
  655. bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line);
  656. code_editor->get_text_edit()->set_line_as_breakpoint(line,dobreak);
  657. ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(),line+1,dobreak);
  658. }
  659. }
  660. case DEBUG_GOTO_NEXT_BREAKPOINT: {
  661. List<int> bpoints;
  662. code_editor->get_text_edit()->get_breakpoints(&bpoints);
  663. if (bpoints.size() <= 0) {
  664. return;
  665. }
  666. int line=code_editor->get_text_edit()->cursor_get_line();
  667. // wrap around
  668. if (line >= bpoints[bpoints.size() - 1]) {
  669. code_editor->get_text_edit()->cursor_set_line(bpoints[0]);
  670. } else {
  671. for(List<int>::Element *E=bpoints.front();E;E=E->next()) {
  672. int bline = E->get();
  673. if (bline > line) {
  674. code_editor->get_text_edit()->cursor_set_line(bline);
  675. return;
  676. }
  677. }
  678. }
  679. } break;
  680. case DEBUG_GOTO_PREV_BREAKPOINT: {
  681. List<int> bpoints;
  682. code_editor->get_text_edit()->get_breakpoints(&bpoints);
  683. if (bpoints.size() <= 0) {
  684. return;
  685. }
  686. int line=code_editor->get_text_edit()->cursor_get_line();
  687. // wrap around
  688. if (line <= bpoints[0]) {
  689. code_editor->get_text_edit()->cursor_set_line(bpoints[bpoints.size() - 1]);
  690. } else {
  691. for(List<int>::Element *E=bpoints.back();E;E=E->prev()) {
  692. int bline = E->get();
  693. if (bline < line) {
  694. code_editor->get_text_edit()->cursor_set_line(bline);
  695. return;
  696. }
  697. }
  698. }
  699. } break;
  700. case HELP_CONTEXTUAL: {
  701. String text = code_editor->get_text_edit()->get_selection_text();
  702. if (text == "")
  703. text = code_editor->get_text_edit()->get_word_under_cursor();
  704. if (text != "") {
  705. emit_signal("request_help_search",text);
  706. }
  707. } break;
  708. }
  709. }
  710. void ScriptTextEditor::_bind_methods() {
  711. ObjectTypeDB::bind_method("_validate_script",&ScriptTextEditor::_validate_script);
  712. ObjectTypeDB::bind_method("_load_theme_settings",&ScriptTextEditor::_load_theme_settings);
  713. ObjectTypeDB::bind_method("_breakpoint_toggled",&ScriptTextEditor::_breakpoint_toggled);
  714. ObjectTypeDB::bind_method("_edit_option",&ScriptTextEditor::_edit_option);
  715. ObjectTypeDB::bind_method("_goto_line",&ScriptTextEditor::_goto_line);
  716. ADD_SIGNAL(MethodInfo("name_changed"));
  717. ADD_SIGNAL(MethodInfo("request_help_search",PropertyInfo(Variant::STRING,"topic")));
  718. }
  719. Control *ScriptTextEditor::get_edit_menu() {
  720. return edit_hb;
  721. }
  722. void ScriptTextEditor::reload(bool p_soft) {
  723. TextEdit *te = code_editor->get_text_edit();
  724. Ref<Script> scr = get_edited_script();
  725. if (scr.is_null())
  726. return;
  727. scr->set_source_code(te->get_text());
  728. bool soft = p_soft || scr->get_instance_base_type()=="EditorPlugin"; //always soft-reload editor plugins
  729. scr->get_language()->reload_tool_script(scr,soft);
  730. }
  731. void ScriptTextEditor::get_breakpoints(List<int> *p_breakpoints) {
  732. code_editor->get_text_edit()->get_breakpoints(p_breakpoints);
  733. }
  734. void ScriptTextEditor::set_tooltip_request_func(String p_method,Object* p_obj) {
  735. code_editor->get_text_edit()->set_tooltip_request_func(p_obj,p_method,this);
  736. }
  737. ScriptTextEditor::ScriptTextEditor() {
  738. code_editor = memnew( CodeTextEditor );
  739. add_child(code_editor);
  740. code_editor->set_area_as_parent_rect();
  741. code_editor->connect("validate_script",this,"_validate_script");
  742. code_editor->connect("load_theme_settings",this,"_load_theme_settings");
  743. code_editor->set_code_complete_func(_code_complete_scripts,this);
  744. code_editor->get_text_edit()->connect("breakpoint_toggled", this, "_breakpoint_toggled");
  745. code_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/scroll_past_end_of_file"));
  746. code_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/auto_brace_complete"));
  747. code_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/tab_size"));
  748. code_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/draw_tabs"));
  749. code_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/show_line_numbers"));
  750. code_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/syntax_highlighting"));
  751. code_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlight_all_occurrences"));
  752. code_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/caret_blink"));
  753. code_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/caret_blink_speed"));
  754. code_editor->get_text_edit()->set_draw_breakpoint_gutter(EditorSettings::get_singleton()->get("text_editor/show_breakpoint_gutter"));
  755. code_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/block_caret"));
  756. code_editor->get_text_edit()->set_callhint_settings(
  757. EditorSettings::get_singleton()->get("text_editor/put_callhint_tooltip_below_current_line"),
  758. EditorSettings::get_singleton()->get("text_editor/callhint_tooltip_offset"));
  759. edit_hb = memnew (HBoxContainer);
  760. edit_menu = memnew( MenuButton );
  761. edit_menu->set_text(TTR("Edit"));
  762. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
  763. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
  764. edit_menu->get_popup()->add_separator();
  765. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
  766. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
  767. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
  768. edit_menu->get_popup()->add_separator();
  769. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
  770. edit_menu->get_popup()->add_separator();
  771. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
  772. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
  773. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
  774. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
  775. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
  776. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
  777. edit_menu->get_popup()->add_separator();
  778. #ifdef OSX_ENABLED
  779. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE);
  780. #else
  781. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE);
  782. #endif
  783. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE);
  784. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/auto_indent"), EDIT_AUTO_INDENT);
  785. edit_menu->get_popup()->connect("item_pressed", this,"_edit_option");
  786. edit_menu->get_popup()->add_separator();
  787. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_breakpoint"), DEBUG_TOGGLE_BREAKPOINT);
  788. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_breakpoints"), DEBUG_REMOVE_ALL_BREAKPOINTS);
  789. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_breakpoint"), DEBUG_GOTO_NEXT_BREAKPOINT);
  790. edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_breakpoint"), DEBUG_GOTO_PREV_BREAKPOINT);
  791. search_menu = memnew( MenuButton );
  792. edit_hb->add_child(search_menu);
  793. search_menu->set_text(TTR("Search"));
  794. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND);
  795. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT);
  796. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV);
  797. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE);
  798. search_menu->get_popup()->add_separator();
  799. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_function"), SEARCH_LOCATE_FUNCTION);
  800. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE);
  801. search_menu->get_popup()->add_separator();
  802. search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/contextual_help"), HELP_CONTEXTUAL);
  803. search_menu->get_popup()->connect("item_pressed", this,"_edit_option");
  804. edit_hb->add_child(edit_menu);
  805. quick_open = memnew( ScriptEditorQuickOpen );
  806. add_child(quick_open);
  807. quick_open->connect("goto_line",this,"_goto_line");
  808. goto_line_dialog = memnew(GotoLineDialog);
  809. add_child(goto_line_dialog);
  810. }
  811. static ScriptEditorBase * create_editor(const Ref<Script>& p_script) {
  812. if (p_script->has_source_code()) {
  813. return memnew( ScriptTextEditor );
  814. }
  815. return NULL;
  816. }
  817. void ScriptTextEditor::register_editor() {
  818. ED_SHORTCUT("script_text_editor/undo", TTR("Undo"), KEY_MASK_CMD|KEY_Z);
  819. ED_SHORTCUT("script_text_editor/redo", TTR("Redo"), KEY_MASK_CMD|KEY_Y);
  820. ED_SHORTCUT("script_text_editor/cut", TTR("Cut"), KEY_MASK_CMD|KEY_X);
  821. ED_SHORTCUT("script_text_editor/copy", TTR("Copy"), KEY_MASK_CMD|KEY_C);
  822. ED_SHORTCUT("script_text_editor/paste", TTR("Paste"), KEY_MASK_CMD|KEY_V);
  823. ED_SHORTCUT("script_text_editor/select_all", TTR("Select All"), KEY_MASK_CMD|KEY_A);
  824. ED_SHORTCUT("script_text_editor/move_up", TTR("Move Up"), KEY_MASK_ALT|KEY_UP);
  825. ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KEY_MASK_ALT|KEY_DOWN);
  826. ED_SHORTCUT("script_text_editor/indent_left", TTR("Indent Left"), KEY_MASK_ALT|KEY_LEFT);
  827. ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), KEY_MASK_ALT|KEY_RIGHT);
  828. ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KEY_MASK_CMD|KEY_K);
  829. ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD|KEY_B);
  830. #ifdef OSX_ENABLED
  831. ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CTRL|KEY_SPACE);
  832. #else
  833. ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD|KEY_SPACE);
  834. #endif
  835. ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CTRL|KEY_MASK_ALT|KEY_T);
  836. ED_SHORTCUT("script_text_editor/auto_indent", TTR("Auto Indent"), KEY_MASK_CMD|KEY_I);
  837. ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9);
  838. ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CTRL|KEY_MASK_SHIFT|KEY_F9);
  839. ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Goto Next Breakpoint"), KEY_MASK_CTRL|KEY_PERIOD);
  840. ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Goto Previous Breakpoint"), KEY_MASK_CTRL|KEY_COMMA);
  841. ED_SHORTCUT("script_text_editor/find", TTR("Find.."), KEY_MASK_CMD|KEY_F);
  842. ED_SHORTCUT("script_text_editor/find_next", TTR("Find Next"), KEY_F3);
  843. ED_SHORTCUT("script_text_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT|KEY_F3);
  844. ED_SHORTCUT("script_text_editor/replace", TTR("Replace.."), KEY_MASK_CMD|KEY_R);
  845. ED_SHORTCUT("script_text_editor/goto_function", TTR("Goto Function.."), KEY_MASK_SHIFT|KEY_MASK_CMD|KEY_F);
  846. ED_SHORTCUT("script_text_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD|KEY_L);
  847. ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_SHIFT|KEY_F1);
  848. ScriptEditor::register_create_script_editor_function(create_editor);
  849. }