code_editor.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  1. /*************************************************************************/
  2. /* code_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 "code_editor.h"
  31. #include "editor/editor_scale.h"
  32. #include "editor_node.h"
  33. #include "editor_settings.h"
  34. #include "os/keyboard.h"
  35. #include "scene/gui/margin_container.h"
  36. #include "scene/gui/separator.h"
  37. #include "scene/resources/dynamic_font.h"
  38. void GotoLineDialog::popup_find_line(TextEdit *p_edit) {
  39. text_editor = p_edit;
  40. line->set_text(itos(text_editor->cursor_get_line()));
  41. line->select_all();
  42. popup_centered(Size2(180, 80));
  43. line->grab_focus();
  44. }
  45. int GotoLineDialog::get_line() const {
  46. return line->get_text().to_int();
  47. }
  48. void GotoLineDialog::ok_pressed() {
  49. if (get_line() < 1 || get_line() > text_editor->get_line_count())
  50. return;
  51. text_editor->cursor_set_line(get_line() - 1);
  52. hide();
  53. }
  54. GotoLineDialog::GotoLineDialog() {
  55. set_title(TTR("Go to Line"));
  56. Label *l = memnew(Label);
  57. l->set_text(TTR("Line Number:"));
  58. l->set_position(Point2(5, 5));
  59. add_child(l);
  60. line = memnew(LineEdit);
  61. line->set_anchor(MARGIN_RIGHT, ANCHOR_END);
  62. line->set_begin(Point2(15, 22));
  63. line->set_end(Point2(-15, 35));
  64. add_child(line);
  65. register_text_enter(line);
  66. text_editor = NULL;
  67. set_hide_on_ok(false);
  68. }
  69. void FindReplaceBar::_notification(int p_what) {
  70. if (p_what == NOTIFICATION_READY) {
  71. find_prev->set_icon(get_icon("MoveUp", "EditorIcons"));
  72. find_next->set_icon(get_icon("MoveDown", "EditorIcons"));
  73. hide_button->set_normal_texture(get_icon("Close", "EditorIcons"));
  74. hide_button->set_hover_texture(get_icon("CloseHover", "EditorIcons"));
  75. hide_button->set_pressed_texture(get_icon("Close", "EditorIcons"));
  76. } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
  77. set_process_unhandled_input(is_visible_in_tree());
  78. } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
  79. find_prev->set_icon(get_icon("MoveUp", "EditorIcons"));
  80. find_next->set_icon(get_icon("MoveDown", "EditorIcons"));
  81. hide_button->set_normal_texture(get_icon("Close", "EditorIcons"));
  82. hide_button->set_hover_texture(get_icon("CloseHover", "EditorIcons"));
  83. hide_button->set_pressed_texture(get_icon("Close", "EditorIcons"));
  84. }
  85. }
  86. void FindReplaceBar::_unhandled_input(const Ref<InputEvent> &p_event) {
  87. Ref<InputEventKey> k = p_event;
  88. if (k.is_valid()) {
  89. if (k->is_pressed() && (text_edit->has_focus() || text_vbc->is_a_parent_of(get_focus_owner()))) {
  90. bool accepted = true;
  91. switch (k->get_scancode()) {
  92. case KEY_ESCAPE: {
  93. _hide_bar();
  94. } break;
  95. default: {
  96. accepted = false;
  97. } break;
  98. }
  99. if (accepted) {
  100. accept_event();
  101. }
  102. }
  103. }
  104. }
  105. bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) {
  106. int line, col;
  107. String text = get_search_text();
  108. bool found = text_edit->search(text, p_flags, p_from_line, p_from_col, line, col);
  109. if (found) {
  110. if (!preserve_cursor) {
  111. text_edit->cursor_set_line(line, false);
  112. text_edit->cursor_set_column(col + text.length(), false);
  113. text_edit->center_viewport_to_cursor();
  114. }
  115. text_edit->set_search_text(text);
  116. text_edit->set_search_flags(p_flags);
  117. text_edit->set_current_search_result(line, col);
  118. result_line = line;
  119. result_col = col;
  120. set_error("");
  121. } else {
  122. result_line = -1;
  123. result_col = -1;
  124. text_edit->set_search_text("");
  125. set_error(text.empty() ? "" : TTR("No Matches"));
  126. }
  127. return found;
  128. }
  129. void FindReplaceBar::_replace() {
  130. if (result_line != -1 && result_col != -1) {
  131. text_edit->begin_complex_operation();
  132. text_edit->select(result_line, result_col, result_line, result_col + get_search_text().length());
  133. text_edit->insert_text_at_cursor(get_replace_text());
  134. text_edit->end_complex_operation();
  135. }
  136. search_current();
  137. }
  138. void FindReplaceBar::_replace_all() {
  139. // line as x so it gets priority in comparison, column as y
  140. Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column());
  141. Point2i prev_match = Point2(-1, -1);
  142. bool selection_enabled = text_edit->is_selection_active();
  143. Point2i selection_begin, selection_end;
  144. if (selection_enabled) {
  145. selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column());
  146. selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column());
  147. }
  148. int vsval = text_edit->get_v_scroll();
  149. text_edit->cursor_set_line(0);
  150. text_edit->cursor_set_column(0);
  151. String replace_text = get_replace_text();
  152. int search_text_len = get_search_text().length();
  153. int rc = 0;
  154. replace_all_mode = true;
  155. text_edit->begin_complex_operation();
  156. while (search_next()) {
  157. // replace area
  158. Point2i match_from(result_line, result_col);
  159. Point2i match_to(result_line, result_col + search_text_len);
  160. if (match_from < prev_match)
  161. break; // done
  162. prev_match = Point2i(result_line, result_col + replace_text.length());
  163. text_edit->select(result_line, result_col, result_line, match_to.y);
  164. if (selection_enabled && is_selection_only()) {
  165. if (match_from < selection_begin || match_to > selection_end)
  166. continue;
  167. // replace but adjust selection bounds
  168. text_edit->insert_text_at_cursor(replace_text);
  169. if (match_to.x == selection_end.x)
  170. selection_end.y += replace_text.length() - search_text_len;
  171. } else {
  172. // just replace
  173. text_edit->insert_text_at_cursor(replace_text);
  174. }
  175. rc++;
  176. }
  177. text_edit->end_complex_operation();
  178. replace_all_mode = false;
  179. // restore editor state (selection, cursor, scroll)
  180. text_edit->cursor_set_line(orig_cursor.x);
  181. text_edit->cursor_set_column(orig_cursor.y);
  182. if (selection_enabled && is_selection_only()) {
  183. // reselect
  184. text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y);
  185. } else {
  186. text_edit->deselect();
  187. }
  188. text_edit->set_v_scroll(vsval);
  189. set_error(vformat(TTR("Replaced %d occurrence(s)."), rc));
  190. }
  191. void FindReplaceBar::_get_search_from(int &r_line, int &r_col) {
  192. r_line = text_edit->cursor_get_line();
  193. r_col = text_edit->cursor_get_column();
  194. if (text_edit->is_selection_active() && !replace_all_mode) {
  195. int selection_line = text_edit->get_selection_from_line();
  196. if (text_edit->get_selection_text() == get_search_text() && r_line == selection_line) {
  197. int selection_from_col = text_edit->get_selection_from_column();
  198. if (r_col >= selection_from_col && r_col <= text_edit->get_selection_to_column()) {
  199. r_col = selection_from_col;
  200. }
  201. }
  202. }
  203. if (r_line == result_line && r_col >= result_col && r_col <= result_col + get_search_text().length()) {
  204. r_col = result_col;
  205. }
  206. }
  207. bool FindReplaceBar::search_current() {
  208. uint32_t flags = 0;
  209. if (is_whole_words())
  210. flags |= TextEdit::SEARCH_WHOLE_WORDS;
  211. if (is_case_sensitive())
  212. flags |= TextEdit::SEARCH_MATCH_CASE;
  213. int line, col;
  214. _get_search_from(line, col);
  215. return _search(flags, line, col);
  216. }
  217. bool FindReplaceBar::search_prev() {
  218. uint32_t flags = 0;
  219. String text = get_search_text();
  220. if (is_whole_words())
  221. flags |= TextEdit::SEARCH_WHOLE_WORDS;
  222. if (is_case_sensitive())
  223. flags |= TextEdit::SEARCH_MATCH_CASE;
  224. flags |= TextEdit::SEARCH_BACKWARDS;
  225. int line, col;
  226. _get_search_from(line, col);
  227. col -= text.length();
  228. if (col < 0) {
  229. line -= 1;
  230. if (line < 0)
  231. line = text_edit->get_line_count() - 1;
  232. col = text_edit->get_line(line).length();
  233. }
  234. return _search(flags, line, col);
  235. }
  236. bool FindReplaceBar::search_next() {
  237. uint32_t flags = 0;
  238. String text = get_search_text();
  239. if (is_whole_words())
  240. flags |= TextEdit::SEARCH_WHOLE_WORDS;
  241. if (is_case_sensitive())
  242. flags |= TextEdit::SEARCH_MATCH_CASE;
  243. int line, col;
  244. _get_search_from(line, col);
  245. if (line == result_line && col == result_col) {
  246. col += text.length();
  247. if (col > text_edit->get_line(line).length()) {
  248. line += 1;
  249. if (line >= text_edit->get_line_count())
  250. line = 0;
  251. col = 0;
  252. }
  253. }
  254. return _search(flags, line, col);
  255. }
  256. void FindReplaceBar::_hide_bar() {
  257. if (replace_text->has_focus() || search_text->has_focus())
  258. text_edit->grab_focus();
  259. text_edit->set_search_text("");
  260. result_line = -1;
  261. result_col = -1;
  262. replace_hbc->hide();
  263. replace_options_hbc->hide();
  264. hide();
  265. }
  266. void FindReplaceBar::_show_search() {
  267. show();
  268. search_text->grab_focus();
  269. if (text_edit->is_selection_active() && !selection_only->is_pressed()) {
  270. search_text->set_text(text_edit->get_selection_text());
  271. }
  272. if (!get_search_text().empty()) {
  273. search_text->select_all();
  274. search_text->set_cursor_position(search_text->get_text().length());
  275. search_current();
  276. }
  277. }
  278. void FindReplaceBar::popup_search() {
  279. replace_hbc->hide();
  280. replace_options_hbc->hide();
  281. _show_search();
  282. }
  283. void FindReplaceBar::popup_replace() {
  284. if (!replace_hbc->is_visible_in_tree() || !replace_options_hbc->is_visible_in_tree()) {
  285. replace_text->clear();
  286. replace_hbc->show();
  287. replace_options_hbc->show();
  288. }
  289. selection_only->set_pressed((text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line()));
  290. _show_search();
  291. }
  292. void FindReplaceBar::_search_options_changed(bool p_pressed) {
  293. search_current();
  294. }
  295. void FindReplaceBar::_editor_text_changed() {
  296. if (is_visible_in_tree()) {
  297. preserve_cursor = true;
  298. search_current();
  299. preserve_cursor = false;
  300. }
  301. }
  302. void FindReplaceBar::_search_text_changed(const String &p_text) {
  303. search_current();
  304. }
  305. void FindReplaceBar::_search_text_entered(const String &p_text) {
  306. search_next();
  307. }
  308. void FindReplaceBar::_replace_text_entered(const String &p_text) {
  309. if (selection_only->is_pressed() && text_edit->is_selection_active()) {
  310. _replace_all();
  311. _hide_bar();
  312. }
  313. }
  314. String FindReplaceBar::get_search_text() const {
  315. return search_text->get_text();
  316. }
  317. String FindReplaceBar::get_replace_text() const {
  318. return replace_text->get_text();
  319. }
  320. bool FindReplaceBar::is_case_sensitive() const {
  321. return case_sensitive->is_pressed();
  322. }
  323. bool FindReplaceBar::is_whole_words() const {
  324. return whole_words->is_pressed();
  325. }
  326. bool FindReplaceBar::is_selection_only() const {
  327. return selection_only->is_pressed();
  328. }
  329. void FindReplaceBar::set_error(const String &p_label) {
  330. error_label->set_text(p_label);
  331. }
  332. void FindReplaceBar::set_text_edit(TextEdit *p_text_edit) {
  333. text_edit = p_text_edit;
  334. text_edit->connect("text_changed", this, "_editor_text_changed");
  335. }
  336. void FindReplaceBar::_bind_methods() {
  337. ClassDB::bind_method("_unhandled_input", &FindReplaceBar::_unhandled_input);
  338. ClassDB::bind_method("_editor_text_changed", &FindReplaceBar::_editor_text_changed);
  339. ClassDB::bind_method("_search_text_changed", &FindReplaceBar::_search_text_changed);
  340. ClassDB::bind_method("_search_text_entered", &FindReplaceBar::_search_text_entered);
  341. ClassDB::bind_method("_replace_text_entered", &FindReplaceBar::_replace_text_entered);
  342. ClassDB::bind_method("_search_current", &FindReplaceBar::search_current);
  343. ClassDB::bind_method("_search_next", &FindReplaceBar::search_next);
  344. ClassDB::bind_method("_search_prev", &FindReplaceBar::search_prev);
  345. ClassDB::bind_method("_replace_pressed", &FindReplaceBar::_replace);
  346. ClassDB::bind_method("_replace_all_pressed", &FindReplaceBar::_replace_all);
  347. ClassDB::bind_method("_search_options_changed", &FindReplaceBar::_search_options_changed);
  348. ClassDB::bind_method("_hide_pressed", &FindReplaceBar::_hide_bar);
  349. ADD_SIGNAL(MethodInfo("search"));
  350. }
  351. FindReplaceBar::FindReplaceBar() {
  352. replace_all_mode = false;
  353. preserve_cursor = false;
  354. text_vbc = memnew(VBoxContainer);
  355. add_child(text_vbc);
  356. HBoxContainer *search_hbc = memnew(HBoxContainer);
  357. text_vbc->add_child(search_hbc);
  358. search_text = memnew(LineEdit);
  359. search_hbc->add_child(search_text);
  360. search_text->set_custom_minimum_size(Size2(200, 0));
  361. search_text->connect("text_changed", this, "_search_text_changed");
  362. search_text->connect("text_entered", this, "_search_text_entered");
  363. find_prev = memnew(ToolButton);
  364. search_hbc->add_child(find_prev);
  365. find_prev->set_focus_mode(FOCUS_NONE);
  366. find_prev->connect("pressed", this, "_search_prev");
  367. find_next = memnew(ToolButton);
  368. search_hbc->add_child(find_next);
  369. find_next->set_focus_mode(FOCUS_NONE);
  370. find_next->connect("pressed", this, "_search_next");
  371. replace_hbc = memnew(HBoxContainer);
  372. text_vbc->add_child(replace_hbc);
  373. replace_hbc->hide();
  374. replace_text = memnew(LineEdit);
  375. replace_hbc->add_child(replace_text);
  376. replace_text->set_custom_minimum_size(Size2(200, 0));
  377. replace_text->connect("text_entered", this, "_replace_text_entered");
  378. replace = memnew(Button);
  379. replace_hbc->add_child(replace);
  380. replace->set_text(TTR("Replace"));
  381. //replace->set_focus_mode(FOCUS_NONE);
  382. replace->connect("pressed", this, "_replace_pressed");
  383. replace_all = memnew(Button);
  384. replace_hbc->add_child(replace_all);
  385. replace_all->set_text(TTR("Replace All"));
  386. //replace_all->set_focus_mode(FOCUS_NONE);
  387. replace_all->connect("pressed", this, "_replace_all_pressed");
  388. Control *spacer_split = memnew(Control);
  389. spacer_split->set_custom_minimum_size(Size2(0, 1));
  390. text_vbc->add_child(spacer_split);
  391. VBoxContainer *options_vbc = memnew(VBoxContainer);
  392. add_child(options_vbc);
  393. options_vbc->set_h_size_flags(SIZE_EXPAND_FILL);
  394. HBoxContainer *search_options = memnew(HBoxContainer);
  395. options_vbc->add_child(search_options);
  396. case_sensitive = memnew(CheckBox);
  397. search_options->add_child(case_sensitive);
  398. case_sensitive->set_text(TTR("Match Case"));
  399. case_sensitive->set_focus_mode(FOCUS_NONE);
  400. case_sensitive->connect("toggled", this, "_search_options_changed");
  401. whole_words = memnew(CheckBox);
  402. search_options->add_child(whole_words);
  403. whole_words->set_text(TTR("Whole Words"));
  404. whole_words->set_focus_mode(FOCUS_NONE);
  405. whole_words->connect("toggled", this, "_search_options_changed");
  406. error_label = memnew(Label);
  407. search_options->add_child(error_label);
  408. error_label->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
  409. search_options->add_spacer();
  410. hide_button = memnew(TextureButton);
  411. search_options->add_child(hide_button);
  412. hide_button->set_focus_mode(FOCUS_NONE);
  413. hide_button->connect("pressed", this, "_hide_pressed");
  414. replace_options_hbc = memnew(HBoxContainer);
  415. options_vbc->add_child(replace_options_hbc);
  416. replace_options_hbc->hide();
  417. selection_only = memnew(CheckBox);
  418. replace_options_hbc->add_child(selection_only);
  419. selection_only->set_text(TTR("Selection Only"));
  420. selection_only->set_focus_mode(FOCUS_NONE);
  421. selection_only->connect("toggled", this, "_search_options_changed");
  422. }
  423. void FindReplaceDialog::popup_search() {
  424. set_title(TTR("Search"));
  425. replace_mc->hide();
  426. replace_label->hide();
  427. replace_vb->hide();
  428. skip->hide();
  429. popup_centered(Point2(300, 190));
  430. get_ok()->set_text(TTR("Find"));
  431. search_text->grab_focus();
  432. if (text_edit->is_selection_active() && (text_edit->get_selection_from_line() == text_edit->get_selection_to_line())) {
  433. search_text->set_text(text_edit->get_selection_text());
  434. }
  435. search_text->select_all();
  436. error_label->set_text("");
  437. }
  438. void FindReplaceDialog::popup_replace() {
  439. set_title(TTR("Replace"));
  440. bool do_selection = (text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line());
  441. set_replace_selection_only(do_selection);
  442. if (!do_selection && text_edit->is_selection_active()) {
  443. search_text->set_text(text_edit->get_selection_text());
  444. }
  445. replace_mc->show();
  446. replace_label->show();
  447. replace_vb->show();
  448. popup_centered(Point2(300, 300));
  449. if (search_text->get_text() != "" && replace_text->get_text() == "") {
  450. search_text->select(0, 0);
  451. replace_text->grab_focus();
  452. } else {
  453. search_text->grab_focus();
  454. search_text->select_all();
  455. }
  456. error_label->set_text("");
  457. if (prompt->is_pressed()) {
  458. skip->show();
  459. get_ok()->set_text(TTR("Next"));
  460. selection_only->set_disabled(true);
  461. } else {
  462. skip->hide();
  463. get_ok()->set_text(TTR("Replace"));
  464. selection_only->set_disabled(false);
  465. }
  466. }
  467. void FindReplaceDialog::_search_callback() {
  468. if (is_replace_mode())
  469. _replace();
  470. else
  471. _search();
  472. }
  473. void FindReplaceDialog::_replace_skip_callback() {
  474. _search();
  475. }
  476. void FindReplaceDialog::_replace() {
  477. text_edit->begin_complex_operation();
  478. if (is_replace_all_mode()) {
  479. //line as x so it gets priority in comparison, column as y
  480. Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column());
  481. Point2i prev_match = Point2(-1, -1);
  482. bool selection_enabled = text_edit->is_selection_active();
  483. Point2i selection_begin, selection_end;
  484. if (selection_enabled) {
  485. selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column());
  486. selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column());
  487. }
  488. int vsval = text_edit->get_v_scroll();
  489. //int hsval = text_edit->get_h_scroll();
  490. text_edit->cursor_set_line(0);
  491. text_edit->cursor_set_column(0);
  492. int rc = 0;
  493. while (_search()) {
  494. if (!text_edit->is_selection_active()) {
  495. //search selects
  496. break;
  497. }
  498. //replace area
  499. Point2i match_from(text_edit->get_selection_from_line(), text_edit->get_selection_from_column());
  500. Point2i match_to(text_edit->get_selection_to_line(), text_edit->get_selection_to_column());
  501. if (match_from < prev_match)
  502. break; //done
  503. prev_match = match_to;
  504. if (selection_enabled && is_replace_selection_only()) {
  505. if (match_from < selection_begin || match_to > selection_end)
  506. continue;
  507. //replace but adjust selection bounds
  508. text_edit->insert_text_at_cursor(get_replace_text());
  509. if (match_to.x == selection_end.x)
  510. selection_end.y += get_replace_text().length() - get_search_text().length();
  511. } else {
  512. //just replace
  513. text_edit->insert_text_at_cursor(get_replace_text());
  514. }
  515. rc++;
  516. }
  517. //restore editor state (selection, cursor, scroll)
  518. text_edit->cursor_set_line(orig_cursor.x);
  519. text_edit->cursor_set_column(orig_cursor.y);
  520. if (selection_enabled && is_replace_selection_only()) {
  521. //reselect
  522. text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y);
  523. } else {
  524. text_edit->deselect();
  525. }
  526. text_edit->set_v_scroll(vsval);
  527. //text_edit->set_h_scroll(hsval);
  528. error_label->set_text(vformat(TTR("Replaced %d occurrence(s)."), rc));
  529. //hide();
  530. } else {
  531. if (text_edit->get_selection_text() == get_search_text()) {
  532. text_edit->insert_text_at_cursor(get_replace_text());
  533. }
  534. _search();
  535. }
  536. text_edit->end_complex_operation();
  537. }
  538. bool FindReplaceDialog::_search() {
  539. String text = get_search_text();
  540. uint32_t flags = 0;
  541. if (is_whole_words())
  542. flags |= TextEdit::SEARCH_WHOLE_WORDS;
  543. if (is_case_sensitive())
  544. flags |= TextEdit::SEARCH_MATCH_CASE;
  545. if (is_backwards())
  546. flags |= TextEdit::SEARCH_BACKWARDS;
  547. int line = text_edit->cursor_get_line(), col = text_edit->cursor_get_column();
  548. if (is_backwards()) {
  549. col -= 1;
  550. if (col < 0) {
  551. line -= 1;
  552. if (line < 0) {
  553. line = text_edit->get_line_count() - 1;
  554. }
  555. col = text_edit->get_line(line).length();
  556. }
  557. }
  558. bool found = text_edit->search(text, flags, line, col, line, col);
  559. if (found) {
  560. // print_line("found");
  561. text_edit->cursor_set_line(line);
  562. if (is_backwards())
  563. text_edit->cursor_set_column(col);
  564. else
  565. text_edit->cursor_set_column(col + text.length());
  566. text_edit->select(line, col, line, col + text.length());
  567. set_error("");
  568. return true;
  569. } else {
  570. set_error(TTR("Not found!"));
  571. return false;
  572. }
  573. }
  574. void FindReplaceDialog::_prompt_changed() {
  575. if (prompt->is_pressed()) {
  576. skip->show();
  577. get_ok()->set_text(TTR("Next"));
  578. selection_only->set_disabled(true);
  579. } else {
  580. skip->hide();
  581. get_ok()->set_text(TTR("Replace"));
  582. selection_only->set_disabled(false);
  583. }
  584. }
  585. void FindReplaceDialog::_skip_pressed() {
  586. _replace_skip_callback();
  587. }
  588. bool FindReplaceDialog::is_replace_mode() const {
  589. return replace_text->is_visible_in_tree();
  590. }
  591. bool FindReplaceDialog::is_replace_all_mode() const {
  592. return !prompt->is_pressed();
  593. }
  594. bool FindReplaceDialog::is_replace_selection_only() const {
  595. return selection_only->is_pressed();
  596. }
  597. void FindReplaceDialog::set_replace_selection_only(bool p_enable) {
  598. selection_only->set_pressed(p_enable);
  599. }
  600. void FindReplaceDialog::ok_pressed() {
  601. _search_callback();
  602. }
  603. void FindReplaceDialog::_search_text_entered(const String &p_text) {
  604. if (replace_text->is_visible_in_tree())
  605. return;
  606. emit_signal("search");
  607. _search();
  608. }
  609. void FindReplaceDialog::_replace_text_entered(const String &p_text) {
  610. if (!replace_text->is_visible_in_tree())
  611. return;
  612. emit_signal("search");
  613. _replace();
  614. }
  615. String FindReplaceDialog::get_search_text() const {
  616. return search_text->get_text();
  617. }
  618. String FindReplaceDialog::get_replace_text() const {
  619. return replace_text->get_text();
  620. }
  621. bool FindReplaceDialog::is_whole_words() const {
  622. return whole_words->is_pressed();
  623. }
  624. bool FindReplaceDialog::is_case_sensitive() const {
  625. return case_sensitive->is_pressed();
  626. }
  627. bool FindReplaceDialog::is_backwards() const {
  628. return backwards->is_pressed();
  629. }
  630. void FindReplaceDialog::set_error(const String &p_error) {
  631. error_label->set_text(p_error);
  632. }
  633. void FindReplaceDialog::set_text_edit(TextEdit *p_text_edit) {
  634. text_edit = p_text_edit;
  635. }
  636. void FindReplaceDialog::search_next() {
  637. _search();
  638. }
  639. void FindReplaceDialog::_bind_methods() {
  640. ClassDB::bind_method("_search_text_entered", &FindReplaceDialog::_search_text_entered);
  641. ClassDB::bind_method("_replace_text_entered", &FindReplaceDialog::_replace_text_entered);
  642. ClassDB::bind_method("_prompt_changed", &FindReplaceDialog::_prompt_changed);
  643. ClassDB::bind_method("_skip_pressed", &FindReplaceDialog::_skip_pressed);
  644. ADD_SIGNAL(MethodInfo("search"));
  645. ADD_SIGNAL(MethodInfo("skip"));
  646. }
  647. FindReplaceDialog::FindReplaceDialog() {
  648. set_self_modulate(Color(1, 1, 1, 0.8));
  649. VBoxContainer *vb = memnew(VBoxContainer);
  650. add_child(vb);
  651. search_text = memnew(LineEdit);
  652. vb->add_margin_child(TTR("Search"), search_text);
  653. search_text->connect("text_entered", this, "_search_text_entered");
  654. replace_label = memnew(Label);
  655. replace_label->set_text(TTR("Replace By"));
  656. vb->add_child(replace_label);
  657. replace_mc = memnew(MarginContainer);
  658. vb->add_child(replace_mc);
  659. replace_text = memnew(LineEdit);
  660. replace_text->set_anchor(MARGIN_RIGHT, ANCHOR_END);
  661. replace_text->set_begin(Point2(15, 132));
  662. replace_text->set_end(Point2(-15, 135));
  663. replace_mc->add_child(replace_text);
  664. replace_text->connect("text_entered", this, "_replace_text_entered");
  665. MarginContainer *opt_mg = memnew(MarginContainer);
  666. vb->add_child(opt_mg);
  667. VBoxContainer *svb = memnew(VBoxContainer);
  668. opt_mg->add_child(svb);
  669. svb->add_child(memnew(Label));
  670. whole_words = memnew(CheckButton);
  671. whole_words->set_text(TTR("Whole Words"));
  672. svb->add_child(whole_words);
  673. case_sensitive = memnew(CheckButton);
  674. case_sensitive->set_text(TTR("Case Sensitive"));
  675. svb->add_child(case_sensitive);
  676. backwards = memnew(CheckButton);
  677. backwards->set_text(TTR("Backwards"));
  678. svb->add_child(backwards);
  679. opt_mg = memnew(MarginContainer);
  680. vb->add_child(opt_mg);
  681. VBoxContainer *rvb = memnew(VBoxContainer);
  682. opt_mg->add_child(rvb);
  683. replace_vb = rvb;
  684. //rvb ->add_child(memnew(HSeparator));
  685. rvb->add_child(memnew(Label));
  686. prompt = memnew(CheckButton);
  687. prompt->set_text(TTR("Prompt On Replace"));
  688. rvb->add_child(prompt);
  689. prompt->connect("pressed", this, "_prompt_changed");
  690. selection_only = memnew(CheckButton);
  691. selection_only->set_text(TTR("Selection Only"));
  692. rvb->add_child(selection_only);
  693. int margin = get_constant("margin", "Dialogs");
  694. int button_margin = get_constant("button_margin", "Dialogs");
  695. skip = memnew(Button);
  696. skip->set_anchor(MARGIN_LEFT, ANCHOR_END);
  697. skip->set_anchor(MARGIN_TOP, ANCHOR_END);
  698. skip->set_anchor(MARGIN_RIGHT, ANCHOR_END);
  699. skip->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
  700. skip->set_begin(Point2(-70, -button_margin));
  701. skip->set_end(Point2(-10, -margin));
  702. skip->set_text(TTR("Skip"));
  703. add_child(skip);
  704. skip->connect("pressed", this, "_skip_pressed");
  705. error_label = memnew(Label);
  706. error_label->set_align(Label::ALIGN_CENTER);
  707. error_label->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
  708. vb->add_child(error_label);
  709. set_hide_on_ok(false);
  710. }
  711. /*** CODE EDITOR ****/
  712. void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) {
  713. Ref<InputEventMouseButton> mb = p_event;
  714. if (mb.is_valid()) {
  715. if (mb->is_pressed() && mb->get_command()) {
  716. if (mb->get_button_index() == BUTTON_WHEEL_UP) {
  717. _zoom_in();
  718. } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN) {
  719. _zoom_out();
  720. }
  721. }
  722. }
  723. Ref<InputEventKey> k = p_event;
  724. if (k.is_valid()) {
  725. if (k->is_pressed()) {
  726. if (ED_IS_SHORTCUT("script_editor/zoom_in", p_event)) {
  727. _zoom_in();
  728. }
  729. if (ED_IS_SHORTCUT("script_editor/zoom_out", p_event)) {
  730. _zoom_out();
  731. }
  732. if (ED_IS_SHORTCUT("script_editor/reset_zoom", p_event)) {
  733. _reset_zoom();
  734. }
  735. }
  736. }
  737. }
  738. void CodeTextEditor::_zoom_in() {
  739. font_resize_val += EDSCALE;
  740. if (font_resize_timer->get_time_left() == 0)
  741. font_resize_timer->start();
  742. }
  743. void CodeTextEditor::_zoom_out() {
  744. font_resize_val -= EDSCALE;
  745. if (font_resize_timer->get_time_left() == 0)
  746. font_resize_timer->start();
  747. }
  748. void CodeTextEditor::_reset_zoom() {
  749. Ref<DynamicFont> font = text_editor->get_font("font"); // reset source font size to default
  750. if (font.is_valid()) {
  751. EditorSettings::get_singleton()->set("interface/source_font_size", 14);
  752. font->set_size(14);
  753. }
  754. }
  755. void CodeTextEditor::_line_col_changed() {
  756. line_nb->set_text(itos(text_editor->cursor_get_line() + 1));
  757. col_nb->set_text(itos(text_editor->cursor_get_column() + 1));
  758. }
  759. void CodeTextEditor::_text_changed() {
  760. if (text_editor->is_insert_text_operation()) {
  761. code_complete_timer->start();
  762. idle->start();
  763. }
  764. }
  765. void CodeTextEditor::_code_complete_timer_timeout() {
  766. if (!is_visible_in_tree())
  767. return;
  768. if (enable_complete_timer)
  769. text_editor->query_code_comple();
  770. }
  771. void CodeTextEditor::_complete_request() {
  772. List<String> entries;
  773. String ctext = text_editor->get_text_for_completion();
  774. _code_complete_script(ctext, &entries);
  775. bool forced = false;
  776. if (code_complete_func) {
  777. code_complete_func(code_complete_ud, ctext, &entries, forced);
  778. }
  779. // print_line("COMPLETE: "+p_request);
  780. if (entries.size() == 0)
  781. return;
  782. Vector<String> strs;
  783. strs.resize(entries.size());
  784. int i = 0;
  785. for (List<String>::Element *E = entries.front(); E; E = E->next()) {
  786. strs[i++] = E->get();
  787. }
  788. text_editor->code_complete(strs, forced);
  789. }
  790. void CodeTextEditor::_font_resize_timeout() {
  791. Ref<DynamicFont> font = text_editor->get_font("font");
  792. if (font.is_valid()) {
  793. int new_size = CLAMP(font->get_size() + font_resize_val, 8 * EDSCALE, 96 * EDSCALE);
  794. if (new_size != font->get_size()) {
  795. EditorSettings::get_singleton()->set("interface/source_font_size", new_size / EDSCALE);
  796. font->set_size(new_size);
  797. }
  798. font_resize_val = 0;
  799. }
  800. }
  801. void CodeTextEditor::update_editor_settings() {
  802. text_editor->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete"));
  803. text_editor->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file"));
  804. text_editor->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type"));
  805. text_editor->set_indent_size(EditorSettings::get_singleton()->get("text_editor/indent/size"));
  806. text_editor->set_auto_indent(EditorSettings::get_singleton()->get("text_editor/indent/auto_indent"));
  807. text_editor->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs"));
  808. text_editor->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers"));
  809. text_editor->set_line_numbers_zero_padded(EditorSettings::get_singleton()->get("text_editor/line_numbers/line_numbers_zero_padded"));
  810. text_editor->set_show_line_length_guideline(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_length_guideline"));
  811. text_editor->set_line_length_guideline_column(EditorSettings::get_singleton()->get("text_editor/line_numbers/line_length_guideline_column"));
  812. text_editor->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting"));
  813. text_editor->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences"));
  814. text_editor->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink"));
  815. text_editor->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed"));
  816. text_editor->set_draw_breakpoint_gutter(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_breakpoint_gutter"));
  817. text_editor->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret"));
  818. text_editor->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/open_scripts/smooth_scrolling"));
  819. text_editor->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/open_scripts/v_scroll_speed"));
  820. }
  821. void CodeTextEditor::set_error(const String &p_error) {
  822. error->set_text(p_error);
  823. }
  824. void CodeTextEditor::_update_font() {
  825. // FONTS
  826. String editor_font = EDITOR_DEF("text_editor/theme/font", "");
  827. bool font_overridden = false;
  828. if (editor_font != "") {
  829. Ref<Font> fnt = ResourceLoader::load(editor_font);
  830. if (fnt.is_valid()) {
  831. text_editor->add_font_override("font", fnt);
  832. font_overridden = true;
  833. }
  834. }
  835. if (!font_overridden) {
  836. text_editor->add_font_override("font", get_font("source", "EditorFonts"));
  837. }
  838. }
  839. void CodeTextEditor::_on_settings_change() {
  840. _update_font();
  841. // AUTO BRACE COMPLETION
  842. text_editor->set_auto_brace_completion(
  843. EDITOR_DEF("text_editor/completion/auto_brace_complete", true));
  844. code_complete_timer->set_wait_time(
  845. EDITOR_DEF("text_editor/completion/code_complete_delay", .3f));
  846. enable_complete_timer = EDITOR_DEF("text_editor/completion/enable_code_completion_delay", true);
  847. // call hint settings
  848. text_editor->set_callhint_settings(
  849. EDITOR_DEF("text_editor/completion/put_callhint_tooltip_below_current_line", true),
  850. EDITOR_DEF("text_editor/completion/callhint_tooltip_offset", Vector2()));
  851. }
  852. void CodeTextEditor::_text_changed_idle_timeout() {
  853. _validate_script();
  854. emit_signal("validate_script");
  855. }
  856. void CodeTextEditor::_notification(int p_what) {
  857. if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
  858. _load_theme_settings();
  859. emit_signal("load_theme_settings");
  860. }
  861. if (p_what == NOTIFICATION_THEME_CHANGED) {
  862. _update_font();
  863. }
  864. }
  865. void CodeTextEditor::_bind_methods() {
  866. ClassDB::bind_method("_text_editor_gui_input", &CodeTextEditor::_text_editor_gui_input);
  867. ClassDB::bind_method("_line_col_changed", &CodeTextEditor::_line_col_changed);
  868. ClassDB::bind_method("_text_changed", &CodeTextEditor::_text_changed);
  869. ClassDB::bind_method("_on_settings_change", &CodeTextEditor::_on_settings_change);
  870. ClassDB::bind_method("_text_changed_idle_timeout", &CodeTextEditor::_text_changed_idle_timeout);
  871. ClassDB::bind_method("_code_complete_timer_timeout", &CodeTextEditor::_code_complete_timer_timeout);
  872. ClassDB::bind_method("_complete_request", &CodeTextEditor::_complete_request);
  873. ClassDB::bind_method("_font_resize_timeout", &CodeTextEditor::_font_resize_timeout);
  874. ADD_SIGNAL(MethodInfo("validate_script"));
  875. ADD_SIGNAL(MethodInfo("load_theme_settings"));
  876. }
  877. void CodeTextEditor::set_code_complete_func(CodeTextEditorCodeCompleteFunc p_code_complete_func, void *p_ud) {
  878. code_complete_func = p_code_complete_func;
  879. code_complete_ud = p_ud;
  880. }
  881. CodeTextEditor::CodeTextEditor() {
  882. code_complete_func = NULL;
  883. ED_SHORTCUT("script_editor/zoom_in", TTR("Zoom In"), KEY_MASK_CMD | KEY_EQUAL);
  884. ED_SHORTCUT("script_editor/zoom_out", TTR("Zoom Out"), KEY_MASK_CMD | KEY_MINUS);
  885. ED_SHORTCUT("script_editor/reset_zoom", TTR("Reset Zoom"), KEY_MASK_CMD | KEY_0);
  886. find_replace_bar = memnew(FindReplaceBar);
  887. add_child(find_replace_bar);
  888. find_replace_bar->set_h_size_flags(SIZE_EXPAND_FILL);
  889. find_replace_bar->hide();
  890. text_editor = memnew(TextEdit);
  891. add_child(text_editor);
  892. text_editor->set_v_size_flags(SIZE_EXPAND_FILL);
  893. find_replace_bar->set_text_edit(text_editor);
  894. text_editor->set_show_line_numbers(true);
  895. text_editor->set_brace_matching(true);
  896. text_editor->set_auto_indent(true);
  897. MarginContainer *status_mc = memnew(MarginContainer);
  898. add_child(status_mc);
  899. status_mc->set("custom_constants/margin_left", 2);
  900. status_mc->set("custom_constants/margin_top", 5);
  901. status_mc->set("custom_constants/margin_right", 2);
  902. status_mc->set("custom_constants/margin_bottom", 1);
  903. HBoxContainer *status_bar = memnew(HBoxContainer);
  904. status_mc->add_child(status_bar);
  905. status_bar->set_h_size_flags(SIZE_EXPAND_FILL);
  906. status_bar->add_child(memnew(Label)); //to keep the height if the other labels are not visible
  907. idle = memnew(Timer);
  908. add_child(idle);
  909. idle->set_one_shot(true);
  910. idle->set_wait_time(EDITOR_DEF("text_editor/completion/idle_parse_delay", 2));
  911. code_complete_timer = memnew(Timer);
  912. add_child(code_complete_timer);
  913. code_complete_timer->set_one_shot(true);
  914. enable_complete_timer = EDITOR_DEF("text_editor/completion/enable_code_completion_delay", true);
  915. code_complete_timer->set_wait_time(EDITOR_DEF("text_editor/completion/code_complete_delay", .3f));
  916. error = memnew(Label);
  917. status_bar->add_child(error);
  918. error->set_clip_text(true); //do not change, or else very long errors can push the whole container to the right
  919. error->set_valign(Label::VALIGN_CENTER);
  920. error->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
  921. error->set_h_size_flags(SIZE_EXPAND_FILL); //required for it to display, given now it's clipping contents, do not touch
  922. Label *line_txt = memnew(Label);
  923. status_bar->add_child(line_txt);
  924. line_txt->set_align(Label::ALIGN_RIGHT);
  925. line_txt->set_valign(Label::VALIGN_CENTER);
  926. line_txt->set_v_size_flags(SIZE_FILL);
  927. line_txt->set_text(TTR("Line:"));
  928. line_nb = memnew(Label);
  929. status_bar->add_child(line_nb);
  930. line_nb->set_valign(Label::VALIGN_CENTER);
  931. line_nb->set_v_size_flags(SIZE_FILL);
  932. line_nb->set_autowrap(true); // workaround to prevent resizing the label on each change, do not touch
  933. line_nb->set_clip_text(true); // workaround to prevent resizing the label on each change, do not touch
  934. line_nb->set_custom_minimum_size(Size2(40, 1) * EDSCALE);
  935. Label *col_txt = memnew(Label);
  936. status_bar->add_child(col_txt);
  937. col_txt->set_align(Label::ALIGN_RIGHT);
  938. col_txt->set_valign(Label::VALIGN_CENTER);
  939. col_txt->set_v_size_flags(SIZE_FILL);
  940. col_txt->set_text(TTR("Col:"));
  941. col_nb = memnew(Label);
  942. status_bar->add_child(col_nb);
  943. col_nb->set_valign(Label::VALIGN_CENTER);
  944. col_nb->set_v_size_flags(SIZE_FILL);
  945. col_nb->set_autowrap(true); // workaround to prevent resizing the label on each change, do not touch
  946. col_nb->set_clip_text(true); // workaround to prevent resizing the label on each change, do not touch
  947. col_nb->set_custom_minimum_size(Size2(40, 1) * EDSCALE);
  948. text_editor->connect("gui_input", this, "_text_editor_gui_input");
  949. text_editor->connect("cursor_changed", this, "_line_col_changed");
  950. text_editor->connect("text_changed", this, "_text_changed");
  951. text_editor->connect("request_completion", this, "_complete_request");
  952. Vector<String> cs;
  953. cs.push_back(".");
  954. cs.push_back(",");
  955. cs.push_back("(");
  956. cs.push_back("=");
  957. cs.push_back("$");
  958. text_editor->set_completion(true, cs);
  959. idle->connect("timeout", this, "_text_changed_idle_timeout");
  960. code_complete_timer->connect("timeout", this, "_code_complete_timer_timeout");
  961. font_resize_val = 0;
  962. font_resize_timer = memnew(Timer);
  963. add_child(font_resize_timer);
  964. font_resize_timer->set_one_shot(true);
  965. font_resize_timer->set_wait_time(0.07);
  966. font_resize_timer->connect("timeout", this, "_font_resize_timeout");
  967. EditorSettings::get_singleton()->connect("settings_changed", this, "_on_settings_change");
  968. }