1 /*************************************************************************/ 2 /* editor_help_search.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 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/ordered_hash_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_METHODS = 1 << 1, 47 SEARCH_SIGNALS = 1 << 2, 48 SEARCH_CONSTANTS = 1 << 3, 49 SEARCH_PROPERTIES = 1 << 4, 50 SEARCH_THEME_ITEMS = 1 << 5, 51 SEARCH_ALL = SEARCH_CLASSES | SEARCH_METHODS | SEARCH_SIGNALS | SEARCH_CONSTANTS | SEARCH_PROPERTIES | SEARCH_THEME_ITEMS, 52 SEARCH_CASE_SENSITIVE = 1 << 29, 53 SEARCH_SHOW_HIERARCHY = 1 << 30 54 }; 55 56 LineEdit *search_box; 57 ToolButton *case_sensitive_button; 58 ToolButton *hierarchy_button; 59 OptionButton *filter_combo; 60 Tree *results_tree; 61 bool old_search; 62 String old_term; 63 64 class Runner; 65 Ref<Runner> search; 66 67 void _update_icons(); 68 void _update_results(); 69 70 void _search_box_gui_input(const Ref<InputEvent> &p_event); 71 void _search_box_text_changed(const String &p_text); 72 void _filter_combo_item_selected(int p_option); 73 void _confirmed(); 74 75 protected: 76 void _notification(int p_what); 77 static void _bind_methods(); 78 79 public: 80 void popup_dialog(); 81 void popup_dialog(const String &p_term); 82 83 EditorHelpSearch(); 84 }; 85 86 class EditorHelpSearch::Runner : public Reference { 87 88 enum Phase { 89 PHASE_MATCH_CLASSES_INIT, 90 PHASE_MATCH_CLASSES, 91 PHASE_CLASS_ITEMS_INIT, 92 PHASE_CLASS_ITEMS, 93 PHASE_MEMBER_ITEMS_INIT, 94 PHASE_MEMBER_ITEMS, 95 PHASE_SELECT_MATCH, 96 PHASE_MAX 97 }; 98 int phase; 99 100 struct ClassMatch { 101 DocData::ClassDoc *doc; 102 bool name; 103 Vector<DocData::MethodDoc *> methods; 104 Vector<DocData::MethodDoc *> signals; 105 Vector<DocData::ConstantDoc *> constants; 106 Vector<DocData::PropertyDoc *> properties; 107 Vector<DocData::PropertyDoc *> theme_properties; 108 requiredClassMatch109 bool required() { 110 return name || methods.size() || signals.size() || constants.size() || properties.size() || theme_properties.size(); 111 } 112 }; 113 114 Control *ui_service; 115 Tree *results_tree; 116 String term; 117 int search_flags; 118 119 Ref<Texture> empty_icon; 120 Color disabled_color; 121 122 Map<String, DocData::ClassDoc>::Element *iterator_doc; 123 Map<String, ClassMatch> matches; 124 Map<String, ClassMatch>::Element *iterator_match; 125 TreeItem *root_item; 126 Map<String, TreeItem *> class_items; 127 TreeItem *matched_item; 128 129 bool _is_class_disabled_by_feature_profile(const StringName &p_class); 130 131 bool _slice(); 132 bool _phase_match_classes_init(); 133 bool _phase_match_classes(); 134 bool _phase_class_items_init(); 135 bool _phase_class_items(); 136 bool _phase_member_items_init(); 137 bool _phase_member_items(); 138 bool _phase_select_match(); 139 140 bool _match_string(const String &p_term, const String &p_string) const; 141 void _match_item(TreeItem *p_item, const String &p_text); 142 TreeItem *_create_class_hierarchy(const ClassMatch &p_match); 143 TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray); 144 TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc); 145 TreeItem *_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc); 146 TreeItem *_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc); 147 TreeItem *_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc); 148 TreeItem *_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc); 149 TreeItem *_create_member_item(TreeItem *p_parent, const String &p_class_name, const String &p_icon, const String &p_name, const String &p_type, const String &p_metatype, const String &p_tooltip); 150 151 public: 152 bool work(uint64_t slot = 100000); 153 154 Runner(Control *p_icon_service, Tree *p_results_tree, const String &p_term, int p_search_flags); 155 }; 156 157 #endif // EDITOR_HELP_SEARCH_H 158