mirror of
https://github.com/godotengine/godot.git
synced 2024-11-10 14:12:51 +00:00
Merge pull request #65207 from RedMser/annotation-search
Allow searching for annotations in help
This commit is contained in:
commit
93f177bd03
@ -231,6 +231,7 @@ EditorHelpSearch::EditorHelpSearch() {
|
||||
filter_combo->add_item(TTR("Methods Only"), SEARCH_METHODS);
|
||||
filter_combo->add_item(TTR("Operators Only"), SEARCH_OPERATORS);
|
||||
filter_combo->add_item(TTR("Signals Only"), SEARCH_SIGNALS);
|
||||
filter_combo->add_item(TTR("Annotations Only"), SEARCH_ANNOTATIONS);
|
||||
filter_combo->add_item(TTR("Constants Only"), SEARCH_CONSTANTS);
|
||||
filter_combo->add_item(TTR("Properties Only"), SEARCH_PROPERTIES);
|
||||
filter_combo->add_item(TTR("Theme Properties Only"), SEARCH_THEME_ITEMS);
|
||||
@ -339,8 +340,9 @@ bool EditorHelpSearch::Runner::_phase_match_classes() {
|
||||
match.name = (term.is_empty() && (!class_doc.is_script_doc || class_doc.name[0] != '\"')) || _match_string(term, class_doc.name);
|
||||
}
|
||||
|
||||
// Match members if the term is long enough.
|
||||
if (term.length() > 1) {
|
||||
// Match members only if the term is long enough, to avoid slow performance from building a large tree.
|
||||
// Make an exception for annotations, since there are not that many of them.
|
||||
if (term.length() > 1 || term == "@") {
|
||||
if (search_flags & SEARCH_CONSTRUCTORS) {
|
||||
for (int i = 0; i < class_doc.constructors.size(); i++) {
|
||||
String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? class_doc.constructors[i].name : class_doc.constructors[i].name.to_lower();
|
||||
@ -402,6 +404,13 @@ bool EditorHelpSearch::Runner::_phase_match_classes() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (search_flags & SEARCH_ANNOTATIONS) {
|
||||
for (int i = 0; i < class_doc.annotations.size(); i++) {
|
||||
if (_match_string(term, class_doc.annotations[i].name)) {
|
||||
match.annotations.push_back(const_cast<DocData::MethodDoc *>(&class_doc.annotations[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
matches[class_doc.name] = match;
|
||||
}
|
||||
matches[class_doc.name] = match;
|
||||
@ -485,6 +494,10 @@ bool EditorHelpSearch::Runner::_phase_member_items() {
|
||||
for (int i = 0; i < match.theme_properties.size(); i++) {
|
||||
_create_theme_property_item(parent, match.doc, match.theme_properties[i]);
|
||||
}
|
||||
for (int i = 0; i < match.annotations.size(); i++) {
|
||||
// Hide the redundant leading @ symbol.
|
||||
_create_annotation_item(parent, match.doc, match.annotations[i]->name.substr(1), match.annotations[i]);
|
||||
}
|
||||
|
||||
++iterator_match;
|
||||
return !iterator_match;
|
||||
@ -523,6 +536,22 @@ void EditorHelpSearch::Runner::_match_item(TreeItem *p_item, const String &p_tex
|
||||
}
|
||||
}
|
||||
|
||||
String EditorHelpSearch::Runner::_build_method_tooltip(const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) const {
|
||||
String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
|
||||
for (int i = 0; i < p_doc->arguments.size(); i++) {
|
||||
const DocData::ArgumentDoc &arg = p_doc->arguments[i];
|
||||
tooltip += arg.type + " " + arg.name;
|
||||
if (!arg.default_value.is_empty()) {
|
||||
tooltip += " = " + arg.default_value;
|
||||
}
|
||||
if (i < p_doc->arguments.size() - 1) {
|
||||
tooltip += ", ";
|
||||
}
|
||||
}
|
||||
tooltip += ")";
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_match) {
|
||||
if (p_match.doc->name.is_empty()) {
|
||||
return nullptr;
|
||||
@ -576,37 +605,20 @@ TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const
|
||||
}
|
||||
|
||||
TreeItem *EditorHelpSearch::Runner::_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc) {
|
||||
String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
|
||||
for (int i = 0; i < p_doc->arguments.size(); i++) {
|
||||
const DocData::ArgumentDoc &arg = p_doc->arguments[i];
|
||||
tooltip += arg.type + " " + arg.name;
|
||||
if (!arg.default_value.is_empty()) {
|
||||
tooltip += " = " + arg.default_value;
|
||||
}
|
||||
if (i < p_doc->arguments.size() - 1) {
|
||||
tooltip += ", ";
|
||||
}
|
||||
}
|
||||
tooltip += ")";
|
||||
String tooltip = _build_method_tooltip(p_class_doc, p_doc);
|
||||
return _create_member_item(p_parent, p_class_doc->name, "MemberMethod", p_doc->name, p_text, TTRC("Method"), "method", tooltip);
|
||||
}
|
||||
|
||||
TreeItem *EditorHelpSearch::Runner::_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) {
|
||||
String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "(";
|
||||
for (int i = 0; i < p_doc->arguments.size(); i++) {
|
||||
const DocData::ArgumentDoc &arg = p_doc->arguments[i];
|
||||
tooltip += arg.type + " " + arg.name;
|
||||
if (!arg.default_value.is_empty()) {
|
||||
tooltip += " = " + arg.default_value;
|
||||
}
|
||||
if (i < p_doc->arguments.size() - 1) {
|
||||
tooltip += ", ";
|
||||
}
|
||||
}
|
||||
tooltip += ")";
|
||||
String tooltip = _build_method_tooltip(p_class_doc, p_doc);
|
||||
return _create_member_item(p_parent, p_class_doc->name, "MemberSignal", p_doc->name, p_doc->name, TTRC("Signal"), "signal", tooltip);
|
||||
}
|
||||
|
||||
TreeItem *EditorHelpSearch::Runner::_create_annotation_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc) {
|
||||
String tooltip = _build_method_tooltip(p_class_doc, p_doc);
|
||||
return _create_member_item(p_parent, p_class_doc->name, "MemberAnnotation", p_doc->name, p_text, TTRC("Annotation"), "annotation", tooltip);
|
||||
}
|
||||
|
||||
TreeItem *EditorHelpSearch::Runner::_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc) {
|
||||
String tooltip = p_class_doc->name + "." + p_doc->name;
|
||||
return _create_member_item(p_parent, p_class_doc->name, "MemberConstant", p_doc->name, p_doc->name, TTRC("Constant"), "constant", tooltip);
|
||||
|
@ -50,7 +50,8 @@ class EditorHelpSearch : public ConfirmationDialog {
|
||||
SEARCH_CONSTANTS = 1 << 5,
|
||||
SEARCH_PROPERTIES = 1 << 6,
|
||||
SEARCH_THEME_ITEMS = 1 << 7,
|
||||
SEARCH_ALL = SEARCH_CLASSES | SEARCH_CONSTRUCTORS | SEARCH_METHODS | SEARCH_OPERATORS | SEARCH_SIGNALS | SEARCH_CONSTANTS | SEARCH_PROPERTIES | SEARCH_THEME_ITEMS,
|
||||
SEARCH_ANNOTATIONS = 1 << 8,
|
||||
SEARCH_ALL = SEARCH_CLASSES | SEARCH_CONSTRUCTORS | SEARCH_METHODS | SEARCH_OPERATORS | SEARCH_SIGNALS | SEARCH_CONSTANTS | SEARCH_PROPERTIES | SEARCH_THEME_ITEMS | SEARCH_ANNOTATIONS,
|
||||
SEARCH_CASE_SENSITIVE = 1 << 29,
|
||||
SEARCH_SHOW_HIERARCHY = 1 << 30
|
||||
};
|
||||
@ -108,9 +109,10 @@ class EditorHelpSearch::Runner : public RefCounted {
|
||||
Vector<DocData::ConstantDoc *> constants;
|
||||
Vector<DocData::PropertyDoc *> properties;
|
||||
Vector<DocData::ThemeItemDoc *> theme_properties;
|
||||
Vector<DocData::MethodDoc *> annotations;
|
||||
|
||||
bool required() {
|
||||
return name || methods.size() || signals.size() || constants.size() || properties.size() || theme_properties.size();
|
||||
return name || methods.size() || signals.size() || constants.size() || properties.size() || theme_properties.size() || annotations.size();
|
||||
}
|
||||
};
|
||||
|
||||
@ -141,12 +143,15 @@ class EditorHelpSearch::Runner : public RefCounted {
|
||||
bool _phase_member_items();
|
||||
bool _phase_select_match();
|
||||
|
||||
String _build_method_tooltip(const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) const;
|
||||
|
||||
bool _match_string(const String &p_term, const String &p_string) const;
|
||||
void _match_item(TreeItem *p_item, const String &p_text);
|
||||
TreeItem *_create_class_hierarchy(const ClassMatch &p_match);
|
||||
TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray);
|
||||
TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc);
|
||||
TreeItem *_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc);
|
||||
TreeItem *_create_annotation_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc);
|
||||
TreeItem *_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc);
|
||||
TreeItem *_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc);
|
||||
TreeItem *_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ThemeItemDoc *p_doc);
|
||||
|
1
editor/icons/MemberAnnotation.svg
Normal file
1
editor/icons/MemberAnnotation.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg width="16" height="16" version="1.0" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><script id="custom-useragent-string-page-script"/><path d="m13.821 12.756c-5.0033 3.9148-12.551 2.248-12.49-4.538 0.67424-11.471 17.312-7.4502 12.446 2.1173-1.0549 1.1955-2.0737 1.4617-3.1983 0.4329-0.21023-0.19282-0.44783-1.1594-0.3819-1.5089 0.35827-1.8946 1.0885-4.0778-0.72151-4.7234-2.4171-0.86457-4.5592 1.6495-4.9697 4.0193-0.47396 2.7343 2.284 3.3749 4.1487 1.9879 0.4553-0.36324 1.6433-1.3796 1.6806-1.9742" fill="none" stroke="#e0e0e0" stroke-linejoin="round" stroke-width="1.4928"/></svg>
|
After Width: | Height: | Size: 597 B |
Loading…
Reference in New Issue
Block a user