From fbb9a215070139b9872cc6f57bdd1d5ff17888bb Mon Sep 17 00:00:00 2001 From: RedMser Date: Thu, 1 Sep 2022 18:11:19 +0200 Subject: Allow searching for annotations in help --- editor/editor_help_search.cpp | 64 +++++++++++++++++++++++---------------- editor/editor_help_search.h | 9 ++++-- editor/icons/MemberAnnotation.svg | 1 + 3 files changed, 46 insertions(+), 28 deletions(-) create mode 100644 editor/icons/MemberAnnotation.svg (limited to 'editor') diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index 2e35f21e47..af0cff9ad6 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -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(&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); diff --git a/editor/editor_help_search.h b/editor/editor_help_search.h index 3f17c992ac..26abaec6e6 100644 --- a/editor/editor_help_search.h +++ b/editor/editor_help_search.h @@ -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 constants; Vector properties; Vector theme_properties; + Vector 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); diff --git a/editor/icons/MemberAnnotation.svg b/editor/icons/MemberAnnotation.svg new file mode 100644 index 0000000000..c73ebf7b9b --- /dev/null +++ b/editor/icons/MemberAnnotation.svg @@ -0,0 +1 @@ + -- cgit v1.2.3