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