| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/os/thread.h" |
| 34 |
#include "editor/doc/doc_tools.h" |
| 35 |
#include "editor/plugins/editor_plugin.h" |
| 36 |
#include "scene/gui/dialogs.h" |
| 37 |
#include "scene/gui/popup.h" |
| 38 |
#include "scene/gui/rich_text_label.h" |
| 39 |
#include "scene/gui/split_container.h" |
| 40 |
#include "scene/gui/text_edit.h" |
| 41 |
#include "scene/main/timer.h" |
| 42 |
|
| 43 |
class FindBar : public HBoxContainer { |
| 44 |
GDCLASS(FindBar, HBoxContainer); |
| 45 |
|
| 46 |
LineEdit *search_text = nullptr; |
| 47 |
Button *find_prev = nullptr; |
| 48 |
Button *find_next = nullptr; |
| 49 |
Label *matches_label = nullptr; |
| 50 |
Button *hide_button = nullptr; |
| 51 |
|
| 52 |
RichTextLabel *rich_text_label = nullptr; |
| 53 |
|
| 54 |
String prev_search; |
| 55 |
int results_count = 0; |
| 56 |
int results_count_to_current = 0; |
| 57 |
|
| 58 |
virtual void input(const Ref<InputEvent> &p_event) override; |
| 59 |
|
| 60 |
void _hide_bar(); |
| 61 |
|
| 62 |
void _search_text_changed(const String &p_text); |
| 63 |
void _search_text_submitted(const String &p_text); |
| 64 |
|
| 65 |
void _update_results_count(bool p_search_previous); |
| 66 |
void _update_matches_label(); |
| 67 |
|
| 68 |
protected: |
| 69 |
void _notification(int p_what); |
| 70 |
|
| 71 |
bool _search(bool p_search_previous = false); |
| 72 |
|
| 73 |
public: |
| 74 |
void set_rich_text_label(RichTextLabel *p_rich_text_label); |
| 75 |
|
| 76 |
void popup_search(); |
| 77 |
|
| 78 |
bool search_prev(); |
| 79 |
bool search_next(); |
| 80 |
|
| 81 |
FindBar(); |
| 82 |
}; |
| 83 |
|
| 84 |
class EditorFileSystemDirectory; |
| 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 |
bool update_pending = false; |
| 98 |
|
| 99 |
String prev_search; |
| 100 |
|
| 101 |
String edited_class; |
| 102 |
|
| 103 |
Vector<Pair<String, int>> section_line; |
| 104 |
HashMap<String, int> method_line; |
| 105 |
HashMap<String, int> signal_line; |
| 106 |
HashMap<String, int> property_line; |
| 107 |
HashMap<String, int> theme_property_line; |
| 108 |
HashMap<String, int> constant_line; |
| 109 |
HashMap<String, int> annotation_line; |
| 110 |
HashMap<String, int> enum_line; |
| 111 |
HashMap<String, HashMap<String, int>> enum_values_line; |
| 112 |
int description_line = 0; |
| 113 |
|
| 114 |
RichTextLabel *class_desc = nullptr; |
| 115 |
inline static DocTools *doc = nullptr; |
| 116 |
inline static DocTools *ext_doc = nullptr; |
| 117 |
|
| 118 |
LineEdit *search = nullptr; |
| 119 |
FindBar *find_bar = nullptr; |
| 120 |
HBoxContainer *status_bar = nullptr; |
| 121 |
Button *toggle_files_button = nullptr; |
| 122 |
|
| 123 |
struct ThemeCache { |
| 124 |
Ref<StyleBox> background_style; |
| 125 |
|
| 126 |
Color text_color; |
| 127 |
Color title_color; |
| 128 |
Color headline_color; |
| 129 |
Color comment_color; |
| 130 |
Color symbol_color; |
| 131 |
Color value_color; |
| 132 |
Color qualifier_color; |
| 133 |
Color type_color; |
| 134 |
Color override_color; |
| 135 |
|
| 136 |
Ref<Font> doc_font; |
| 137 |
Ref<Font> doc_bold_font; |
| 138 |
Ref<Font> doc_italic_font; |
| 139 |
Ref<Font> doc_title_font; |
| 140 |
Ref<Font> doc_code_font; |
| 141 |
Ref<Font> doc_kbd_font; |
| 142 |
|
| 143 |
int doc_font_size = 0; |
| 144 |
int doc_title_font_size = 0; |
| 145 |
int doc_code_font_size = 0; |
| 146 |
int doc_kbd_font_size = 0; |
| 147 |
} theme_cache; |
| 148 |
|
| 149 |
int scroll_to = -1; |
| 150 |
|
| 151 |
void _help_callback(const String &p_topic); |
| 152 |
|
| 153 |
void _add_text(const String &p_bbcode); |
| 154 |
bool scroll_locked = false; |
| 155 |
|
| 156 |
|
| 157 |
void _add_type(const String &p_type, const String &p_enum = String(), bool p_is_bitfield = false); |
| 158 |
void _add_type_icon(const String &p_type, int p_size = 0, const String &p_fallback = ""); |
| 159 |
void _add_method(const DocData::MethodDoc &p_method, bool p_overview, bool p_override = true); |
| 160 |
|
| 161 |
void _add_bulletpoint(); |
| 162 |
|
| 163 |
void _push_normal_font(); |
| 164 |
void _pop_normal_font(); |
| 165 |
void _push_title_font(); |
| 166 |
void _pop_title_font(); |
| 167 |
void _push_code_font(); |
| 168 |
void _pop_code_font(); |
| 169 |
|
| 170 |
void _class_desc_finished(); |
| 171 |
void _class_list_select(const String &p_select); |
| 172 |
void _class_desc_select(const String &p_select); |
| 173 |
void _class_desc_input(const Ref<InputEvent> &p_input); |
| 174 |
void _class_desc_resized(bool p_force_update_theme); |
| 175 |
int display_margin = 0; |
| 176 |
|
| 177 |
Error _goto_desc(const String &p_class); |
| 178 |
|
| 179 |
void _update_method_list(MethodType p_method_type, const Vector<DocData::MethodDoc> &p_methods); |
| 180 |
void _update_method_descriptions(const DocData::ClassDoc &p_classdoc, MethodType p_method_type, const Vector<DocData::MethodDoc> &p_methods); |
| 181 |
void _update_doc(); |
| 182 |
|
| 183 |
void _request_help(const String &p_string); |
| 184 |
void _search(bool p_search_previous = false); |
| 185 |
|
| 186 |
void _toggle_files_pressed(); |
| 187 |
|
| 188 |
inline static int doc_generation_count = 0; |
| 189 |
inline static String doc_version_hash; |
| 190 |
inline static Thread worker_thread; |
| 191 |
inline static Thread loader_thread; |
| 192 |
|
| 193 |
inline static SafeFlag _script_docs_loaded = SafeFlag(false); |
| 194 |
inline static LocalVector<DocData::ClassDoc> _docs_to_add; |
| 195 |
inline static LocalVector<String> _docs_to_remove; |
| 196 |
inline static LocalVector<String> _docs_to_remove_by_path; |
| 197 |
|
| 198 |
static void _wait_for_thread(Thread &p_thread = worker_thread); |
| 199 |
static void _load_doc_thread(void *p_udata); |
| 200 |
static void _gen_doc_thread(void *p_udata); |
| 201 |
static void _gen_extensions_docs(); |
| 202 |
static void _process_postponed_docs(); |
| 203 |
static void _load_script_doc_cache_thread(void *p_udata); |
| 204 |
static void _regen_script_doc_thread(void *p_udata); |
| 205 |
static void _finish_regen_script_doc_thread(void *p_udata); |
| 206 |
static void _reload_scripts_documentation(EditorFileSystemDirectory *p_dir); |
| 207 |
static void _delete_script_doc_cache(); |
| 208 |
static void _compute_doc_version_hash(); |
| 209 |
|
| 210 |
struct PropertyCompare { |
| 211 |
_FORCE_INLINE_ bool operator()(const DocData::PropertyDoc &p_l, const DocData::PropertyDoc &p_r) const { |
| 212 |
|
| 213 |
if (p_l.overridden == p_r.overridden) { |
| 214 |
return p_l.name.naturalcasecmp_to(p_r.name) < 0; |
| 215 |
} |
| 216 |
return p_l.overridden; |
| 217 |
} |
| 218 |
}; |
| 219 |
|
| 220 |
protected: |
| 221 |
virtual void _update_theme_item_cache() override; |
| 222 |
|
| 223 |
void _notification(int p_what); |
| 224 |
static void _bind_methods(); |
| 225 |
|
| 226 |
public: |
| 227 |
static void generate_doc(bool p_use_cache = true, bool p_use_script_cache = true); |
| 228 |
static void cleanup_doc(); |
| 229 |
static void load_script_doc_cache(); |
| 230 |
static void regenerate_script_doc_cache(); |
| 231 |
static void save_script_doc_cache(); |
| 232 |
static String get_cache_full_path(); |
| 233 |
static String get_script_doc_cache_full_path(); |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
static DocTools *get_doc_data(); |
| 238 |
|
| 239 |
static DocData::ClassDoc *get_doc(const String &p_class_name); |
| 240 |
static void add_doc(const DocData::ClassDoc &p_class_doc); |
| 241 |
static void remove_doc(const String &p_class_name); |
| 242 |
static void remove_script_doc_by_path(const String &p_path); |
| 243 |
static bool has_doc(const String &p_class_name); |
| 244 |
|
| 245 |
static void load_xml_buffer(const uint8_t *p_buffer, int p_size); |
| 246 |
static void remove_class(const String &p_class); |
| 247 |
|
| 248 |
void go_to_help(const String &p_help); |
| 249 |
void go_to_class(const String &p_class); |
| 250 |
void update_doc(); |
| 251 |
|
| 252 |
Vector<Pair<String, int>> get_sections(); |
| 253 |
void scroll_to_section(int p_section_index); |
| 254 |
|
| 255 |
void popup_search(); |
| 256 |
void search_again(bool p_search_previous = false); |
| 257 |
|
| 258 |
String get_class(); |
| 259 |
|
| 260 |
void set_focused() { class_desc->grab_focus(); } |
| 261 |
|
| 262 |
int get_scroll() const; |
| 263 |
void set_scroll(int p_scroll); |
| 264 |
|
| 265 |
void update_toggle_files_button(); |
| 266 |
|
| 267 |
static void init_gdext_pointers(); |
| 268 |
|
| 269 |
EditorHelp(); |
| 270 |
}; |
| 271 |
|
| 272 |
class EditorHelpBit : public VBoxContainer { |
| 273 |
GDCLASS(EditorHelpBit, VBoxContainer); |
| 274 |
|
| 275 |
enum SymbolHint { |
| 276 |
SYMBOL_HINT_NONE, |
| 277 |
SYMBOL_HINT_INHERITANCE, |
| 278 |
SYMBOL_HINT_ASSIGNABLE, |
| 279 |
SYMBOL_HINT_SIGNATURE, |
| 280 |
}; |
| 281 |
|
| 282 |
struct DocType { |
| 283 |
String type; |
| 284 |
String enumeration; |
| 285 |
bool is_bitfield = false; |
| 286 |
}; |
| 287 |
|
| 288 |
struct ArgumentData { |
| 289 |
String name; |
| 290 |
DocType doc_type; |
| 291 |
String default_value; |
| 292 |
}; |
| 293 |
|
| 294 |
struct HelpData { |
| 295 |
String description; |
| 296 |
String deprecated_message; |
| 297 |
String experimental_message; |
| 298 |
DocType doc_type; |
| 299 |
String value; |
| 300 |
Vector<ArgumentData> arguments; |
| 301 |
ArgumentData rest_argument; |
| 302 |
String qualifiers; |
| 303 |
String resource_path; |
| 304 |
}; |
| 305 |
|
| 306 |
inline static HashMap<StringName, HelpData> doc_class_cache; |
| 307 |
inline static HashMap<StringName, HashMap<StringName, HelpData>> doc_enum_cache; |
| 308 |
inline static HashMap<StringName, HashMap<StringName, HelpData>> doc_constant_cache; |
| 309 |
inline static HashMap<StringName, HashMap<StringName, HelpData>> doc_property_cache; |
| 310 |
inline static HashMap<StringName, HashMap<StringName, HelpData>> doc_theme_item_cache; |
| 311 |
inline static HashMap<StringName, HashMap<StringName, HelpData>> doc_method_cache; |
| 312 |
inline static HashMap<StringName, HashMap<StringName, HelpData>> doc_signal_cache; |
| 313 |
inline static HashMap<StringName, HashMap<StringName, HelpData>> doc_annotation_cache; |
| 314 |
|
| 315 |
RichTextLabel *title = nullptr; |
| 316 |
RichTextLabel *content = nullptr; |
| 317 |
|
| 318 |
bool use_class_prefix = false; |
| 319 |
|
| 320 |
String symbol_doc_link; |
| 321 |
String symbol_class_name; |
| 322 |
String symbol_type; |
| 323 |
String symbol_name; |
| 324 |
SymbolHint symbol_hint = SYMBOL_HINT_NONE; |
| 325 |
|
| 326 |
HelpData help_data; |
| 327 |
|
| 328 |
float content_min_height = 0.0; |
| 329 |
float content_max_height = 0.0; |
| 330 |
|
| 331 |
static HelpData _get_class_help_data(const StringName &p_class_name); |
| 332 |
static HelpData _get_enum_help_data(const StringName &p_class_name, const StringName &p_enum_name); |
| 333 |
static HelpData _get_constant_help_data(const StringName &p_class_name, const StringName &p_constant_name); |
| 334 |
static HelpData _get_property_help_data(const StringName &p_class_name, const StringName &p_property_name); |
| 335 |
static HelpData _get_theme_item_help_data(const StringName &p_class_name, const StringName &p_theme_item_name); |
| 336 |
static HelpData _get_method_help_data(const StringName &p_class_name, const StringName &p_method_name); |
| 337 |
static HelpData _get_signal_help_data(const StringName &p_class_name, const StringName &p_signal_name); |
| 338 |
static HelpData _get_annotation_help_data(const StringName &p_class_name, const StringName &p_annotation_name); |
| 339 |
|
| 340 |
void _add_type_to_title(const DocType &p_doc_type); |
| 341 |
void _update_labels(); |
| 342 |
void _go_to_help(const String &p_what); |
| 343 |
void _go_to_url(const String &p_what); |
| 344 |
void _meta_clicked(const String &p_select); |
| 345 |
|
| 346 |
protected: |
| 347 |
static void _bind_methods(); |
| 348 |
void _notification(int p_what); |
| 349 |
|
| 350 |
public: |
| 351 |
void parse_symbol(const String &p_symbol, const String &p_prologue = String()); |
| 352 |
void set_custom_text(const String &p_type, const String &p_name, const String &p_description); |
| 353 |
|
| 354 |
void set_content_height_limits(float p_min, float p_max); |
| 355 |
void update_content_height(); |
| 356 |
|
| 357 |
EditorHelpBit(const String &p_symbol = String(), const String &p_prologue = String(), bool p_use_class_prefix = false, bool p_allow_selection = true, bool p_in_tooltip = false); |
| 358 |
}; |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
class EditorHelpBitTooltip : public PopupPanel { |
| 363 |
GDCLASS(EditorHelpBitTooltip, PopupPanel); |
| 364 |
|
| 365 |
static bool _is_tooltip_visible; |
| 366 |
|
| 367 |
Timer *timer = nullptr; |
| 368 |
uint64_t _enter_tree_time = 0; |
| 369 |
bool _is_mouse_inside_tooltip = false; |
| 370 |
|
| 371 |
static Control *_make_invisible_control(); |
| 372 |
|
| 373 |
void _start_timer(); |
| 374 |
void _target_gui_input(const Ref<InputEvent> &p_event); |
| 375 |
|
| 376 |
protected: |
| 377 |
void _notification(int p_what); |
| 378 |
|
| 379 |
public: |
| 380 |
|
| 381 |
[[nodiscard]] static Control *make_tooltip(Control *p_target, const String &p_symbol, const String &p_prologue = String(), bool p_use_class_prefix = false); |
| 382 |
|
| 383 |
void popup_under_cursor(); |
| 384 |
|
| 385 |
EditorHelpBitTooltip(Control *p_target); |
| 386 |
}; |
| 387 |
|
| 388 |
class EditorSyntaxHighlighter; |
| 389 |
|
| 390 |
class EditorHelpHighlighter { |
| 391 |
public: |
| 392 |
enum Language { |
| 393 |
LANGUAGE_GDSCRIPT, |
| 394 |
LANGUAGE_CSHARP, |
| 395 |
LANGUAGE_MAX, |
| 396 |
}; |
| 397 |
|
| 398 |
private: |
| 399 |
using HighlightData = Vector<Pair<int, Color>>; |
| 400 |
|
| 401 |
static EditorHelpHighlighter *singleton; |
| 402 |
|
| 403 |
HashMap<String, HighlightData> highlight_data_caches[LANGUAGE_MAX]; |
| 404 |
|
| 405 |
TextEdit *text_edits[LANGUAGE_MAX]; |
| 406 |
Ref<Script> scripts[LANGUAGE_MAX]; |
| 407 |
Ref<EditorSyntaxHighlighter> highlighters[LANGUAGE_MAX]; |
| 408 |
|
| 409 |
HighlightData _get_highlight_data(Language p_language, const String &p_source, bool p_use_cache); |
| 410 |
|
| 411 |
public: |
| 412 |
static void create_singleton(); |
| 413 |
static void free_singleton(); |
| 414 |
static EditorHelpHighlighter *get_singleton(); |
| 415 |
|
| 416 |
void highlight(RichTextLabel *p_rich_text_label, Language p_language, const String &p_source, bool p_use_cache); |
| 417 |
void reset_cache(); |
| 418 |
|
| 419 |
EditorHelpHighlighter(); |
| 420 |
virtual ~EditorHelpHighlighter(); |
| 421 |
}; |