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