editor_help_search.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**************************************************************************/
  2. /* editor_help_search.h */
  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. #ifndef EDITOR_HELP_SEARCH_H
  31. #define EDITOR_HELP_SEARCH_H
  32. #include "core/templates/rb_map.h"
  33. #include "editor/code_editor.h"
  34. #include "editor/editor_help.h"
  35. #include "editor/editor_plugin.h"
  36. #include "scene/gui/option_button.h"
  37. #include "scene/gui/tree.h"
  38. class EditorHelpSearch : public ConfirmationDialog {
  39. GDCLASS(EditorHelpSearch, ConfirmationDialog);
  40. enum SearchFlags {
  41. SEARCH_CLASSES = 1 << 0,
  42. SEARCH_CONSTRUCTORS = 1 << 1,
  43. SEARCH_METHODS = 1 << 2,
  44. SEARCH_OPERATORS = 1 << 3,
  45. SEARCH_SIGNALS = 1 << 4,
  46. SEARCH_CONSTANTS = 1 << 5,
  47. SEARCH_PROPERTIES = 1 << 6,
  48. SEARCH_THEME_ITEMS = 1 << 7,
  49. SEARCH_ANNOTATIONS = 1 << 8,
  50. SEARCH_ALL = SEARCH_CLASSES | SEARCH_CONSTRUCTORS | SEARCH_METHODS | SEARCH_OPERATORS | SEARCH_SIGNALS | SEARCH_CONSTANTS | SEARCH_PROPERTIES | SEARCH_THEME_ITEMS | SEARCH_ANNOTATIONS,
  51. SEARCH_CASE_SENSITIVE = 1 << 29,
  52. SEARCH_SHOW_HIERARCHY = 1 << 30
  53. };
  54. LineEdit *search_box = nullptr;
  55. Button *case_sensitive_button = nullptr;
  56. Button *hierarchy_button = nullptr;
  57. OptionButton *filter_combo = nullptr;
  58. Tree *results_tree = nullptr;
  59. bool old_search = false;
  60. String old_term;
  61. class Runner;
  62. Ref<Runner> search;
  63. void _update_results();
  64. void _search_box_gui_input(const Ref<InputEvent> &p_event);
  65. void _search_box_text_changed(const String &p_text);
  66. void _filter_combo_item_selected(int p_option);
  67. void _confirmed();
  68. protected:
  69. void _notification(int p_what);
  70. static void _bind_methods();
  71. public:
  72. void popup_dialog();
  73. void popup_dialog(const String &p_term);
  74. EditorHelpSearch();
  75. };
  76. class EditorHelpSearch::Runner : public RefCounted {
  77. enum Phase {
  78. PHASE_MATCH_CLASSES_INIT,
  79. PHASE_MATCH_CLASSES,
  80. PHASE_CLASS_ITEMS_INIT,
  81. PHASE_CLASS_ITEMS,
  82. PHASE_MEMBER_ITEMS_INIT,
  83. PHASE_MEMBER_ITEMS,
  84. PHASE_SELECT_MATCH,
  85. PHASE_MAX
  86. };
  87. int phase = 0;
  88. struct ClassMatch {
  89. DocData::ClassDoc *doc = nullptr;
  90. bool name = false;
  91. Vector<DocData::MethodDoc *> constructors;
  92. Vector<DocData::MethodDoc *> methods;
  93. Vector<DocData::MethodDoc *> operators;
  94. Vector<DocData::MethodDoc *> signals;
  95. Vector<DocData::ConstantDoc *> constants;
  96. Vector<DocData::PropertyDoc *> properties;
  97. Vector<DocData::ThemeItemDoc *> theme_properties;
  98. Vector<DocData::MethodDoc *> annotations;
  99. bool required() {
  100. return name || methods.size() || signals.size() || constants.size() || properties.size() || theme_properties.size() || annotations.size();
  101. }
  102. };
  103. Control *ui_service = nullptr;
  104. Tree *results_tree = nullptr;
  105. String term;
  106. Vector<String> terms;
  107. int search_flags;
  108. Color disabled_color;
  109. HashMap<String, DocData::ClassDoc>::Iterator iterator_doc;
  110. HashMap<String, ClassMatch> matches;
  111. HashMap<String, ClassMatch>::Iterator iterator_match;
  112. TreeItem *root_item = nullptr;
  113. HashMap<String, TreeItem *> class_items;
  114. TreeItem *matched_item = nullptr;
  115. float match_highest_score = 0;
  116. bool _is_class_disabled_by_feature_profile(const StringName &p_class);
  117. bool _slice();
  118. bool _phase_match_classes_init();
  119. bool _phase_match_classes();
  120. bool _phase_class_items_init();
  121. bool _phase_class_items();
  122. bool _phase_member_items_init();
  123. bool _phase_member_items();
  124. bool _phase_select_match();
  125. String _build_method_tooltip(const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) const;
  126. void _match_method_name_and_push_back(Vector<DocData::MethodDoc> &p_methods, Vector<DocData::MethodDoc *> *r_match_methods);
  127. bool _all_terms_in_name(String name);
  128. bool _match_string(const String &p_term, const String &p_string) const;
  129. void _match_item(TreeItem *p_item, const String &p_text);
  130. TreeItem *_create_class_hierarchy(const ClassMatch &p_match);
  131. TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray);
  132. TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc);
  133. TreeItem *_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc);
  134. TreeItem *_create_annotation_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc);
  135. TreeItem *_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc);
  136. TreeItem *_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc);
  137. TreeItem *_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ThemeItemDoc *p_doc);
  138. TreeItem *_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, bool is_deprecated, bool is_experimental);
  139. public:
  140. bool work(uint64_t slot = 100000);
  141. Runner(Control *p_icon_service, Tree *p_results_tree, const String &p_term, int p_search_flags);
  142. };
  143. #endif // EDITOR_HELP_SEARCH_H