editor_help_search.cpp 21 KB

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