editor_help_search.cpp 21 KB

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