code_editor.cpp 37 KB

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