find_in_files.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. /**************************************************************************/
  2. /* find_in_files.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "find_in_files.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/io/dir_access.h"
  33. #include "core/os/os.h"
  34. #include "editor/editor_node.h"
  35. #include "editor/editor_string_names.h"
  36. #include "editor/themes/editor_scale.h"
  37. #include "scene/gui/box_container.h"
  38. #include "scene/gui/button.h"
  39. #include "scene/gui/check_box.h"
  40. #include "scene/gui/file_dialog.h"
  41. #include "scene/gui/grid_container.h"
  42. #include "scene/gui/label.h"
  43. #include "scene/gui/line_edit.h"
  44. #include "scene/gui/progress_bar.h"
  45. #include "scene/gui/tree.h"
  46. const char *FindInFiles::SIGNAL_RESULT_FOUND = "result_found";
  47. // TODO: Would be nice in Vector and Vectors.
  48. template <typename T>
  49. inline void pop_back(T &container) {
  50. container.resize(container.size() - 1);
  51. }
  52. static bool find_next(const String &line, const String &pattern, int from, bool match_case, bool whole_words, int &out_begin, int &out_end) {
  53. int end = from;
  54. while (true) {
  55. int begin = match_case ? line.find(pattern, end) : line.findn(pattern, end);
  56. if (begin == -1) {
  57. return false;
  58. }
  59. end = begin + pattern.length();
  60. out_begin = begin;
  61. out_end = end;
  62. if (whole_words) {
  63. if (begin > 0 && (is_ascii_identifier_char(line[begin - 1]))) {
  64. continue;
  65. }
  66. if (end < line.size() && (is_ascii_identifier_char(line[end]))) {
  67. continue;
  68. }
  69. }
  70. return true;
  71. }
  72. }
  73. //--------------------------------------------------------------------------------
  74. void FindInFiles::set_search_text(const String &p_pattern) {
  75. _pattern = p_pattern;
  76. }
  77. void FindInFiles::set_whole_words(bool p_whole_word) {
  78. _whole_words = p_whole_word;
  79. }
  80. void FindInFiles::set_match_case(bool p_match_case) {
  81. _match_case = p_match_case;
  82. }
  83. void FindInFiles::set_folder(const String &folder) {
  84. _root_dir = folder;
  85. }
  86. void FindInFiles::set_filter(const HashSet<String> &exts) {
  87. _extension_filter = exts;
  88. }
  89. void FindInFiles::set_includes(const HashSet<String> &p_include_wildcards) {
  90. _include_wildcards = p_include_wildcards;
  91. }
  92. void FindInFiles::set_excludes(const HashSet<String> &p_exclude_wildcards) {
  93. _exclude_wildcards = p_exclude_wildcards;
  94. }
  95. void FindInFiles::_notification(int p_what) {
  96. switch (p_what) {
  97. case NOTIFICATION_PROCESS: {
  98. _process();
  99. } break;
  100. }
  101. }
  102. void FindInFiles::start() {
  103. if (_pattern.is_empty()) {
  104. print_verbose("Nothing to search, pattern is empty");
  105. emit_signal(SceneStringName(finished));
  106. return;
  107. }
  108. if (_extension_filter.is_empty()) {
  109. print_verbose("Nothing to search, filter matches no files");
  110. emit_signal(SceneStringName(finished));
  111. return;
  112. }
  113. // Init search.
  114. _current_dir = "";
  115. PackedStringArray init_folder;
  116. init_folder.push_back(_root_dir);
  117. _folders_stack.clear();
  118. _folders_stack.push_back(init_folder);
  119. _initial_files_count = 0;
  120. _searching = true;
  121. set_process(true);
  122. }
  123. void FindInFiles::stop() {
  124. _searching = false;
  125. _current_dir = "";
  126. set_process(false);
  127. }
  128. void FindInFiles::_process() {
  129. // This part can be moved to a thread if needed.
  130. OS &os = *OS::get_singleton();
  131. uint64_t time_before = os.get_ticks_msec();
  132. while (is_processing()) {
  133. _iterate();
  134. uint64_t elapsed = (os.get_ticks_msec() - time_before);
  135. if (elapsed > 8) { // Process again after waiting 8 ticks.
  136. break;
  137. }
  138. }
  139. }
  140. void FindInFiles::_iterate() {
  141. if (_folders_stack.size() != 0) {
  142. // Scan folders first so we can build a list of files and have progress info later.
  143. PackedStringArray &folders_to_scan = _folders_stack.write[_folders_stack.size() - 1];
  144. if (folders_to_scan.size() != 0) {
  145. // Scan one folder below.
  146. String folder_name = folders_to_scan[folders_to_scan.size() - 1];
  147. pop_back(folders_to_scan);
  148. _current_dir = _current_dir.path_join(folder_name);
  149. PackedStringArray sub_dirs;
  150. PackedStringArray files_to_scan;
  151. _scan_dir("res://" + _current_dir, sub_dirs, files_to_scan);
  152. _folders_stack.push_back(sub_dirs);
  153. _files_to_scan.append_array(files_to_scan);
  154. } else {
  155. // Go back one level.
  156. pop_back(_folders_stack);
  157. _current_dir = _current_dir.get_base_dir();
  158. if (_folders_stack.is_empty()) {
  159. // All folders scanned.
  160. _initial_files_count = _files_to_scan.size();
  161. }
  162. }
  163. } else if (_files_to_scan.size() != 0) {
  164. // Then scan files.
  165. String fpath = _files_to_scan[_files_to_scan.size() - 1];
  166. pop_back(_files_to_scan);
  167. _scan_file(fpath);
  168. } else {
  169. print_verbose("Search complete");
  170. set_process(false);
  171. _current_dir = "";
  172. _searching = false;
  173. emit_signal(SceneStringName(finished));
  174. }
  175. }
  176. float FindInFiles::get_progress() const {
  177. if (_initial_files_count != 0) {
  178. return static_cast<float>(_initial_files_count - _files_to_scan.size()) / static_cast<float>(_initial_files_count);
  179. }
  180. return 0;
  181. }
  182. void FindInFiles::_scan_dir(const String &path, PackedStringArray &out_folders, PackedStringArray &out_files_to_scan) {
  183. Ref<DirAccess> dir = DirAccess::open(path);
  184. if (dir.is_null()) {
  185. print_verbose("Cannot open directory! " + path);
  186. return;
  187. }
  188. dir->list_dir_begin();
  189. // Limit to 100,000 iterations to avoid an infinite loop just in case
  190. // (this technically limits results to 100,000 files per folder).
  191. for (int i = 0; i < 100'000; ++i) {
  192. String file = dir->get_next();
  193. if (file.is_empty()) {
  194. break;
  195. }
  196. // If there is a .gdignore file in the directory, clear all the files/folders
  197. // to be searched on this path and skip searching the directory.
  198. if (file == ".gdignore") {
  199. out_folders.clear();
  200. out_files_to_scan.clear();
  201. break;
  202. }
  203. // Ignore special directories (such as those beginning with . and the project data directory).
  204. String project_data_dir_name = ProjectSettings::get_singleton()->get_project_data_dir_name();
  205. if (file.begins_with(".") || file == project_data_dir_name) {
  206. continue;
  207. }
  208. if (dir->current_is_hidden()) {
  209. continue;
  210. }
  211. if (dir->current_is_dir()) {
  212. out_folders.push_back(file);
  213. } else {
  214. String file_ext = file.get_extension();
  215. if (_extension_filter.has(file_ext)) {
  216. String file_path = path.path_join(file);
  217. bool case_sensitive = dir->is_case_sensitive(path);
  218. if (!_exclude_wildcards.is_empty() && _is_file_matched(_exclude_wildcards, file_path, case_sensitive)) {
  219. continue;
  220. }
  221. if (_include_wildcards.is_empty() || _is_file_matched(_include_wildcards, file_path, case_sensitive)) {
  222. out_files_to_scan.push_back(file_path);
  223. }
  224. }
  225. }
  226. }
  227. }
  228. void FindInFiles::_scan_file(const String &fpath) {
  229. Ref<FileAccess> f = FileAccess::open(fpath, FileAccess::READ);
  230. if (f.is_null()) {
  231. print_verbose(String("Cannot open file ") + fpath);
  232. return;
  233. }
  234. int line_number = 0;
  235. while (!f->eof_reached()) {
  236. // Line number starts at 1.
  237. ++line_number;
  238. int begin = 0;
  239. int end = 0;
  240. String line = f->get_line();
  241. while (find_next(line, _pattern, end, _match_case, _whole_words, begin, end)) {
  242. emit_signal(SNAME(SIGNAL_RESULT_FOUND), fpath, line_number, begin, end, line);
  243. }
  244. }
  245. }
  246. bool FindInFiles::_is_file_matched(const HashSet<String> &p_wildcards, const String &p_file_path, bool p_case_sensitive) const {
  247. const String file_path = "/" + p_file_path.replace_char('\\', '/') + "/";
  248. for (const String &wildcard : p_wildcards) {
  249. if (p_case_sensitive && file_path.match(wildcard)) {
  250. return true;
  251. } else if (!p_case_sensitive && file_path.matchn(wildcard)) {
  252. return true;
  253. }
  254. }
  255. return false;
  256. }
  257. void FindInFiles::_bind_methods() {
  258. ADD_SIGNAL(MethodInfo(SIGNAL_RESULT_FOUND,
  259. PropertyInfo(Variant::STRING, "path"),
  260. PropertyInfo(Variant::INT, "line_number"),
  261. PropertyInfo(Variant::INT, "begin"),
  262. PropertyInfo(Variant::INT, "end"),
  263. PropertyInfo(Variant::STRING, "text")));
  264. ADD_SIGNAL(MethodInfo("finished"));
  265. }
  266. //-----------------------------------------------------------------------------
  267. const char *FindInFilesDialog::SIGNAL_FIND_REQUESTED = "find_requested";
  268. const char *FindInFilesDialog::SIGNAL_REPLACE_REQUESTED = "replace_requested";
  269. FindInFilesDialog::FindInFilesDialog() {
  270. set_min_size(Size2(500 * EDSCALE, 0));
  271. set_title(TTRC("Find in Files"));
  272. VBoxContainer *vbc = memnew(VBoxContainer);
  273. vbc->set_anchor_and_offset(SIDE_LEFT, Control::ANCHOR_BEGIN, 8 * EDSCALE);
  274. vbc->set_anchor_and_offset(SIDE_TOP, Control::ANCHOR_BEGIN, 8 * EDSCALE);
  275. vbc->set_anchor_and_offset(SIDE_RIGHT, Control::ANCHOR_END, -8 * EDSCALE);
  276. vbc->set_anchor_and_offset(SIDE_BOTTOM, Control::ANCHOR_END, -8 * EDSCALE);
  277. add_child(vbc);
  278. GridContainer *gc = memnew(GridContainer);
  279. gc->set_columns(2);
  280. vbc->add_child(gc);
  281. Label *find_label = memnew(Label);
  282. find_label->set_text(TTRC("Find:"));
  283. gc->add_child(find_label);
  284. _search_text_line_edit = memnew(LineEdit);
  285. _search_text_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  286. _search_text_line_edit->set_accessibility_name(TTRC("Find:"));
  287. _search_text_line_edit->connect(SceneStringName(text_changed), callable_mp(this, &FindInFilesDialog::_on_search_text_modified));
  288. _search_text_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesDialog::_on_search_text_submitted));
  289. gc->add_child(_search_text_line_edit);
  290. _replace_label = memnew(Label);
  291. _replace_label->set_text(TTRC("Replace:"));
  292. _replace_label->hide();
  293. gc->add_child(_replace_label);
  294. _replace_text_line_edit = memnew(LineEdit);
  295. _replace_text_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  296. _replace_text_line_edit->set_accessibility_name(TTRC("Replace:"));
  297. _replace_text_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesDialog::_on_replace_text_submitted));
  298. _replace_text_line_edit->hide();
  299. gc->add_child(_replace_text_line_edit);
  300. gc->add_child(memnew(Control)); // Space to maintain the grid alignment.
  301. {
  302. HBoxContainer *hbc = memnew(HBoxContainer);
  303. _whole_words_checkbox = memnew(CheckBox);
  304. _whole_words_checkbox->set_text(TTRC("Whole Words"));
  305. hbc->add_child(_whole_words_checkbox);
  306. _match_case_checkbox = memnew(CheckBox);
  307. _match_case_checkbox->set_text(TTRC("Match Case"));
  308. hbc->add_child(_match_case_checkbox);
  309. gc->add_child(hbc);
  310. }
  311. Label *folder_label = memnew(Label);
  312. folder_label->set_text(TTRC("Folder:"));
  313. gc->add_child(folder_label);
  314. {
  315. HBoxContainer *hbc = memnew(HBoxContainer);
  316. Label *prefix_label = memnew(Label);
  317. prefix_label->set_text("res://");
  318. prefix_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  319. hbc->add_child(prefix_label);
  320. _folder_line_edit = memnew(LineEdit);
  321. _folder_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  322. _folder_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesDialog::_on_search_text_submitted));
  323. _folder_line_edit->set_accessibility_name(TTRC("Folder:"));
  324. hbc->add_child(_folder_line_edit);
  325. Button *folder_button = memnew(Button);
  326. folder_button->set_accessibility_name(TTRC("Select Folder"));
  327. folder_button->set_text("...");
  328. folder_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesDialog::_on_folder_button_pressed));
  329. hbc->add_child(folder_button);
  330. _folder_dialog = memnew(FileDialog);
  331. _folder_dialog->set_file_mode(FileDialog::FILE_MODE_OPEN_DIR);
  332. _folder_dialog->connect("dir_selected", callable_mp(this, &FindInFilesDialog::_on_folder_selected));
  333. add_child(_folder_dialog);
  334. gc->add_child(hbc);
  335. }
  336. Label *includes_label = memnew(Label);
  337. includes_label->set_text(TTRC("Includes:"));
  338. includes_label->set_tooltip_text(TTRC("Include the files with the following expressions. Use \",\" to separate."));
  339. includes_label->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  340. gc->add_child(includes_label);
  341. _includes_line_edit = memnew(LineEdit);
  342. _includes_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  343. _includes_line_edit->set_placeholder(TTRC("example: scripts,scenes/*/test.gd"));
  344. _includes_line_edit->set_accessibility_name(TTRC("Includes:"));
  345. _includes_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesDialog::_on_search_text_submitted));
  346. gc->add_child(_includes_line_edit);
  347. Label *excludes_label = memnew(Label);
  348. excludes_label->set_text(TTRC("Excludes:"));
  349. excludes_label->set_tooltip_text(TTRC("Exclude the files with the following expressions. Use \",\" to separate."));
  350. excludes_label->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  351. gc->add_child(excludes_label);
  352. _excludes_line_edit = memnew(LineEdit);
  353. _excludes_line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  354. _excludes_line_edit->set_placeholder(TTRC("example: res://addons,scenes/test/*.gd"));
  355. _excludes_line_edit->set_accessibility_name(TTRC("Excludes:"));
  356. _excludes_line_edit->connect(SceneStringName(text_submitted), callable_mp(this, &FindInFilesDialog::_on_search_text_submitted));
  357. gc->add_child(_excludes_line_edit);
  358. Label *filter_label = memnew(Label);
  359. filter_label->set_text(TTRC("Filters:"));
  360. filter_label->set_tooltip_text(TTRC("Include the files with the following extensions. Add or remove them in ProjectSettings."));
  361. filter_label->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  362. gc->add_child(filter_label);
  363. _filters_container = memnew(HBoxContainer);
  364. gc->add_child(_filters_container);
  365. _find_button = add_button(TTRC("Find..."), false, "find");
  366. _find_button->set_disabled(true);
  367. _replace_button = add_button(TTRC("Replace..."), false, "replace");
  368. _replace_button->set_disabled(true);
  369. Button *cancel_button = get_ok_button();
  370. cancel_button->set_text(TTRC("Cancel"));
  371. _mode = SEARCH_MODE;
  372. }
  373. void FindInFilesDialog::set_search_text(const String &text) {
  374. if (_mode == SEARCH_MODE) {
  375. if (!text.is_empty()) {
  376. _search_text_line_edit->set_text(text);
  377. _on_search_text_modified(text);
  378. }
  379. callable_mp((Control *)_search_text_line_edit, &Control::grab_focus).call_deferred();
  380. _search_text_line_edit->select_all();
  381. } else if (_mode == REPLACE_MODE) {
  382. if (!text.is_empty()) {
  383. _search_text_line_edit->set_text(text);
  384. callable_mp((Control *)_replace_text_line_edit, &Control::grab_focus).call_deferred();
  385. _replace_text_line_edit->select_all();
  386. _on_search_text_modified(text);
  387. } else {
  388. callable_mp((Control *)_search_text_line_edit, &Control::grab_focus).call_deferred();
  389. _search_text_line_edit->select_all();
  390. }
  391. }
  392. }
  393. void FindInFilesDialog::set_replace_text(const String &text) {
  394. _replace_text_line_edit->set_text(text);
  395. }
  396. void FindInFilesDialog::set_find_in_files_mode(FindInFilesMode p_mode) {
  397. if (_mode == p_mode) {
  398. return;
  399. }
  400. _mode = p_mode;
  401. if (p_mode == SEARCH_MODE) {
  402. set_title(TTRC("Find in Files"));
  403. _replace_label->hide();
  404. _replace_text_line_edit->hide();
  405. } else if (p_mode == REPLACE_MODE) {
  406. set_title(TTRC("Replace in Files"));
  407. _replace_label->show();
  408. _replace_text_line_edit->show();
  409. }
  410. // Recalculate the dialog size after hiding child controls.
  411. set_size(Size2(get_size().x, 0));
  412. }
  413. String FindInFilesDialog::get_search_text() const {
  414. return _search_text_line_edit->get_text();
  415. }
  416. String FindInFilesDialog::get_replace_text() const {
  417. return _replace_text_line_edit->get_text();
  418. }
  419. bool FindInFilesDialog::is_match_case() const {
  420. return _match_case_checkbox->is_pressed();
  421. }
  422. bool FindInFilesDialog::is_whole_words() const {
  423. return _whole_words_checkbox->is_pressed();
  424. }
  425. String FindInFilesDialog::get_folder() const {
  426. String text = _folder_line_edit->get_text();
  427. return text.strip_edges();
  428. }
  429. HashSet<String> FindInFilesDialog::get_filter() const {
  430. // Could check the _filters_preferences but it might not have been generated yet.
  431. HashSet<String> filters;
  432. for (int i = 0; i < _filters_container->get_child_count(); ++i) {
  433. CheckBox *cb = static_cast<CheckBox *>(_filters_container->get_child(i));
  434. if (cb->is_pressed()) {
  435. filters.insert(cb->get_text());
  436. }
  437. }
  438. return filters;
  439. }
  440. HashSet<String> FindInFilesDialog::get_includes() const {
  441. HashSet<String> includes;
  442. String text = _includes_line_edit->get_text();
  443. if (text.is_empty()) {
  444. return includes;
  445. }
  446. PackedStringArray wildcards = text.split(",", false);
  447. for (const String &wildcard : wildcards) {
  448. includes.insert(validate_filter_wildcard(wildcard));
  449. }
  450. return includes;
  451. }
  452. HashSet<String> FindInFilesDialog::get_excludes() const {
  453. HashSet<String> excludes;
  454. String text = _excludes_line_edit->get_text();
  455. if (text.is_empty()) {
  456. return excludes;
  457. }
  458. PackedStringArray wildcards = text.split(",", false);
  459. for (const String &wildcard : wildcards) {
  460. excludes.insert(validate_filter_wildcard(wildcard));
  461. }
  462. return excludes;
  463. }
  464. void FindInFilesDialog::_notification(int p_what) {
  465. switch (p_what) {
  466. case NOTIFICATION_VISIBILITY_CHANGED: {
  467. if (is_visible()) {
  468. // Extensions might have changed in the meantime, we clean them and instance them again.
  469. for (int i = 0; i < _filters_container->get_child_count(); i++) {
  470. _filters_container->get_child(i)->queue_free();
  471. }
  472. Array exts = GLOBAL_GET("editor/script/search_in_file_extensions");
  473. for (int i = 0; i < exts.size(); ++i) {
  474. CheckBox *cb = memnew(CheckBox);
  475. cb->set_text(exts[i]);
  476. if (!_filters_preferences.has(exts[i])) {
  477. _filters_preferences[exts[i]] = true;
  478. }
  479. cb->set_pressed(_filters_preferences[exts[i]]);
  480. _filters_container->add_child(cb);
  481. }
  482. }
  483. } break;
  484. }
  485. }
  486. void FindInFilesDialog::_on_folder_button_pressed() {
  487. _folder_dialog->popup_file_dialog();
  488. }
  489. void FindInFilesDialog::custom_action(const String &p_action) {
  490. for (int i = 0; i < _filters_container->get_child_count(); ++i) {
  491. CheckBox *cb = static_cast<CheckBox *>(_filters_container->get_child(i));
  492. _filters_preferences[cb->get_text()] = cb->is_pressed();
  493. }
  494. if (p_action == "find") {
  495. emit_signal(SNAME(SIGNAL_FIND_REQUESTED));
  496. hide();
  497. } else if (p_action == "replace") {
  498. emit_signal(SNAME(SIGNAL_REPLACE_REQUESTED));
  499. hide();
  500. }
  501. }
  502. void FindInFilesDialog::_on_search_text_modified(const String &text) {
  503. ERR_FAIL_NULL(_find_button);
  504. ERR_FAIL_NULL(_replace_button);
  505. _find_button->set_disabled(get_search_text().is_empty());
  506. _replace_button->set_disabled(get_search_text().is_empty());
  507. }
  508. void FindInFilesDialog::_on_search_text_submitted(const String &text) {
  509. // This allows to trigger a global search without leaving the keyboard.
  510. if (!_find_button->is_disabled()) {
  511. if (_mode == SEARCH_MODE) {
  512. custom_action("find");
  513. }
  514. }
  515. if (!_replace_button->is_disabled()) {
  516. if (_mode == REPLACE_MODE) {
  517. custom_action("replace");
  518. }
  519. }
  520. }
  521. void FindInFilesDialog::_on_replace_text_submitted(const String &text) {
  522. // This allows to trigger a global search without leaving the keyboard.
  523. if (!_replace_button->is_disabled()) {
  524. if (_mode == REPLACE_MODE) {
  525. custom_action("replace");
  526. }
  527. }
  528. }
  529. void FindInFilesDialog::_on_folder_selected(String path) {
  530. int i = path.find("://");
  531. if (i != -1) {
  532. path = path.substr(i + 3);
  533. }
  534. _folder_line_edit->set_text(path);
  535. }
  536. String FindInFilesDialog::validate_filter_wildcard(const String &p_expression) const {
  537. String ret = p_expression.replace_char('\\', '/');
  538. if (ret.begins_with("./")) {
  539. // Relative to the project root.
  540. ret = "res://" + ret.trim_prefix("./");
  541. }
  542. if (ret.begins_with(".")) {
  543. // To match extension.
  544. ret = "*" + ret;
  545. }
  546. if (!ret.begins_with("*")) {
  547. ret = "*/" + ret.trim_prefix("/");
  548. }
  549. if (!ret.ends_with("*")) {
  550. ret = ret.trim_suffix("/") + "/*";
  551. }
  552. return ret;
  553. }
  554. void FindInFilesDialog::_bind_methods() {
  555. ADD_SIGNAL(MethodInfo(SIGNAL_FIND_REQUESTED));
  556. ADD_SIGNAL(MethodInfo(SIGNAL_REPLACE_REQUESTED));
  557. }
  558. //-----------------------------------------------------------------------------
  559. const char *FindInFilesPanel::SIGNAL_RESULT_SELECTED = "result_selected";
  560. const char *FindInFilesPanel::SIGNAL_FILES_MODIFIED = "files_modified";
  561. const char *FindInFilesPanel::SIGNAL_CLOSE_BUTTON_CLICKED = "close_button_clicked";
  562. FindInFilesPanel::FindInFilesPanel() {
  563. _finder = memnew(FindInFiles);
  564. _finder->connect(FindInFiles::SIGNAL_RESULT_FOUND, callable_mp(this, &FindInFilesPanel::_on_result_found));
  565. _finder->connect(SceneStringName(finished), callable_mp(this, &FindInFilesPanel::_on_finished));
  566. add_child(_finder);
  567. VBoxContainer *vbc = memnew(VBoxContainer);
  568. vbc->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, 0);
  569. vbc->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);
  570. vbc->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
  571. vbc->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
  572. add_child(vbc);
  573. {
  574. HBoxContainer *hbc = memnew(HBoxContainer);
  575. Label *find_label = memnew(Label);
  576. find_label->set_text(TTRC("Find:"));
  577. hbc->add_child(find_label);
  578. _search_text_label = memnew(Label);
  579. _search_text_label->set_focus_mode(FOCUS_ACCESSIBILITY);
  580. _search_text_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  581. hbc->add_child(_search_text_label);
  582. _progress_bar = memnew(ProgressBar);
  583. _progress_bar->set_h_size_flags(SIZE_EXPAND_FILL);
  584. _progress_bar->set_v_size_flags(SIZE_SHRINK_CENTER);
  585. hbc->add_child(_progress_bar);
  586. set_progress_visible(false);
  587. _status_label = memnew(Label);
  588. _status_label->set_focus_mode(FOCUS_ACCESSIBILITY);
  589. hbc->add_child(_status_label);
  590. _refresh_button = memnew(Button);
  591. _refresh_button->set_text(TTRC("Refresh"));
  592. _refresh_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesPanel::_on_refresh_button_clicked));
  593. _refresh_button->hide();
  594. hbc->add_child(_refresh_button);
  595. _cancel_button = memnew(Button);
  596. _cancel_button->set_text(TTRC("Cancel"));
  597. _cancel_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesPanel::_on_cancel_button_clicked));
  598. _cancel_button->hide();
  599. hbc->add_child(_cancel_button);
  600. _close_button = memnew(Button);
  601. _close_button->set_text(TTRC("Close"));
  602. _close_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesPanel::_on_close_button_clicked));
  603. hbc->add_child(_close_button);
  604. vbc->add_child(hbc);
  605. }
  606. _results_display = memnew(Tree);
  607. _results_display->set_accessibility_name(TTRC("Search Results"));
  608. _results_display->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  609. _results_display->set_v_size_flags(SIZE_EXPAND_FILL);
  610. _results_display->connect(SceneStringName(item_selected), callable_mp(this, &FindInFilesPanel::_on_result_selected));
  611. _results_display->connect("item_edited", callable_mp(this, &FindInFilesPanel::_on_item_edited));
  612. _results_display->connect("button_clicked", callable_mp(this, &FindInFilesPanel::_on_button_clicked));
  613. _results_display->set_hide_root(true);
  614. _results_display->set_select_mode(Tree::SELECT_ROW);
  615. _results_display->set_allow_rmb_select(true);
  616. _results_display->set_allow_reselect(true);
  617. _results_display->add_theme_constant_override("inner_item_margin_left", 0);
  618. _results_display->add_theme_constant_override("inner_item_margin_right", 0);
  619. _results_display->create_item(); // Root
  620. vbc->add_child(_results_display);
  621. {
  622. _replace_container = memnew(HBoxContainer);
  623. Label *replace_label = memnew(Label);
  624. replace_label->set_text(TTRC("Replace:"));
  625. _replace_container->add_child(replace_label);
  626. _replace_line_edit = memnew(LineEdit);
  627. _replace_line_edit->set_accessibility_name(TTRC("Replace:"));
  628. _replace_line_edit->set_h_size_flags(SIZE_EXPAND_FILL);
  629. _replace_line_edit->connect(SceneStringName(text_changed), callable_mp(this, &FindInFilesPanel::_on_replace_text_changed));
  630. _replace_container->add_child(_replace_line_edit);
  631. _replace_all_button = memnew(Button);
  632. _replace_all_button->set_text(TTRC("Replace all (no undo)"));
  633. _replace_all_button->connect(SceneStringName(pressed), callable_mp(this, &FindInFilesPanel::_on_replace_all_clicked));
  634. _replace_container->add_child(_replace_all_button);
  635. _replace_container->hide();
  636. vbc->add_child(_replace_container);
  637. }
  638. }
  639. void FindInFilesPanel::set_with_replace(bool with_replace) {
  640. _with_replace = with_replace;
  641. _replace_container->set_visible(with_replace);
  642. if (with_replace) {
  643. // Results show checkboxes on their left so they can be opted out.
  644. _results_display->set_columns(2);
  645. _results_display->set_column_expand(0, false);
  646. _results_display->set_column_custom_minimum_width(0, 48 * EDSCALE);
  647. } else {
  648. // Results are single-cell items.
  649. _results_display->set_column_expand(0, true);
  650. _results_display->set_columns(1);
  651. }
  652. }
  653. void FindInFilesPanel::set_replace_text(const String &text) {
  654. _replace_line_edit->set_text(text);
  655. }
  656. void FindInFilesPanel::clear() {
  657. _file_items.clear();
  658. _result_items.clear();
  659. _results_display->clear();
  660. _results_display->create_item(); // Root
  661. }
  662. void FindInFilesPanel::start_search() {
  663. clear();
  664. _status_label->set_text(TTRC("Searching..."));
  665. _search_text_label->set_text(_finder->get_search_text());
  666. set_process(true);
  667. set_progress_visible(true);
  668. _finder->start();
  669. update_replace_buttons();
  670. _refresh_button->hide();
  671. _cancel_button->show();
  672. }
  673. void FindInFilesPanel::stop_search() {
  674. _finder->stop();
  675. _status_label->set_text("");
  676. update_replace_buttons();
  677. set_progress_visible(false);
  678. _refresh_button->show();
  679. _cancel_button->hide();
  680. }
  681. void FindInFilesPanel::_notification(int p_what) {
  682. switch (p_what) {
  683. case NOTIFICATION_THEME_CHANGED: {
  684. _search_text_label->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("source"), EditorStringName(EditorFonts)));
  685. _search_text_label->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("source_size"), EditorStringName(EditorFonts)));
  686. _results_display->add_theme_font_override(SceneStringName(font), get_theme_font(SNAME("source"), EditorStringName(EditorFonts)));
  687. _results_display->add_theme_font_size_override(SceneStringName(font_size), get_theme_font_size(SNAME("source_size"), EditorStringName(EditorFonts)));
  688. // Rebuild search tree.
  689. if (!_finder->get_search_text().is_empty()) {
  690. start_search();
  691. }
  692. } break;
  693. case NOTIFICATION_TRANSLATION_CHANGED: {
  694. update_matches_text();
  695. TreeItem *file_item = _results_display->get_root()->get_first_child();
  696. while (file_item) {
  697. file_item->set_button_tooltip_text(0, 0, TTR("Remove result"));
  698. TreeItem *result_item = file_item->get_first_child();
  699. while (result_item) {
  700. result_item->set_button_tooltip_text(_with_replace ? 1 : 0, 0, TTR("Remove result"));
  701. result_item = result_item->get_next();
  702. }
  703. file_item = file_item->get_next();
  704. }
  705. } break;
  706. case NOTIFICATION_PROCESS: {
  707. _progress_bar->set_as_ratio(_finder->get_progress());
  708. } break;
  709. }
  710. }
  711. void FindInFilesPanel::_on_result_found(const String &fpath, int line_number, int begin, int end, String text) {
  712. TreeItem *file_item;
  713. Ref<Texture2D> remove_texture = get_editor_theme_icon(SNAME("Close"));
  714. HashMap<String, TreeItem *>::Iterator E = _file_items.find(fpath);
  715. if (!E) {
  716. file_item = _results_display->create_item();
  717. file_item->set_text(0, fpath);
  718. file_item->set_metadata(0, fpath);
  719. file_item->add_button(0, remove_texture, 0, false, TTR("Remove result"));
  720. // The width of this column is restrained to checkboxes,
  721. // but that doesn't make sense for the parent items,
  722. // so we override their width so they can expand to full width.
  723. file_item->set_expand_right(0, true);
  724. _file_items[fpath] = file_item;
  725. } else {
  726. file_item = E->value;
  727. }
  728. Color file_item_color = _results_display->get_theme_color(SceneStringName(font_color)) * Color(1, 1, 1, 0.67);
  729. file_item->set_custom_color(0, file_item_color);
  730. file_item->set_selectable(0, false);
  731. int text_index = _with_replace ? 1 : 0;
  732. TreeItem *item = _results_display->create_item(file_item);
  733. // Do this first because it resets properties of the cell...
  734. item->set_cell_mode(text_index, TreeItem::CELL_MODE_CUSTOM);
  735. // Trim result item line.
  736. int old_text_size = text.size();
  737. text = text.strip_edges(true, false);
  738. int chars_removed = old_text_size - text.size();
  739. String start = vformat("%3s: ", line_number);
  740. item->set_text(text_index, start + text);
  741. item->set_custom_draw_callback(text_index, callable_mp(this, &FindInFilesPanel::draw_result_text));
  742. Result r;
  743. r.line_number = line_number;
  744. r.begin = begin;
  745. r.end = end;
  746. r.begin_trimmed = begin - chars_removed + start.size() - 1;
  747. _result_items[item] = r;
  748. if (_with_replace) {
  749. item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  750. item->set_checked(0, true);
  751. item->set_editable(0, true);
  752. item->add_button(1, remove_texture, 0, false, TTR("Remove result"));
  753. } else {
  754. item->add_button(0, remove_texture, 0, false, TTR("Remove result"));
  755. }
  756. }
  757. void FindInFilesPanel::draw_result_text(Object *item_obj, Rect2 rect) {
  758. TreeItem *item = Object::cast_to<TreeItem>(item_obj);
  759. if (!item) {
  760. return;
  761. }
  762. HashMap<TreeItem *, Result>::Iterator E = _result_items.find(item);
  763. if (!E) {
  764. return;
  765. }
  766. Result r = E->value;
  767. String item_text = item->get_text(_with_replace ? 1 : 0);
  768. Ref<Font> font = _results_display->get_theme_font(SceneStringName(font));
  769. int font_size = _results_display->get_theme_font_size(SceneStringName(font_size));
  770. Rect2 match_rect = rect;
  771. match_rect.position.x += font->get_string_size(item_text.left(r.begin_trimmed), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x - 1;
  772. match_rect.size.x = font->get_string_size(_search_text_label->get_text(), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x + 1;
  773. match_rect.position.y += 1 * EDSCALE;
  774. match_rect.size.y -= 2 * EDSCALE;
  775. _results_display->draw_rect(match_rect, get_theme_color(SNAME("accent_color"), EditorStringName(Editor)) * Color(1, 1, 1, 0.33), false, 2.0);
  776. _results_display->draw_rect(match_rect, get_theme_color(SNAME("accent_color"), EditorStringName(Editor)) * Color(1, 1, 1, 0.17), true);
  777. // Text is drawn by Tree already.
  778. }
  779. void FindInFilesPanel::_on_item_edited() {
  780. TreeItem *item = _results_display->get_selected();
  781. // Change opacity to half if checkbox is checked, otherwise full.
  782. Color use_color = _results_display->get_theme_color(SceneStringName(font_color));
  783. if (!item->is_checked(0)) {
  784. use_color.a *= 0.5;
  785. }
  786. item->set_custom_color(1, use_color);
  787. }
  788. void FindInFilesPanel::_on_finished() {
  789. update_matches_text();
  790. update_replace_buttons();
  791. set_progress_visible(false);
  792. _refresh_button->show();
  793. _cancel_button->hide();
  794. }
  795. void FindInFilesPanel::_on_refresh_button_clicked() {
  796. start_search();
  797. }
  798. void FindInFilesPanel::_on_cancel_button_clicked() {
  799. stop_search();
  800. }
  801. void FindInFilesPanel::_on_close_button_clicked() {
  802. emit_signal(SNAME(SIGNAL_CLOSE_BUTTON_CLICKED));
  803. }
  804. void FindInFilesPanel::_on_result_selected() {
  805. TreeItem *item = _results_display->get_selected();
  806. HashMap<TreeItem *, Result>::Iterator E = _result_items.find(item);
  807. if (!E) {
  808. return;
  809. }
  810. Result r = E->value;
  811. TreeItem *file_item = item->get_parent();
  812. String fpath = file_item->get_metadata(0);
  813. emit_signal(SNAME(SIGNAL_RESULT_SELECTED), fpath, r.line_number, r.begin, r.end);
  814. }
  815. void FindInFilesPanel::_on_replace_text_changed(const String &text) {
  816. update_replace_buttons();
  817. }
  818. void FindInFilesPanel::_on_replace_all_clicked() {
  819. String replace_text = get_replace_text();
  820. PackedStringArray modified_files;
  821. for (KeyValue<String, TreeItem *> &E : _file_items) {
  822. TreeItem *file_item = E.value;
  823. String fpath = file_item->get_metadata(0);
  824. Vector<Result> locations;
  825. for (TreeItem *item = file_item->get_first_child(); item; item = item->get_next()) {
  826. if (!item->is_checked(0)) {
  827. continue;
  828. }
  829. HashMap<TreeItem *, Result>::Iterator F = _result_items.find(item);
  830. ERR_FAIL_COND(!F);
  831. locations.push_back(F->value);
  832. }
  833. if (locations.size() != 0) {
  834. // Results are sorted by file, so we can batch replaces.
  835. apply_replaces_in_file(fpath, locations, replace_text);
  836. modified_files.push_back(fpath);
  837. }
  838. }
  839. // Hide replace bar so we can't trigger the action twice without doing a new search.
  840. _replace_container->hide();
  841. emit_signal(SNAME(SIGNAL_FILES_MODIFIED), modified_files);
  842. }
  843. void FindInFilesPanel::_on_button_clicked(TreeItem *p_item, int p_column, int p_id, int p_mouse_button_index) {
  844. const String file_path = p_item->get_text(0);
  845. _result_items.erase(p_item);
  846. if (_file_items.find(file_path)) {
  847. TreeItem *file_result = _file_items.get(file_path);
  848. int match_count = file_result->get_child_count();
  849. for (int i = 0; i < match_count; i++) {
  850. TreeItem *child_item = file_result->get_child(i);
  851. _result_items.erase(child_item);
  852. }
  853. file_result->clear_children();
  854. _file_items.erase(file_path);
  855. }
  856. TreeItem *item_parent = p_item->get_parent();
  857. if (item_parent && item_parent->get_child_count() < 2) {
  858. _file_items.erase(item_parent->get_text(0));
  859. get_tree()->queue_delete(item_parent);
  860. }
  861. get_tree()->queue_delete(p_item);
  862. update_matches_text();
  863. }
  864. // Same as get_line, but preserves line ending characters.
  865. class ConservativeGetLine {
  866. public:
  867. String get_line(Ref<FileAccess> f) {
  868. _line_buffer.clear();
  869. char32_t c = f->get_8();
  870. while (!f->eof_reached()) {
  871. if (c == '\n') {
  872. _line_buffer.push_back(c);
  873. _line_buffer.push_back(0);
  874. return String::utf8(_line_buffer.ptr());
  875. } else if (c == '\0') {
  876. _line_buffer.push_back(c);
  877. return String::utf8(_line_buffer.ptr());
  878. } else if (c != '\r') {
  879. _line_buffer.push_back(c);
  880. }
  881. c = f->get_8();
  882. }
  883. _line_buffer.push_back(0);
  884. return String::utf8(_line_buffer.ptr());
  885. }
  886. private:
  887. Vector<char> _line_buffer;
  888. };
  889. void FindInFilesPanel::apply_replaces_in_file(const String &fpath, const Vector<Result> &locations, const String &new_text) {
  890. // If the file is already open, I assume the editor will reload it.
  891. // If there are unsaved changes, the user will be asked on focus,
  892. // however that means either losing changes or losing replaces.
  893. Ref<FileAccess> f = FileAccess::open(fpath, FileAccess::READ);
  894. ERR_FAIL_COND_MSG(f.is_null(), "Cannot open file from path '" + fpath + "'.");
  895. String buffer;
  896. int current_line = 1;
  897. ConservativeGetLine conservative;
  898. String line = conservative.get_line(f);
  899. String search_text = _finder->get_search_text();
  900. int offset = 0;
  901. for (int i = 0; i < locations.size(); ++i) {
  902. int repl_line_number = locations[i].line_number;
  903. while (current_line < repl_line_number) {
  904. buffer += line;
  905. line = conservative.get_line(f);
  906. ++current_line;
  907. offset = 0;
  908. }
  909. int repl_begin = locations[i].begin + offset;
  910. int repl_end = locations[i].end + offset;
  911. int _;
  912. if (!find_next(line, search_text, repl_begin, _finder->is_match_case(), _finder->is_whole_words(), _, _)) {
  913. // Make sure the replace is still valid in case the file was tampered with.
  914. print_verbose(String("Occurrence no longer matches, replace will be ignored in {0}: line {1}, col {2}").format(varray(fpath, repl_line_number, repl_begin)));
  915. continue;
  916. }
  917. line = line.left(repl_begin) + new_text + line.substr(repl_end);
  918. // Keep an offset in case there are successive replaces in the same line.
  919. offset += new_text.length() - (repl_end - repl_begin);
  920. }
  921. buffer += line;
  922. while (!f->eof_reached()) {
  923. buffer += conservative.get_line(f);
  924. }
  925. // Now the modified contents are in the buffer, rewrite the file with our changes.
  926. Error err = f->reopen(fpath, FileAccess::WRITE);
  927. ERR_FAIL_COND_MSG(err != OK, "Cannot create file in path '" + fpath + "'.");
  928. f->store_string(buffer);
  929. }
  930. String FindInFilesPanel::get_replace_text() {
  931. return _replace_line_edit->get_text();
  932. }
  933. void FindInFilesPanel::update_replace_buttons() {
  934. bool disabled = _finder->is_searching();
  935. _replace_all_button->set_disabled(disabled);
  936. }
  937. void FindInFilesPanel::update_matches_text() {
  938. String results_text;
  939. int result_count = _result_items.size();
  940. int file_count = _file_items.size();
  941. if (result_count == 1 && file_count == 1) {
  942. results_text = vformat(TTR("%d match in %d file"), result_count, file_count);
  943. } else if (result_count != 1 && file_count == 1) {
  944. results_text = vformat(TTR("%d matches in %d file"), result_count, file_count);
  945. } else {
  946. results_text = vformat(TTR("%d matches in %d files"), result_count, file_count);
  947. }
  948. _status_label->set_text(results_text);
  949. }
  950. void FindInFilesPanel::set_progress_visible(bool p_visible) {
  951. _progress_bar->set_self_modulate(Color(1, 1, 1, p_visible ? 1 : 0));
  952. }
  953. void FindInFilesPanel::_bind_methods() {
  954. ClassDB::bind_method("_on_result_found", &FindInFilesPanel::_on_result_found);
  955. ClassDB::bind_method("_on_finished", &FindInFilesPanel::_on_finished);
  956. ADD_SIGNAL(MethodInfo(SIGNAL_RESULT_SELECTED,
  957. PropertyInfo(Variant::STRING, "path"),
  958. PropertyInfo(Variant::INT, "line_number"),
  959. PropertyInfo(Variant::INT, "begin"),
  960. PropertyInfo(Variant::INT, "end")));
  961. ADD_SIGNAL(MethodInfo(SIGNAL_FILES_MODIFIED, PropertyInfo(Variant::STRING, "paths")));
  962. ADD_SIGNAL(MethodInfo(SIGNAL_CLOSE_BUTTON_CLICKED));
  963. }