| 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 | #ifndef EDITOR_HELP_SEARCH_H |
| 32 | #define EDITOR_HELP_SEARCH_H |
| 33 | |
| 34 | #include "core/templates/rb_map.h" |
| 35 | #include "editor/code_editor.h" |
| 36 | #include "editor/editor_help.h" |
| 37 | #include "editor/editor_plugin.h" |
| 38 | #include "scene/gui/option_button.h" |
| 39 | #include "scene/gui/tree.h" |
| 40 | |
| 41 | class EditorHelpSearch : public ConfirmationDialog { |
| 42 | GDCLASS(EditorHelpSearch, ConfirmationDialog); |
| 43 | |
| 44 | enum SearchFlags { |
| 45 | SEARCH_CLASSES = 1 << 0, |
| 46 | SEARCH_CONSTRUCTORS = 1 << 1, |
| 47 | SEARCH_METHODS = 1 << 2, |
| 48 | SEARCH_OPERATORS = 1 << 3, |
| 49 | SEARCH_SIGNALS = 1 << 4, |
| 50 | SEARCH_CONSTANTS = 1 << 5, |
| 51 | SEARCH_PROPERTIES = 1 << 6, |
| 52 | SEARCH_THEME_ITEMS = 1 << 7, |
| 53 | SEARCH_ANNOTATIONS = 1 << 8, |
| 54 | SEARCH_ALL = SEARCH_CLASSES | SEARCH_CONSTRUCTORS | SEARCH_METHODS | SEARCH_OPERATORS | SEARCH_SIGNALS | SEARCH_CONSTANTS | SEARCH_PROPERTIES | SEARCH_THEME_ITEMS | SEARCH_ANNOTATIONS, |
| 55 | SEARCH_CASE_SENSITIVE = 1 << 29, |
| 56 | SEARCH_SHOW_HIERARCHY = 1 << 30 |
| 57 | }; |
| 58 | |
| 59 | LineEdit *search_box = nullptr; |
| 60 | Button *case_sensitive_button = nullptr; |
| 61 | Button *hierarchy_button = nullptr; |
| 62 | OptionButton *filter_combo = nullptr; |
| 63 | Tree *results_tree = nullptr; |
| 64 | bool old_search = false; |
| 65 | String old_term; |
| 66 | |
| 67 | class Runner; |
| 68 | Ref<Runner> search; |
| 69 | |
| 70 | void _update_icons(); |
| 71 | void _update_results(); |
| 72 | |
| 73 | void _search_box_gui_input(const Ref<InputEvent> &p_event); |
| 74 | void _search_box_text_changed(const String &p_text); |
| 75 | void _filter_combo_item_selected(int p_option); |
| 76 | void _confirmed(); |
| 77 | |
| 78 | protected: |
| 79 | void _notification(int p_what); |
| 80 | static void _bind_methods(); |
| 81 | |
| 82 | public: |
| 83 | void (); |
| 84 | void (const String &p_term); |
| 85 | |
| 86 | EditorHelpSearch(); |
| 87 | }; |
| 88 | |
| 89 | class EditorHelpSearch::Runner : public RefCounted { |
| 90 | enum Phase { |
| 91 | PHASE_MATCH_CLASSES_INIT, |
| 92 | PHASE_MATCH_CLASSES, |
| 93 | PHASE_CLASS_ITEMS_INIT, |
| 94 | PHASE_CLASS_ITEMS, |
| 95 | PHASE_MEMBER_ITEMS_INIT, |
| 96 | PHASE_MEMBER_ITEMS, |
| 97 | PHASE_SELECT_MATCH, |
| 98 | PHASE_MAX |
| 99 | }; |
| 100 | int phase = 0; |
| 101 | |
| 102 | struct ClassMatch { |
| 103 | DocData::ClassDoc *doc = nullptr; |
| 104 | bool name = false; |
| 105 | Vector<DocData::MethodDoc *> constructors; |
| 106 | Vector<DocData::MethodDoc *> methods; |
| 107 | Vector<DocData::MethodDoc *> operators; |
| 108 | Vector<DocData::MethodDoc *> signals; |
| 109 | Vector<DocData::ConstantDoc *> constants; |
| 110 | Vector<DocData::PropertyDoc *> properties; |
| 111 | Vector<DocData::ThemeItemDoc *> theme_properties; |
| 112 | Vector<DocData::MethodDoc *> annotations; |
| 113 | |
| 114 | bool required() { |
| 115 | return name || methods.size() || signals.size() || constants.size() || properties.size() || theme_properties.size() || annotations.size(); |
| 116 | } |
| 117 | }; |
| 118 | |
| 119 | Control *ui_service = nullptr; |
| 120 | Tree *results_tree = nullptr; |
| 121 | String term; |
| 122 | Vector<String> terms; |
| 123 | int search_flags; |
| 124 | |
| 125 | Color disabled_color; |
| 126 | |
| 127 | HashMap<String, DocData::ClassDoc>::Iterator iterator_doc; |
| 128 | HashMap<String, ClassMatch> matches; |
| 129 | HashMap<String, ClassMatch>::Iterator iterator_match; |
| 130 | TreeItem *root_item = nullptr; |
| 131 | HashMap<String, TreeItem *> class_items; |
| 132 | TreeItem *matched_item = nullptr; |
| 133 | float match_highest_score = 0; |
| 134 | |
| 135 | bool _is_class_disabled_by_feature_profile(const StringName &p_class); |
| 136 | |
| 137 | bool _slice(); |
| 138 | bool _phase_match_classes_init(); |
| 139 | bool _phase_match_classes(); |
| 140 | bool _phase_class_items_init(); |
| 141 | bool _phase_class_items(); |
| 142 | bool _phase_member_items_init(); |
| 143 | bool _phase_member_items(); |
| 144 | bool _phase_select_match(); |
| 145 | |
| 146 | String _build_method_tooltip(const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) const; |
| 147 | |
| 148 | void _match_method_name_and_push_back(Vector<DocData::MethodDoc> &p_methods, Vector<DocData::MethodDoc *> *r_match_methods); |
| 149 | bool _all_terms_in_name(String name); |
| 150 | bool _match_string(const String &p_term, const String &p_string) const; |
| 151 | void _match_item(TreeItem *p_item, const String &p_text); |
| 152 | TreeItem *_create_class_hierarchy(const ClassMatch &p_match); |
| 153 | TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray); |
| 154 | TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc); |
| 155 | TreeItem *_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc); |
| 156 | TreeItem *_create_annotation_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const String &p_text, const DocData::MethodDoc *p_doc); |
| 157 | TreeItem *_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc); |
| 158 | TreeItem *_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc); |
| 159 | TreeItem *_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ThemeItemDoc *p_doc); |
| 160 | TreeItem *_create_member_item(TreeItem *p_parent, const String &p_class_name, const String &p_icon, const String &p_name, const String &p_text, const String &p_type, const String &p_metatype, const String &p_tooltip, bool is_deprecated, bool is_experimental); |
| 161 | |
| 162 | public: |
| 163 | bool work(uint64_t slot = 100000); |
| 164 | |
| 165 | Runner(Control *p_icon_service, Tree *p_results_tree, const String &p_term, int p_search_flags); |
| 166 | }; |
| 167 | |
| 168 | #endif // EDITOR_HELP_SEARCH_H |
| 169 | |