editor_help_search.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. /**************************************************************************/
  2. /* editor_help_search.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_help_search.h"
  31. #include "core/os/keyboard.h"
  32. #include "editor/editor_feature_profile.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/editor_settings.h"
  35. #include "editor/editor_string_names.h"
  36. #include "editor/themes/editor_scale.h"
  37. #include "editor/themes/editor_theme_manager.h"
  38. bool EditorHelpSearch::_all_terms_in_name(const Vector<String> &p_terms, const String &p_name) const {
  39. for (int i = 0; i < p_terms.size(); i++) {
  40. if (!p_name.containsn(p_terms[i])) {
  41. return false;
  42. }
  43. }
  44. return true;
  45. }
  46. void EditorHelpSearch::_match_method_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::MethodDoc> &p_methods, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const {
  47. // Constructors, Methods, Operators...
  48. for (int i = 0; i < p_methods.size(); i++) {
  49. String method_name = p_methods[i].name.to_lower();
  50. if (_all_terms_in_name(p_terms, method_name) ||
  51. (p_term.begins_with(".") && method_name.begins_with(p_term.substr(1))) ||
  52. (p_term.ends_with("(") && method_name.ends_with(p_term.left(p_term.length() - 1).strip_edges())) ||
  53. (p_term.begins_with(".") && p_term.ends_with("(") && method_name == p_term.substr(1, p_term.length() - 2).strip_edges())) {
  54. r_result[vformat("class_%s:%s:%s", p_metatype, p_class_name, p_methods[i].name)] = vformat("%s > %s: %s", p_class_name, p_type, p_methods[i].name);
  55. }
  56. }
  57. }
  58. void EditorHelpSearch::_match_const_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::ConstantDoc> &p_constants, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const {
  59. for (int i = 0; i < p_constants.size(); i++) {
  60. String method_name = p_constants[i].name.to_lower();
  61. if (_all_terms_in_name(p_terms, method_name) ||
  62. (p_term.begins_with(".") && method_name.begins_with(p_term.substr(1))) ||
  63. (p_term.ends_with("(") && method_name.ends_with(p_term.left(p_term.length() - 1).strip_edges())) ||
  64. (p_term.begins_with(".") && p_term.ends_with("(") && method_name == p_term.substr(1, p_term.length() - 2).strip_edges())) {
  65. r_result[vformat("class_%s:%s:%s", p_metatype, p_class_name, p_constants[i].name)] = vformat("%s > %s: %s", p_class_name, p_type, p_constants[i].name);
  66. }
  67. }
  68. }
  69. void EditorHelpSearch::_match_property_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::PropertyDoc> &p_properties, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const {
  70. for (int i = 0; i < p_properties.size(); i++) {
  71. String method_name = p_properties[i].name.to_lower();
  72. if (_all_terms_in_name(p_terms, method_name) ||
  73. (p_term.begins_with(".") && method_name.begins_with(p_term.substr(1))) ||
  74. (p_term.ends_with("(") && method_name.ends_with(p_term.left(p_term.length() - 1).strip_edges())) ||
  75. (p_term.begins_with(".") && p_term.ends_with("(") && method_name == p_term.substr(1, p_term.length() - 2).strip_edges())) {
  76. r_result[vformat("class_%s:%s:%s", p_metatype, p_class_name, p_properties[i].name)] = vformat("%s > %s: %s", p_class_name, p_type, p_properties[i].name);
  77. }
  78. }
  79. }
  80. void EditorHelpSearch::_match_theme_property_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::ThemeItemDoc> &p_properties, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const {
  81. for (int i = 0; i < p_properties.size(); i++) {
  82. String method_name = p_properties[i].name.to_lower();
  83. if (_all_terms_in_name(p_terms, method_name) ||
  84. (p_term.begins_with(".") && method_name.begins_with(p_term.substr(1))) ||
  85. (p_term.ends_with("(") && method_name.ends_with(p_term.left(p_term.length() - 1).strip_edges())) ||
  86. (p_term.begins_with(".") && p_term.ends_with("(") && method_name == p_term.substr(1, p_term.length() - 2).strip_edges())) {
  87. r_result[vformat("class_%s:%s:%s", p_metatype, p_class_name, p_properties[i].name)] = vformat("%s > %s: %s", p_class_name, p_type, p_properties[i].name);
  88. }
  89. }
  90. }
  91. Dictionary EditorHelpSearch::_native_search_cb(const String &p_search_string, int p_result_limit) {
  92. Dictionary ret;
  93. const String &term = p_search_string.strip_edges().to_lower();
  94. Vector<String> terms = term.split_spaces();
  95. if (terms.is_empty()) {
  96. terms.append(term);
  97. }
  98. for (HashMap<String, DocData::ClassDoc>::Iterator iterator_doc = EditorHelp::get_doc_data()->class_list.begin(); iterator_doc; ++iterator_doc) {
  99. DocData::ClassDoc &class_doc = iterator_doc->value;
  100. if (class_doc.name.is_empty()) {
  101. continue;
  102. }
  103. if (class_doc.name.containsn(term)) {
  104. ret[vformat("class_name:%s", class_doc.name)] = class_doc.name;
  105. }
  106. if (term.length() > 1 || term == "@") {
  107. _match_method_name_and_push_back(term, terms, class_doc.constructors, TTRC("Constructor"), "method", class_doc.name, ret);
  108. _match_method_name_and_push_back(term, terms, class_doc.methods, TTRC("Method"), "method", class_doc.name, ret);
  109. _match_method_name_and_push_back(term, terms, class_doc.operators, TTRC("Operator"), "method", class_doc.name, ret);
  110. _match_method_name_and_push_back(term, terms, class_doc.signals, TTRC("Signal"), "signal", class_doc.name, ret);
  111. _match_const_name_and_push_back(term, terms, class_doc.constants, TTRC("Constant"), "constant", class_doc.name, ret);
  112. _match_property_name_and_push_back(term, terms, class_doc.properties, TTRC("Property"), "property", class_doc.name, ret);
  113. _match_theme_property_name_and_push_back(term, terms, class_doc.theme_properties, TTRC("Theme Property"), "theme_item", class_doc.name, ret);
  114. _match_method_name_and_push_back(term, terms, class_doc.annotations, TTRC("Annotation"), "annotation", class_doc.name, ret);
  115. }
  116. if (ret.size() > p_result_limit) {
  117. break;
  118. }
  119. }
  120. return ret;
  121. }
  122. void EditorHelpSearch::_native_action_cb(const String &p_item_string) {
  123. emit_signal(SNAME("go_to_help"), p_item_string);
  124. }
  125. void EditorHelpSearch::_update_results() {
  126. String term = search_box->get_text();
  127. int search_flags = filter_combo->get_selected_id();
  128. if (case_sensitive_button->is_pressed()) {
  129. search_flags |= SEARCH_CASE_SENSITIVE;
  130. }
  131. if (hierarchy_button->is_pressed()) {
  132. search_flags |= SEARCH_SHOW_HIERARCHY;
  133. }
  134. search = Ref<Runner>(memnew(Runner(results_tree, results_tree, &tree_cache, term, search_flags)));
  135. set_process(true);
  136. }
  137. void EditorHelpSearch::_search_box_gui_input(const Ref<InputEvent> &p_event) {
  138. // Redirect up and down navigational key events to the results list.
  139. Ref<InputEventKey> key = p_event;
  140. if (key.is_valid()) {
  141. switch (key->get_keycode()) {
  142. case Key::UP:
  143. case Key::DOWN:
  144. case Key::PAGEUP:
  145. case Key::PAGEDOWN: {
  146. results_tree->gui_input(key);
  147. search_box->accept_event();
  148. } break;
  149. default:
  150. break;
  151. }
  152. }
  153. }
  154. void EditorHelpSearch::_search_box_text_changed(const String &p_text) {
  155. _update_results();
  156. }
  157. void EditorHelpSearch::_filter_combo_item_selected(int p_option) {
  158. _update_results();
  159. }
  160. void EditorHelpSearch::_confirmed() {
  161. TreeItem *item = results_tree->get_selected();
  162. if (!item) {
  163. return;
  164. }
  165. // Activate the script editor and emit the signal with the documentation link to display.
  166. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  167. emit_signal(SNAME("go_to_help"), item->get_metadata(0));
  168. hide();
  169. }
  170. void EditorHelpSearch::_notification(int p_what) {
  171. switch (p_what) {
  172. case NOTIFICATION_ENTER_TREE: {
  173. if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_HELP)) {
  174. DisplayServer::get_singleton()->help_set_search_callbacks(callable_mp(this, &EditorHelpSearch::_native_search_cb), callable_mp(this, &EditorHelpSearch::_native_action_cb));
  175. }
  176. } break;
  177. case NOTIFICATION_EXIT_TREE: {
  178. if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_NATIVE_HELP)) {
  179. DisplayServer::get_singleton()->help_set_search_callbacks();
  180. }
  181. } break;
  182. case NOTIFICATION_VISIBILITY_CHANGED: {
  183. if (!is_visible()) {
  184. tree_cache.clear();
  185. callable_mp(results_tree, &Tree::clear).call_deferred(); // Wait for the Tree's mouse event propagation.
  186. get_ok_button()->set_disabled(true);
  187. EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "search_help", Rect2(get_position(), get_size()));
  188. }
  189. } break;
  190. case NOTIFICATION_READY: {
  191. connect("confirmed", callable_mp(this, &EditorHelpSearch::_confirmed));
  192. } break;
  193. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  194. if (!EditorThemeManager::is_generated_theme_outdated()) {
  195. break;
  196. }
  197. [[fallthrough]];
  198. }
  199. case NOTIFICATION_THEME_CHANGED: {
  200. const int icon_width = get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor));
  201. results_tree->add_theme_constant_override("icon_max_width", icon_width);
  202. search_box->set_right_icon(get_editor_theme_icon(SNAME("Search")));
  203. search_box->add_theme_icon_override("right_icon", get_editor_theme_icon(SNAME("Search")));
  204. case_sensitive_button->set_icon(get_editor_theme_icon(SNAME("MatchCase")));
  205. hierarchy_button->set_icon(get_editor_theme_icon(SNAME("ClassList")));
  206. if (is_visible()) {
  207. _update_results();
  208. }
  209. } break;
  210. case NOTIFICATION_PROCESS: {
  211. // Update background search.
  212. if (search.is_valid()) {
  213. if (search->work()) {
  214. // Search done.
  215. // Only point to the match if it's a new search, and not just reopening a old one.
  216. if (!old_search) {
  217. results_tree->ensure_cursor_is_visible();
  218. } else {
  219. old_search = false;
  220. }
  221. get_ok_button()->set_disabled(!results_tree->get_selected());
  222. search = Ref<Runner>();
  223. set_process(false);
  224. }
  225. } else {
  226. set_process(false);
  227. }
  228. } break;
  229. }
  230. }
  231. void EditorHelpSearch::_bind_methods() {
  232. ADD_SIGNAL(MethodInfo("go_to_help"));
  233. }
  234. void EditorHelpSearch::popup_dialog() {
  235. popup_dialog(search_box->get_text());
  236. }
  237. void EditorHelpSearch::popup_dialog(const String &p_term) {
  238. // Restore valid window bounds or pop up at default size.
  239. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "search_help", Rect2());
  240. if (saved_size != Rect2()) {
  241. popup(saved_size);
  242. } else {
  243. popup_centered_ratio(0.5F);
  244. }
  245. if (p_term.is_empty()) {
  246. search_box->clear();
  247. } else {
  248. if (old_term == p_term) {
  249. old_search = true;
  250. } else {
  251. old_term = p_term;
  252. }
  253. search_box->set_text(p_term);
  254. search_box->select_all();
  255. }
  256. search_box->grab_focus();
  257. _update_results();
  258. }
  259. EditorHelpSearch::EditorHelpSearch() {
  260. set_hide_on_ok(false);
  261. set_clamp_to_embedder(true);
  262. set_title(TTR("Search Help"));
  263. get_ok_button()->set_disabled(true);
  264. set_ok_button_text(TTR("Open"));
  265. // Split search and results area.
  266. VBoxContainer *vbox = memnew(VBoxContainer);
  267. add_child(vbox);
  268. // Create the search box and filter controls (at the top).
  269. HBoxContainer *hbox = memnew(HBoxContainer);
  270. vbox->add_child(hbox);
  271. search_box = memnew(LineEdit);
  272. search_box->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
  273. search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  274. search_box->set_clear_button_enabled(true);
  275. search_box->connect(SceneStringName(gui_input), callable_mp(this, &EditorHelpSearch::_search_box_gui_input));
  276. search_box->connect("text_changed", callable_mp(this, &EditorHelpSearch::_search_box_text_changed));
  277. register_text_enter(search_box);
  278. hbox->add_child(search_box);
  279. case_sensitive_button = memnew(Button);
  280. case_sensitive_button->set_theme_type_variation("FlatButton");
  281. case_sensitive_button->set_tooltip_text(TTR("Case Sensitive"));
  282. case_sensitive_button->connect(SceneStringName(pressed), callable_mp(this, &EditorHelpSearch::_update_results));
  283. case_sensitive_button->set_toggle_mode(true);
  284. case_sensitive_button->set_focus_mode(Control::FOCUS_NONE);
  285. hbox->add_child(case_sensitive_button);
  286. hierarchy_button = memnew(Button);
  287. hierarchy_button->set_theme_type_variation("FlatButton");
  288. hierarchy_button->set_tooltip_text(TTR("Show Hierarchy"));
  289. hierarchy_button->connect(SceneStringName(pressed), callable_mp(this, &EditorHelpSearch::_update_results));
  290. hierarchy_button->set_toggle_mode(true);
  291. hierarchy_button->set_pressed(true);
  292. hierarchy_button->set_focus_mode(Control::FOCUS_NONE);
  293. hbox->add_child(hierarchy_button);
  294. filter_combo = memnew(OptionButton);
  295. filter_combo->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
  296. filter_combo->set_stretch_ratio(0); // Fixed width.
  297. filter_combo->add_item(TTR("Display All"), SEARCH_ALL);
  298. filter_combo->add_separator();
  299. filter_combo->add_item(TTR("Classes Only"), SEARCH_CLASSES);
  300. filter_combo->add_item(TTR("Constructors Only"), SEARCH_CONSTRUCTORS);
  301. filter_combo->add_item(TTR("Methods Only"), SEARCH_METHODS);
  302. filter_combo->add_item(TTR("Operators Only"), SEARCH_OPERATORS);
  303. filter_combo->add_item(TTR("Signals Only"), SEARCH_SIGNALS);
  304. filter_combo->add_item(TTR("Annotations Only"), SEARCH_ANNOTATIONS);
  305. filter_combo->add_item(TTR("Constants Only"), SEARCH_CONSTANTS);
  306. filter_combo->add_item(TTR("Properties Only"), SEARCH_PROPERTIES);
  307. filter_combo->add_item(TTR("Theme Properties Only"), SEARCH_THEME_ITEMS);
  308. filter_combo->connect("item_selected", callable_mp(this, &EditorHelpSearch::_filter_combo_item_selected));
  309. hbox->add_child(filter_combo);
  310. // Create the results tree.
  311. results_tree = memnew(Tree);
  312. results_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  313. results_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  314. results_tree->set_columns(2);
  315. results_tree->set_column_title(0, TTR("Name"));
  316. results_tree->set_column_clip_content(0, true);
  317. results_tree->set_column_title(1, TTR("Member Type"));
  318. results_tree->set_column_expand(1, false);
  319. results_tree->set_column_custom_minimum_width(1, 150 * EDSCALE);
  320. results_tree->set_column_clip_content(1, true);
  321. results_tree->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
  322. results_tree->set_hide_root(true);
  323. results_tree->set_select_mode(Tree::SELECT_ROW);
  324. results_tree->connect("item_activated", callable_mp(this, &EditorHelpSearch::_confirmed));
  325. results_tree->connect("item_selected", callable_mp((BaseButton *)get_ok_button(), &BaseButton::set_disabled).bind(false));
  326. vbox->add_child(results_tree, true);
  327. }
  328. void EditorHelpSearch::TreeCache::clear() {
  329. for (const KeyValue<String, TreeItem *> &E : item_cache) {
  330. memdelete(E.value);
  331. }
  332. item_cache.clear();
  333. }
  334. bool EditorHelpSearch::Runner::_is_class_disabled_by_feature_profile(const StringName &p_class) {
  335. Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile();
  336. if (profile.is_null()) {
  337. return false;
  338. }
  339. StringName class_name = p_class;
  340. while (class_name != StringName()) {
  341. if (!ClassDB::class_exists(class_name)) {
  342. return false;
  343. }
  344. if (profile->is_class_disabled(class_name)) {
  345. return true;
  346. }
  347. class_name = ClassDB::get_parent_class(class_name);
  348. }
  349. return false;
  350. }
  351. bool EditorHelpSearch::Runner::_slice() {
  352. bool phase_done = false;
  353. switch (phase) {
  354. case PHASE_MATCH_CLASSES_INIT:
  355. phase_done = _phase_match_classes_init();
  356. break;
  357. case PHASE_MATCH_CLASSES:
  358. phase_done = _phase_match_classes();
  359. break;
  360. case PHASE_CLASS_ITEMS_INIT:
  361. phase_done = _phase_class_items_init();
  362. break;
  363. case PHASE_CLASS_ITEMS:
  364. phase_done = _phase_class_items();
  365. break;
  366. case PHASE_MEMBER_ITEMS_INIT:
  367. phase_done = _phase_member_items_init();
  368. break;
  369. case PHASE_MEMBER_ITEMS:
  370. phase_done = _phase_member_items();
  371. break;
  372. case PHASE_SELECT_MATCH:
  373. phase_done = _phase_select_match();
  374. break;
  375. case PHASE_MAX:
  376. return true;
  377. default:
  378. WARN_PRINT("Invalid or unhandled phase in EditorHelpSearch::Runner, aborting search.");
  379. return true;
  380. };
  381. if (phase_done) {
  382. phase++;
  383. }
  384. return false;
  385. }
  386. bool EditorHelpSearch::Runner::_phase_match_classes_init() {
  387. iterator_doc = nullptr;
  388. iterator_stack.clear();
  389. if (search_flags & SEARCH_SHOW_HIERARCHY) {
  390. iterator_stack.push_back(EditorHelp::get_doc_data()->inheriting[""].front());
  391. } else {
  392. iterator_doc = EditorHelp::get_doc_data()->class_list.begin();
  393. }
  394. matches.clear();
  395. matched_item = nullptr;
  396. match_highest_score = 0;
  397. terms = term.split_spaces();
  398. if (terms.is_empty()) {
  399. terms.append(term);
  400. }
  401. return true;
  402. }
  403. bool EditorHelpSearch::Runner::_phase_match_classes() {
  404. if (!iterator_doc && iterator_stack.is_empty()) {
  405. return true;
  406. }
  407. DocData::ClassDoc *class_doc = nullptr;
  408. if (iterator_doc) {
  409. class_doc = &iterator_doc->value;
  410. } else if (!iterator_stack.is_empty() && iterator_stack[iterator_stack.size() - 1]) {
  411. class_doc = EditorHelp::get_doc_data()->class_list.getptr(iterator_stack[iterator_stack.size() - 1]->get());
  412. }
  413. if (class_doc && class_doc->name.is_empty()) {
  414. class_doc = nullptr;
  415. }
  416. if (class_doc && !_is_class_disabled_by_feature_profile(class_doc->name)) {
  417. ClassMatch match;
  418. match.doc = class_doc;
  419. // Match class name.
  420. if (search_flags & SEARCH_CLASSES) {
  421. // If the search term is empty, add any classes which are not script docs or which don't start with
  422. // a double-quotation. This will ensure that only C++ classes and explicitly named classes will
  423. // be added.
  424. match.name = (term.is_empty() && (!class_doc->is_script_doc || class_doc->name[0] != '\"')) || _match_string(term, class_doc->name);
  425. match.keyword = _match_keywords(term, class_doc->keywords);
  426. }
  427. // Match members only if the term is long enough, to avoid slow performance from building a large tree.
  428. // Make an exception for annotations, since there are not that many of them.
  429. if (term.length() > 1 || term == "@") {
  430. if (search_flags & SEARCH_CONSTRUCTORS) {
  431. _match_method_name_and_push_back(class_doc->constructors, &match.constructors);
  432. }
  433. if (search_flags & SEARCH_METHODS) {
  434. _match_method_name_and_push_back(class_doc->methods, &match.methods);
  435. }
  436. if (search_flags & SEARCH_OPERATORS) {
  437. _match_method_name_and_push_back(class_doc->operators, &match.operators);
  438. }
  439. if (search_flags & SEARCH_SIGNALS) {
  440. for (int i = 0; i < class_doc->signals.size(); i++) {
  441. MemberMatch<DocData::MethodDoc> signal;
  442. signal.name = _all_terms_in_name(class_doc->signals[i].name);
  443. signal.keyword = _match_keywords_in_all_terms(class_doc->signals[i].keywords);
  444. if (signal.name || !signal.keyword.is_empty()) {
  445. signal.doc = const_cast<DocData::MethodDoc *>(&class_doc->signals[i]);
  446. match.signals.push_back(signal);
  447. }
  448. }
  449. }
  450. if (search_flags & SEARCH_CONSTANTS) {
  451. for (int i = 0; i < class_doc->constants.size(); i++) {
  452. MemberMatch<DocData::ConstantDoc> constant;
  453. constant.name = _all_terms_in_name(class_doc->constants[i].name);
  454. constant.keyword = _match_keywords_in_all_terms(class_doc->constants[i].keywords);
  455. if (constant.name || !constant.keyword.is_empty()) {
  456. constant.doc = const_cast<DocData::ConstantDoc *>(&class_doc->constants[i]);
  457. match.constants.push_back(constant);
  458. }
  459. }
  460. }
  461. if (search_flags & SEARCH_PROPERTIES) {
  462. for (int i = 0; i < class_doc->properties.size(); i++) {
  463. MemberMatch<DocData::PropertyDoc> property;
  464. property.name = _all_terms_in_name(class_doc->properties[i].name);
  465. property.keyword = _match_keywords_in_all_terms(class_doc->properties[i].keywords);
  466. if (property.name || !property.keyword.is_empty()) {
  467. property.doc = const_cast<DocData::PropertyDoc *>(&class_doc->properties[i]);
  468. match.properties.push_back(property);
  469. }
  470. }
  471. }
  472. if (search_flags & SEARCH_THEME_ITEMS) {
  473. for (int i = 0; i < class_doc->theme_properties.size(); i++) {
  474. MemberMatch<DocData::ThemeItemDoc> theme_property;
  475. theme_property.name = _all_terms_in_name(class_doc->theme_properties[i].name);
  476. theme_property.keyword = _match_keywords_in_all_terms(class_doc->theme_properties[i].keywords);
  477. if (theme_property.name || !theme_property.keyword.is_empty()) {
  478. theme_property.doc = const_cast<DocData::ThemeItemDoc *>(&class_doc->theme_properties[i]);
  479. match.theme_properties.push_back(theme_property);
  480. }
  481. }
  482. }
  483. if (search_flags & SEARCH_ANNOTATIONS) {
  484. for (int i = 0; i < class_doc->annotations.size(); i++) {
  485. MemberMatch<DocData::MethodDoc> annotation;
  486. annotation.name = _all_terms_in_name(class_doc->annotations[i].name);
  487. annotation.keyword = _match_keywords_in_all_terms(class_doc->annotations[i].keywords);
  488. if (annotation.name || !annotation.keyword.is_empty()) {
  489. annotation.doc = const_cast<DocData::MethodDoc *>(&class_doc->annotations[i]);
  490. match.annotations.push_back(annotation);
  491. }
  492. }
  493. }
  494. }
  495. matches[class_doc->name] = match;
  496. }
  497. if (iterator_doc) {
  498. ++iterator_doc;
  499. return !iterator_doc;
  500. }
  501. if (!iterator_stack.is_empty()) {
  502. if (iterator_stack[iterator_stack.size() - 1]) {
  503. iterator_stack[iterator_stack.size() - 1] = iterator_stack[iterator_stack.size() - 1]->next();
  504. }
  505. if (!iterator_stack[iterator_stack.size() - 1]) {
  506. iterator_stack.resize(iterator_stack.size() - 1);
  507. }
  508. }
  509. if (class_doc && EditorHelp::get_doc_data()->inheriting.has(class_doc->name)) {
  510. iterator_stack.push_back(EditorHelp::get_doc_data()->inheriting[class_doc->name].front());
  511. }
  512. return iterator_stack.is_empty();
  513. }
  514. void EditorHelpSearch::Runner::_populate_cache() {
  515. // Deselect to prevent re-selection issues.
  516. results_tree->deselect_all();
  517. root_item = results_tree->get_root();
  518. if (root_item) {
  519. LocalVector<TreeItem *> stack;
  520. // Add children of root item to stack.
  521. for (TreeItem *child = root_item->get_first_child(); child; child = child->get_next()) {
  522. stack.push_back(child);
  523. }
  524. // Traverse stack and cache items.
  525. while (!stack.is_empty()) {
  526. TreeItem *cur_item = stack[stack.size() - 1];
  527. stack.resize(stack.size() - 1);
  528. // Add to the cache.
  529. tree_cache->item_cache.insert(cur_item->get_metadata(0).operator String(), cur_item);
  530. // Add any children to the stack.
  531. for (TreeItem *child = cur_item->get_first_child(); child; child = child->get_next()) {
  532. stack.push_back(child);
  533. }
  534. // Remove from parent.
  535. cur_item->get_parent()->remove_child(cur_item);
  536. }
  537. } else {
  538. root_item = results_tree->create_item();
  539. }
  540. }
  541. bool EditorHelpSearch::Runner::_phase_class_items_init() {
  542. iterator_match = matches.begin();
  543. _populate_cache();
  544. class_items.clear();
  545. return true;
  546. }
  547. bool EditorHelpSearch::Runner::_phase_class_items() {
  548. if (!iterator_match) {
  549. return true;
  550. }
  551. ClassMatch &match = iterator_match->value;
  552. if (search_flags & SEARCH_SHOW_HIERARCHY) {
  553. if (match.required()) {
  554. _create_class_hierarchy(match);
  555. }
  556. } else {
  557. if (match.name || !match.keyword.is_empty()) {
  558. _create_class_item(root_item, match.doc, false, match.name ? String() : match.keyword);
  559. }
  560. }
  561. ++iterator_match;
  562. return !iterator_match;
  563. }
  564. bool EditorHelpSearch::Runner::_phase_member_items_init() {
  565. iterator_match = matches.begin();
  566. return true;
  567. }
  568. bool EditorHelpSearch::Runner::_phase_member_items() {
  569. if (!iterator_match) {
  570. return true;
  571. }
  572. ClassMatch &match = iterator_match->value;
  573. if (!match.doc || match.doc->name.is_empty()) {
  574. ++iterator_match;
  575. return false;
  576. }
  577. TreeItem *parent_item = (search_flags & SEARCH_SHOW_HIERARCHY) ? class_items[match.doc->name] : root_item;
  578. bool constructor_created = false;
  579. for (int i = 0; i < match.methods.size(); i++) {
  580. String text = match.methods[i].doc->name;
  581. if (!constructor_created) {
  582. if (match.doc->name == match.methods[i].doc->name) {
  583. text += " " + TTR("(constructors)");
  584. constructor_created = true;
  585. }
  586. } else {
  587. if (match.doc->name == match.methods[i].doc->name) {
  588. continue;
  589. }
  590. }
  591. _create_method_item(parent_item, match.doc, text, match.methods[i]);
  592. }
  593. for (int i = 0; i < match.signals.size(); i++) {
  594. _create_signal_item(parent_item, match.doc, match.signals[i]);
  595. }
  596. for (int i = 0; i < match.constants.size(); i++) {
  597. _create_constant_item(parent_item, match.doc, match.constants[i]);
  598. }
  599. for (int i = 0; i < match.properties.size(); i++) {
  600. _create_property_item(parent_item, match.doc, match.properties[i]);
  601. }
  602. for (int i = 0; i < match.theme_properties.size(); i++) {
  603. _create_theme_property_item(parent_item, match.doc, match.theme_properties[i]);
  604. }
  605. for (int i = 0; i < match.annotations.size(); i++) {
  606. _create_annotation_item(parent_item, match.doc, match.annotations[i]);
  607. }
  608. ++iterator_match;
  609. return !iterator_match;
  610. }
  611. bool EditorHelpSearch::Runner::_phase_select_match() {
  612. if (matched_item) {
  613. matched_item->select(0);
  614. }
  615. return true;
  616. }
  617. void EditorHelpSearch::Runner::_match_method_name_and_push_back(Vector<DocData::MethodDoc> &p_methods, Vector<MemberMatch<DocData::MethodDoc>> *r_match_methods) {
  618. // Constructors, Methods, Operators...
  619. for (int i = 0; i < p_methods.size(); i++) {
  620. String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? p_methods[i].name : p_methods[i].name.to_lower();
  621. String keywords = (search_flags & SEARCH_CASE_SENSITIVE) ? p_methods[i].keywords : p_methods[i].keywords.to_lower();
  622. MemberMatch<DocData::MethodDoc> method;
  623. method.name = _all_terms_in_name(method_name);
  624. method.keyword = _match_keywords_in_all_terms(keywords);
  625. if (method.name || !method.keyword.is_empty() ||
  626. (term.begins_with(".") && method_name.begins_with(term.substr(1))) ||
  627. (term.ends_with("(") && method_name.ends_with(term.left(term.length() - 1).strip_edges())) ||
  628. (term.begins_with(".") && term.ends_with("(") && method_name == term.substr(1, term.length() - 2).strip_edges())) {
  629. method.doc = const_cast<DocData::MethodDoc *>(&p_methods[i]);
  630. r_match_methods->push_back(method);
  631. }
  632. }
  633. }
  634. bool EditorHelpSearch::Runner::_all_terms_in_name(const String &p_name) const {
  635. for (int i = 0; i < terms.size(); i++) {
  636. if (!_match_string(terms[i], p_name)) {
  637. return false;
  638. }
  639. }
  640. return true;
  641. }
  642. String EditorHelpSearch::Runner::_match_keywords_in_all_terms(const String &p_keywords) const {
  643. String matching_keyword;
  644. for (int i = 0; i < terms.size(); i++) {
  645. matching_keyword = _match_keywords(terms[i], p_keywords);
  646. if (matching_keyword.is_empty()) {
  647. return String();
  648. }
  649. }
  650. return matching_keyword;
  651. }
  652. bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String &p_string) const {
  653. if (search_flags & SEARCH_CASE_SENSITIVE) {
  654. return p_string.contains(p_term);
  655. } else {
  656. return p_string.containsn(p_term);
  657. }
  658. }
  659. String EditorHelpSearch::Runner::_match_keywords(const String &p_term, const String &p_keywords) const {
  660. for (const String &k : p_keywords.split(",")) {
  661. const String keyword = k.strip_edges();
  662. if (_match_string(p_term, keyword)) {
  663. return keyword;
  664. }
  665. }
  666. return String();
  667. }
  668. void EditorHelpSearch::Runner::_match_item(TreeItem *p_item, const String &p_text, bool p_is_keywords) {
  669. if (p_text.is_empty()) {
  670. return;
  671. }
  672. float inverse_length = 1.f / float(p_text.length());
  673. // Favor types where search term is a substring close to the start of the type.
  674. float w = 0.5f;
  675. int pos = p_text.findn(term);
  676. float score = (pos > -1) ? 1.0f - w * MIN(1, 3 * pos * inverse_length) : MAX(0.f, .9f - w);
  677. // Favor shorter items: they resemble the search term more.
  678. w = 0.1f;
  679. score *= (1 - w) + w * (term.length() * inverse_length);
  680. // Reduce the score of keywords, since they are an indirect match.
  681. if (p_is_keywords) {
  682. score *= 0.9f;
  683. }
  684. if (match_highest_score == 0 || score > match_highest_score) {
  685. matched_item = p_item;
  686. match_highest_score = score;
  687. }
  688. }
  689. String EditorHelpSearch::Runner::_build_method_tooltip(const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) const {
  690. String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
  691. for (int i = 0; i < p_doc->arguments.size(); i++) {
  692. const DocData::ArgumentDoc &arg = p_doc->arguments[i];
  693. tooltip += arg.type + " " + arg.name;
  694. if (!arg.default_value.is_empty()) {
  695. tooltip += " = " + arg.default_value;
  696. }
  697. if (i < p_doc->arguments.size() - 1) {
  698. tooltip += ", ";
  699. }
  700. }
  701. tooltip += ")";
  702. tooltip += _build_keywords_tooltip(p_doc->keywords);
  703. return tooltip;
  704. }
  705. String EditorHelpSearch::Runner::_build_keywords_tooltip(const String &p_keywords) const {
  706. String tooltip;
  707. if (p_keywords.is_empty()) {
  708. return tooltip;
  709. }
  710. tooltip = "\n\n" + TTR("Keywords") + ": ";
  711. for (const String &keyword : p_keywords.split(",")) {
  712. tooltip += keyword.strip_edges().quote() + ", ";
  713. }
  714. // Remove trailing comma and space.
  715. return tooltip.left(-2);
  716. }
  717. TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_match) {
  718. if (p_match.doc->name.is_empty()) {
  719. return nullptr;
  720. }
  721. if (class_items.has(p_match.doc->name)) {
  722. return class_items[p_match.doc->name];
  723. }
  724. // Ensure parent nodes are created first.
  725. TreeItem *parent_item = root_item;
  726. if (!p_match.doc->inherits.is_empty()) {
  727. if (class_items.has(p_match.doc->inherits)) {
  728. parent_item = class_items[p_match.doc->inherits];
  729. } else {
  730. ClassMatch &base_match = matches[p_match.doc->inherits];
  731. if (base_match.doc) {
  732. parent_item = _create_class_hierarchy(base_match);
  733. }
  734. }
  735. }
  736. TreeItem *class_item = _create_class_item(parent_item, p_match.doc, !p_match.name && p_match.keyword.is_empty(), p_match.name ? String() : p_match.keyword);
  737. class_items[p_match.doc->name] = class_item;
  738. return class_item;
  739. }
  740. bool EditorHelpSearch::Runner::_find_or_create_item(TreeItem *p_parent, const String &p_item_meta, TreeItem *&r_item) {
  741. // Attempt to find in cache.
  742. if (tree_cache->item_cache.has(p_item_meta)) {
  743. r_item = tree_cache->item_cache[p_item_meta];
  744. // Remove from cache.
  745. tree_cache->item_cache.erase(p_item_meta);
  746. // Add to tree.
  747. p_parent->add_child(r_item);
  748. return false;
  749. } else {
  750. // Otherwise create item.
  751. r_item = results_tree->create_item(p_parent);
  752. return true;
  753. }
  754. }
  755. TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray, const String &p_matching_keyword) {
  756. String tooltip = DTR(p_doc->brief_description.strip_edges());
  757. tooltip += _build_keywords_tooltip(p_doc->keywords);
  758. const String item_meta = "class_name:" + p_doc->name;
  759. TreeItem *item = nullptr;
  760. if (_find_or_create_item(p_parent, item_meta, item)) {
  761. item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_doc->name));
  762. item->set_text(1, TTR("Class"));
  763. item->set_tooltip_text(0, tooltip);
  764. item->set_tooltip_text(1, tooltip);
  765. item->set_metadata(0, item_meta);
  766. if (p_doc->is_deprecated) {
  767. Ref<Texture2D> error_icon = ui_service->get_editor_theme_icon(SNAME("StatusError"));
  768. item->add_button(0, error_icon, 0, false, TTR("This class is marked as deprecated."));
  769. } else if (p_doc->is_experimental) {
  770. Ref<Texture2D> warning_icon = ui_service->get_editor_theme_icon(SNAME("NodeWarning"));
  771. item->add_button(0, warning_icon, 0, false, TTR("This class is marked as experimental."));
  772. }
  773. }
  774. if (p_gray) {
  775. item->set_custom_color(0, disabled_color);
  776. item->set_custom_color(1, disabled_color);
  777. } else {
  778. item->clear_custom_color(0);
  779. item->clear_custom_color(1);
  780. }
  781. if (p_matching_keyword.is_empty()) {
  782. item->set_text(0, p_doc->name);
  783. } else {
  784. item->set_text(0, p_doc->name + " - " + TTR(vformat("Matches the \"%s\" keyword.", p_matching_keyword)));
  785. }
  786. _match_item(item, p_doc->name);
  787. for (const String &keyword : p_doc->keywords.split(",")) {
  788. _match_item(item, keyword.strip_edges(), true);
  789. }
  790. return item;
  791. }
  792. TreeItem *EditorHelpSearch::Runner::_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const MemberMatch<DocData::MethodDoc> &p_match) {
  793. String tooltip = _build_method_tooltip(p_class_doc, p_match.doc);
  794. return _create_member_item(p_parent, p_class_doc->name, "MemberMethod", p_match.doc->name, p_text, TTRC("Method"), "method", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
  795. }
  796. TreeItem *EditorHelpSearch::Runner::_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match) {
  797. String tooltip = _build_method_tooltip(p_class_doc, p_match.doc);
  798. return _create_member_item(p_parent, p_class_doc->name, "MemberSignal", p_match.doc->name, p_match.doc->name, TTRC("Signal"), "signal", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
  799. }
  800. TreeItem *EditorHelpSearch::Runner::_create_annotation_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match) {
  801. String tooltip = _build_method_tooltip(p_class_doc, p_match.doc);
  802. // Hide the redundant leading @ symbol.
  803. String text = p_match.doc->name.substr(1);
  804. return _create_member_item(p_parent, p_class_doc->name, "MemberAnnotation", p_match.doc->name, text, TTRC("Annotation"), "annotation", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
  805. }
  806. TreeItem *EditorHelpSearch::Runner::_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::ConstantDoc> &p_match) {
  807. String tooltip = p_class_doc->name + "." + p_match.doc->name;
  808. tooltip += _build_keywords_tooltip(p_match.doc->keywords);
  809. return _create_member_item(p_parent, p_class_doc->name, "MemberConstant", p_match.doc->name, p_match.doc->name, TTRC("Constant"), "constant", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
  810. }
  811. TreeItem *EditorHelpSearch::Runner::_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::PropertyDoc> &p_match) {
  812. String tooltip = p_match.doc->type + " " + p_class_doc->name + "." + p_match.doc->name;
  813. tooltip += "\n " + p_class_doc->name + "." + p_match.doc->setter + "(value) setter";
  814. tooltip += "\n " + p_class_doc->name + "." + p_match.doc->getter + "() getter";
  815. tooltip += _build_keywords_tooltip(p_match.doc->keywords);
  816. return _create_member_item(p_parent, p_class_doc->name, "MemberProperty", p_match.doc->name, p_match.doc->name, TTRC("Property"), "property", tooltip, p_match.doc->keywords, p_match.doc->is_deprecated, p_match.doc->is_experimental, p_match.name ? String() : p_match.keyword);
  817. }
  818. TreeItem *EditorHelpSearch::Runner::_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::ThemeItemDoc> &p_match) {
  819. String tooltip = p_match.doc->type + " " + p_class_doc->name + "." + p_match.doc->name;
  820. tooltip += _build_keywords_tooltip(p_match.doc->keywords);
  821. return _create_member_item(p_parent, p_class_doc->name, "MemberTheme", p_match.doc->name, p_match.doc->name, TTRC("Theme Property"), "theme_item", p_match.doc->keywords, tooltip, false, false, p_match.name ? String() : p_match.keyword);
  822. }
  823. TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, const String &p_class_name, const String &p_icon, const String &p_name, const String &p_text, const String &p_type, const String &p_metatype, const String &p_tooltip, const String &p_keywords, bool p_is_deprecated, bool p_is_experimental, const String &p_matching_keyword) {
  824. const String item_meta = "class_" + p_metatype + ":" + p_class_name + ":" + p_name;
  825. TreeItem *item = nullptr;
  826. if (_find_or_create_item(p_parent, item_meta, item)) {
  827. item->set_icon(0, ui_service->get_editor_theme_icon(p_icon));
  828. item->set_text(1, TTRGET(p_type));
  829. item->set_tooltip_text(0, p_tooltip);
  830. item->set_tooltip_text(1, p_tooltip);
  831. item->set_metadata(0, item_meta);
  832. if (p_is_deprecated) {
  833. Ref<Texture2D> error_icon = ui_service->get_editor_theme_icon(SNAME("StatusError"));
  834. item->add_button(0, error_icon, 0, false, TTR("This member is marked as deprecated."));
  835. } else if (p_is_experimental) {
  836. Ref<Texture2D> warning_icon = ui_service->get_editor_theme_icon(SNAME("NodeWarning"));
  837. item->add_button(0, warning_icon, 0, false, TTR("This member is marked as experimental."));
  838. }
  839. }
  840. String text;
  841. if (search_flags & SEARCH_SHOW_HIERARCHY) {
  842. text = p_text;
  843. } else {
  844. text = p_class_name + "." + p_text;
  845. }
  846. if (!p_matching_keyword.is_empty()) {
  847. text += " - " + TTR(vformat("Matches the \"%s\" keyword.", p_matching_keyword));
  848. }
  849. item->set_text(0, text);
  850. _match_item(item, p_name);
  851. for (const String &keyword : p_keywords.split(",")) {
  852. _match_item(item, keyword.strip_edges(), true);
  853. }
  854. return item;
  855. }
  856. bool EditorHelpSearch::Runner::work(uint64_t slot) {
  857. // Return true when the search has been completed, otherwise false.
  858. const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot;
  859. while (!_slice()) {
  860. if (OS::get_singleton()->get_ticks_usec() > until) {
  861. return false;
  862. }
  863. }
  864. return true;
  865. }
  866. EditorHelpSearch::Runner::Runner(Control *p_icon_service, Tree *p_results_tree, TreeCache *p_tree_cache, const String &p_term, int p_search_flags) :
  867. ui_service(p_icon_service),
  868. results_tree(p_results_tree),
  869. tree_cache(p_tree_cache),
  870. term((p_search_flags & SEARCH_CASE_SENSITIVE) == 0 ? p_term.strip_edges().to_lower() : p_term.strip_edges()),
  871. search_flags(p_search_flags),
  872. disabled_color(ui_service->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))) {
  873. }