editor_help.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*************************************************************************/
  2. /* editor_help.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 "editor/code_editor.h"
  33. #include "editor/doc/doc_data.h"
  34. #include "editor/editor_plugin.h"
  35. #include "scene/gui/margin_container.h"
  36. #include "scene/gui/menu_button.h"
  37. #include "scene/gui/panel_container.h"
  38. #include "scene/gui/rich_text_label.h"
  39. #include "scene/gui/split_container.h"
  40. #include "scene/gui/tab_container.h"
  41. #include "scene/gui/text_edit.h"
  42. #include "scene/main/timer.h"
  43. class FindBar : public HBoxContainer {
  44. GDCLASS(FindBar, HBoxContainer);
  45. LineEdit *search_text;
  46. ToolButton *find_prev;
  47. ToolButton *find_next;
  48. Label *matches_label;
  49. TextureButton *hide_button;
  50. String prev_search;
  51. RichTextLabel *rich_text_label;
  52. int results_count;
  53. void _show_search();
  54. void _hide_bar();
  55. void _search_text_changed(const String &p_text);
  56. void _search_text_entered(const String &p_text);
  57. void _update_results_count();
  58. void _update_matches_label();
  59. void _update_size();
  60. protected:
  61. void _notification(int p_what);
  62. void _unhandled_input(const Ref<InputEvent> &p_event);
  63. bool _search(bool p_search_previous = false);
  64. static void _bind_methods();
  65. public:
  66. void set_rich_text_label(RichTextLabel *p_rich_text_label);
  67. void popup_search();
  68. bool search_prev();
  69. bool search_next();
  70. FindBar();
  71. };
  72. class EditorHelp : public VBoxContainer {
  73. GDCLASS(EditorHelp, VBoxContainer);
  74. enum Page {
  75. PAGE_CLASS_LIST,
  76. PAGE_CLASS_DESC,
  77. PAGE_CLASS_PREV,
  78. PAGE_CLASS_NEXT,
  79. PAGE_SEARCH,
  80. CLASS_SEARCH,
  81. };
  82. bool select_locked;
  83. String prev_search;
  84. String edited_class;
  85. Vector<Pair<String, int> > section_line;
  86. Map<String, int> method_line;
  87. Map<String, int> signal_line;
  88. Map<String, int> property_line;
  89. Map<String, int> theme_property_line;
  90. Map<String, int> constant_line;
  91. Map<String, int> enum_line;
  92. Map<String, Map<String, int> > enum_values_line;
  93. int description_line;
  94. RichTextLabel *class_desc;
  95. HSplitContainer *h_split;
  96. static DocData *doc;
  97. ConfirmationDialog *search_dialog;
  98. LineEdit *search;
  99. FindBar *find_bar;
  100. String base_path;
  101. Color title_color;
  102. Color text_color;
  103. Color headline_color;
  104. Color base_type_color;
  105. Color type_color;
  106. Color comment_color;
  107. Color symbol_color;
  108. Color value_color;
  109. Color qualifier_color;
  110. void _init_colors();
  111. void _help_callback(const String &p_topic);
  112. void _add_text(const String &p_bbcode);
  113. bool scroll_locked;
  114. //void _button_pressed(int p_idx);
  115. void _add_type(const String &p_type, const String &p_enum = String());
  116. void _add_method(const DocData::MethodDoc &p_method, bool p_overview = true);
  117. void _class_list_select(const String &p_select);
  118. void _class_desc_select(const String &p_select);
  119. void _class_desc_input(const Ref<InputEvent> &p_input);
  120. void _class_desc_resized();
  121. Error _goto_desc(const String &p_class, int p_vscr = -1);
  122. //void _update_history_buttons();
  123. void _update_doc();
  124. void _request_help(const String &p_string);
  125. void _search(bool p_search_previous = false);
  126. void _unhandled_key_input(const Ref<InputEvent> &p_ev);
  127. String _fix_constant(const String &p_constant) const;
  128. protected:
  129. void _notification(int p_what);
  130. static void _bind_methods();
  131. public:
  132. static void generate_doc();
  133. static DocData *get_doc_data() { return doc; }
  134. void go_to_help(const String &p_help);
  135. void go_to_class(const String &p_class, int p_scroll = 0);
  136. Vector<Pair<String, int> > get_sections();
  137. void scroll_to_section(int p_section_index);
  138. void popup_search();
  139. void search_again(bool p_search_previous = false);
  140. String get_class();
  141. void set_focused() { class_desc->grab_focus(); }
  142. int get_scroll() const;
  143. void set_scroll(int p_scroll);
  144. EditorHelp();
  145. ~EditorHelp();
  146. };
  147. class EditorHelpBit : public PanelContainer {
  148. GDCLASS(EditorHelpBit, PanelContainer);
  149. RichTextLabel *rich_text;
  150. void _go_to_help(String p_what);
  151. void _meta_clicked(String p_select);
  152. protected:
  153. static void _bind_methods();
  154. void _notification(int p_what);
  155. public:
  156. RichTextLabel *get_rich_text() { return rich_text; }
  157. void set_text(const String &p_text);
  158. EditorHelpBit();
  159. };
  160. #endif // EDITOR_HELP_H