From f556bffea544c61ffa900cf0e8615872ad55115f Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Thu, 7 Dec 2023 16:18:47 +0100 Subject: [PATCH] Nest hierarchy --- editor/editor_help_search.cpp | 82 ++++++++++++++++++++++++++++------- editor/editor_help_search.h | 1 + 2 files changed, 67 insertions(+), 16 deletions(-) diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index 856f37266529..c00f3bffd4ee 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -536,6 +536,21 @@ bool EditorHelpSearch::Runner::_phase_fill_member_items_init() { return true; } +TreeItem *EditorHelpSearch::Runner::_create_category_item(TreeItem *p_parent, const String &p_class, const StringName &p_icon, const String &p_metatype, const String &p_text) { + const String item_meta = "class_" + p_metatype + ":" + p_class; + + TreeItem *item = nullptr; + if (_find_or_create_item(p_parent, item_meta, item)) { + item->set_icon(0, ui_service->get_editor_theme_icon(p_icon)); + item->set_text(0, p_text); + item->set_selectable(0, false); + item->set_metadata(0, item_meta); + } + item->set_collapsed(true); + + return item; +} + bool EditorHelpSearch::Runner::_phase_fill_member_items() { if (matched_classes.is_empty()) { return true; @@ -561,44 +576,79 @@ bool EditorHelpSearch::Runner::_phase_fill_member_items() { item->set_custom_color(1, disabled_color); } - if (search_flags & SEARCH_CONSTRUCTORS) { + // Create common header if required. + const bool search_all = (search_flags & SEARCH_ALL) == SEARCH_ALL; + + if ((search_flags & SEARCH_CONSTRUCTORS) && !class_doc->constructors.is_empty()) { + TreeItem *parent_item = item; + if (search_all) { + parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberConstructor"), TTRC("Constructors"), "constructors"); + } for (const DocData::MethodDoc &constructor_doc : class_doc->constructors) { - _create_constructor_item(item, class_doc, &constructor_doc); + _create_constructor_item(parent_item, class_doc, &constructor_doc); } } - if (search_flags & SEARCH_METHODS) { + if ((search_flags & SEARCH_METHODS) && !class_doc->methods.is_empty()) { + TreeItem *parent_item = item; + if (search_all) { + parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberMethod"), TTRC("Methods"), "methods"); + } for (const DocData::MethodDoc &method_doc : class_doc->methods) { - _create_method_item(item, class_doc, &method_doc); + _create_method_item(parent_item, class_doc, &method_doc); } } - if (search_flags & SEARCH_SIGNALS) { + if ((search_flags & SEARCH_OPERATORS) && !class_doc->operators.is_empty()) { + TreeItem *parent_item = item; + if (search_all) { + parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberOperator"), TTRC("Operators"), "operators"); + } for (const DocData::MethodDoc &operator_doc : class_doc->operators) { - _create_operator_item(item, class_doc, &operator_doc); + _create_operator_item(parent_item, class_doc, &operator_doc); } } - if (search_flags & SEARCH_SIGNALS) { + if ((search_flags & SEARCH_SIGNALS) && !class_doc->signals.is_empty()) { + TreeItem *parent_item = item; + if (search_all) { + parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberSignal"), TTRC("Signals"), "signals"); + } for (const DocData::MethodDoc &signal_doc : class_doc->signals) { - _create_signal_item(item, class_doc, &signal_doc); + _create_signal_item(parent_item, class_doc, &signal_doc); } } - if (search_flags & SEARCH_CONSTANTS) { + if ((search_flags & SEARCH_CONSTANTS) && !class_doc->constants.is_empty()) { + TreeItem *parent_item = item; + if (search_all) { + parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberConstant"), TTRC("Constants"), "constants"); + } for (const DocData::ConstantDoc &constant_doc : class_doc->constants) { - _create_constant_item(item, class_doc, &constant_doc); + _create_constant_item(parent_item, class_doc, &constant_doc); } } - if (search_flags & SEARCH_PROPERTIES) { + if ((search_flags & SEARCH_PROPERTIES) && !class_doc->properties.is_empty()) { + TreeItem *parent_item = item; + if (search_all) { + parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberProperty"), TTRC("Prtoperties"), "propertiess"); + } for (const DocData::PropertyDoc &property_doc : class_doc->properties) { - _create_property_item(item, class_doc, &property_doc); + _create_property_item(parent_item, class_doc, &property_doc); } } - if (search_flags & SEARCH_THEME_ITEMS) { + if ((search_flags & SEARCH_THEME_ITEMS) && !class_doc->theme_properties.is_empty()) { + TreeItem *parent_item = item; + if (search_all) { + parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberTheme"), TTRC("Theme Properties"), "theme_items"); + } for (const DocData::ThemeItemDoc &theme_property_doc : class_doc->theme_properties) { - _create_theme_property_item(item, class_doc, &theme_property_doc); + _create_theme_property_item(parent_item, class_doc, &theme_property_doc); } } - if (search_flags & SEARCH_ANNOTATIONS) { + if ((search_flags & SEARCH_ANNOTATIONS) && !class_doc->annotations.is_empty()) { + TreeItem *parent_item = item; + if (search_all) { + parent_item = _create_category_item(parent_item, class_doc->name, SNAME("MemberAnnotation"), TTRC("Annotations"), "annotations"); + } for (const DocData::MethodDoc &annotation_doc : class_doc->annotations) { - _create_annotation_item(item, class_doc, &annotation_doc); + _create_annotation_item(parent_item, class_doc, &annotation_doc); } } } diff --git a/editor/editor_help_search.h b/editor/editor_help_search.h index 78ba6f93d053..b8b3c26b41e8 100644 --- a/editor/editor_help_search.h +++ b/editor/editor_help_search.h @@ -198,6 +198,7 @@ class EditorHelpSearch::Runner : public RefCounted { TreeItem *_create_class_hierarchy(const ClassMatch &p_match); TreeItem *_create_class_hierarchy(const DocData::ClassDoc *p_class_doc, const String &p_matching_keyword, bool p_gray); TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray, const String &p_matching_keyword); + TreeItem *_create_category_item(TreeItem *p_parent, const String &p_class, const StringName &p_icon, const String &p_metatype, const String &p_type); TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch &p_match); TreeItem *_create_constructor_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch &p_match); TreeItem *_create_operator_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const MemberMatch &p_match);