diff options
Diffstat (limited to 'editor/editor_help.cpp')
-rw-r--r-- | editor/editor_help.cpp | 102 |
1 files changed, 67 insertions, 35 deletions
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 6e448d8866..fc4c8ea4b7 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -31,18 +31,19 @@ #include "editor_help.h" #include "core/core_constants.h" +#include "core/extension/gdextension.h" #include "core/input/input.h" #include "core/object/script_language.h" #include "core/os/keyboard.h" #include "core/version.h" -#include "doc_data_compressed.gen.h" +#include "editor/doc_data_compressed.gen.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_property_name_processor.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/themes/editor_scale.h" #include "scene/gui/line_edit.h" #define CONTRIBUTE_URL vformat("%s/contributing/documentation/updating_the_class_reference.html", VERSION_DOCS_URL) @@ -83,6 +84,7 @@ const Vector<String> classes_with_csharp_differences = { // TODO: this is sometimes used directly as doc->something, other times as EditorHelp::get_doc_data(), which is thread-safe. // Might this be a problem? DocTools *EditorHelp::doc = nullptr; +DocTools *EditorHelp::ext_doc = nullptr; static bool _attempt_doc_load(const String &p_class) { // Docgen always happens in the outer-most class: it also generates docs for inner classes. @@ -218,31 +220,31 @@ void EditorHelp::_class_desc_select(const String &p_select) { if (tag == "method") { topic = "class_method"; - table = &this->method_line; + table = &method_line; } else if (tag == "constructor") { topic = "class_method"; - table = &this->method_line; + table = &method_line; } else if (tag == "operator") { topic = "class_method"; - table = &this->method_line; + table = &method_line; } else if (tag == "member") { topic = "class_property"; - table = &this->property_line; + table = &property_line; } else if (tag == "enum") { topic = "class_enum"; - table = &this->enum_line; + table = &enum_line; } else if (tag == "signal") { topic = "class_signal"; - table = &this->signal_line; + table = &signal_line; } else if (tag == "constant") { topic = "class_constant"; - table = &this->constant_line; + table = &constant_line; } else if (tag == "annotation") { topic = "class_annotation"; - table = &this->annotation_line; + table = &annotation_line; } else if (tag == "theme_item") { topic = "theme_item"; - table = &this->theme_property_line; + table = &theme_property_line; } else { return; } @@ -812,35 +814,25 @@ void EditorHelp::_update_doc() { class_desc->add_newline(); } - // Descendents - if (cd.is_script_doc || ClassDB::class_exists(cd.name)) { - bool found = false; - bool prev = false; - + // Descendants + if ((cd.is_script_doc || ClassDB::class_exists(cd.name)) && doc->inheriting.has(cd.name)) { _push_normal_font(); - for (const KeyValue<String, DocData::ClassDoc> &E : doc->class_list) { - if (E.value.inherits == cd.name) { - if (!found) { - class_desc->push_color(theme_cache.title_color); - class_desc->add_text(TTR("Inherited by:") + " "); - found = true; - } + class_desc->push_color(theme_cache.title_color); + class_desc->add_text(TTR("Inherited by:") + " "); - if (prev) { - class_desc->add_text(" , "); - } - _add_type_icon(E.value.name, theme_cache.doc_font_size, "ArrowRight"); - class_desc->add_text(non_breaking_space); // Otherwise icon borrows hyperlink from _add_type(). - _add_type(E.value.name); - prev = true; + for (RBSet<String, NaturalNoCaseComparator>::Element *itr = doc->inheriting[cd.name].front(); itr; itr = itr->next()) { + if (itr->prev()) { + class_desc->add_text(" , "); } + + _add_type_icon(itr->get(), theme_cache.doc_font_size, "ArrowRight"); + class_desc->add_text(non_breaking_space); // Otherwise icon borrows hyperlink from _add_type(). + _add_type(itr->get()); } _pop_normal_font(); - if (found) { - class_desc->pop(); - class_desc->add_newline(); - } + class_desc->pop(); + class_desc->add_newline(); } // Note if deprecated. @@ -2379,6 +2371,28 @@ String EditorHelp::get_cache_full_path() { return EditorPaths::get_singleton()->get_cache_dir().path_join("editor_doc_cache.res"); } +void EditorHelp::load_xml_buffer(const uint8_t *p_buffer, int p_size) { + if (!ext_doc) { + ext_doc = memnew(DocTools); + } + + ext_doc->load_xml(p_buffer, p_size); + + if (doc) { + doc->load_xml(p_buffer, p_size); + } +} + +void EditorHelp::remove_class(const String &p_class) { + if (ext_doc && ext_doc->has_doc(p_class)) { + ext_doc->remove_doc(p_class); + } + + if (doc && doc->has_doc(p_class)) { + doc->remove_doc(p_class); + } +} + void EditorHelp::_load_doc_thread(void *p_udata) { Ref<Resource> cache_res = ResourceLoader::load(get_cache_full_path()); if (cache_res.is_valid() && cache_res->get_meta("version_hash", "") == doc_version_hash) { @@ -2426,6 +2440,11 @@ void EditorHelp::_gen_doc_thread(void *p_udata) { void EditorHelp::_gen_extensions_docs() { doc->generate((DocTools::GENERATE_FLAG_SKIP_BASIC_TYPES | DocTools::GENERATE_FLAG_EXTENSION_CLASSES_ONLY)); + + // Append extra doc data, as it gets overridden by the generation step. + if (ext_doc) { + doc->merge_from(*ext_doc); + } } void EditorHelp::generate_doc(bool p_use_cache) { @@ -2564,6 +2583,11 @@ void EditorHelp::_bind_methods() { ADD_SIGNAL(MethodInfo("go_to_help")); } +void EditorHelp::init_gdext_pointers() { + GDExtensionEditorHelp::editor_help_load_xml_buffer = &EditorHelp::load_xml_buffer; + GDExtensionEditorHelp::editor_help_remove_class = &EditorHelp::remove_class; +} + EditorHelp::EditorHelp() { set_custom_minimum_size(Size2(150 * EDSCALE, 0)); @@ -2872,9 +2896,17 @@ void EditorHelpTooltip::parse_tooltip(const String &p_text) { const String &property_name = slices[2]; const String &property_args = slices[3]; + String formatted_text; + + // Exclude internal properties, they are not documented. + if (type == "internal_property") { + formatted_text = "[i]" + TTR("This property can only be set in the Inspector.") + "[/i]"; + set_text(formatted_text); + return; + } + String title; String description; - String formatted_text; if (type == "class") { title = class_name; |