editor_help_search.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #ifndef EDITOR_HELP_SEARCH_H
  31. #define EDITOR_HELP_SEARCH_H
  32. #include "core/ordered_hash_map.h"
  33. #include "editor/code_editor.h"
  34. #include "editor/editor_help.h"
  35. #include "editor/editor_plugin.h"
  36. #include "scene/gui/option_button.h"
  37. #include "scene/gui/tree.h"
  38. class EditorHelpSearch : public ConfirmationDialog {
  39. GDCLASS(EditorHelpSearch, ConfirmationDialog);
  40. enum SearchFlags {
  41. SEARCH_CLASSES = 1 << 0,
  42. SEARCH_METHODS = 1 << 1,
  43. SEARCH_SIGNALS = 1 << 2,
  44. SEARCH_CONSTANTS = 1 << 3,
  45. SEARCH_PROPERTIES = 1 << 4,
  46. SEARCH_THEME_ITEMS = 1 << 5,
  47. SEARCH_ALL = SEARCH_CLASSES | SEARCH_METHODS | SEARCH_SIGNALS | SEARCH_CONSTANTS | SEARCH_PROPERTIES | SEARCH_THEME_ITEMS,
  48. SEARCH_CASE_SENSITIVE = 1 << 29,
  49. SEARCH_SHOW_HIERARCHY = 1 << 30
  50. };
  51. LineEdit *search_box;
  52. ToolButton *case_sensitive_button;
  53. ToolButton *hierarchy_button;
  54. OptionButton *filter_combo;
  55. Tree *results_tree;
  56. bool old_search;
  57. String old_term;
  58. class Runner;
  59. Ref<Runner> search;
  60. void _update_icons();
  61. void _update_results();
  62. void _search_box_gui_input(const Ref<InputEvent> &p_event);
  63. void _search_box_text_changed(const String &p_text);
  64. void _filter_combo_item_selected(int p_option);
  65. void _confirmed();
  66. protected:
  67. void _notification(int p_what);
  68. static void _bind_methods();
  69. public:
  70. void popup_dialog();
  71. void popup_dialog(const String &p_term);
  72. EditorHelpSearch();
  73. };
  74. class EditorHelpSearch::Runner : public Reference {
  75. enum Phase {
  76. PHASE_MATCH_CLASSES_INIT,
  77. PHASE_MATCH_CLASSES,
  78. PHASE_CLASS_ITEMS_INIT,
  79. PHASE_CLASS_ITEMS,
  80. PHASE_MEMBER_ITEMS_INIT,
  81. PHASE_MEMBER_ITEMS,
  82. PHASE_SELECT_MATCH,
  83. PHASE_MAX
  84. };
  85. int phase;
  86. struct ClassMatch {
  87. DocData::ClassDoc *doc;
  88. bool name;
  89. Vector<DocData::MethodDoc *> methods;
  90. Vector<DocData::MethodDoc *> signals;
  91. Vector<DocData::ConstantDoc *> constants;
  92. Vector<DocData::PropertyDoc *> properties;
  93. Vector<DocData::ThemeItemDoc *> theme_properties;
  94. bool required() {
  95. return name || methods.size() || signals.size() || constants.size() || properties.size() || theme_properties.size();
  96. }
  97. };
  98. Control *ui_service;
  99. Tree *results_tree;
  100. String term;
  101. int search_flags;
  102. Ref<Texture> empty_icon;
  103. Color disabled_color;
  104. Map<String, DocData::ClassDoc>::Element *iterator_doc;
  105. Map<String, ClassMatch> matches;
  106. Map<String, ClassMatch>::Element *iterator_match;
  107. TreeItem *root_item;
  108. Map<String, TreeItem *> class_items;
  109. TreeItem *matched_item;
  110. float match_highest_score = 0;
  111. bool _is_class_disabled_by_feature_profile(const StringName &p_class);
  112. bool _slice();
  113. bool _phase_match_classes_init();
  114. bool _phase_match_classes();
  115. bool _phase_class_items_init();
  116. bool _phase_class_items();
  117. bool _phase_member_items_init();
  118. bool _phase_member_items();
  119. bool _phase_select_match();
  120. bool _match_string(const String &p_term, const String &p_string) const;
  121. void _match_item(TreeItem *p_item, const String &p_text);
  122. TreeItem *_create_class_hierarchy(const ClassMatch &p_match);
  123. TreeItem *_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray);
  124. TreeItem *_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc);
  125. TreeItem *_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc);
  126. TreeItem *_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc);
  127. TreeItem *_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc);
  128. TreeItem *_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ThemeItemDoc *p_doc);
  129. 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);
  130. public:
  131. bool work(uint64_t slot = 100000);
  132. Runner(Control *p_icon_service, Tree *p_results_tree, const String &p_term, int p_search_flags);
  133. };
  134. #endif // EDITOR_HELP_SEARCH_H