editor_help_search.cpp 21 KB

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