editor_help.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /**************************************************************************/
  2. /* editor_help.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_H
  31. #define EDITOR_HELP_H
  32. #include "core/os/thread.h"
  33. #include "editor/code_editor.h"
  34. #include "editor/doc_tools.h"
  35. #include "editor/editor_plugin.h"
  36. #include "scene/gui/margin_container.h"
  37. #include "scene/gui/menu_button.h"
  38. #include "scene/gui/panel_container.h"
  39. #include "scene/gui/rich_text_label.h"
  40. #include "scene/gui/split_container.h"
  41. #include "scene/gui/tab_container.h"
  42. #include "scene/gui/text_edit.h"
  43. #include "scene/main/timer.h"
  44. class FindBar : public HBoxContainer {
  45. GDCLASS(FindBar, HBoxContainer);
  46. LineEdit *search_text = nullptr;
  47. Button *find_prev = nullptr;
  48. Button *find_next = nullptr;
  49. Label *matches_label = nullptr;
  50. TextureButton *hide_button = nullptr;
  51. String prev_search;
  52. RichTextLabel *rich_text_label = nullptr;
  53. int results_count = 0;
  54. void _hide_bar();
  55. void _search_text_changed(const String &p_text);
  56. void _search_text_submitted(const String &p_text);
  57. void _update_results_count();
  58. void _update_matches_label();
  59. protected:
  60. void _notification(int p_what);
  61. virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
  62. bool _search(bool p_search_previous = false);
  63. public:
  64. void set_rich_text_label(RichTextLabel *p_rich_text_label);
  65. void popup_search();
  66. bool search_prev();
  67. bool search_next();
  68. FindBar();
  69. };
  70. class EditorHelp : public VBoxContainer {
  71. GDCLASS(EditorHelp, VBoxContainer);
  72. enum MethodType {
  73. METHOD_TYPE_METHOD,
  74. METHOD_TYPE_CONSTRUCTOR,
  75. METHOD_TYPE_OPERATOR,
  76. METHOD_TYPE_MAX
  77. };
  78. bool select_locked = false;
  79. String prev_search;
  80. String edited_class;
  81. Vector<Pair<String, int>> section_line;
  82. HashMap<String, int> method_line;
  83. HashMap<String, int> signal_line;
  84. HashMap<String, int> property_line;
  85. HashMap<String, int> theme_property_line;
  86. HashMap<String, int> constant_line;
  87. HashMap<String, int> annotation_line;
  88. HashMap<String, int> enum_line;
  89. HashMap<String, HashMap<String, int>> enum_values_line;
  90. int description_line = 0;
  91. RichTextLabel *class_desc = nullptr;
  92. HSplitContainer *h_split = nullptr;
  93. static DocTools *doc;
  94. ConfirmationDialog *search_dialog = nullptr;
  95. LineEdit *search = nullptr;
  96. FindBar *find_bar = nullptr;
  97. HBoxContainer *status_bar = nullptr;
  98. Button *toggle_scripts_button = nullptr;
  99. String base_path;
  100. struct ThemeCache {
  101. Ref<StyleBox> background_style;
  102. Color text_color;
  103. Color title_color;
  104. Color headline_color;
  105. Color comment_color;
  106. Color symbol_color;
  107. Color value_color;
  108. Color qualifier_color;
  109. Color type_color;
  110. Ref<Font> doc_font;
  111. Ref<Font> doc_bold_font;
  112. Ref<Font> doc_italic_font;
  113. Ref<Font> doc_title_font;
  114. Ref<Font> doc_code_font;
  115. Ref<Font> doc_kbd_font;
  116. int doc_font_size = 0;
  117. int doc_title_font_size = 0;
  118. int doc_code_font_size = 0;
  119. int doc_kbd_font_size = 0;
  120. } theme_cache;
  121. int scroll_to = -1;
  122. void _help_callback(const String &p_topic);
  123. void _add_text(const String &p_bbcode);
  124. bool scroll_locked = false;
  125. //void _button_pressed(int p_idx);
  126. void _add_type(const String &p_type, const String &p_enum = String(), bool p_is_bitfield = false);
  127. void _add_type_icon(const String &p_type, int p_size = 0, const String &p_fallback = "");
  128. void _add_method(const DocData::MethodDoc &p_method, bool p_overview, bool p_override = true);
  129. void _add_bulletpoint();
  130. void _push_normal_font();
  131. void _pop_normal_font();
  132. void _push_title_font();
  133. void _pop_title_font();
  134. void _push_code_font();
  135. void _pop_code_font();
  136. void _class_desc_finished();
  137. void _class_list_select(const String &p_select);
  138. void _class_desc_select(const String &p_select);
  139. void _class_desc_input(const Ref<InputEvent> &p_input);
  140. void _class_desc_resized(bool p_force_update_theme);
  141. int display_margin = 0;
  142. Error _goto_desc(const String &p_class);
  143. //void _update_history_buttons();
  144. void _update_method_list(const Vector<DocData::MethodDoc> p_methods, MethodType p_method_type);
  145. void _update_method_descriptions(const DocData::ClassDoc p_classdoc, const Vector<DocData::MethodDoc> p_methods, MethodType p_method_type);
  146. void _update_doc();
  147. void _request_help(const String &p_string);
  148. void _search(bool p_search_previous = false);
  149. String _fix_constant(const String &p_constant) const;
  150. void _toggle_scripts_pressed();
  151. static String doc_version_hash;
  152. static Thread worker_thread;
  153. static void _wait_for_thread();
  154. static void _load_doc_thread(void *p_udata);
  155. static void _gen_doc_thread(void *p_udata);
  156. static void _gen_extensions_docs();
  157. static void _compute_doc_version_hash();
  158. protected:
  159. virtual void _update_theme_item_cache() override;
  160. void _notification(int p_what);
  161. static void _bind_methods();
  162. public:
  163. static void generate_doc(bool p_use_cache = true);
  164. static DocTools *get_doc_data();
  165. static void cleanup_doc();
  166. static String get_cache_full_path();
  167. void go_to_help(const String &p_help);
  168. void go_to_class(const String &p_class);
  169. void update_doc();
  170. Vector<Pair<String, int>> get_sections();
  171. void scroll_to_section(int p_section_index);
  172. void popup_search();
  173. void search_again(bool p_search_previous = false);
  174. String get_class();
  175. void set_focused() { class_desc->grab_focus(); }
  176. int get_scroll() const;
  177. void set_scroll(int p_scroll);
  178. void update_toggle_scripts_button();
  179. EditorHelp();
  180. ~EditorHelp();
  181. };
  182. class EditorHelpBit : public MarginContainer {
  183. GDCLASS(EditorHelpBit, MarginContainer);
  184. inline static HashMap<StringName, String> doc_class_cache;
  185. inline static HashMap<StringName, HashMap<StringName, String>> doc_property_cache;
  186. inline static HashMap<StringName, HashMap<StringName, String>> doc_method_cache;
  187. inline static HashMap<StringName, HashMap<StringName, String>> doc_signal_cache;
  188. inline static HashMap<StringName, HashMap<StringName, String>> doc_theme_item_cache;
  189. RichTextLabel *rich_text = nullptr;
  190. void _go_to_help(String p_what);
  191. void _meta_clicked(String p_select);
  192. String text;
  193. protected:
  194. static void _bind_methods();
  195. void _notification(int p_what);
  196. public:
  197. String get_class_description(const StringName &p_class_name) const;
  198. String get_property_description(const StringName &p_class_name, const StringName &p_property_name) const;
  199. String get_method_description(const StringName &p_class_name, const StringName &p_method_name) const;
  200. String get_signal_description(const StringName &p_class_name, const StringName &p_signal_name) const;
  201. String get_theme_item_description(const StringName &p_class_name, const StringName &p_theme_item_name) const;
  202. RichTextLabel *get_rich_text() { return rich_text; }
  203. void set_text(const String &p_text);
  204. EditorHelpBit();
  205. };
  206. class EditorHelpTooltip : public EditorHelpBit {
  207. GDCLASS(EditorHelpTooltip, EditorHelpBit);
  208. String tooltip_text;
  209. protected:
  210. void _notification(int p_what);
  211. public:
  212. void parse_tooltip(const String &p_text);
  213. EditorHelpTooltip(const String &p_text = String());
  214. };
  215. #endif // EDITOR_HELP_H