editor_help.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*************************************************************************/
  2. /* editor_help.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. #ifndef EDITOR_HELP_H
  31. #define EDITOR_HELP_H
  32. #include "editor/editor_plugin.h"
  33. #include "scene/gui/menu_button.h"
  34. #include "scene/gui/panel_container.h"
  35. #include "scene/gui/rich_text_label.h"
  36. #include "scene/gui/split_container.h"
  37. #include "scene/gui/tab_container.h"
  38. #include "scene/gui/text_edit.h"
  39. #include "scene/gui/tree.h"
  40. #include "editor/code_editor.h"
  41. #include "editor/doc/doc_data.h"
  42. #include "scene/main/timer.h"
  43. class EditorNode;
  44. class EditorHelpSearch : public ConfirmationDialog {
  45. OBJ_TYPE(EditorHelpSearch, ConfirmationDialog)
  46. EditorNode *editor;
  47. LineEdit *search_box;
  48. Tree *search_options;
  49. String base_type;
  50. void _update_search();
  51. void _sbox_input(const InputEvent &p_ie);
  52. void _confirmed();
  53. void _text_changed(const String &p_newtext);
  54. protected:
  55. void _notification(int p_what);
  56. static void _bind_methods();
  57. public:
  58. void popup();
  59. void popup(const String &p_term);
  60. EditorHelpSearch();
  61. };
  62. class EditorHelpIndex : public ConfirmationDialog {
  63. OBJ_TYPE(EditorHelpIndex, ConfirmationDialog);
  64. LineEdit *search_box;
  65. Tree *class_list;
  66. HashMap<String, TreeItem *> tree_item_map;
  67. void _tree_item_selected();
  68. void _text_changed(const String &p_text);
  69. void _sbox_input(const InputEvent &p_ie);
  70. void _update_class_list();
  71. void add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root);
  72. protected:
  73. void _notification(int p_what);
  74. static void _bind_methods();
  75. public:
  76. void select_class(const String &p_class);
  77. void popup();
  78. EditorHelpIndex();
  79. };
  80. class EditorHelp : public VBoxContainer {
  81. OBJ_TYPE(EditorHelp, VBoxContainer);
  82. enum Page {
  83. PAGE_CLASS_LIST,
  84. PAGE_CLASS_DESC,
  85. PAGE_CLASS_PREV,
  86. PAGE_CLASS_NEXT,
  87. PAGE_SEARCH,
  88. CLASS_SEARCH,
  89. };
  90. bool select_locked;
  91. String prev_search;
  92. String edited_class;
  93. EditorNode *editor;
  94. Map<String, int> method_line;
  95. Map<String, int> signal_line;
  96. Map<String, int> property_line;
  97. Map<String, int> theme_property_line;
  98. Map<String, int> constant_line;
  99. int description_line;
  100. RichTextLabel *class_desc;
  101. HSplitContainer *h_split;
  102. static DocData *doc;
  103. ConfirmationDialog *search_dialog;
  104. LineEdit *search;
  105. String base_path;
  106. void _help_callback(const String &p_topic);
  107. void _add_text(const String &p_text);
  108. bool scroll_locked;
  109. //void _button_pressed(int p_idx);
  110. void _add_type(const String &p_type);
  111. void _scroll_changed(double p_scroll);
  112. void _class_list_select(const String &p_select);
  113. void _class_desc_select(const String &p_select);
  114. void _class_desc_input(const InputEvent &p_input);
  115. Error _goto_desc(const String &p_class, int p_vscr = -1);
  116. //void _update_history_buttons();
  117. void _update_doc();
  118. void _request_help(const String &p_string);
  119. void _search(const String &p_str);
  120. void _search_cbk();
  121. void _unhandled_key_input(const InputEvent &p_ev);
  122. protected:
  123. void _notification(int p_what);
  124. static void _bind_methods();
  125. public:
  126. static void generate_doc();
  127. static DocData *get_doc_data() { return doc; }
  128. void go_to_help(const String &p_help);
  129. void go_to_class(const String &p_class, int p_scroll = 0);
  130. void popup_search();
  131. void search_again();
  132. String get_class_name();
  133. void set_focused() { class_desc->grab_focus(); }
  134. int get_scroll() const;
  135. void set_scroll(int p_scroll);
  136. EditorHelp();
  137. ~EditorHelp();
  138. };
  139. class EditorHelpBit : public Panel {
  140. OBJ_TYPE(EditorHelpBit, Panel);
  141. RichTextLabel *rich_text;
  142. void _go_to_help(String p_what);
  143. void _meta_clicked(String p_what);
  144. protected:
  145. static void _bind_methods();
  146. void _notification(int p_what);
  147. public:
  148. void set_text(const String &p_text);
  149. EditorHelpBit();
  150. };
  151. #endif // EDITOR_HELP_H