diff options
author | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2019-06-01 16:42:22 +0300 |
---|---|---|
committer | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2019-06-27 18:29:35 +0300 |
commit | 0c4c36d823bb6792917dfac86491f61cec3f9b27 (patch) | |
tree | db6b87ccc416f6e9a23c69c0b625e7b4521d79f1 /editor/doc | |
parent | 2df8b5606b9de9d11873c27f0a297127bbbfc255 (diff) |
Add default values to the editor help, docs, and generated RST
Also, make spacing of "=" in the editor help a bit more consistent.
Closes #16086
Diffstat (limited to 'editor/doc')
-rw-r--r-- | editor/doc/doc_data.cpp | 35 | ||||
-rw-r--r-- | editor/doc/doc_data.h | 1 |
2 files changed, 32 insertions, 4 deletions
diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp index 041f81d063..468819151f 100644 --- a/editor/doc/doc_data.cpp +++ b/editor/doc/doc_data.cpp @@ -248,6 +248,21 @@ void DocData::generate(bool p_basic_types) { prop.setter = setter; prop.getter = getter; + if (ClassDB::can_instance(name)) { // Cannot get default value of classes that can't be instanced + Variant default_value = ClassDB::class_get_default_property_value(name, E->get().name); + prop.default_value = default_value.get_construct_string(); + } else { + List<StringName> inheriting_classes; + ClassDB::get_direct_inheriters_from_class(name, &inheriting_classes); + for (List<StringName>::Element *E2 = inheriting_classes.front(); E2; E2 = E2->next()) { + if (ClassDB::can_instance(E2->get())) { + Variant default_value = ClassDB::class_get_default_property_value(E2->get(), E->get().name); + prop.default_value = default_value.get_construct_string(); + break; + } + } + } + bool found_type = false; if (getter != StringName()) { MethodBind *mb = ClassDB::get_method(name, getter); @@ -412,6 +427,7 @@ void DocData::generate(bool p_basic_types) { PropertyDoc pd; pd.name = E->get(); pd.type = "int"; + pd.default_value = itos(Theme::get_default()->get_constant(E->get(), cname)); c.theme_properties.push_back(pd); } @@ -422,6 +438,7 @@ void DocData::generate(bool p_basic_types) { PropertyDoc pd; pd.name = E->get(); pd.type = "Color"; + pd.default_value = Variant(Theme::get_default()->get_color(E->get(), cname)).get_construct_string(); c.theme_properties.push_back(pd); } @@ -530,6 +547,7 @@ void DocData::generate(bool p_basic_types) { PropertyDoc property; property.name = pi.name; property.type = Variant::get_type_name(pi.type); + property.default_value = v.get(pi.name).get_construct_string(); c.properties.push_back(property); } @@ -1063,12 +1081,15 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri for (int i = 0; i < c.properties.size(); i++) { - String enum_text; + String additional_attributes; if (c.properties[i].enumeration != String()) { - enum_text = " enum=\"" + c.properties[i].enumeration + "\""; + additional_attributes += " enum=\"" + c.properties[i].enumeration + "\""; + } + if (c.properties[i].default_value != String()) { + additional_attributes += " default=\"" + c.properties[i].default_value.xml_escape(true) + "\""; } const PropertyDoc &p = c.properties[i]; - _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\"" + enum_text + ">"); + _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\"" + additional_attributes + ">"); _write_string(f, 3, p.description.strip_edges().xml_escape()); _write_string(f, 2, "</member>"); } @@ -1125,8 +1146,14 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri for (int i = 0; i < c.theme_properties.size(); i++) { const PropertyDoc &p = c.theme_properties[i]; - _write_string(f, 2, "<theme_item name=\"" + p.name + "\" type=\"" + p.type + "\">"); + + if (p.default_value != "") + _write_string(f, 2, "<theme_item name=\"" + p.name + "\" type=\"" + p.type + "\" default=\"" + p.default_value.xml_escape(true) + "\">"); + else + _write_string(f, 2, "<theme_item name=\"" + p.name + "\" type=\"" + p.type + "\">"); + _write_string(f, 3, p.description.strip_edges().xml_escape()); + _write_string(f, 2, "</theme_item>"); } _write_string(f, 1, "</theme_items>"); diff --git a/editor/doc/doc_data.h b/editor/doc/doc_data.h index d3844adb7e..3d5867dcca 100644 --- a/editor/doc/doc_data.h +++ b/editor/doc/doc_data.h @@ -73,6 +73,7 @@ public: String enumeration; String description; String setter, getter; + String default_value; bool operator<(const PropertyDoc &p_prop) const { return name < p_prop.name; } |