From fda49b74a1e5f25009303c27c5ba10a4df5567e6 Mon Sep 17 00:00:00 2001 From: SaviHex Date: Sat, 6 Jun 2020 22:26:35 -0300 Subject: [PATCH] Added a "title" attribute for the link tag in the docs xml (cherry picked from commit 18c08f65d6b3dd7918a1f6c1d08f30262497af56) --- doc/classes/KinematicBody2D.xml | 2 +- editor/doc/doc_data.cpp | 15 +++++++++++---- editor/doc/doc_data.h | 7 ++++++- editor/editor_help.cpp | 4 ++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/doc/classes/KinematicBody2D.xml b/doc/classes/KinematicBody2D.xml index d6995df8146..666a4bcf404 100644 --- a/doc/classes/KinematicBody2D.xml +++ b/doc/classes/KinematicBody2D.xml @@ -9,7 +9,7 @@ [b]Kinematic characters:[/b] KinematicBody2D also has an API for moving objects (the [method move_and_collide] and [method move_and_slide] methods) while performing collision tests. This makes them really useful to implement characters that collide against a world, but that don't require advanced physics. - https://docs.godotengine.org/en/latest/tutorials/physics/kinematic_character_2d.html + https://docs.godotengine.org/en/latest/tutorials/physics/kinematic_character_2d.html https://docs.godotengine.org/en/latest/tutorials/physics/using_kinematic_body_2d.html diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp index 4c7cd435a82..fe3eba593e9 100644 --- a/editor/doc/doc_data.cpp +++ b/editor/doc/doc_data.cpp @@ -873,10 +873,15 @@ Error DocData::_load(Ref parser) { String name3 = parser->get_node_name(); if (name3 == "link") { - + TutorialDoc tutorial; + if (parser->has_attribute("title")) { + tutorial.title = parser->get_attribute_value("title"); + } parser->read(); - if (parser->get_node_type() == XMLParser::NODE_TEXT) - c.tutorials.push_back(parser->get_node_data().strip_edges()); + if (parser->get_node_type() == XMLParser::NODE_TEXT) { + tutorial.link = parser->get_node_data().strip_edges(); + c.tutorials.push_back(tutorial); + } } else { ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + "."); } @@ -1051,7 +1056,9 @@ Error DocData::save_classes(const String &p_default_path, const Map"); for (int i = 0; i < c.tutorials.size(); i++) { - _write_string(f, 2, "" + c.tutorials.get(i).xml_escape() + ""); + TutorialDoc tutorial = c.tutorials.get(i); + String title_attribute = (!tutorial.title.empty()) ? " title=\"" + tutorial.title.xml_escape() + "\"" : ""; + _write_string(f, 2, "" + tutorial.link.xml_escape() + ""); } _write_string(f, 1, ""); diff --git a/editor/doc/doc_data.h b/editor/doc/doc_data.h index 073705f0b1c..133c7ee232d 100644 --- a/editor/doc/doc_data.h +++ b/editor/doc/doc_data.h @@ -83,6 +83,11 @@ public: } }; + struct TutorialDoc { + String link; + String title; + }; + struct ClassDoc { String name; @@ -90,7 +95,7 @@ public: String category; String brief_description; String description; - Vector tutorials; + Vector tutorials; Vector methods; Vector signals; Vector constants; diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 1d9a2f9f875..b34105e7a64 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -478,8 +478,8 @@ void EditorHelp::_update_doc() { class_desc->add_newline(); for (int i = 0; i < cd.tutorials.size(); i++) { - const String link = cd.tutorials[i]; - String linktxt = link; + const String link = cd.tutorials[i].link; + String linktxt = (cd.tutorials[i].title.empty()) ? link : cd.tutorials[i].title; const int seppos = linktxt.find("//"); if (seppos != -1) { linktxt = link.right(seppos + 2);