editor_help.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*************************************************************************/
  2. /* editor_help.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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. #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. static void _bind_methods();
  64. public:
  65. void set_rich_text_label(RichTextLabel *p_rich_text_label);
  66. void popup_search();
  67. bool search_prev();
  68. bool search_next();
  69. FindBar();
  70. };
  71. class EditorHelp : public VBoxContainer {
  72. GDCLASS(EditorHelp, VBoxContainer);
  73. enum Page {
  74. PAGE_CLASS_LIST,
  75. PAGE_CLASS_DESC,
  76. PAGE_CLASS_PREV,
  77. PAGE_CLASS_NEXT,
  78. PAGE_SEARCH,
  79. CLASS_SEARCH,
  80. };
  81. bool select_locked = false;
  82. String prev_search;
  83. String edited_class;
  84. Vector<Pair<String, int>> section_line;
  85. HashMap<String, int> method_line;
  86. HashMap<String, int> signal_line;
  87. HashMap<String, int> property_line;
  88. HashMap<String, int> theme_property_line;
  89. HashMap<String, int> constant_line;
  90. HashMap<String, int> annotation_line;
  91. HashMap<String, int> enum_line;
  92. HashMap<String, HashMap<String, int>> enum_values_line;
  93. int description_line = 0;
  94. RichTextLabel *class_desc = nullptr;
  95. HSplitContainer *h_split = nullptr;
  96. static DocTools *doc;
  97. ConfirmationDialog *search_dialog = nullptr;
  98. LineEdit *search = nullptr;
  99. FindBar *find_bar = nullptr;
  100. HBoxContainer *status_bar = nullptr;
  101. Button *toggle_scripts_button = nullptr;
  102. String base_path;
  103. Color text_color;
  104. Color title_color;
  105. Color headline_color;
  106. Color comment_color;
  107. Color symbol_color;
  108. Color value_color;
  109. Color qualifier_color;
  110. Color type_color;
  111. Ref<Font> doc_font;
  112. Ref<Font> doc_bold_font;
  113. Ref<Font> doc_title_font;
  114. Ref<Font> doc_code_font;
  115. int doc_title_font_size;
  116. int scroll_to = -1;
  117. void _update_theme();
  118. void _help_callback(const String &p_topic);
  119. void _add_text(const String &p_bbcode);
  120. bool scroll_locked = false;
  121. //void _button_pressed(int p_idx);
  122. void _add_type(const String &p_type, const String &p_enum = String());
  123. void _add_type_icon(const String &p_type, int p_size = 0);
  124. void _add_method(const DocData::MethodDoc &p_method, bool p_overview = true);
  125. void _add_bulletpoint();
  126. void _class_desc_finished();
  127. void _class_list_select(const String &p_select);
  128. void _class_desc_select(const String &p_select);
  129. void _class_desc_input(const Ref<InputEvent> &p_input);
  130. void _class_desc_resized(bool p_force_update_theme);
  131. int display_margin = 0;
  132. Error _goto_desc(const String &p_class, int p_vscr = -1);
  133. //void _update_history_buttons();
  134. void _update_method_list(const Vector<DocData::MethodDoc> p_methods, bool &r_method_descrpitons);
  135. void _update_method_descriptions(const DocData::ClassDoc p_classdoc, const Vector<DocData::MethodDoc> p_methods, const String &p_method_type);
  136. void _update_doc();
  137. void _request_help(const String &p_string);
  138. void _search(bool p_search_previous = false);
  139. String _fix_constant(const String &p_constant) const;
  140. void _toggle_scripts_pressed();
  141. static Thread thread;
  142. static void _wait_for_thread();
  143. static void _gen_doc_thread(void *p_udata);
  144. protected:
  145. void _notification(int p_what);
  146. static void _bind_methods();
  147. public:
  148. static void generate_doc();
  149. static DocTools *get_doc_data();
  150. static void cleanup_doc();
  151. void go_to_help(const String &p_help);
  152. void go_to_class(const String &p_class, int p_scroll = 0);
  153. void update_doc();
  154. Vector<Pair<String, int>> get_sections();
  155. void scroll_to_section(int p_section_index);
  156. void popup_search();
  157. void search_again(bool p_search_previous = false);
  158. String get_class();
  159. void set_focused() { class_desc->grab_focus(); }
  160. int get_scroll() const;
  161. void set_scroll(int p_scroll);
  162. void update_toggle_scripts_button();
  163. EditorHelp();
  164. ~EditorHelp();
  165. };
  166. class EditorHelpBit : public MarginContainer {
  167. GDCLASS(EditorHelpBit, MarginContainer);
  168. RichTextLabel *rich_text = nullptr;
  169. void _go_to_help(String p_what);
  170. void _meta_clicked(String p_select);
  171. String text;
  172. protected:
  173. static void _bind_methods();
  174. void _notification(int p_what);
  175. public:
  176. RichTextLabel *get_rich_text() { return rich_text; }
  177. void set_text(const String &p_text);
  178. EditorHelpBit();
  179. };
  180. #endif // EDITOR_HELP_H