editor_help_search.cpp 22 KB

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