| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "editor/plugins/editor_plugin.h" |
| 34 |
#include "scene/gui/dialogs.h" |
| 35 |
#include "scene/gui/option_button.h" |
| 36 |
#include "scene/gui/tree.h" |
| 37 |
|
| 38 |
class EditorHelpSearch : public ConfirmationDialog { |
| 39 |
GDCLASS(EditorHelpSearch, ConfirmationDialog); |
| 40 |
|
| 41 |
enum SearchFlags { |
| 42 |
SEARCH_CLASSES = 1 << 0, |
| 43 |
SEARCH_CONSTRUCTORS = 1 << 1, |
| 44 |
SEARCH_METHODS = 1 << 2, |
| 45 |
SEARCH_OPERATORS = 1 << 3, |
| 46 |
SEARCH_SIGNALS = 1 << 4, |
| 47 |
SEARCH_CONSTANTS = 1 << 5, |
| 48 |
SEARCH_PROPERTIES = 1 << 6, |
| 49 |
SEARCH_THEME_ITEMS = 1 << 7, |
| 50 |
SEARCH_ANNOTATIONS = 1 << 8, |
| 51 |
SEARCH_ALL = SEARCH_CLASSES | SEARCH_CONSTRUCTORS | SEARCH_METHODS | SEARCH_OPERATORS | SEARCH_SIGNALS | SEARCH_CONSTANTS | SEARCH_PROPERTIES | SEARCH_THEME_ITEMS | SEARCH_ANNOTATIONS, |
| 52 |
SEARCH_CASE_SENSITIVE = 1 << 29, |
| 53 |
SEARCH_SHOW_HIERARCHY = 1 << 30 |
| 54 |
}; |
| 55 |
|
| 56 |
LineEdit *search_box = nullptr; |
| 57 |
Button *case_sensitive_button = nullptr; |
| 58 |
Button *hierarchy_button = nullptr; |
| 59 |
OptionButton *filter_combo = nullptr; |
| 60 |
Tree *results_tree = nullptr; |
| 61 |
bool old_search = false; |
| 62 |
String old_term; |
| 63 |
int old_search_flags = 0; |
| 64 |
|
| 65 |
class Runner; |
| 66 |
Ref<Runner> search; |
| 67 |
|
| 68 |
struct TreeCache { |
| 69 |
HashMap<String, TreeItem *> item_cache; |
| 70 |
|
| 71 |
void clear(); |
| 72 |
|
| 73 |
~TreeCache() { |
| 74 |
clear(); |
| 75 |
} |
| 76 |
} tree_cache; |
| 77 |
|
| 78 |
void _update_results(); |
| 79 |
|
| 80 |
void _search_box_gui_input(const Ref<InputEvent> &p_event); |
| 81 |
void _search_box_text_changed(const String &p_text); |
| 82 |
void _filter_combo_item_selected(int p_option); |
| 83 |
void _confirmed(); |
| 84 |
|
| 85 |
bool _all_terms_in_name(const Vector<String> &p_terms, const String &p_name) const; |
| 86 |
void _match_method_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::MethodDoc> &p_methods, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const; |
| 87 |
void _match_const_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::ConstantDoc> &p_constants, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const; |
| 88 |
void _match_property_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::PropertyDoc> &p_properties, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const; |
| 89 |
void _match_theme_property_name_and_push_back(const String &p_term, const Vector<String> &p_terms, Vector<DocData::ThemeItemDoc> &p_properties, const String &p_type, const String &p_metatype, const String &p_class_name, Dictionary &r_result) const; |
| 90 |
|
| 91 |
Dictionary _native_search_cb(const String &p_search_string, int p_result_limit); |
| 92 |
void _native_action_cb(const String &p_item_string); |
| 93 |
|
| 94 |
protected: |
| 95 |
void _notification(int p_what); |
| 96 |
static void _bind_methods(); |
| 97 |
|
| 98 |
public: |
| 99 |
void popup_dialog(); |
| 100 |
void popup_dialog(const String &p_term); |
| 101 |
|
| 102 |
EditorHelpSearch(); |
| 103 |
}; |
| 104 |
|
| 105 |
class EditorHelpSearch::Runner : public RefCounted { |
| 106 |
enum Phase { |
| 107 |
PHASE_MATCH_CLASSES_INIT, |
| 108 |
PHASE_MATCH_CLASSES, |
| 109 |
PHASE_CLASS_ITEMS_INIT, |
| 110 |
PHASE_CLASS_ITEMS, |
| 111 |
PHASE_MEMBER_ITEMS_INIT, |
| 112 |
PHASE_MEMBER_ITEMS, |
| 113 |
PHASE_SELECT_MATCH, |
| 114 |
PHASE_MAX |
| 115 |
}; |
| 116 |
int phase = 0; |
| 117 |
|
| 118 |
template <typename T> |
| 119 |
struct MemberMatch { |
| 120 |
const T *doc = nullptr; |
| 121 |
bool name = false; |
| 122 |
String keyword; |
| 123 |
|
| 124 |
MemberMatch() {} |
| 125 |
MemberMatch(const T *p_doc) : |
| 126 |
doc(p_doc) {} |
| 127 |
}; |
| 128 |
|
| 129 |
struct ClassMatch { |
| 130 |
const DocData::ClassDoc *doc = nullptr; |
| 131 |
bool name = false; |
| 132 |
String keyword; |
| 133 |
LocalVector<MemberMatch<DocData::MethodDoc>> constructors; |
| 134 |
LocalVector<MemberMatch<DocData::MethodDoc>> methods; |
| 135 |
LocalVector<MemberMatch<DocData::MethodDoc>> operators; |
| 136 |
LocalVector<MemberMatch<DocData::MethodDoc>> signals; |
| 137 |
LocalVector<MemberMatch<DocData::ConstantDoc>> constants; |
| 138 |
LocalVector<MemberMatch<DocData::PropertyDoc>> properties; |
| 139 |
LocalVector<MemberMatch<DocData::ThemeItemDoc>> theme_properties; |
| 140 |
LocalVector<MemberMatch<DocData::MethodDoc>> annotations; |
| 141 |
|
| 142 |
bool required() { |
| 143 |
return name || !keyword.is_empty() || !constructors.is_empty() || !methods.is_empty() || !operators.is_empty() || !signals.is_empty() || !constants.is_empty() || !properties.is_empty() || !theme_properties.is_empty() || !annotations.is_empty(); |
| 144 |
} |
| 145 |
}; |
| 146 |
|
| 147 |
Control *ui_service = nullptr; |
| 148 |
Tree *results_tree = nullptr; |
| 149 |
TreeCache *tree_cache = nullptr; |
| 150 |
String term; |
| 151 |
Vector<String> terms; |
| 152 |
int search_flags; |
| 153 |
|
| 154 |
Color disabled_color; |
| 155 |
|
| 156 |
HashMap<String, DocData::ClassDoc>::Iterator iterator_doc; |
| 157 |
LocalVector<RBSet<String, NaturalNoCaseComparator>::Element *> iterator_stack; |
| 158 |
HashMap<String, ClassMatch> matches; |
| 159 |
HashMap<String, ClassMatch>::Iterator iterator_match; |
| 160 |
LocalVector<Pair<DocData::ClassDoc *, String>> matched_classes; |
| 161 |
TreeItem *root_item = nullptr; |
| 162 |
HashMap<String, TreeItem *> class_items; |
| 163 |
TreeItem *matched_item = nullptr; |
| 164 |
float match_highest_score = 0; |
| 165 |
|
| 166 |
bool _is_class_disabled_by_feature_profile(const StringName &p_class); |
| 167 |
|
| 168 |
void _populate_cache(); |
| 169 |
bool _find_or_create_item(TreeItem *p_parent, const String &p_item_meta, TreeItem *&r_item); |
| 170 |
|
| 171 |
bool _fill(); |
| 172 |
bool _phase_fill_classes_init(); |
| 173 |
bool _phase_fill_classes(); |
| 174 |
bool _phase_fill_member_items_init(); |
| 175 |
bool _phase_fill_member_items(); |
| 176 |
|
| 177 |
bool _slice(); |
| 178 |
bool _phase_match_classes_init(); |
| 179 |
bool _phase_match_classes(); |
| 180 |
bool _phase_class_items_init(); |
| 181 |
bool _phase_class_items(); |
| 182 |
bool _phase_member_items_init(); |
| 183 |
bool _phase_member_items(); |
| 184 |
bool _phase_select_match(); |
| 185 |
|
| 186 |
String _build_method_tooltip(const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) const; |
| 187 |
String _build_keywords_tooltip(const String &p_keywords) const; |
| 188 |
|
| 189 |
void _match_method_name_and_push_back(Vector<DocData::MethodDoc> &p_methods, LocalVector<MemberMatch<DocData::MethodDoc>> *r_match_methods); |
| 190 |
bool _all_terms_in_name(const String &p_name) const; |
| 191 |
String _match_keywords_in_all_terms(const String &p_keywords) const; |
| 192 |
bool _match_string(const String &p_term, const String &p_string) const; |
| 193 |
String _match_keywords(const String &p_term, const String &p_keywords) const; |
| 194 |
void _match_item(TreeItem *p_item, const String &p_text, bool p_is_keywords = false); |
| 195 |
TreeItem *_create_class_hierarchy(const ClassMatch &p_match); |
| 196 |
TreeItem *_create_class_hierarchy(const DocData::ClassDoc *p_class_doc, const String &p_matching_keyword, bool p_gray); |
| 197 |
TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray, const String &p_matching_keyword); |
| 198 |
TreeItem *_create_category_item(TreeItem *p_parent, const String &p_class, const StringName &p_icon, const String &p_text, const String &p_metatype); |
| 199 |
TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match); |
| 200 |
TreeItem *_create_constructor_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match); |
| 201 |
TreeItem *_create_operator_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match); |
| 202 |
TreeItem *_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match); |
| 203 |
TreeItem *_create_annotation_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::MethodDoc> &p_match); |
| 204 |
TreeItem *_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::ConstantDoc> &p_match); |
| 205 |
TreeItem *_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::PropertyDoc> &p_match); |
| 206 |
TreeItem *_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch<DocData::ThemeItemDoc> &p_match); |
| 207 |
TreeItem *_create_member_item(TreeItem *p_parent, const String &p_class_name, const StringName &p_icon, const String &p_name, const String &p_text, const String &p_type, const String &p_metatype, const String &p_tooltip, const String &p_keywords, bool p_is_deprecated, bool p_is_experimental, const String &p_matching_keyword); |
| 208 |
|
| 209 |
public: |
| 210 |
bool work(uint64_t slot = 100000); |
| 211 |
|
| 212 |
Runner(Control *p_icon_service, Tree *p_results_tree, TreeCache *p_tree_cache, const String &p_term, int p_search_flags); |
| 213 |
}; |