editor_quick_open_dialog.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. /**************************************************************************/
  2. /* editor_quick_open_dialog.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 "editor_quick_open_dialog.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/string/fuzzy_search.h"
  33. #include "editor/editor_file_system.h"
  34. #include "editor/editor_node.h"
  35. #include "editor/editor_paths.h"
  36. #include "editor/editor_resource_preview.h"
  37. #include "editor/editor_settings.h"
  38. #include "editor/editor_string_names.h"
  39. #include "editor/filesystem_dock.h"
  40. #include "editor/themes/editor_scale.h"
  41. #include "scene/gui/center_container.h"
  42. #include "scene/gui/check_button.h"
  43. #include "scene/gui/flow_container.h"
  44. #include "scene/gui/margin_container.h"
  45. #include "scene/gui/panel_container.h"
  46. #include "scene/gui/separator.h"
  47. #include "scene/gui/texture_rect.h"
  48. #include "scene/gui/tree.h"
  49. void HighlightedLabel::draw_substr_rects(const Vector2i &p_substr, Vector2 p_offset, int p_line_limit, int line_spacing) {
  50. for (int i = get_lines_skipped(); i < p_line_limit; i++) {
  51. RID line = get_line_rid(i);
  52. Vector<Vector2> ranges = TS->shaped_text_get_selection(line, p_substr.x, p_substr.x + p_substr.y);
  53. Rect2 line_rect = get_line_rect(i);
  54. for (const Vector2 &range : ranges) {
  55. Rect2 rect = Rect2(Point2(range.x, 0) + line_rect.position, Size2(range.y - range.x, line_rect.size.y));
  56. rect.position = p_offset + line_rect.position;
  57. rect.position.x += range.x;
  58. rect.size = Size2(range.y - range.x, line_rect.size.y);
  59. rect.size.x = MIN(rect.size.x, line_rect.size.x - range.x);
  60. if (rect.size.x > 0) {
  61. draw_rect(rect, Color(1, 1, 1, 0.07), true);
  62. draw_rect(rect, Color(0.5, 0.7, 1.0, 0.4), false, 1);
  63. }
  64. }
  65. p_offset.y += line_spacing + TS->shaped_text_get_ascent(line) + TS->shaped_text_get_descent(line);
  66. }
  67. }
  68. void HighlightedLabel::add_highlight(const Vector2i &p_interval) {
  69. if (p_interval.y > 0) {
  70. highlights.append(p_interval);
  71. queue_redraw();
  72. }
  73. }
  74. void HighlightedLabel::reset_highlights() {
  75. highlights.clear();
  76. queue_redraw();
  77. }
  78. void HighlightedLabel::_notification(int p_notification) {
  79. if (p_notification == NOTIFICATION_DRAW) {
  80. if (highlights.is_empty()) {
  81. return;
  82. }
  83. Vector2 offset;
  84. int line_limit;
  85. int line_spacing;
  86. get_layout_data(offset, line_limit, line_spacing);
  87. for (const Vector2i &substr : highlights) {
  88. draw_substr_rects(substr, offset, line_limit, line_spacing);
  89. }
  90. }
  91. }
  92. EditorQuickOpenDialog::EditorQuickOpenDialog() {
  93. VBoxContainer *vbc = memnew(VBoxContainer);
  94. vbc->add_theme_constant_override("separation", 0);
  95. add_child(vbc);
  96. {
  97. // Search bar
  98. MarginContainer *mc = memnew(MarginContainer);
  99. mc->add_theme_constant_override("margin_top", 6);
  100. mc->add_theme_constant_override("margin_bottom", 6);
  101. mc->add_theme_constant_override("margin_left", 1);
  102. mc->add_theme_constant_override("margin_right", 1);
  103. vbc->add_child(mc);
  104. search_box = memnew(LineEdit);
  105. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  106. search_box->set_placeholder(TTR("Search files..."));
  107. search_box->set_clear_button_enabled(true);
  108. mc->add_child(search_box);
  109. }
  110. {
  111. container = memnew(QuickOpenResultContainer);
  112. container->connect("result_clicked", callable_mp(this, &EditorQuickOpenDialog::ok_pressed));
  113. vbc->add_child(container);
  114. }
  115. search_box->connect(SceneStringName(text_changed), callable_mp(this, &EditorQuickOpenDialog::_search_box_text_changed));
  116. search_box->connect(SceneStringName(gui_input), callable_mp(container, &QuickOpenResultContainer::handle_search_box_input));
  117. register_text_enter(search_box);
  118. get_ok_button()->hide();
  119. }
  120. String EditorQuickOpenDialog::get_dialog_title(const Vector<StringName> &p_base_types) {
  121. if (p_base_types.size() > 1) {
  122. return TTR("Select Resource");
  123. }
  124. if (p_base_types[0] == SNAME("PackedScene")) {
  125. return TTR("Select Scene");
  126. }
  127. return TTR("Select") + " " + p_base_types[0];
  128. }
  129. void EditorQuickOpenDialog::popup_dialog(const Vector<StringName> &p_base_types, const Callable &p_item_selected_callback) {
  130. ERR_FAIL_COND(p_base_types.is_empty());
  131. ERR_FAIL_COND(!p_item_selected_callback.is_valid());
  132. item_selected_callback = p_item_selected_callback;
  133. container->init(p_base_types);
  134. get_ok_button()->set_disabled(container->has_nothing_selected());
  135. set_title(get_dialog_title(p_base_types));
  136. popup_centered_clamped(Size2(780, 650) * EDSCALE, 0.8f);
  137. search_box->grab_focus();
  138. }
  139. void EditorQuickOpenDialog::ok_pressed() {
  140. item_selected_callback.call(container->get_selected());
  141. container->save_selected_item();
  142. container->cleanup();
  143. search_box->clear();
  144. hide();
  145. }
  146. void EditorQuickOpenDialog::cancel_pressed() {
  147. container->cleanup();
  148. search_box->clear();
  149. }
  150. void EditorQuickOpenDialog::_search_box_text_changed(const String &p_query) {
  151. container->set_query_and_update(p_query);
  152. get_ok_button()->set_disabled(container->has_nothing_selected());
  153. }
  154. //------------------------- Result Container
  155. void style_button(Button *p_button) {
  156. p_button->set_flat(true);
  157. p_button->set_focus_mode(Control::FOCUS_NONE);
  158. p_button->set_default_cursor_shape(Control::CURSOR_POINTING_HAND);
  159. }
  160. QuickOpenResultContainer::QuickOpenResultContainer() {
  161. set_h_size_flags(Control::SIZE_EXPAND_FILL);
  162. set_v_size_flags(Control::SIZE_EXPAND_FILL);
  163. add_theme_constant_override("separation", 0);
  164. history_file.instantiate();
  165. {
  166. // Results section
  167. panel_container = memnew(PanelContainer);
  168. panel_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  169. add_child(panel_container);
  170. {
  171. // No search results
  172. no_results_container = memnew(CenterContainer);
  173. no_results_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  174. no_results_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  175. panel_container->add_child(no_results_container);
  176. no_results_label = memnew(Label);
  177. no_results_label->add_theme_font_size_override(SceneStringName(font_size), 24 * EDSCALE);
  178. no_results_container->add_child(no_results_label);
  179. no_results_container->hide();
  180. }
  181. {
  182. // Search results
  183. scroll_container = memnew(ScrollContainer);
  184. scroll_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  185. scroll_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  186. scroll_container->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED);
  187. scroll_container->hide();
  188. panel_container->add_child(scroll_container);
  189. list = memnew(VBoxContainer);
  190. list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  191. list->add_theme_constant_override(SNAME("separation"), 0);
  192. list->hide();
  193. scroll_container->add_child(list);
  194. grid = memnew(HFlowContainer);
  195. grid->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  196. grid->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  197. grid->add_theme_constant_override(SNAME("v_separation"), 0);
  198. grid->add_theme_constant_override(SNAME("h_separation"), 0);
  199. grid->hide();
  200. scroll_container->add_child(grid);
  201. file_context_menu = memnew(PopupMenu);
  202. file_context_menu->add_item(TTR("Show in FileSystem"), FILE_SHOW_IN_FILESYSTEM);
  203. file_context_menu->add_item(TTR("Show in File Manager"), FILE_SHOW_IN_FILE_MANAGER);
  204. file_context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &QuickOpenResultContainer::_menu_option));
  205. file_context_menu->hide();
  206. scroll_container->add_child(file_context_menu);
  207. }
  208. }
  209. {
  210. // Selected filepath
  211. file_details_path = memnew(Label);
  212. file_details_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  213. file_details_path->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER);
  214. file_details_path->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
  215. add_child(file_details_path);
  216. }
  217. {
  218. // Bottom bar
  219. HBoxContainer *bottom_bar = memnew(HBoxContainer);
  220. bottom_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  221. bottom_bar->set_alignment(ALIGNMENT_END);
  222. bottom_bar->add_theme_constant_override("separation", 3);
  223. add_child(bottom_bar);
  224. fuzzy_search_toggle = memnew(CheckButton);
  225. style_button(fuzzy_search_toggle);
  226. fuzzy_search_toggle->set_text(TTR("Fuzzy Search"));
  227. fuzzy_search_toggle->set_tooltip_text(TTR("Enable fuzzy matching"));
  228. fuzzy_search_toggle->connect(SceneStringName(toggled), callable_mp(this, &QuickOpenResultContainer::_toggle_fuzzy_search));
  229. bottom_bar->add_child(fuzzy_search_toggle);
  230. include_addons_toggle = memnew(CheckButton);
  231. style_button(include_addons_toggle);
  232. include_addons_toggle->set_text(TTR("Addons"));
  233. include_addons_toggle->set_tooltip_text(TTR("Include files from addons"));
  234. include_addons_toggle->connect(SceneStringName(toggled), callable_mp(this, &QuickOpenResultContainer::_toggle_include_addons));
  235. bottom_bar->add_child(include_addons_toggle);
  236. VSeparator *vsep = memnew(VSeparator);
  237. vsep->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  238. vsep->set_custom_minimum_size(Size2i(0, 14 * EDSCALE));
  239. bottom_bar->add_child(vsep);
  240. display_mode_toggle = memnew(Button);
  241. style_button(display_mode_toggle);
  242. display_mode_toggle->connect(SceneStringName(pressed), callable_mp(this, &QuickOpenResultContainer::_toggle_display_mode));
  243. bottom_bar->add_child(display_mode_toggle);
  244. }
  245. }
  246. void QuickOpenResultContainer::_menu_option(int p_option) {
  247. switch (p_option) {
  248. case FILE_SHOW_IN_FILESYSTEM: {
  249. FileSystemDock::get_singleton()->navigate_to_path(get_selected());
  250. } break;
  251. case FILE_SHOW_IN_FILE_MANAGER: {
  252. String dir = ProjectSettings::get_singleton()->globalize_path(get_selected());
  253. OS::get_singleton()->shell_show_in_file_manager(dir, true);
  254. } break;
  255. }
  256. }
  257. void QuickOpenResultContainer::_ensure_result_vector_capacity() {
  258. int target_size = EDITOR_GET("filesystem/quick_open_dialog/max_results");
  259. int initial_size = result_items.size();
  260. for (int i = target_size; i < initial_size; i++) {
  261. result_items[i]->queue_free();
  262. }
  263. result_items.resize(target_size);
  264. for (int i = initial_size; i < target_size; i++) {
  265. QuickOpenResultItem *item = memnew(QuickOpenResultItem);
  266. item->connect(SceneStringName(gui_input), callable_mp(this, &QuickOpenResultContainer::_item_input).bind(i));
  267. result_items.write[i] = item;
  268. if (!never_opened) {
  269. _layout_result_item(item);
  270. }
  271. }
  272. }
  273. void QuickOpenResultContainer::init(const Vector<StringName> &p_base_types) {
  274. _ensure_result_vector_capacity();
  275. base_types = p_base_types;
  276. const int display_mode_behavior = EDITOR_GET("filesystem/quick_open_dialog/default_display_mode");
  277. const bool adaptive_display_mode = (display_mode_behavior == 0);
  278. const bool first_open = never_opened;
  279. if (adaptive_display_mode) {
  280. _set_display_mode(get_adaptive_display_mode(p_base_types));
  281. } else if (never_opened) {
  282. int last = EditorSettings::get_singleton()->get_project_metadata("quick_open_dialog", "last_mode", (int)QuickOpenDisplayMode::LIST);
  283. _set_display_mode((QuickOpenDisplayMode)last);
  284. }
  285. const bool fuzzy_matching = EDITOR_GET("filesystem/quick_open_dialog/enable_fuzzy_matching");
  286. const bool include_addons = EDITOR_GET("filesystem/quick_open_dialog/include_addons");
  287. fuzzy_search_toggle->set_pressed_no_signal(fuzzy_matching);
  288. include_addons_toggle->set_pressed_no_signal(include_addons);
  289. never_opened = false;
  290. const bool enable_highlights = EDITOR_GET("filesystem/quick_open_dialog/show_search_highlight");
  291. for (QuickOpenResultItem *E : result_items) {
  292. E->enable_highlights = enable_highlights;
  293. }
  294. if (first_open && history_file->load(_get_cache_file_path()) == OK) {
  295. // Load history when opening for the first time.
  296. file_type_icons.insert(SNAME("__default_icon"), get_editor_theme_icon(SNAME("Object")));
  297. List<String> history_keys;
  298. history_file->get_section_keys("selected_history", &history_keys);
  299. for (const String &type : history_keys) {
  300. const StringName type_name = type;
  301. const PackedStringArray paths = history_file->get_value("selected_history", type);
  302. Vector<QuickOpenResultCandidate> loaded_candidates;
  303. loaded_candidates.resize(paths.size());
  304. {
  305. QuickOpenResultCandidate *candidates_write = loaded_candidates.ptrw();
  306. int i = 0;
  307. for (const String &path : paths) {
  308. if (!ResourceLoader::exists(path)) {
  309. continue;
  310. }
  311. filetypes.insert(path, type_name);
  312. QuickOpenResultCandidate candidate;
  313. _setup_candidate(candidate, path);
  314. candidates_write[i] = candidate;
  315. i++;
  316. }
  317. loaded_candidates.resize(i);
  318. selected_history.insert(type, loaded_candidates);
  319. }
  320. }
  321. }
  322. _create_initial_results();
  323. }
  324. void QuickOpenResultContainer::_create_initial_results() {
  325. file_type_icons.clear();
  326. file_type_icons.insert(SNAME("__default_icon"), get_editor_theme_icon(SNAME("Object")));
  327. filepaths.clear();
  328. filetypes.clear();
  329. _find_filepaths_in_folder(EditorFileSystem::get_singleton()->get_filesystem(), include_addons_toggle->is_pressed());
  330. max_total_results = MIN(filepaths.size(), result_items.size());
  331. update_results();
  332. }
  333. void QuickOpenResultContainer::_find_filepaths_in_folder(EditorFileSystemDirectory *p_directory, bool p_include_addons) {
  334. for (int i = 0; i < p_directory->get_subdir_count(); i++) {
  335. if (p_include_addons || p_directory->get_name() != "addons") {
  336. _find_filepaths_in_folder(p_directory->get_subdir(i), p_include_addons);
  337. }
  338. }
  339. for (int i = 0; i < p_directory->get_file_count(); i++) {
  340. String file_path = p_directory->get_file_path(i);
  341. const StringName engine_type = p_directory->get_file_type(i);
  342. const StringName script_type = p_directory->get_file_resource_script_class(i);
  343. const bool is_engine_type = script_type == StringName();
  344. const StringName &actual_type = is_engine_type ? engine_type : script_type;
  345. for (const StringName &parent_type : base_types) {
  346. bool is_valid = ClassDB::is_parent_class(engine_type, parent_type) || (!is_engine_type && EditorNode::get_editor_data().script_class_is_parent(script_type, parent_type));
  347. if (is_valid) {
  348. filepaths.append(file_path);
  349. filetypes.insert(file_path, actual_type);
  350. break; // Stop testing base types as soon as we get a match.
  351. }
  352. }
  353. }
  354. }
  355. void QuickOpenResultContainer::set_query_and_update(const String &p_query) {
  356. query = p_query;
  357. update_results();
  358. }
  359. void QuickOpenResultContainer::_setup_candidate(QuickOpenResultCandidate &p_candidate, const String &p_filepath) {
  360. ResourceUID::ID id = EditorFileSystem::get_singleton()->get_file_uid(p_filepath);
  361. if (id == ResourceUID::INVALID_ID) {
  362. p_candidate.file_path = p_filepath;
  363. } else {
  364. p_candidate.file_path = ResourceUID::get_singleton()->id_to_text(id);
  365. }
  366. p_candidate.result = nullptr;
  367. StringName actual_type;
  368. {
  369. StringName *actual_type_ptr = filetypes.lookup_ptr(p_filepath);
  370. if (actual_type_ptr) {
  371. actual_type = *actual_type_ptr;
  372. } else {
  373. ERR_PRINT(vformat("EditorQuickOpenDialog: No type for path %s.", p_filepath));
  374. }
  375. }
  376. EditorResourcePreview::PreviewItem item = EditorResourcePreview::get_singleton()->get_resource_preview_if_available(p_filepath);
  377. if (item.preview.is_valid()) {
  378. p_candidate.thumbnail = item.preview;
  379. } else if (file_type_icons.has(actual_type)) {
  380. p_candidate.thumbnail = *file_type_icons.lookup_ptr(actual_type);
  381. } else if (has_theme_icon(actual_type, EditorStringName(EditorIcons))) {
  382. p_candidate.thumbnail = get_editor_theme_icon(actual_type);
  383. file_type_icons.insert(actual_type, p_candidate.thumbnail);
  384. } else {
  385. p_candidate.thumbnail = *file_type_icons.lookup_ptr(SNAME("__default_icon"));
  386. }
  387. }
  388. void QuickOpenResultContainer::_setup_candidate(QuickOpenResultCandidate &p_candidate, const FuzzySearchResult &p_result) {
  389. _setup_candidate(p_candidate, p_result.target);
  390. p_candidate.result = &p_result;
  391. }
  392. void QuickOpenResultContainer::update_results() {
  393. showing_history = false;
  394. candidates.clear();
  395. if (query.is_empty()) {
  396. _use_default_candidates();
  397. } else {
  398. _score_and_sort_candidates();
  399. }
  400. _update_result_items(MIN(candidates.size(), max_total_results), 0);
  401. }
  402. void QuickOpenResultContainer::_use_default_candidates() {
  403. if (filepaths.size() <= SHOW_ALL_FILES_THRESHOLD) {
  404. candidates.resize(filepaths.size());
  405. QuickOpenResultCandidate *candidates_write = candidates.ptrw();
  406. for (const String &filepath : filepaths) {
  407. _setup_candidate(*candidates_write++, filepath);
  408. }
  409. } else if (base_types.size() == 1) {
  410. Vector<QuickOpenResultCandidate> *history = selected_history.lookup_ptr(base_types[0]);
  411. if (history) {
  412. showing_history = true;
  413. candidates.append_array(*history);
  414. }
  415. }
  416. }
  417. void QuickOpenResultContainer::_update_fuzzy_search_results() {
  418. FuzzySearch fuzzy_search;
  419. fuzzy_search.start_offset = 6; // Don't match against "res://" at the start of each filepath.
  420. fuzzy_search.set_query(query);
  421. fuzzy_search.max_results = max_total_results;
  422. bool fuzzy_matching = EDITOR_GET("filesystem/quick_open_dialog/enable_fuzzy_matching");
  423. int max_misses = EDITOR_GET("filesystem/quick_open_dialog/max_fuzzy_misses");
  424. fuzzy_search.allow_subsequences = fuzzy_matching;
  425. fuzzy_search.max_misses = fuzzy_matching ? max_misses : 0;
  426. fuzzy_search.search_all(filepaths, search_results);
  427. }
  428. void QuickOpenResultContainer::_score_and_sort_candidates() {
  429. _update_fuzzy_search_results();
  430. candidates.resize(search_results.size());
  431. QuickOpenResultCandidate *candidates_write = candidates.ptrw();
  432. for (const FuzzySearchResult &result : search_results) {
  433. _setup_candidate(*candidates_write++, result);
  434. }
  435. }
  436. void QuickOpenResultContainer::_update_result_items(int p_new_visible_results_count, int p_new_selection_index) {
  437. // Only need to update items that were not hidden in previous update.
  438. int num_items_needing_updates = MAX(num_visible_results, p_new_visible_results_count);
  439. num_visible_results = p_new_visible_results_count;
  440. for (int i = 0; i < num_items_needing_updates; i++) {
  441. QuickOpenResultItem *item = result_items[i];
  442. if (i < num_visible_results) {
  443. item->set_content(candidates[i]);
  444. } else {
  445. item->reset();
  446. }
  447. };
  448. const bool any_results = num_visible_results > 0;
  449. _select_item(any_results ? p_new_selection_index : -1);
  450. scroll_container->set_visible(any_results);
  451. no_results_container->set_visible(!any_results);
  452. if (!any_results) {
  453. if (filepaths.is_empty()) {
  454. no_results_label->set_text(TTR("No files found for this type"));
  455. } else if (query.is_empty()) {
  456. no_results_label->set_text(TTR("Start searching to find files..."));
  457. } else {
  458. no_results_label->set_text(TTR("No results found"));
  459. }
  460. }
  461. }
  462. void QuickOpenResultContainer::handle_search_box_input(const Ref<InputEvent> &p_ie) {
  463. if (num_visible_results < 0) {
  464. return;
  465. }
  466. Ref<InputEventKey> key_event = p_ie;
  467. if (key_event.is_valid() && key_event->is_pressed()) {
  468. bool move_selection = false;
  469. switch (key_event->get_keycode()) {
  470. case Key::UP:
  471. case Key::DOWN:
  472. case Key::PAGEUP:
  473. case Key::PAGEDOWN: {
  474. move_selection = true;
  475. } break;
  476. case Key::LEFT:
  477. case Key::RIGHT: {
  478. if (content_display_mode == QuickOpenDisplayMode::GRID) {
  479. // Maybe strip off the shift modifier to allow non-selecting navigation by character?
  480. if (key_event->get_modifiers_mask() == 0) {
  481. move_selection = true;
  482. }
  483. }
  484. } break;
  485. default:
  486. break; // Let the event through so it will reach the search box.
  487. }
  488. if (move_selection) {
  489. _move_selection_index(key_event->get_keycode());
  490. queue_redraw();
  491. accept_event();
  492. }
  493. }
  494. }
  495. void QuickOpenResultContainer::_move_selection_index(Key p_key) {
  496. // Don't move selection if there are no results.
  497. if (num_visible_results <= 0) {
  498. return;
  499. }
  500. const int max_index = num_visible_results - 1;
  501. int idx = selection_index;
  502. if (content_display_mode == QuickOpenDisplayMode::LIST) {
  503. if (p_key == Key::UP) {
  504. idx = (idx == 0) ? max_index : (idx - 1);
  505. } else if (p_key == Key::DOWN) {
  506. idx = (idx == max_index) ? 0 : (idx + 1);
  507. } else if (p_key == Key::PAGEUP) {
  508. idx = (idx == 0) ? idx : MAX(idx - 10, 0);
  509. } else if (p_key == Key::PAGEDOWN) {
  510. idx = (idx == max_index) ? idx : MIN(idx + 10, max_index);
  511. }
  512. } else {
  513. int column_count = grid->get_line_max_child_count();
  514. if (p_key == Key::LEFT) {
  515. idx = (idx == 0) ? max_index : (idx - 1);
  516. } else if (p_key == Key::RIGHT) {
  517. idx = (idx == max_index) ? 0 : (idx + 1);
  518. } else if (p_key == Key::UP) {
  519. idx = (idx == 0) ? max_index : MAX(idx - column_count, 0);
  520. } else if (p_key == Key::DOWN) {
  521. idx = (idx == max_index) ? 0 : MIN(idx + column_count, max_index);
  522. } else if (p_key == Key::PAGEUP) {
  523. idx = (idx == 0) ? idx : MAX(idx - (3 * column_count), 0);
  524. } else if (p_key == Key::PAGEDOWN) {
  525. idx = (idx == max_index) ? idx : MIN(idx + (3 * column_count), max_index);
  526. }
  527. }
  528. _select_item(idx);
  529. }
  530. void QuickOpenResultContainer::_select_item(int p_index) {
  531. if (!has_nothing_selected()) {
  532. result_items[selection_index]->highlight_item(false);
  533. }
  534. selection_index = p_index;
  535. if (has_nothing_selected()) {
  536. file_details_path->set_text("");
  537. return;
  538. }
  539. result_items[selection_index]->highlight_item(true);
  540. file_details_path->set_text(get_selected() + (showing_history ? TTR(" (recently opened)") : ""));
  541. const QuickOpenResultItem *item = result_items[selection_index];
  542. // Copied from Tree.
  543. const int selected_position = item->get_position().y;
  544. const int selected_size = item->get_size().y;
  545. const int scroll_window_size = scroll_container->get_size().y;
  546. const int scroll_position = scroll_container->get_v_scroll();
  547. if (selected_position <= scroll_position) {
  548. scroll_container->set_v_scroll(selected_position);
  549. } else if (selected_position + selected_size > scroll_position + scroll_window_size) {
  550. scroll_container->set_v_scroll(selected_position + selected_size - scroll_window_size);
  551. }
  552. }
  553. void QuickOpenResultContainer::_item_input(const Ref<InputEvent> &p_ev, int p_index) {
  554. Ref<InputEventMouseButton> mb = p_ev;
  555. if (mb.is_valid() && mb->is_pressed()) {
  556. if (mb->get_button_index() == MouseButton::LEFT) {
  557. _select_item(p_index);
  558. emit_signal(SNAME("result_clicked"));
  559. } else if (mb->get_button_index() == MouseButton::RIGHT) {
  560. _select_item(p_index);
  561. file_context_menu->set_position(result_items[p_index]->get_screen_position() + mb->get_position());
  562. file_context_menu->reset_size();
  563. file_context_menu->popup();
  564. }
  565. }
  566. }
  567. void QuickOpenResultContainer::_toggle_fuzzy_search(bool p_pressed) {
  568. EditorSettings::get_singleton()->set("filesystem/quick_open_dialog/enable_fuzzy_matching", p_pressed);
  569. update_results();
  570. }
  571. String QuickOpenResultContainer::_get_cache_file_path() const {
  572. return EditorPaths::get_singleton()->get_project_settings_dir().path_join("quick_open_dialog_cache.cfg");
  573. }
  574. void QuickOpenResultContainer::_toggle_include_addons(bool p_pressed) {
  575. EditorSettings::get_singleton()->set("filesystem/quick_open_dialog/include_addons", p_pressed);
  576. cleanup();
  577. _create_initial_results();
  578. }
  579. void QuickOpenResultContainer::_toggle_display_mode() {
  580. QuickOpenDisplayMode new_display_mode = (content_display_mode == QuickOpenDisplayMode::LIST) ? QuickOpenDisplayMode::GRID : QuickOpenDisplayMode::LIST;
  581. _set_display_mode(new_display_mode);
  582. }
  583. CanvasItem *QuickOpenResultContainer::_get_result_root() {
  584. if (content_display_mode == QuickOpenDisplayMode::LIST) {
  585. return list;
  586. } else {
  587. return grid;
  588. }
  589. }
  590. void QuickOpenResultContainer::_layout_result_item(QuickOpenResultItem *item) {
  591. item->set_display_mode(content_display_mode);
  592. Node *parent = item->get_parent();
  593. if (parent) {
  594. parent->remove_child(item);
  595. }
  596. _get_result_root()->add_child(item);
  597. }
  598. void QuickOpenResultContainer::_set_display_mode(QuickOpenDisplayMode p_display_mode) {
  599. CanvasItem *prev_root = _get_result_root();
  600. if (prev_root->is_visible() && content_display_mode == p_display_mode) {
  601. return;
  602. }
  603. content_display_mode = p_display_mode;
  604. CanvasItem *next_root = _get_result_root();
  605. EditorSettings::get_singleton()->set_project_metadata("quick_open_dialog", "last_mode", (int)content_display_mode);
  606. prev_root->hide();
  607. next_root->show();
  608. for (QuickOpenResultItem *item : result_items) {
  609. _layout_result_item(item);
  610. }
  611. _update_result_items(num_visible_results, selection_index);
  612. if (content_display_mode == QuickOpenDisplayMode::LIST) {
  613. display_mode_toggle->set_button_icon(get_editor_theme_icon(SNAME("FileThumbnail")));
  614. display_mode_toggle->set_tooltip_text(TTR("Grid view"));
  615. } else {
  616. display_mode_toggle->set_button_icon(get_editor_theme_icon(SNAME("FileList")));
  617. display_mode_toggle->set_tooltip_text(TTR("List view"));
  618. }
  619. }
  620. bool QuickOpenResultContainer::has_nothing_selected() const {
  621. return selection_index < 0;
  622. }
  623. String QuickOpenResultContainer::get_selected() const {
  624. ERR_FAIL_COND_V_MSG(has_nothing_selected(), String(), "Tried to get selected file, but nothing was selected.");
  625. return ResourceUID::ensure_path(candidates[selection_index].file_path);
  626. }
  627. QuickOpenDisplayMode QuickOpenResultContainer::get_adaptive_display_mode(const Vector<StringName> &p_base_types) {
  628. static const Vector<StringName> grid_preferred_types = {
  629. "Font",
  630. "Texture2D",
  631. "Material",
  632. "Mesh"
  633. };
  634. for (const StringName &type : grid_preferred_types) {
  635. for (const StringName &base_type : p_base_types) {
  636. if (base_type == type || ClassDB::is_parent_class(base_type, type)) {
  637. return QuickOpenDisplayMode::GRID;
  638. }
  639. }
  640. }
  641. return QuickOpenDisplayMode::LIST;
  642. }
  643. void QuickOpenResultContainer::save_selected_item() {
  644. if (base_types.size() > 1) {
  645. // Getting the type of the file and checking which base type it belongs to should be possible.
  646. // However, for now these are not supported, and we don't record this.
  647. return;
  648. }
  649. const StringName &base_type = base_types[0];
  650. QuickOpenResultCandidate &selected = candidates.write[selection_index];
  651. Vector<QuickOpenResultCandidate> *type_history = selected_history.lookup_ptr(base_type);
  652. if (!type_history) {
  653. selected_history.insert(base_type, Vector<QuickOpenResultCandidate>());
  654. type_history = selected_history.lookup_ptr(base_type);
  655. } else {
  656. for (int i = 0; i < type_history->size(); i++) {
  657. if (selected.file_path == type_history->get(i).file_path) {
  658. type_history->remove_at(i);
  659. break;
  660. }
  661. }
  662. }
  663. selected.result = nullptr;
  664. type_history->insert(0, selected);
  665. if (type_history->size() > MAX_HISTORY_SIZE) {
  666. type_history->resize(MAX_HISTORY_SIZE);
  667. }
  668. PackedStringArray paths;
  669. paths.resize(type_history->size());
  670. {
  671. String *paths_write = paths.ptrw();
  672. int i = 0;
  673. for (const QuickOpenResultCandidate &candidate : *type_history) {
  674. paths_write[i] = candidate.file_path;
  675. i++;
  676. }
  677. }
  678. history_file->set_value("selected_history", base_type, paths);
  679. history_file->save(_get_cache_file_path());
  680. }
  681. void QuickOpenResultContainer::cleanup() {
  682. num_visible_results = 0;
  683. candidates.clear();
  684. _select_item(-1);
  685. for (QuickOpenResultItem *item : result_items) {
  686. item->reset();
  687. }
  688. }
  689. void QuickOpenResultContainer::_notification(int p_what) {
  690. switch (p_what) {
  691. case NOTIFICATION_THEME_CHANGED: {
  692. Color text_color = get_theme_color("font_readonly_color", EditorStringName(Editor));
  693. file_details_path->add_theme_color_override(SceneStringName(font_color), text_color);
  694. no_results_label->add_theme_color_override(SceneStringName(font_color), text_color);
  695. panel_container->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
  696. if (content_display_mode == QuickOpenDisplayMode::LIST) {
  697. display_mode_toggle->set_button_icon(get_editor_theme_icon(SNAME("FileThumbnail")));
  698. } else {
  699. display_mode_toggle->set_button_icon(get_editor_theme_icon(SNAME("FileList")));
  700. }
  701. } break;
  702. }
  703. }
  704. void QuickOpenResultContainer::_bind_methods() {
  705. ADD_SIGNAL(MethodInfo("result_clicked"));
  706. }
  707. //------------------------- Result Item
  708. QuickOpenResultItem::QuickOpenResultItem() {
  709. set_focus_mode(FocusMode::FOCUS_ALL);
  710. _set_enabled(false);
  711. set_default_cursor_shape(CURSOR_POINTING_HAND);
  712. list_item = memnew(QuickOpenResultListItem);
  713. list_item->hide();
  714. add_child(list_item);
  715. grid_item = memnew(QuickOpenResultGridItem);
  716. grid_item->hide();
  717. add_child(grid_item);
  718. }
  719. void QuickOpenResultItem::set_display_mode(QuickOpenDisplayMode p_display_mode) {
  720. if (p_display_mode == QuickOpenDisplayMode::LIST) {
  721. grid_item->hide();
  722. grid_item->reset();
  723. list_item->show();
  724. } else {
  725. list_item->hide();
  726. list_item->reset();
  727. grid_item->show();
  728. }
  729. queue_redraw();
  730. }
  731. void QuickOpenResultItem::set_content(const QuickOpenResultCandidate &p_candidate) {
  732. _set_enabled(true);
  733. if (list_item->is_visible()) {
  734. list_item->set_content(p_candidate, enable_highlights);
  735. } else {
  736. grid_item->set_content(p_candidate, enable_highlights);
  737. }
  738. queue_redraw();
  739. }
  740. void QuickOpenResultItem::reset() {
  741. _set_enabled(false);
  742. is_hovering = false;
  743. is_selected = false;
  744. list_item->reset();
  745. grid_item->reset();
  746. }
  747. void QuickOpenResultItem::highlight_item(bool p_enabled) {
  748. is_selected = p_enabled;
  749. if (list_item->is_visible()) {
  750. if (p_enabled) {
  751. list_item->highlight_item(highlighted_font_color);
  752. } else {
  753. list_item->remove_highlight();
  754. }
  755. } else {
  756. if (p_enabled) {
  757. grid_item->highlight_item(highlighted_font_color);
  758. } else {
  759. grid_item->remove_highlight();
  760. }
  761. }
  762. queue_redraw();
  763. }
  764. void QuickOpenResultItem::_set_enabled(bool p_enabled) {
  765. set_visible(p_enabled);
  766. set_process(p_enabled);
  767. set_process_input(p_enabled);
  768. }
  769. void QuickOpenResultItem::_notification(int p_what) {
  770. switch (p_what) {
  771. case NOTIFICATION_MOUSE_ENTER:
  772. case NOTIFICATION_MOUSE_EXIT: {
  773. is_hovering = is_visible() && p_what == NOTIFICATION_MOUSE_ENTER;
  774. queue_redraw();
  775. } break;
  776. case NOTIFICATION_THEME_CHANGED: {
  777. selected_stylebox = get_theme_stylebox("selected", "Tree");
  778. hovering_stylebox = get_theme_stylebox(SNAME("hovered"), "Tree");
  779. highlighted_font_color = get_theme_color("font_focus_color", EditorStringName(Editor));
  780. } break;
  781. case NOTIFICATION_DRAW: {
  782. if (is_selected) {
  783. draw_style_box(selected_stylebox, Rect2(Point2(), get_size()));
  784. } else if (is_hovering) {
  785. draw_style_box(hovering_stylebox, Rect2(Point2(), get_size()));
  786. }
  787. } break;
  788. }
  789. }
  790. //----------------- List item
  791. static Vector2i _get_path_interval(const Vector2i &p_interval, int p_dir_index) {
  792. if (p_interval.x >= p_dir_index || p_interval.y < 1) {
  793. return { -1, -1 };
  794. }
  795. return { p_interval.x, MIN(p_interval.x + p_interval.y, p_dir_index) - p_interval.x };
  796. }
  797. static Vector2i _get_name_interval(const Vector2i &p_interval, int p_dir_index) {
  798. if (p_interval.x + p_interval.y <= p_dir_index || p_interval.y < 1) {
  799. return { -1, -1 };
  800. }
  801. int first_name_idx = p_dir_index + 1;
  802. int start = MAX(p_interval.x, first_name_idx);
  803. return { start - first_name_idx, p_interval.y - start + p_interval.x };
  804. }
  805. QuickOpenResultListItem::QuickOpenResultListItem() {
  806. set_h_size_flags(Control::SIZE_EXPAND_FILL);
  807. add_theme_constant_override("margin_left", 6 * EDSCALE);
  808. add_theme_constant_override("margin_right", 6 * EDSCALE);
  809. hbc = memnew(HBoxContainer);
  810. hbc->add_theme_constant_override(SNAME("separation"), 4 * EDSCALE);
  811. add_child(hbc);
  812. const int max_size = 36 * EDSCALE;
  813. thumbnail = memnew(TextureRect);
  814. thumbnail->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
  815. thumbnail->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  816. thumbnail->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE);
  817. thumbnail->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
  818. thumbnail->set_custom_minimum_size(Size2i(max_size, max_size));
  819. hbc->add_child(thumbnail);
  820. text_container = memnew(VBoxContainer);
  821. text_container->add_theme_constant_override(SNAME("separation"), -7 * EDSCALE);
  822. text_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  823. text_container->set_v_size_flags(Control::SIZE_FILL);
  824. hbc->add_child(text_container);
  825. name = memnew(HighlightedLabel);
  826. name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  827. name->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
  828. name->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_LEFT);
  829. text_container->add_child(name);
  830. path = memnew(HighlightedLabel);
  831. path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  832. path->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
  833. path->add_theme_font_size_override(SceneStringName(font_size), 12 * EDSCALE);
  834. text_container->add_child(path);
  835. }
  836. void QuickOpenResultListItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) {
  837. thumbnail->set_texture(p_candidate.thumbnail);
  838. const String file_path = ResourceUID::ensure_path(p_candidate.file_path);
  839. name->set_text(file_path.get_file());
  840. path->set_text(file_path.get_base_dir());
  841. name->reset_highlights();
  842. path->reset_highlights();
  843. if (p_highlight && p_candidate.result != nullptr) {
  844. for (const FuzzyTokenMatch &match : p_candidate.result->token_matches) {
  845. for (const Vector2i &interval : match.substrings) {
  846. path->add_highlight(_get_path_interval(interval, p_candidate.result->dir_index));
  847. name->add_highlight(_get_name_interval(interval, p_candidate.result->dir_index));
  848. }
  849. }
  850. }
  851. }
  852. void QuickOpenResultListItem::reset() {
  853. thumbnail->set_texture(nullptr);
  854. name->set_text("");
  855. path->set_text("");
  856. name->reset_highlights();
  857. path->reset_highlights();
  858. }
  859. void QuickOpenResultListItem::highlight_item(const Color &p_color) {
  860. name->add_theme_color_override(SceneStringName(font_color), p_color);
  861. }
  862. void QuickOpenResultListItem::remove_highlight() {
  863. name->remove_theme_color_override(SceneStringName(font_color));
  864. }
  865. void QuickOpenResultListItem::_notification(int p_what) {
  866. switch (p_what) {
  867. case NOTIFICATION_THEME_CHANGED: {
  868. path->add_theme_color_override(SceneStringName(font_color), get_theme_color("font_disabled_color", EditorStringName(Editor)));
  869. } break;
  870. }
  871. }
  872. //--------------- Grid Item
  873. QuickOpenResultGridItem::QuickOpenResultGridItem() {
  874. set_custom_minimum_size(Size2i(120 * EDSCALE, 0));
  875. add_theme_constant_override("margin_top", 6 * EDSCALE);
  876. add_theme_constant_override("margin_left", 2 * EDSCALE);
  877. add_theme_constant_override("margin_right", 2 * EDSCALE);
  878. vbc = memnew(VBoxContainer);
  879. vbc->set_h_size_flags(Control::SIZE_FILL);
  880. vbc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  881. vbc->add_theme_constant_override(SNAME("separation"), 0);
  882. add_child(vbc);
  883. const int max_size = 64 * EDSCALE;
  884. thumbnail = memnew(TextureRect);
  885. thumbnail->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
  886. thumbnail->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  887. thumbnail->set_custom_minimum_size(Size2i(max_size, max_size));
  888. vbc->add_child(thumbnail);
  889. name = memnew(HighlightedLabel);
  890. name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  891. name->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
  892. name->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER);
  893. name->add_theme_font_size_override(SceneStringName(font_size), 13 * EDSCALE);
  894. vbc->add_child(name);
  895. }
  896. void QuickOpenResultGridItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) {
  897. thumbnail->set_texture(p_candidate.thumbnail);
  898. const String file_path = ResourceUID::ensure_path(p_candidate.file_path);
  899. name->set_text(file_path.get_file());
  900. name->set_tooltip_text(file_path);
  901. name->reset_highlights();
  902. if (p_highlight && p_candidate.result != nullptr) {
  903. for (const FuzzyTokenMatch &match : p_candidate.result->token_matches) {
  904. for (const Vector2i &interval : match.substrings) {
  905. name->add_highlight(_get_name_interval(interval, p_candidate.result->dir_index));
  906. }
  907. }
  908. }
  909. bool uses_icon = p_candidate.thumbnail->get_width() < (32 * EDSCALE);
  910. if (uses_icon || p_candidate.thumbnail->get_height() <= thumbnail->get_custom_minimum_size().y) {
  911. thumbnail->set_expand_mode(TextureRect::EXPAND_KEEP_SIZE);
  912. thumbnail->set_stretch_mode(TextureRect::StretchMode::STRETCH_KEEP_CENTERED);
  913. } else {
  914. thumbnail->set_expand_mode(TextureRect::EXPAND_FIT_WIDTH_PROPORTIONAL);
  915. thumbnail->set_stretch_mode(TextureRect::StretchMode::STRETCH_SCALE);
  916. }
  917. }
  918. void QuickOpenResultGridItem::reset() {
  919. thumbnail->set_texture(nullptr);
  920. name->set_text("");
  921. name->reset_highlights();
  922. }
  923. void QuickOpenResultGridItem::highlight_item(const Color &p_color) {
  924. name->add_theme_color_override(SceneStringName(font_color), p_color);
  925. }
  926. void QuickOpenResultGridItem::remove_highlight() {
  927. name->remove_theme_color_override(SceneStringName(font_color));
  928. }