summaryrefslogtreecommitdiff
path: root/editor/doc_tools.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/doc_tools.cpp')
-rw-r--r--editor/doc_tools.cpp181
1 files changed, 83 insertions, 98 deletions
diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp
index d04875f188..beead74c53 100644
--- a/editor/doc_tools.cpp
+++ b/editor/doc_tools.cpp
@@ -44,8 +44,8 @@
#include "modules/modules_enabled.gen.h"
void DocTools::merge_from(const DocTools &p_data) {
- for (Map<String, DocData::ClassDoc>::Element *E = class_list.front(); E; E = E->next()) {
- DocData::ClassDoc &c = E->get();
+ for (KeyValue<String, DocData::ClassDoc> &E : class_list) {
+ DocData::ClassDoc &c = E.value;
if (!p_data.class_list.has(c.name)) {
continue;
@@ -185,9 +185,9 @@ void DocTools::merge_from(const DocTools &p_data) {
}
void DocTools::remove_from(const DocTools &p_data) {
- for (Map<String, DocData::ClassDoc>::Element *E = p_data.class_list.front(); E; E = E->next()) {
- if (class_list.has(E->key())) {
- class_list.erase(E->key());
+ for (const KeyValue<String, DocData::ClassDoc> &E : p_data.class_list) {
+ if (class_list.has(E.key)) {
+ class_list.erase(E.key);
}
}
}
@@ -1173,62 +1173,19 @@ static void _write_string(FileAccess *f, int p_tablevel, const String &p_string)
f->store_string(tab + p_string + "\n");
}
-Error DocTools::save_classes(const String &p_default_path, const Map<String, String> &p_class_path) {
- for (Map<String, DocData::ClassDoc>::Element *E = class_list.front(); E; E = E->next()) {
- DocData::ClassDoc &c = E->get();
-
- String save_path;
- if (p_class_path.has(c.name)) {
- save_path = p_class_path[c.name];
- } else {
- save_path = p_default_path;
- }
-
- Error err;
- String save_file = save_path.plus_file(c.name + ".xml");
- FileAccessRef f = FileAccess::open(save_file, FileAccess::WRITE, &err);
-
- ERR_CONTINUE_MSG(err != OK, "Can't write doc file: " + save_file + ".");
-
- _write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
-
- String header = "<class name=\"" + c.name + "\"";
- if (c.inherits != "") {
- header += " inherits=\"" + c.inherits + "\"";
- }
- header += String(" version=\"") + VERSION_BRANCH + "\"";
- header += ">";
- _write_string(f, 0, header);
-
- _write_string(f, 1, "<brief_description>");
- _write_string(f, 2, c.brief_description.strip_edges().xml_escape());
- _write_string(f, 1, "</brief_description>");
-
- _write_string(f, 1, "<description>");
- _write_string(f, 2, c.description.strip_edges().xml_escape());
- _write_string(f, 1, "</description>");
-
- _write_string(f, 1, "<tutorials>");
- for (int i = 0; i < c.tutorials.size(); i++) {
- DocData::TutorialDoc tutorial = c.tutorials.get(i);
- String title_attribute = (!tutorial.title.is_empty()) ? " title=\"" + tutorial.title.xml_escape() + "\"" : "";
- _write_string(f, 2, "<link" + title_attribute + ">" + tutorial.link.xml_escape() + "</link>");
- }
- _write_string(f, 1, "</tutorials>");
-
- _write_string(f, 1, "<methods>");
-
- c.methods.sort();
-
- for (int i = 0; i < c.methods.size(); i++) {
- const DocData::MethodDoc &m = c.methods[i];
+static void _write_method_doc(FileAccess *f, const String &p_name, Vector<DocData::MethodDoc> &p_method_docs) {
+ if (!p_method_docs.is_empty()) {
+ p_method_docs.sort();
+ _write_string(f, 1, "<" + p_name + "s>");
+ for (int i = 0; i < p_method_docs.size(); i++) {
+ const DocData::MethodDoc &m = p_method_docs[i];
String qualifiers;
if (m.qualifiers != "") {
qualifiers += " qualifiers=\"" + m.qualifiers.xml_escape() + "\"";
}
- _write_string(f, 2, "<method name=\"" + m.name.xml_escape() + "\"" + qualifiers + ">");
+ _write_string(f, 2, "<" + p_name + " name=\"" + m.name.xml_escape() + "\"" + qualifiers + ">");
if (m.return_type != "") {
String enum_text;
@@ -1262,12 +1219,59 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str
_write_string(f, 4, m.description.strip_edges().xml_escape());
_write_string(f, 3, "</description>");
- _write_string(f, 2, "</method>");
+ _write_string(f, 2, "</" + p_name + ">");
+ }
+
+ _write_string(f, 1, "</" + p_name + "s>");
+ }
+}
+
+Error DocTools::save_classes(const String &p_default_path, const Map<String, String> &p_class_path) {
+ for (KeyValue<String, DocData::ClassDoc> &E : class_list) {
+ DocData::ClassDoc &c = E.value;
+
+ String save_path;
+ if (p_class_path.has(c.name)) {
+ save_path = p_class_path[c.name];
+ } else {
+ save_path = p_default_path;
+ }
+
+ Error err;
+ String save_file = save_path.plus_file(c.name + ".xml");
+ FileAccessRef f = FileAccess::open(save_file, FileAccess::WRITE, &err);
+
+ ERR_CONTINUE_MSG(err != OK, "Can't write doc file: " + save_file + ".");
+
+ _write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
+
+ String header = "<class name=\"" + c.name + "\"";
+ if (c.inherits != "") {
+ header += " inherits=\"" + c.inherits + "\"";
}
+ header += String(" version=\"") + VERSION_BRANCH + "\"";
+ header += ">";
+ _write_string(f, 0, header);
- _write_string(f, 1, "</methods>");
+ _write_string(f, 1, "<brief_description>");
+ _write_string(f, 2, c.brief_description.strip_edges().xml_escape());
+ _write_string(f, 1, "</brief_description>");
+
+ _write_string(f, 1, "<description>");
+ _write_string(f, 2, c.description.strip_edges().xml_escape());
+ _write_string(f, 1, "</description>");
- if (c.properties.size()) {
+ _write_string(f, 1, "<tutorials>");
+ for (int i = 0; i < c.tutorials.size(); i++) {
+ DocData::TutorialDoc tutorial = c.tutorials.get(i);
+ String title_attribute = (!tutorial.title.is_empty()) ? " title=\"" + tutorial.title.xml_escape() + "\"" : "";
+ _write_string(f, 2, "<link" + title_attribute + ">" + tutorial.link.xml_escape() + "</link>");
+ }
+ _write_string(f, 1, "</tutorials>");
+
+ _write_method_doc(f, "method", c.methods);
+
+ if (!c.properties.is_empty()) {
_write_string(f, 1, "<members>");
c.properties.sort();
@@ -1294,52 +1298,33 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str
_write_string(f, 1, "</members>");
}
- if (c.signals.size()) {
- c.signals.sort();
-
- _write_string(f, 1, "<signals>");
- for (int i = 0; i < c.signals.size(); i++) {
- const DocData::MethodDoc &m = c.signals[i];
- _write_string(f, 2, "<signal name=\"" + m.name + "\">");
- for (int j = 0; j < m.arguments.size(); j++) {
- const DocData::ArgumentDoc &a = m.arguments[j];
- _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\" />");
- }
-
- _write_string(f, 3, "<description>");
- _write_string(f, 4, m.description.strip_edges().xml_escape());
- _write_string(f, 3, "</description>");
-
- _write_string(f, 2, "</signal>");
- }
-
- _write_string(f, 1, "</signals>");
- }
-
- _write_string(f, 1, "<constants>");
+ _write_method_doc(f, "signal", c.signals);
- for (int i = 0; i < c.constants.size(); i++) {
- const DocData::ConstantDoc &k = c.constants[i];
- if (k.is_value_valid) {
- if (k.enumeration != String()) {
- _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\">");
- } else {
- _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\">");
- }
- } else {
- if (k.enumeration != String()) {
- _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\" enum=\"" + k.enumeration + "\">");
+ if (!c.constants.is_empty()) {
+ _write_string(f, 1, "<constants>");
+ for (int i = 0; i < c.constants.size(); i++) {
+ const DocData::ConstantDoc &k = c.constants[i];
+ if (k.is_value_valid) {
+ if (k.enumeration != String()) {
+ _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\">");
+ } else {
+ _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\">");
+ }
} else {
- _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\">");
+ if (k.enumeration != String()) {
+ _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\" enum=\"" + k.enumeration + "\">");
+ } else {
+ _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"platform-dependent\">");
+ }
}
+ _write_string(f, 3, k.description.strip_edges().xml_escape());
+ _write_string(f, 2, "</constant>");
}
- _write_string(f, 3, k.description.strip_edges().xml_escape());
- _write_string(f, 2, "</constant>");
- }
- _write_string(f, 1, "</constants>");
+ _write_string(f, 1, "</constants>");
+ }
- if (c.theme_properties.size()) {
+ if (!c.theme_properties.is_empty()) {
c.theme_properties.sort();
_write_string(f, 1, "<theme_items>");