editor_help.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*************************************************************************/
  2. /* editor_help.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef EDITOR_HELP_H
  30. #define EDITOR_HELP_H
  31. #include "tools/editor/editor_plugin.h"
  32. #include "scene/gui/tab_container.h"
  33. #include "scene/gui/text_edit.h"
  34. #include "scene/gui/split_container.h"
  35. #include "scene/gui/menu_button.h"
  36. #include "scene/gui/rich_text_label.h"
  37. #include "scene/gui/panel_container.h"
  38. #include "scene/gui/tree.h"
  39. #include "scene/main/timer.h"
  40. #include "tools/editor/code_editor.h"
  41. #include "tools/doc/doc_data.h"
  42. class EditorNode;
  43. class EditorHelpSearch : public ConfirmationDialog {
  44. OBJ_TYPE(EditorHelpSearch,ConfirmationDialog )
  45. EditorNode *editor;
  46. LineEdit *search_box;
  47. Tree *search_options;
  48. String base_type;
  49. void _update_search();
  50. void _sbox_input(const InputEvent& p_ie);
  51. void _confirmed();
  52. void _text_changed(const String& p_newtext);
  53. protected:
  54. void _notification(int p_what);
  55. static void _bind_methods();
  56. public:
  57. void popup(const String& p_term="");
  58. EditorHelpSearch(EditorNode *p_editor);
  59. };
  60. class EditorHelp : public VBoxContainer {
  61. OBJ_TYPE( EditorHelp, VBoxContainer );
  62. enum Page {
  63. PAGE_CLASS_LIST,
  64. PAGE_CLASS_DESC,
  65. PAGE_CLASS_PREV,
  66. PAGE_CLASS_NEXT,
  67. PAGE_SEARCH,
  68. CLASS_SEARCH,
  69. };
  70. struct History {
  71. String c;
  72. int scroll;
  73. };
  74. Vector<History> history;
  75. int history_pos;
  76. bool select_locked;
  77. String prev_search;
  78. String prev_search_page;
  79. EditorNode *editor;
  80. Map<String,int> method_line;
  81. Map<String,int> signal_line;
  82. Map<String,int> property_line;
  83. Map<String,int> theme_property_line;
  84. Map<String,int> constant_line;
  85. int description_line;
  86. Tree *class_list;
  87. RichTextLabel *class_desc;
  88. HSplitContainer *h_split;
  89. static DocData *doc;
  90. Button *class_list_button;
  91. Button *edited_class;
  92. Button *back;
  93. Button *forward;
  94. LineEdit *search;
  95. String base_path;
  96. HashMap<String,TreeItem*> tree_item_map;
  97. void _help_callback(const String& p_topic);
  98. void _add_text(const String& p_text);
  99. bool scroll_locked;
  100. void _button_pressed(int p_idx);
  101. void _add_type(const String& p_type);
  102. void _scroll_changed(double p_scroll);
  103. void _class_list_select(const String& p_select);
  104. void _class_desc_select(const String& p_select);
  105. Error _goto_desc(const String& p_class,bool p_update_history=true,int p_vscr=-1);
  106. void _update_history_buttons();
  107. void _update_doc();
  108. void _request_help(const String& p_string);
  109. void _search(const String& p_str);
  110. void _unhandled_key_input(const InputEvent& p_ev);
  111. void add_type(const String& p_type,HashMap<String,TreeItem*>& p_types,TreeItem *p_root);
  112. void _tree_item_selected();
  113. EditorHelpSearch *class_search;
  114. protected:
  115. void _notification(int p_what);
  116. static void _bind_methods();
  117. public:
  118. static void generate_doc();
  119. static DocData *get_doc_data() { return doc; }
  120. EditorHelp(EditorNode *p_editor=NULL);
  121. ~EditorHelp();
  122. };
  123. class EditorHelpPlugin : public EditorPlugin {
  124. OBJ_TYPE( EditorHelpPlugin, EditorPlugin );
  125. EditorHelp *editor_help;
  126. EditorNode *editor;
  127. public:
  128. virtual String get_name() const { return "Help"; }
  129. bool has_main_screen() const { return true; }
  130. virtual void edit(Object *p_node);
  131. virtual bool handles(Object *p_node) const;
  132. virtual void make_visible(bool p_visible);
  133. virtual void selected_notify();
  134. Dictionary get_state() const;
  135. virtual void set_state(const Dictionary& p_state);
  136. virtual void clear();
  137. virtual void save_external_data();
  138. virtual void apply_changes();
  139. virtual void restore_global_state();
  140. virtual void save_global_state();
  141. EditorHelpPlugin(EditorNode *p_node);
  142. ~EditorHelpPlugin();
  143. };
  144. #endif // EDITOR_HELP_H