editor_help_search.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*************************************************************************/
  2. /* editor_help_search.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "editor_help_search.h"
  31. #include "core/os/keyboard.h"
  32. #include "editor_node.h"
  33. void EditorHelpSearch::_update_icons() {
  34. search_box->set_right_icon(get_icon("Search", "EditorIcons"));
  35. search_box->set_clear_button_enabled(true);
  36. search_box->add_icon_override("right_icon", get_icon("Search", "EditorIcons"));
  37. case_sensitive_button->set_icon(get_icon("MatchCase", "EditorIcons"));
  38. hierarchy_button->set_icon(get_icon("ClassList", "EditorIcons"));
  39. if (is_visible_in_tree())
  40. _update_results();
  41. }
  42. void EditorHelpSearch::_load_settings() {
  43. bool enable_rl = EditorSettings::get_singleton()->get("docks/scene_tree/draw_relationship_lines");
  44. Color rl_color = EditorSettings::get_singleton()->get("docks/scene_tree/relationship_line_color");
  45. if (enable_rl) {
  46. results_tree->add_constant_override("draw_relationship_lines", 1);
  47. results_tree->add_color_override("relationship_line_color", rl_color);
  48. results_tree->add_constant_override("draw_guides", 0);
  49. } else {
  50. results_tree->add_constant_override("draw_relationship_lines", 0);
  51. results_tree->add_constant_override("draw_guides", 1);
  52. }
  53. }
  54. void EditorHelpSearch::_update_results() {
  55. String term = search_box->get_text();
  56. int search_flags = filter_combo->get_selected_id();
  57. if (case_sensitive_button->is_pressed())
  58. search_flags |= SEARCH_CASE_SENSITIVE;
  59. if (hierarchy_button->is_pressed())
  60. search_flags |= SEARCH_SHOW_HIERARCHY;
  61. search = Ref<Runner>(memnew(Runner(this, results_tree, term, search_flags)));
  62. set_process(true);
  63. }
  64. void EditorHelpSearch::_search_box_gui_input(const Ref<InputEvent> &p_event) {
  65. // Redirect up and down navigational key events to the results list.
  66. Ref<InputEventKey> key = p_event;
  67. if (key.is_valid()) {
  68. switch (key->get_scancode()) {
  69. case KEY_UP:
  70. case KEY_DOWN:
  71. case KEY_PAGEUP:
  72. case KEY_PAGEDOWN: {
  73. results_tree->call("_gui_input", key);
  74. search_box->accept_event();
  75. } break;
  76. }
  77. }
  78. }
  79. void EditorHelpSearch::_search_box_text_changed(const String &p_text) {
  80. _update_results();
  81. }
  82. void EditorHelpSearch::_filter_combo_item_selected(int p_option) {
  83. _update_results();
  84. }
  85. void EditorHelpSearch::_confirmed() {
  86. TreeItem *item = results_tree->get_selected();
  87. if (!item)
  88. return;
  89. // Activate the script editor and emit the signal with the documentation link to display.
  90. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
  91. emit_signal("go_to_help", item->get_metadata(0));
  92. hide();
  93. }
  94. void EditorHelpSearch::_notification(int p_what) {
  95. switch (p_what) {
  96. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  97. _load_settings();
  98. _update_icons();
  99. } break;
  100. case NOTIFICATION_ENTER_TREE: {
  101. connect("confirmed", this, "_confirmed");
  102. _update_icons();
  103. } break;
  104. case NOTIFICATION_POPUP_HIDE: {
  105. results_tree->call_deferred("clear"); // Wait for the Tree's mouse event propagation.
  106. get_ok()->set_disabled(true);
  107. EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "search_help", get_rect());
  108. } break;
  109. case NOTIFICATION_PROCESS: {
  110. // Update background search.
  111. if (search.is_valid()) {
  112. if (search->work()) {
  113. // Search done.
  114. // Only point to the perfect match if it's a new search, and not just reopening a old one.
  115. if (!old_search)
  116. results_tree->ensure_cursor_is_visible();
  117. else
  118. old_search = false;
  119. get_ok()->set_disabled(!results_tree->get_selected());
  120. search = Ref<Runner>();
  121. set_process(false);
  122. }
  123. } else {
  124. set_process(false);
  125. }
  126. } break;
  127. }
  128. }
  129. void EditorHelpSearch::_bind_methods() {
  130. ClassDB::bind_method(D_METHOD("_update_results"), &EditorHelpSearch::_update_results);
  131. ClassDB::bind_method(D_METHOD("_search_box_gui_input"), &EditorHelpSearch::_search_box_gui_input);
  132. ClassDB::bind_method(D_METHOD("_search_box_text_changed"), &EditorHelpSearch::_search_box_text_changed);
  133. ClassDB::bind_method(D_METHOD("_filter_combo_item_selected"), &EditorHelpSearch::_filter_combo_item_selected);
  134. ClassDB::bind_method(D_METHOD("_confirmed"), &EditorHelpSearch::_confirmed);
  135. ADD_SIGNAL(MethodInfo("go_to_help"));
  136. }
  137. void EditorHelpSearch::popup_dialog() {
  138. popup_dialog(search_box->get_text());
  139. }
  140. void EditorHelpSearch::popup_dialog(const String &p_term) {
  141. // Restore valid window bounds or pop up at default size.
  142. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "search_help", Rect2());
  143. if (saved_size != Rect2())
  144. popup(saved_size);
  145. else
  146. popup_centered_ratio(0.5F);
  147. if (p_term == "") {
  148. search_box->clear();
  149. } else {
  150. old_search = true;
  151. search_box->set_text(p_term);
  152. search_box->select_all();
  153. }
  154. search_box->grab_focus();
  155. _update_results();
  156. }
  157. EditorHelpSearch::EditorHelpSearch() {
  158. old_search = false;
  159. set_hide_on_ok(false);
  160. set_resizable(true);
  161. set_title(TTR("Search Help"));
  162. get_ok()->set_disabled(true);
  163. get_ok()->set_text(TTR("Open"));
  164. // Split search and results area.
  165. VBoxContainer *vbox = memnew(VBoxContainer);
  166. add_child(vbox);
  167. // Create the search box and filter controls (at the top).
  168. HBoxContainer *hbox = memnew(HBoxContainer);
  169. vbox->add_child(hbox);
  170. search_box = memnew(LineEdit);
  171. search_box->set_custom_minimum_size(Size2(200, 0));
  172. search_box->set_h_size_flags(SIZE_EXPAND_FILL);
  173. search_box->connect("gui_input", this, "_search_box_gui_input");
  174. search_box->connect("text_changed", this, "_search_box_text_changed");
  175. register_text_enter(search_box);
  176. hbox->add_child(search_box);
  177. case_sensitive_button = memnew(ToolButton);
  178. case_sensitive_button->set_tooltip("Case Sensitive");
  179. case_sensitive_button->connect("pressed", this, "_update_results");
  180. case_sensitive_button->set_toggle_mode(true);
  181. case_sensitive_button->set_focus_mode(FOCUS_NONE);
  182. hbox->add_child(case_sensitive_button);
  183. hierarchy_button = memnew(ToolButton);
  184. hierarchy_button->set_tooltip("Show Hierarchy");
  185. hierarchy_button->connect("pressed", this, "_update_results");
  186. hierarchy_button->set_toggle_mode(true);
  187. hierarchy_button->set_pressed(true);
  188. hierarchy_button->set_focus_mode(FOCUS_NONE);
  189. hbox->add_child(hierarchy_button);
  190. filter_combo = memnew(OptionButton);
  191. filter_combo->set_custom_minimum_size(Size2(200, 0));
  192. filter_combo->set_stretch_ratio(0); // Fixed width.
  193. filter_combo->add_item(TTR("Display All"), SEARCH_ALL);
  194. filter_combo->add_separator();
  195. filter_combo->add_item(TTR("Classes Only"), SEARCH_CLASSES);
  196. filter_combo->add_item(TTR("Methods Only"), SEARCH_METHODS);
  197. filter_combo->add_item(TTR("Signals Only"), SEARCH_SIGNALS);
  198. filter_combo->add_item(TTR("Constants Only"), SEARCH_CONSTANTS);
  199. filter_combo->add_item(TTR("Properties Only"), SEARCH_PROPERTIES);
  200. filter_combo->add_item(TTR("Theme Properties Only"), SEARCH_THEME_ITEMS);
  201. filter_combo->connect("item_selected", this, "_filter_combo_item_selected");
  202. hbox->add_child(filter_combo);
  203. // Create the results tree.
  204. results_tree = memnew(Tree);
  205. results_tree->set_v_size_flags(SIZE_EXPAND_FILL);
  206. results_tree->set_columns(2);
  207. results_tree->set_column_title(0, TTR("Name"));
  208. results_tree->set_column_title(1, TTR("Member Type"));
  209. results_tree->set_column_expand(1, false);
  210. results_tree->set_column_min_width(1, 150);
  211. results_tree->set_custom_minimum_size(Size2(0, 100));
  212. results_tree->set_hide_root(true);
  213. results_tree->set_select_mode(Tree::SELECT_ROW);
  214. results_tree->connect("item_activated", this, "_confirmed");
  215. results_tree->connect("item_selected", get_ok(), "set_disabled", varray(false));
  216. vbox->add_child(results_tree, true);
  217. _load_settings();
  218. }
  219. bool EditorHelpSearch::Runner::_slice() {
  220. bool phase_done = false;
  221. switch (phase) {
  222. case PHASE_MATCH_CLASSES_INIT:
  223. phase_done = _phase_match_classes_init();
  224. break;
  225. case PHASE_MATCH_CLASSES:
  226. phase_done = _phase_match_classes();
  227. break;
  228. case PHASE_CLASS_ITEMS_INIT:
  229. phase_done = _phase_class_items_init();
  230. break;
  231. case PHASE_CLASS_ITEMS:
  232. phase_done = _phase_class_items();
  233. break;
  234. case PHASE_MEMBER_ITEMS_INIT:
  235. phase_done = _phase_member_items_init();
  236. break;
  237. case PHASE_MEMBER_ITEMS:
  238. phase_done = _phase_member_items();
  239. break;
  240. case PHASE_SELECT_MATCH:
  241. phase_done = _phase_select_match();
  242. break;
  243. case PHASE_MAX:
  244. return true;
  245. default:
  246. WARN_PRINTS("Invalid or unhandled phase in EditorHelpSearch::Runner, aborting search.");
  247. return true;
  248. };
  249. if (phase_done)
  250. phase++;
  251. return false;
  252. }
  253. bool EditorHelpSearch::Runner::_phase_match_classes_init() {
  254. iterator_doc = EditorHelp::get_doc_data()->class_list.front();
  255. matches.clear();
  256. matched_item = NULL;
  257. return true;
  258. }
  259. bool EditorHelpSearch::Runner::_phase_match_classes() {
  260. DocData::ClassDoc &class_doc = iterator_doc->value();
  261. matches[class_doc.name] = ClassMatch();
  262. ClassMatch &match = matches[class_doc.name];
  263. match.doc = &class_doc;
  264. // Match class name.
  265. if (search_flags & SEARCH_CLASSES)
  266. match.name = term == "" || _match_string(term, class_doc.name);
  267. // Match members if the term is long enough.
  268. if (term.length() > 1) {
  269. if (search_flags & SEARCH_METHODS)
  270. for (int i = 0; i < class_doc.methods.size(); i++) {
  271. String method_name = search_flags & SEARCH_CASE_SENSITIVE ? class_doc.methods[i].name : class_doc.methods[i].name.to_lower();
  272. if (method_name.find(term) > -1 ||
  273. (term.begins_with(".") && method_name.begins_with(term.right(1))) ||
  274. (term.ends_with("(") && method_name.ends_with(term.left(term.length() - 1).strip_edges())) ||
  275. (term.begins_with(".") && term.ends_with("(") && method_name == term.substr(1, term.length() - 2).strip_edges()))
  276. match.methods.push_back(const_cast<DocData::MethodDoc *>(&class_doc.methods[i]));
  277. }
  278. if (search_flags & SEARCH_SIGNALS)
  279. for (int i = 0; i < class_doc.signals.size(); i++)
  280. if (_match_string(term, class_doc.signals[i].name))
  281. match.signals.push_back(const_cast<DocData::MethodDoc *>(&class_doc.signals[i]));
  282. if (search_flags & SEARCH_CONSTANTS)
  283. for (int i = 0; i < class_doc.constants.size(); i++)
  284. if (_match_string(term, class_doc.constants[i].name))
  285. match.constants.push_back(const_cast<DocData::ConstantDoc *>(&class_doc.constants[i]));
  286. if (search_flags & SEARCH_PROPERTIES)
  287. for (int i = 0; i < class_doc.properties.size(); i++)
  288. if (_match_string(term, class_doc.properties[i].name))
  289. match.properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.properties[i]));
  290. if (search_flags & SEARCH_THEME_ITEMS)
  291. for (int i = 0; i < class_doc.theme_properties.size(); i++)
  292. if (_match_string(term, class_doc.theme_properties[i].name))
  293. match.theme_properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.theme_properties[i]));
  294. }
  295. iterator_doc = iterator_doc->next();
  296. return !iterator_doc;
  297. }
  298. bool EditorHelpSearch::Runner::_phase_class_items_init() {
  299. iterator_match = matches.front();
  300. results_tree->clear();
  301. root_item = results_tree->create_item();
  302. class_items.clear();
  303. return true;
  304. }
  305. bool EditorHelpSearch::Runner::_phase_class_items() {
  306. ClassMatch &match = iterator_match->value();
  307. if (search_flags & SEARCH_SHOW_HIERARCHY) {
  308. if (match.required())
  309. _create_class_hierarchy(match);
  310. } else {
  311. if (match.name)
  312. _create_class_item(root_item, match.doc, false);
  313. }
  314. iterator_match = iterator_match->next();
  315. return !iterator_match;
  316. }
  317. bool EditorHelpSearch::Runner::_phase_member_items_init() {
  318. iterator_match = matches.front();
  319. return true;
  320. }
  321. bool EditorHelpSearch::Runner::_phase_member_items() {
  322. ClassMatch &match = iterator_match->value();
  323. TreeItem *parent = search_flags & SEARCH_SHOW_HIERARCHY ? class_items[match.doc->name] : root_item;
  324. for (int i = 0; i < match.methods.size(); i++)
  325. _create_method_item(parent, match.doc, match.methods[i]);
  326. for (int i = 0; i < match.signals.size(); i++)
  327. _create_signal_item(parent, match.doc, match.signals[i]);
  328. for (int i = 0; i < match.constants.size(); i++)
  329. _create_constant_item(parent, match.doc, match.constants[i]);
  330. for (int i = 0; i < match.properties.size(); i++)
  331. _create_property_item(parent, match.doc, match.properties[i]);
  332. for (int i = 0; i < match.theme_properties.size(); i++)
  333. _create_theme_property_item(parent, match.doc, match.theme_properties[i]);
  334. iterator_match = iterator_match->next();
  335. return !iterator_match;
  336. }
  337. bool EditorHelpSearch::Runner::_phase_select_match() {
  338. if (matched_item)
  339. matched_item->select(0);
  340. return true;
  341. }
  342. bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String &p_string) const {
  343. if (search_flags & SEARCH_CASE_SENSITIVE)
  344. return p_string.find(p_term) > -1;
  345. else
  346. return p_string.findn(p_term) > -1;
  347. }
  348. void EditorHelpSearch::Runner::_match_item(TreeItem *p_item, const String &p_text) {
  349. if (!matched_item) {
  350. if (search_flags & SEARCH_CASE_SENSITIVE) {
  351. if (p_text.casecmp_to(term) == 0)
  352. matched_item = p_item;
  353. } else {
  354. if (p_text.nocasecmp_to(term) == 0)
  355. matched_item = p_item;
  356. }
  357. }
  358. }
  359. TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_match) {
  360. if (class_items.has(p_match.doc->name))
  361. return class_items[p_match.doc->name];
  362. // Ensure parent nodes are created first.
  363. TreeItem *parent = root_item;
  364. if (p_match.doc->inherits != "") {
  365. if (class_items.has(p_match.doc->inherits)) {
  366. parent = class_items[p_match.doc->inherits];
  367. } else {
  368. ClassMatch &base_match = matches[p_match.doc->inherits];
  369. parent = _create_class_hierarchy(base_match);
  370. }
  371. }
  372. TreeItem *class_item = _create_class_item(parent, p_match.doc, !p_match.name);
  373. class_items[p_match.doc->name] = class_item;
  374. return class_item;
  375. }
  376. TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray) {
  377. Ref<Texture> icon = empty_icon;
  378. if (ui_service->has_icon(p_doc->name, "EditorIcons"))
  379. icon = ui_service->get_icon(p_doc->name, "EditorIcons");
  380. else if (ClassDB::class_exists(p_doc->name) && ClassDB::is_parent_class(p_doc->name, "Object"))
  381. icon = ui_service->get_icon("Object", "EditorIcons");
  382. String tooltip = p_doc->brief_description.strip_edges();
  383. TreeItem *item = results_tree->create_item(p_parent);
  384. item->set_icon(0, icon);
  385. item->set_text(0, p_doc->name);
  386. item->set_text(1, TTR("Class"));
  387. item->set_tooltip(0, tooltip);
  388. item->set_tooltip(1, tooltip);
  389. item->set_metadata(0, "class_name:" + p_doc->name);
  390. if (p_gray) {
  391. item->set_custom_color(0, disabled_color);
  392. item->set_custom_color(1, disabled_color);
  393. }
  394. _match_item(item, p_doc->name);
  395. return item;
  396. }
  397. TreeItem *EditorHelpSearch::Runner::_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) {
  398. String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
  399. for (int i = 0; i < p_doc->arguments.size(); i++) {
  400. const DocData::ArgumentDoc &arg = p_doc->arguments[i];
  401. tooltip += arg.type + " " + arg.name;
  402. if (arg.default_value != "")
  403. tooltip += " = " + arg.default_value;
  404. if (i < p_doc->arguments.size() - 1)
  405. tooltip += ", ";
  406. }
  407. tooltip += ")";
  408. return _create_member_item(p_parent, p_class_doc->name, "MemberMethod", p_doc->name, "Method", "method", tooltip);
  409. }
  410. TreeItem *EditorHelpSearch::Runner::_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) {
  411. String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
  412. for (int i = 0; i < p_doc->arguments.size(); i++) {
  413. const DocData::ArgumentDoc &arg = p_doc->arguments[i];
  414. tooltip += arg.type + " " + arg.name;
  415. if (arg.default_value != "")
  416. tooltip += " = " + arg.default_value;
  417. if (i < p_doc->arguments.size() - 1)
  418. tooltip += ", ";
  419. }
  420. tooltip += ")";
  421. return _create_member_item(p_parent, p_class_doc->name, "MemberSignal", p_doc->name, "Signal", "signal", tooltip);
  422. }
  423. TreeItem *EditorHelpSearch::Runner::_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc) {
  424. String tooltip = p_class_doc->name + "." + p_doc->name;
  425. return _create_member_item(p_parent, p_class_doc->name, "MemberConstant", p_doc->name, "Constant", "constant", tooltip);
  426. }
  427. TreeItem *EditorHelpSearch::Runner::_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc) {
  428. String tooltip = p_doc->type + " " + p_class_doc->name + "." + p_doc->name;
  429. tooltip += "\n " + p_class_doc->name + "." + p_doc->setter + "(value) setter";
  430. tooltip += "\n " + p_class_doc->name + "." + p_doc->getter + "() getter";
  431. return _create_member_item(p_parent, p_class_doc->name, "MemberProperty", p_doc->name, "Property", "property", tooltip);
  432. }
  433. TreeItem *EditorHelpSearch::Runner::_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc) {
  434. String tooltip = p_doc->type + " " + p_class_doc->name + "." + p_doc->name;
  435. return _create_member_item(p_parent, p_class_doc->name, "MemberTheme", p_doc->name, "Theme Property", "theme_item", tooltip);
  436. }
  437. 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_type, const String &p_metatype, const String &p_tooltip) {
  438. Ref<Texture> icon;
  439. String text;
  440. if (search_flags & SEARCH_SHOW_HIERARCHY) {
  441. icon = ui_service->get_icon(p_icon, "EditorIcons");
  442. text = p_name;
  443. } else {
  444. icon = ui_service->get_icon(p_icon, "EditorIcons");
  445. /*// In flat mode, show the class icon.
  446. if (ui_service->has_icon(p_class_name, "EditorIcons"))
  447. icon = ui_service->get_icon(p_class_name, "EditorIcons");
  448. else if (ClassDB::is_parent_class(p_class_name, "Object"))
  449. icon = ui_service->get_icon("Object", "EditorIcons");*/
  450. text = p_class_name + "." + p_name;
  451. }
  452. TreeItem *item = results_tree->create_item(p_parent);
  453. item->set_icon(0, icon);
  454. item->set_text(0, text);
  455. item->set_text(1, TTR(p_type));
  456. item->set_tooltip(0, p_tooltip);
  457. item->set_tooltip(1, p_tooltip);
  458. item->set_metadata(0, "class_" + p_metatype + ":" + p_class_name + ":" + p_name);
  459. _match_item(item, p_name);
  460. return item;
  461. }
  462. bool EditorHelpSearch::Runner::work(uint64_t slot) {
  463. // Return true when the search has been completed, otherwise false.
  464. const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot;
  465. while (!_slice())
  466. if (OS::get_singleton()->get_ticks_usec() > until)
  467. return false;
  468. return true;
  469. }
  470. EditorHelpSearch::Runner::Runner(Control *p_icon_service, Tree *p_results_tree, const String &p_term, int p_search_flags) :
  471. phase(0),
  472. ui_service(p_icon_service),
  473. results_tree(p_results_tree),
  474. term((p_search_flags & SEARCH_CASE_SENSITIVE) == 0 ? p_term.strip_edges().to_lower() : p_term.strip_edges()),
  475. search_flags(p_search_flags),
  476. empty_icon(ui_service->get_icon("ArrowRight", "EditorIcons")),
  477. disabled_color(ui_service->get_color("disabled_font_color", "Editor")) {
  478. }