editor_help_search.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 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->clear();
  106. get_ok()->set_disabled(true);
  107. EditorSettings::get_singleton()->set("interface/dialogs/search_help_bounds", 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. get_ok()->set_disabled(!results_tree->get_selected());
  115. search = Ref<Runner>();
  116. set_process(false);
  117. }
  118. } else {
  119. set_process(false);
  120. }
  121. } break;
  122. }
  123. }
  124. void EditorHelpSearch::_bind_methods() {
  125. ClassDB::bind_method(D_METHOD("_update_results"), &EditorHelpSearch::_update_results);
  126. ClassDB::bind_method(D_METHOD("_search_box_gui_input"), &EditorHelpSearch::_search_box_gui_input);
  127. ClassDB::bind_method(D_METHOD("_search_box_text_changed"), &EditorHelpSearch::_search_box_text_changed);
  128. ClassDB::bind_method(D_METHOD("_filter_combo_item_selected"), &EditorHelpSearch::_filter_combo_item_selected);
  129. ClassDB::bind_method(D_METHOD("_confirmed"), &EditorHelpSearch::_confirmed);
  130. ADD_SIGNAL(MethodInfo("go_to_help"));
  131. }
  132. void EditorHelpSearch::popup_dialog() {
  133. popup_dialog(search_box->get_text());
  134. }
  135. void EditorHelpSearch::popup_dialog(const String &p_term) {
  136. // Restore valid window bounds or pop up at default size.
  137. if (EditorSettings::get_singleton()->has_setting("interface/dialogs/search_help_bounds"))
  138. popup(EditorSettings::get_singleton()->get("interface/dialogs/search_help_bounds"));
  139. else
  140. popup_centered_ratio(0.5F);
  141. if (p_term == "") {
  142. search_box->clear();
  143. } else {
  144. search_box->set_text(p_term);
  145. search_box->select_all();
  146. }
  147. search_box->grab_focus();
  148. _update_results();
  149. }
  150. EditorHelpSearch::EditorHelpSearch() {
  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));
  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("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("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));
  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);
  203. results_tree->set_custom_minimum_size(Size2(0, 100));
  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. _load_settings();
  210. }
  211. bool EditorHelpSearch::Runner::_slice() {
  212. bool phase_done = false;
  213. switch (phase) {
  214. case PHASE_MATCH_CLASSES_INIT:
  215. phase_done = _phase_match_classes_init();
  216. break;
  217. case PHASE_MATCH_CLASSES:
  218. phase_done = _phase_match_classes();
  219. break;
  220. case PHASE_CLASS_ITEMS_INIT:
  221. phase_done = _phase_class_items_init();
  222. break;
  223. case PHASE_CLASS_ITEMS:
  224. phase_done = _phase_class_items();
  225. break;
  226. case PHASE_MEMBER_ITEMS_INIT:
  227. phase_done = _phase_member_items_init();
  228. break;
  229. case PHASE_MEMBER_ITEMS:
  230. phase_done = _phase_member_items();
  231. break;
  232. case PHASE_SELECT_MATCH:
  233. phase_done = _phase_select_match();
  234. break;
  235. case PHASE_MAX:
  236. return true;
  237. default:
  238. WARN_PRINTS("Invalid or unhandled phase in EditorHelpSearch::Runner, aborting search.");
  239. return true;
  240. };
  241. if (phase_done)
  242. phase++;
  243. return false;
  244. }
  245. bool EditorHelpSearch::Runner::_phase_match_classes_init() {
  246. iterator_doc = EditorHelp::get_doc_data()->class_list.front();
  247. matches.clear();
  248. matched_item = NULL;
  249. return true;
  250. }
  251. bool EditorHelpSearch::Runner::_phase_match_classes() {
  252. DocData::ClassDoc &class_doc = iterator_doc->value();
  253. matches[class_doc.name] = ClassMatch();
  254. ClassMatch &match = matches[class_doc.name];
  255. match.doc = &class_doc;
  256. // Match class name.
  257. if (search_flags & SEARCH_CLASSES)
  258. match.name = term == "" || _match_string(term, class_doc.name);
  259. // Match members if the term is long enough.
  260. if (term.length() > 1) {
  261. if (search_flags & SEARCH_METHODS)
  262. for (int i = 0; i < class_doc.methods.size(); i++) {
  263. String method_name = search_flags & SEARCH_CASE_SENSITIVE ? class_doc.methods[i].name : class_doc.methods[i].name.to_lower();
  264. if (method_name.find(term) > -1 ||
  265. (term.begins_with(".") && method_name.begins_with(term.right(1))) ||
  266. (term.ends_with("(") && method_name.ends_with(term.left(term.length() - 1).strip_edges())) ||
  267. (term.begins_with(".") && term.ends_with("(") && method_name == term.substr(1, term.length() - 2).strip_edges()))
  268. match.methods.push_back(const_cast<DocData::MethodDoc *>(&class_doc.methods[i]));
  269. }
  270. if (search_flags & SEARCH_SIGNALS)
  271. for (int i = 0; i < class_doc.signals.size(); i++)
  272. if (_match_string(term, class_doc.signals[i].name))
  273. match.signals.push_back(const_cast<DocData::MethodDoc *>(&class_doc.signals[i]));
  274. if (search_flags & SEARCH_CONSTANTS)
  275. for (int i = 0; i < class_doc.constants.size(); i++)
  276. if (_match_string(term, class_doc.constants[i].name))
  277. match.constants.push_back(const_cast<DocData::ConstantDoc *>(&class_doc.constants[i]));
  278. if (search_flags & SEARCH_PROPERTIES)
  279. for (int i = 0; i < class_doc.properties.size(); i++)
  280. if (_match_string(term, class_doc.properties[i].name))
  281. match.properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.properties[i]));
  282. if (search_flags & SEARCH_THEME_ITEMS)
  283. for (int i = 0; i < class_doc.theme_properties.size(); i++)
  284. if (_match_string(term, class_doc.theme_properties[i].name))
  285. match.theme_properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.theme_properties[i]));
  286. }
  287. iterator_doc = iterator_doc->next();
  288. return !iterator_doc;
  289. }
  290. bool EditorHelpSearch::Runner::_phase_class_items_init() {
  291. iterator_match = matches.front();
  292. results_tree->clear();
  293. root_item = results_tree->create_item();
  294. class_items.clear();
  295. return true;
  296. }
  297. bool EditorHelpSearch::Runner::_phase_class_items() {
  298. ClassMatch &match = iterator_match->value();
  299. if (search_flags & SEARCH_SHOW_HIERARCHY) {
  300. if (match.required())
  301. _create_class_hierarchy(match);
  302. } else {
  303. if (match.name)
  304. _create_class_item(root_item, match.doc, false);
  305. }
  306. iterator_match = iterator_match->next();
  307. return !iterator_match;
  308. }
  309. bool EditorHelpSearch::Runner::_phase_member_items_init() {
  310. iterator_match = matches.front();
  311. return true;
  312. }
  313. bool EditorHelpSearch::Runner::_phase_member_items() {
  314. ClassMatch &match = iterator_match->value();
  315. TreeItem *parent = search_flags & SEARCH_SHOW_HIERARCHY ? class_items[match.doc->name] : root_item;
  316. for (int i = 0; i < match.methods.size(); i++)
  317. _create_method_item(parent, match.doc, match.methods[i]);
  318. for (int i = 0; i < match.signals.size(); i++)
  319. _create_signal_item(parent, match.doc, match.signals[i]);
  320. for (int i = 0; i < match.constants.size(); i++)
  321. _create_constant_item(parent, match.doc, match.constants[i]);
  322. for (int i = 0; i < match.properties.size(); i++)
  323. _create_property_item(parent, match.doc, match.properties[i]);
  324. for (int i = 0; i < match.theme_properties.size(); i++)
  325. _create_theme_property_item(parent, match.doc, match.theme_properties[i]);
  326. iterator_match = iterator_match->next();
  327. return !iterator_match;
  328. }
  329. bool EditorHelpSearch::Runner::_phase_select_match() {
  330. if (matched_item)
  331. matched_item->select(0);
  332. results_tree->ensure_cursor_is_visible();
  333. return true;
  334. }
  335. bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String &p_string) const {
  336. if (search_flags & SEARCH_CASE_SENSITIVE)
  337. return p_string.find(p_term) > -1;
  338. else
  339. return p_string.findn(p_term) > -1;
  340. }
  341. void EditorHelpSearch::Runner::_match_item(TreeItem *p_item, const String &p_text) {
  342. if (!matched_item) {
  343. if (search_flags & SEARCH_CASE_SENSITIVE) {
  344. if (p_text.casecmp_to(term) == 0)
  345. matched_item = p_item;
  346. } else {
  347. if (p_text.nocasecmp_to(term) == 0)
  348. matched_item = p_item;
  349. }
  350. }
  351. }
  352. TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_match) {
  353. if (class_items.has(p_match.doc->name))
  354. return class_items[p_match.doc->name];
  355. // Ensure parent nodes are created first.
  356. TreeItem *parent = root_item;
  357. if (p_match.doc->inherits != "") {
  358. if (class_items.has(p_match.doc->inherits)) {
  359. parent = class_items[p_match.doc->inherits];
  360. } else {
  361. ClassMatch &base_match = matches[p_match.doc->inherits];
  362. parent = _create_class_hierarchy(base_match);
  363. }
  364. }
  365. TreeItem *class_item = _create_class_item(parent, p_match.doc, !p_match.name);
  366. class_items[p_match.doc->name] = class_item;
  367. return class_item;
  368. }
  369. TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray) {
  370. Ref<Texture> icon = empty_icon;
  371. if (ui_service->has_icon(p_doc->name, "EditorIcons"))
  372. icon = ui_service->get_icon(p_doc->name, "EditorIcons");
  373. else if (ClassDB::class_exists(p_doc->name) && ClassDB::is_parent_class(p_doc->name, "Object"))
  374. icon = ui_service->get_icon("Object", "EditorIcons");
  375. String tooltip = p_doc->brief_description.strip_edges();
  376. TreeItem *item = results_tree->create_item(p_parent);
  377. item->set_icon(0, icon);
  378. item->set_text(0, p_doc->name);
  379. item->set_text(1, TTR("Class"));
  380. item->set_tooltip(0, tooltip);
  381. item->set_tooltip(1, tooltip);
  382. item->set_metadata(0, "class_name:" + p_doc->name);
  383. if (p_gray) {
  384. item->set_custom_color(0, disabled_color);
  385. item->set_custom_color(1, disabled_color);
  386. }
  387. _match_item(item, p_doc->name);
  388. return item;
  389. }
  390. TreeItem *EditorHelpSearch::Runner::_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) {
  391. String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
  392. for (int i = 0; i < p_doc->arguments.size(); i++) {
  393. const DocData::ArgumentDoc &arg = p_doc->arguments[i];
  394. tooltip += arg.type + " " + arg.name;
  395. if (arg.default_value != "")
  396. tooltip += " = " + arg.default_value;
  397. if (i < p_doc->arguments.size() - 1)
  398. tooltip += ", ";
  399. }
  400. tooltip += ")";
  401. return _create_member_item(p_parent, p_class_doc->name, "MemberMethod", p_doc->name, "Method", "method", tooltip);
  402. }
  403. TreeItem *EditorHelpSearch::Runner::_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) {
  404. String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
  405. for (int i = 0; i < p_doc->arguments.size(); i++) {
  406. const DocData::ArgumentDoc &arg = p_doc->arguments[i];
  407. tooltip += arg.type + " " + arg.name;
  408. if (arg.default_value != "")
  409. tooltip += " = " + arg.default_value;
  410. if (i < p_doc->arguments.size() - 1)
  411. tooltip += ", ";
  412. }
  413. tooltip += ")";
  414. return _create_member_item(p_parent, p_class_doc->name, "MemberSignal", p_doc->name, "Signal", "signal", tooltip);
  415. }
  416. TreeItem *EditorHelpSearch::Runner::_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc) {
  417. String tooltip = p_class_doc->name + "." + p_doc->name;
  418. return _create_member_item(p_parent, p_class_doc->name, "MemberConstant", p_doc->name, "Constant", "constant", tooltip);
  419. }
  420. TreeItem *EditorHelpSearch::Runner::_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc) {
  421. String tooltip = p_doc->type + " " + p_class_doc->name + "." + p_doc->name;
  422. tooltip += "\n " + p_class_doc->name + "." + p_doc->setter + "(value) setter";
  423. tooltip += "\n " + p_class_doc->name + "." + p_doc->getter + "() getter";
  424. return _create_member_item(p_parent, p_class_doc->name, "MemberProperty", p_doc->name, "Property", "property", tooltip);
  425. }
  426. TreeItem *EditorHelpSearch::Runner::_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc) {
  427. String tooltip = p_doc->type + " " + p_class_doc->name + "." + p_doc->name;
  428. return _create_member_item(p_parent, p_class_doc->name, "MemberTheme", p_doc->name, "Theme Property", "theme_item", tooltip);
  429. }
  430. 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) {
  431. Ref<Texture> icon;
  432. String text;
  433. if (search_flags & SEARCH_SHOW_HIERARCHY) {
  434. icon = ui_service->get_icon(p_icon, "EditorIcons");
  435. text = p_name;
  436. } else {
  437. icon = ui_service->get_icon(p_icon, "EditorIcons");
  438. /*// In flat mode, show the class icon.
  439. if (ui_service->has_icon(p_class_name, "EditorIcons"))
  440. icon = ui_service->get_icon(p_class_name, "EditorIcons");
  441. else if (ClassDB::is_parent_class(p_class_name, "Object"))
  442. icon = ui_service->get_icon("Object", "EditorIcons");*/
  443. text = p_class_name + "." + p_name;
  444. }
  445. TreeItem *item = results_tree->create_item(p_parent);
  446. item->set_icon(0, icon);
  447. item->set_text(0, text);
  448. item->set_text(1, TTR(p_type));
  449. item->set_tooltip(0, p_tooltip);
  450. item->set_tooltip(1, p_tooltip);
  451. item->set_metadata(0, "class_" + p_metatype + ":" + p_class_name + ":" + p_name);
  452. _match_item(item, p_name);
  453. return item;
  454. }
  455. bool EditorHelpSearch::Runner::work(uint64_t slot) {
  456. // Return true when the search has been completed, otherwise false.
  457. const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot;
  458. while (!_slice())
  459. if (OS::get_singleton()->get_ticks_usec() > until)
  460. return false;
  461. return true;
  462. }
  463. EditorHelpSearch::Runner::Runner(Control *p_icon_service, Tree *p_results_tree, const String &p_term, int p_search_flags) {
  464. ui_service = p_icon_service;
  465. results_tree = p_results_tree;
  466. term = p_term.strip_edges();
  467. search_flags = p_search_flags;
  468. if ((search_flags & SEARCH_CASE_SENSITIVE) == 0)
  469. term = term.to_lower();
  470. empty_icon = ui_service->get_icon("ArrowRight", "EditorIcons");
  471. disabled_color = ui_service->get_color("disabled_font_color", "Editor");
  472. phase = 0;
  473. }