code_editor.cpp 38 KB

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