summaryrefslogtreecommitdiff
path: root/editor/editor_help.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_help.cpp')
-rw-r--r--editor/editor_help.cpp406
1 files changed, 274 insertions, 132 deletions
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp
index 30cf7d1e7a..283713cd3c 100644
--- a/editor/editor_help.cpp
+++ b/editor/editor_help.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -40,7 +40,7 @@
#define CONTRIBUTE_URL "https://docs.godotengine.org/en/latest/community/contributing/updating_the_class_reference.html"
-DocData *EditorHelp::doc = nullptr;
+DocTools *EditorHelp::doc = nullptr;
void EditorHelp::_init_colors() {
title_color = get_theme_color("accent_color", "Editor");
@@ -56,19 +56,6 @@ void EditorHelp::_init_colors() {
class_desc->add_theme_constant_override("line_separation", Math::round(5 * EDSCALE));
}
-void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
- if (!is_visible_in_tree()) {
- return;
- }
-
- Ref<InputEventKey> k = p_ev;
-
- if (k.is_valid() && k->get_control() && k->get_keycode() == KEY_F) {
- search->grab_focus();
- search->select_all();
- }
-}
-
void EditorHelp::_search(bool p_search_previous) {
if (p_search_previous) {
find_bar->search_prev();
@@ -168,23 +155,24 @@ void EditorHelp::_class_desc_resized() {
// Add extra horizontal margins for better readability.
// The margins increase as the width of the editor help container increases.
Ref<Font> doc_code_font = get_theme_font("doc_source", "EditorFonts");
- real_t char_width = doc_code_font->get_char_size('x').width;
+ int font_size = get_theme_font_size("doc_source_size", "EditorFonts");
+ real_t char_width = doc_code_font->get_char_size('x', 0, font_size).width;
const int display_margin = MAX(30 * EDSCALE, get_parent_anchorable_rect().size.width - char_width * 120 * EDSCALE) * 0.5;
Ref<StyleBox> class_desc_stylebox = EditorNode::get_singleton()->get_theme_base()->get_theme_stylebox("normal", "RichTextLabel")->duplicate();
- class_desc_stylebox->set_default_margin(MARGIN_LEFT, display_margin);
- class_desc_stylebox->set_default_margin(MARGIN_RIGHT, display_margin);
+ class_desc_stylebox->set_default_margin(SIDE_LEFT, display_margin);
+ class_desc_stylebox->set_default_margin(SIDE_RIGHT, display_margin);
class_desc->add_theme_style_override("normal", class_desc_stylebox);
}
void EditorHelp::_add_type(const String &p_type, const String &p_enum) {
String t = p_type;
- if (t.empty()) {
+ if (t.is_empty()) {
t = "void";
}
- bool can_ref = (t != "void") || !p_enum.empty();
+ bool can_ref = (t != "void") || !p_enum.is_empty();
- if (!p_enum.empty()) {
+ if (!p_enum.is_empty()) {
if (p_enum.get_slice_count(".") > 1) {
t = p_enum.get_slice(".", 1);
} else {
@@ -200,7 +188,7 @@ void EditorHelp::_add_type(const String &p_type, const String &p_enum) {
add_array = true;
t = t.replace("[]", "");
}
- if (p_enum.empty()) {
+ if (p_enum.is_empty()) {
class_desc->push_meta("#" + t); //class
} else {
class_desc->push_meta("$" + p_enum); //class
@@ -242,7 +230,10 @@ void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview
if (p_overview) {
class_desc->push_cell();
- class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
+ class_desc->push_paragraph(RichTextLabel::ALIGN_RIGHT, Control::TEXT_DIRECTION_AUTO, "");
+ } else {
+ static const char32_t prefix[3] = { 0x25CF /* filled circle */, ' ', 0 };
+ class_desc->add_text(String(prefix));
}
_add_type(p_method.return_type, p_method.return_enum);
@@ -378,7 +369,6 @@ void EditorHelp::_update_doc() {
class_desc->push_color(title_color);
class_desc->push_font(doc_font);
class_desc->add_text(TTR("Inherits:") + " ");
- class_desc->pop();
String inherits = cd.inherits;
@@ -393,21 +383,21 @@ void EditorHelp::_update_doc() {
}
class_desc->pop();
+ class_desc->pop();
class_desc->add_newline();
}
// Descendents
- if (ClassDB::class_exists(cd.name)) {
+ if (cd.is_script_doc || ClassDB::class_exists(cd.name)) {
bool found = false;
bool prev = false;
+ class_desc->push_font(doc_font);
for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
if (E->get().inherits == cd.name) {
if (!found) {
class_desc->push_color(title_color);
- class_desc->push_font(doc_font);
class_desc->add_text(TTR("Inherited by:") + " ");
- class_desc->pop();
found = true;
}
@@ -419,6 +409,7 @@ void EditorHelp::_update_doc() {
prev = true;
}
}
+ class_desc->pop();
if (found) {
class_desc->pop();
@@ -480,8 +471,8 @@ void EditorHelp::_update_doc() {
class_desc->add_newline();
for (int i = 0; i < cd.tutorials.size(); i++) {
- const String link = DTR(cd.tutorials[i]);
- String linktxt = link;
+ const String link = DTR(cd.tutorials[i].link);
+ String linktxt = (cd.tutorials[i].title.is_empty()) ? link : DTR(cd.tutorials[i].title);
const int seppos = linktxt.find("//");
if (seppos != -1) {
linktxt = link.right(seppos + 2);
@@ -503,7 +494,19 @@ void EditorHelp::_update_doc() {
Set<String> skip_methods;
bool property_descr = false;
- if (cd.properties.size()) {
+ bool has_properties = cd.properties.size() != 0;
+ if (cd.is_script_doc) {
+ has_properties = false;
+ for (int i = 0; i < cd.properties.size(); i++) {
+ if (cd.properties[i].name.begins_with("_") && cd.properties[i].description.is_empty()) {
+ continue;
+ }
+ has_properties = true;
+ break;
+ }
+ }
+
+ if (has_properties) {
section_line.push_back(Pair<String, int>(TTR("Properties"), class_desc->get_line_count() - 2));
class_desc->push_color(title_color);
class_desc->push_font(doc_title_font);
@@ -518,10 +521,14 @@ void EditorHelp::_update_doc() {
class_desc->set_table_column_expand(1, true);
for (int i = 0; i < cd.properties.size(); i++) {
+ // Ignore undocumented private.
+ if (cd.properties[i].name.begins_with("_") && cd.properties[i].description.is_empty()) {
+ continue;
+ }
property_line[cd.properties[i].name] = class_desc->get_line_count() - 2; //gets overridden if description
class_desc->push_cell();
- class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
+ class_desc->push_paragraph(RichTextLabel::ALIGN_RIGHT, Control::TEXT_DIRECTION_AUTO, "");
class_desc->push_font(doc_code_font);
_add_type(cd.properties[i].type, cd.properties[i].enumeration);
class_desc->pop();
@@ -574,6 +581,32 @@ void EditorHelp::_update_doc() {
class_desc->pop();
}
+ if (cd.is_script_doc && (cd.properties[i].setter != "" || cd.properties[i].getter != "")) {
+ class_desc->push_color(symbol_color);
+ class_desc->add_text(" [" + TTR("property:") + " ");
+ class_desc->pop(); // color
+
+ if (cd.properties[i].setter != "") {
+ class_desc->push_color(value_color);
+ class_desc->add_text("setter");
+ class_desc->pop(); // color
+ }
+ if (cd.properties[i].getter != "") {
+ if (cd.properties[i].setter != "") {
+ class_desc->push_color(symbol_color);
+ class_desc->add_text(", ");
+ class_desc->pop(); // color
+ }
+ class_desc->push_color(value_color);
+ class_desc->add_text("getter");
+ class_desc->pop(); // color
+ }
+
+ class_desc->push_color(symbol_color);
+ class_desc->add_text("]");
+ class_desc->pop(); // color
+ }
+
class_desc->pop();
class_desc->pop();
@@ -599,6 +632,10 @@ void EditorHelp::_update_doc() {
continue;
}
}
+ // Ignore undocumented private.
+ if (cd.methods[i].name.begins_with("_") && cd.methods[i].description.is_empty()) {
+ continue;
+ }
methods.push_back(cd.methods[i]);
}
@@ -631,7 +668,7 @@ void EditorHelp::_update_doc() {
}
}
- if (any_previous && !m.empty()) {
+ if (any_previous && !m.is_empty()) {
class_desc->push_cell();
class_desc->pop(); //cell
class_desc->push_cell();
@@ -665,7 +702,7 @@ void EditorHelp::_update_doc() {
_add_method(m[i], true);
}
- any_previous = !m.empty();
+ any_previous = !m.is_empty();
}
class_desc->pop(); //table
@@ -692,7 +729,7 @@ void EditorHelp::_update_doc() {
theme_property_line[cd.theme_properties[i].name] = class_desc->get_line_count() - 2; //gets overridden if description
class_desc->push_cell();
- class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
+ class_desc->push_paragraph(RichTextLabel::ALIGN_RIGHT, Control::TEXT_DIRECTION_AUTO, "");
class_desc->push_font(doc_code_font);
_add_type(cd.theme_properties[i].type);
class_desc->pop();
@@ -758,6 +795,8 @@ void EditorHelp::_update_doc() {
signal_line[cd.signals[i].name] = class_desc->get_line_count() - 2; //gets overridden if description
class_desc->push_font(doc_code_font); // monofont
class_desc->push_color(headline_color);
+ static const char32_t prefix[3] = { 0x25CF /* filled circle */, ' ', 0 };
+ class_desc->add_text(String(prefix));
_add_text(cd.signals[i].name);
class_desc->pop();
class_desc->push_color(symbol_color);
@@ -809,13 +848,17 @@ void EditorHelp::_update_doc() {
Vector<DocData::ConstantDoc> constants;
for (int i = 0; i < cd.constants.size(); i++) {
- if (cd.constants[i].enumeration != String()) {
+ if (!cd.constants[i].enumeration.is_empty()) {
if (!enums.has(cd.constants[i].enumeration)) {
enums[cd.constants[i].enumeration] = Vector<DocData::ConstantDoc>();
}
enums[cd.constants[i].enumeration].push_back(cd.constants[i]);
} else {
+ // Ignore undocumented private.
+ if (cd.constants[i].name.begins_with("_") && cd.constants[i].description.is_empty()) {
+ continue;
+ }
constants.push_back(cd.constants[i]);
}
}
@@ -835,10 +878,10 @@ void EditorHelp::_update_doc() {
for (Map<String, Vector<DocData::ConstantDoc>>::Element *E = enums.front(); E; E = E->next()) {
enum_line[E->key()] = class_desc->get_line_count() - 2;
+ class_desc->push_font(doc_code_font);
class_desc->push_color(title_color);
class_desc->add_text("enum ");
class_desc->pop();
- class_desc->push_font(doc_code_font);
String e = E->key();
if ((e.get_slice_count(".") > 1) && (e.get_slice(".", 0) == edited_class)) {
e = e.get_slice(".", 1);
@@ -851,8 +894,23 @@ void EditorHelp::_update_doc() {
class_desc->push_color(symbol_color);
class_desc->add_text(":");
class_desc->pop();
+
+ class_desc->add_newline();
class_desc->add_newline();
+ // Enum description.
+ if (e != "@unnamed_enums" && cd.enums.has(e)) {
+ class_desc->push_color(text_color);
+ class_desc->push_font(doc_font);
+ class_desc->push_indent(1);
+ _add_text(cd.enums[e]);
+ class_desc->pop();
+ class_desc->pop();
+ class_desc->pop();
+ class_desc->add_newline();
+ class_desc->add_newline();
+ }
+
class_desc->push_indent(1);
Vector<DocData::ConstantDoc> enum_list = E->get();
@@ -869,6 +927,8 @@ void EditorHelp::_update_doc() {
class_desc->push_font(doc_code_font);
class_desc->push_color(headline_color);
+ static const char32_t prefix[3] = { 0x25CF /* filled circle */, ' ', 0 };
+ class_desc->add_text(String(prefix));
_add_text(enum_list[i].name);
class_desc->pop();
class_desc->push_color(symbol_color);
@@ -880,14 +940,15 @@ void EditorHelp::_update_doc() {
class_desc->pop();
if (enum_list[i].description != "") {
class_desc->push_font(doc_font);
- //class_desc->add_text(" ");
- class_desc->push_indent(1);
class_desc->push_color(comment_color);
+ static const char32_t dash[6] = { ' ', ' ', 0x2013 /* en dash */, ' ', ' ', 0 };
+ class_desc->add_text(String(dash));
_add_text(DTR(enum_list[i].description));
class_desc->pop();
class_desc->pop();
- class_desc->pop(); // indent
- class_desc->add_newline();
+ if (DTR(enum_list[i].description).find("\n") > 0) {
+ class_desc->add_newline();
+ }
}
class_desc->add_newline();
@@ -927,10 +988,13 @@ void EditorHelp::_update_doc() {
Vector<float> color = stripped.split_floats(",");
if (color.size() >= 3) {
class_desc->push_color(Color(color[0], color[1], color[2]));
- static const CharType prefix[3] = { 0x25CF /* filled circle */, ' ', 0 };
+ static const char32_t prefix[3] = { 0x25CF /* filled circle */, ' ', 0 };
class_desc->add_text(String(prefix));
class_desc->pop();
}
+ } else {
+ static const char32_t prefix[3] = { 0x25CF /* filled circle */, ' ', 0 };
+ class_desc->add_text(String(prefix));
}
class_desc->push_color(headline_color);
@@ -946,13 +1010,15 @@ void EditorHelp::_update_doc() {
class_desc->pop();
if (constants[i].description != "") {
class_desc->push_font(doc_font);
- class_desc->push_indent(1);
class_desc->push_color(comment_color);
+ static const char32_t dash[6] = { ' ', ' ', 0x2013 /* en dash */, ' ', ' ', 0 };
+ class_desc->add_text(String(dash));
_add_text(DTR(constants[i].description));
class_desc->pop();
class_desc->pop();
- class_desc->pop(); // indent
- class_desc->add_newline();
+ if (DTR(constants[i].description).find("\n") > 0) {
+ class_desc->add_newline();
+ }
}
class_desc->add_newline();
@@ -987,6 +1053,9 @@ void EditorHelp::_update_doc() {
class_desc->push_cell();
class_desc->push_font(doc_code_font);
+ static const char32_t prefix[3] = { 0x25CF /* filled circle */, ' ', 0 };
+ class_desc->add_text(String(prefix));
+
_add_type(cd.properties[i].type, cd.properties[i].enumeration);
class_desc->add_text(" ");
class_desc->pop(); // font
@@ -1012,41 +1081,89 @@ void EditorHelp::_update_doc() {
class_desc->pop(); // color
}
- class_desc->pop(); // font
- class_desc->pop(); // cell
+ if (cd.is_script_doc && (cd.properties[i].setter != "" || cd.properties[i].getter != "")) {
+ class_desc->push_color(symbol_color);
+ class_desc->add_text(" [" + TTR("property:") + " ");
+ class_desc->pop(); // color
- if (cd.properties[i].setter != "") {
- class_desc->push_cell();
- class_desc->pop(); // cell
+ if (cd.properties[i].setter != "") {
+ class_desc->push_color(value_color);
+ class_desc->add_text("setter");
+ class_desc->pop(); // color
+ }
+ if (cd.properties[i].getter != "") {
+ if (cd.properties[i].setter != "") {
+ class_desc->push_color(symbol_color);
+ class_desc->add_text(", ");
+ class_desc->pop(); // color
+ }
+ class_desc->push_color(value_color);
+ class_desc->add_text("getter");
+ class_desc->pop(); // color
+ }
- class_desc->push_cell();
- class_desc->push_font(doc_code_font);
- class_desc->push_color(text_color);
- class_desc->add_text(cd.properties[i].setter + TTR("(value)"));
- class_desc->pop(); // color
- class_desc->push_color(comment_color);
- class_desc->add_text(" setter");
+ class_desc->push_color(symbol_color);
+ class_desc->add_text("]");
class_desc->pop(); // color
- class_desc->pop(); // font
- class_desc->pop(); // cell
- method_line[cd.properties[i].setter] = property_line[cd.properties[i].name];
}
- if (cd.properties[i].getter != "") {
- class_desc->push_cell();
- class_desc->pop(); // cell
+ class_desc->pop(); // font
+ class_desc->pop(); // cell
- class_desc->push_cell();
- class_desc->push_font(doc_code_font);
- class_desc->push_color(text_color);
- class_desc->add_text(cd.properties[i].getter + "()");
- class_desc->pop(); //color
- class_desc->push_color(comment_color);
- class_desc->add_text(" getter");
- class_desc->pop(); //color
- class_desc->pop(); //font
- class_desc->pop(); //cell
- method_line[cd.properties[i].getter] = property_line[cd.properties[i].name];
+ // Script doc doesn't have setter, getter.
+ if (!cd.is_script_doc) {
+ Map<String, DocData::MethodDoc> method_map;
+ for (int j = 0; j < methods.size(); j++) {
+ method_map[methods[j].name] = methods[j];
+ }
+
+ if (cd.properties[i].setter != "") {
+ class_desc->push_cell();
+ class_desc->pop(); // cell
+
+ class_desc->push_cell();
+ class_desc->push_font(doc_code_font);
+ class_desc->push_color(text_color);
+ if (method_map[cd.properties[i].setter].arguments.size() > 1) {
+ // Setters with additional arguments are exposed in the method list, so we link them here for quick access.
+ class_desc->push_meta("@method " + cd.properties[i].setter);
+ class_desc->add_text(cd.properties[i].setter + TTR("(value)"));
+ class_desc->pop();
+ } else {
+ class_desc->add_text(cd.properties[i].setter + TTR("(value)"));
+ }
+ class_desc->pop(); // color
+ class_desc->push_color(comment_color);
+ class_desc->add_text(" setter");
+ class_desc->pop(); // color
+ class_desc->pop(); // font
+ class_desc->pop(); // cell
+ method_line[cd.properties[i].setter] = property_line[cd.properties[i].name];
+ }
+
+ if (cd.properties[i].getter != "") {
+ class_desc->push_cell();
+ class_desc->pop(); // cell
+
+ class_desc->push_cell();
+ class_desc->push_font(doc_code_font);
+ class_desc->push_color(text_color);
+ if (method_map[cd.properties[i].getter].arguments.size() > 0) {
+ // Getters with additional arguments are exposed in the method list, so we link them here for quick access.
+ class_desc->push_meta("@method " + cd.properties[i].getter);
+ class_desc->add_text(cd.properties[i].getter + "()");
+ class_desc->pop();
+ } else {
+ class_desc->add_text(cd.properties[i].getter + "()");
+ }
+ class_desc->pop(); //color
+ class_desc->push_color(comment_color);
+ class_desc->add_text(" getter");
+ class_desc->pop(); //color
+ class_desc->pop(); //font
+ class_desc->pop(); //cell
+ method_line[cd.properties[i].getter] = property_line[cd.properties[i].name];
+ }
}
class_desc->pop(); // table
@@ -1057,13 +1174,17 @@ void EditorHelp::_update_doc() {
class_desc->push_color(text_color);
class_desc->push_font(doc_font);
class_desc->push_indent(1);
- if (cd.properties[i].description.strip_edges() != String()) {
+ if (!cd.properties[i].description.strip_edges().is_empty()) {
_add_text(DTR(cd.properties[i].description));
} else {
class_desc->add_image(get_theme_icon("Error", "EditorIcons"));
class_desc->add_text(" ");
class_desc->push_color(comment_color);
- class_desc->append_bbcode(TTR("There is currently no description for this property. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text));
+ if (cd.is_script_doc) {
+ class_desc->append_bbcode(TTR("There is currently no description for this property."));
+ } else {
+ class_desc->append_bbcode(TTR("There is currently no description for this property. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text));
+ }
class_desc->pop();
}
class_desc->pop();
@@ -1108,13 +1229,17 @@ void EditorHelp::_update_doc() {
class_desc->push_color(text_color);
class_desc->push_font(doc_font);
class_desc->push_indent(1);
- if (methods_filtered[i].description.strip_edges() != String()) {
+ if (!methods_filtered[i].description.strip_edges().is_empty()) {
_add_text(DTR(methods_filtered[i].description));
} else {
class_desc->add_image(get_theme_icon("Error", "EditorIcons"));
class_desc->add_text(" ");
class_desc->push_color(comment_color);
- class_desc->append_bbcode(TTR("There is currently no description for this method. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text));
+ if (cd.is_script_doc) {
+ class_desc->append_bbcode(TTR("There is currently no description for this method."));
+ } else {
+ class_desc->append_bbcode(TTR("There is currently no description for this method. Please help us by [color=$color][url=$url]contributing one[/url][/color]!").replace("$url", CONTRIBUTE_URL).replace("$color", link_color_text));
+ }
class_desc->pop();
}
@@ -1198,7 +1323,7 @@ void EditorHelp::_help_callback(const String &p_topic) {
}
static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
- DocData *doc = EditorHelp::get_doc_data();
+ DocTools *doc = EditorHelp::get_doc_data();
String base_path;
Ref<Font> doc_font = p_rt->get_theme_font("doc", "EditorFonts");
@@ -1206,15 +1331,64 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
Ref<Font> doc_code_font = p_rt->get_theme_font("doc_source", "EditorFonts");
Ref<Font> doc_kbd_font = p_rt->get_theme_font("doc_keyboard", "EditorFonts");
- Color font_color_hl = p_rt->get_theme_color("headline_color", "EditorHelp");
+ Color headline_color = p_rt->get_theme_color("headline_color", "EditorHelp");
Color accent_color = p_rt->get_theme_color("accent_color", "Editor");
Color property_color = p_rt->get_theme_color("property_color", "Editor");
- Color link_color = accent_color.lerp(font_color_hl, 0.8);
- Color code_color = accent_color.lerp(font_color_hl, 0.6);
+ Color link_color = accent_color.lerp(headline_color, 0.8);
+ Color code_color = accent_color.lerp(headline_color, 0.6);
Color kbd_color = accent_color.lerp(property_color, 0.6);
String bbcode = p_bbcode.dedent().replace("\t", "").replace("\r", "").strip_edges();
+ // Select the correct code examples
+ switch ((int)EDITOR_GET("text_editor/help/class_reference_examples")) {
+ case 0: // GDScript
+ bbcode = bbcode.replace("[gdscript]", "[codeblock]");
+ bbcode = bbcode.replace("[/gdscript]", "[/codeblock]");
+
+ for (int pos = bbcode.find("[csharp]"); pos != -1; pos = bbcode.find("[csharp]")) {
+ if (bbcode.find("[/csharp]") == -1) {
+ WARN_PRINT("Unclosed [csharp] block or parse fail in code (search for tag errors)");
+ break;
+ }
+
+ bbcode.erase(pos, bbcode.find("[/csharp]") + 9 - pos);
+ while (bbcode[pos] == '\n') {
+ bbcode.erase(pos, 1);
+ }
+ }
+ break;
+ case 1: // C#
+ bbcode = bbcode.replace("[csharp]", "[codeblock]");
+ bbcode = bbcode.replace("[/csharp]", "[/codeblock]");
+
+ for (int pos = bbcode.find("[gdscript]"); pos != -1; pos = bbcode.find("[gdscript]")) {
+ if (bbcode.find("[/gdscript]") == -1) {
+ WARN_PRINT("Unclosed [gdscript] block or parse fail in code (search for tag errors)");
+ break;
+ }
+
+ bbcode.erase(pos, bbcode.find("[/gdscript]") + 11 - pos);
+ while (bbcode[pos] == '\n') {
+ bbcode.erase(pos, 1);
+ }
+ }
+ break;
+ case 2: // GDScript and C#
+ bbcode = bbcode.replace("[csharp]", "[b]C#:[/b]\n[codeblock]");
+ bbcode = bbcode.replace("[gdscript]", "[b]GDScript:[/b]\n[codeblock]");
+
+ bbcode = bbcode.replace("[/csharp]", "[/codeblock]");
+ bbcode = bbcode.replace("[/gdscript]", "[/codeblock]");
+ break;
+ }
+
+ // Remove codeblocks (they would be printed otherwise)
+ bbcode = bbcode.replace("[codeblocks]\n", "");
+ bbcode = bbcode.replace("\n[/codeblocks]", "");
+ bbcode = bbcode.replace("[codeblocks]", "");
+ bbcode = bbcode.replace("[/codeblocks]", "");
+
// remove extra new lines around code blocks
bbcode = bbcode.replace("[codeblock]\n", "[codeblock]");
bbcode = bbcode.replace("\n[/codeblock]", "[/codeblock]");
@@ -1307,7 +1481,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
tag_stack.push_front(tag);
} else if (tag == "i") {
//use italics font
- p_rt->push_color(font_color_hl);
+ p_rt->push_color(headline_color);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "code" || tag == "codeblock") {
@@ -1326,7 +1500,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
tag_stack.push_front(tag);
} else if (tag == "center") {
//align to center
- p_rt->push_align(RichTextLabel::ALIGN_CENTER);
+ p_rt->push_paragraph(RichTextLabel::ALIGN_CENTER, Control::TEXT_DIRECTION_AUTO, "");
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "br") {
@@ -1375,46 +1549,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
tag_stack.push_front(tag);
} else if (tag.begins_with("color=")) {
String col = tag.substr(6, tag.length());
- Color color;
-
- if (col.begins_with("#")) {
- color = Color::html(col);
- } else if (col == "aqua") {
- color = Color(0, 1, 1);
- } else if (col == "black") {
- color = Color(0, 0, 0);
- } else if (col == "blue") {
- color = Color(0, 0, 1);
- } else if (col == "fuchsia") {
- color = Color(1, 0, 1);
- } else if (col == "gray" || col == "grey") {
- color = Color(0.5, 0.5, 0.5);
- } else if (col == "green") {
- color = Color(0, 0.5, 0);
- } else if (col == "lime") {
- color = Color(0, 1, 0);
- } else if (col == "maroon") {
- color = Color(0.5, 0, 0);
- } else if (col == "navy") {
- color = Color(0, 0, 0.5);
- } else if (col == "olive") {
- color = Color(0.5, 0.5, 0);
- } else if (col == "purple") {
- color = Color(0.5, 0, 0.5);
- } else if (col == "red") {
- color = Color(1, 0, 0);
- } else if (col == "silver") {
- color = Color(0.75, 0.75, 0.75);
- } else if (col == "teal") {
- color = Color(0, 0.5, 0.5);
- } else if (col == "white") {
- color = Color(1, 1, 1);
- } else if (col == "yellow") {
- color = Color(1, 1, 0);
- } else {
- color = Color(0, 0, 0); //base_color;
- }
-
+ Color color = Color::from_string(col, Color());
p_rt->push_color(color);
pos = brk_end + 1;
tag_stack.push_front("color");
@@ -1444,9 +1579,9 @@ void EditorHelp::_add_text(const String &p_bbcode) {
}
void EditorHelp::generate_doc() {
- doc = memnew(DocData);
+ doc = memnew(DocTools);
doc->generate(true);
- DocData compdoc;
+ DocTools compdoc;
compdoc.load_compressed(_doc_data_compressed, _doc_data_compressed_size, _doc_data_uncompressed_size);
doc->merge_from(compdoc); //ensure all is up to date
}
@@ -1475,6 +1610,12 @@ void EditorHelp::go_to_class(const String &p_class, int p_scroll) {
_goto_desc(p_class, p_scroll);
}
+void EditorHelp::update_doc() {
+ ERR_FAIL_COND(!doc->class_list.has(edited_class));
+ ERR_FAIL_COND(!doc->class_list[edited_class].is_script_doc);
+ _update_doc();
+}
+
Vector<Pair<String, int>> EditorHelp::get_sections() {
Vector<Pair<String, int>> sections;
@@ -1512,7 +1653,6 @@ void EditorHelp::set_scroll(int p_scroll) {
void EditorHelp::_bind_methods() {
ClassDB::bind_method("_class_list_select", &EditorHelp::_class_list_select);
ClassDB::bind_method("_request_help", &EditorHelp::_request_help);
- ClassDB::bind_method("_unhandled_key_input", &EditorHelp::_unhandled_key_input);
ClassDB::bind_method("_search", &EditorHelp::_search);
ClassDB::bind_method("_help_callback", &EditorHelp::_help_callback);
@@ -1627,12 +1767,14 @@ FindBar::FindBar() {
add_child(matches_label);
matches_label->hide();
- find_prev = memnew(ToolButton);
+ find_prev = memnew(Button);
+ find_prev->set_flat(true);
add_child(find_prev);
find_prev->set_focus_mode(FOCUS_NONE);
find_prev->connect("pressed", callable_mp(this, &FindBar::search_prev));
- find_next = memnew(ToolButton);
+ find_next = memnew(Button);
+ find_next->set_flat(true);
add_child(find_next);
find_next->set_focus_mode(FOCUS_NONE);
find_next->connect("pressed", callable_mp(this, &FindBar::search_next));
@@ -1657,7 +1799,7 @@ void FindBar::popup_search() {
grabbed_focus = true;
}
- if (!search_text->get_text().empty()) {
+ if (!search_text->get_text().is_empty()) {
search_text->select_all();
search_text->set_cursor_position(search_text->get_text().length());
if (grabbed_focus) {
@@ -1727,7 +1869,7 @@ void FindBar::_update_results_count() {
results_count = 0;
String searched = search_text->get_text();
- if (searched.empty()) {
+ if (searched.is_empty()) {
return;
}
@@ -1747,7 +1889,7 @@ void FindBar::_update_results_count() {
}
void FindBar::_update_matches_label() {
- if (search_text->get_text().empty() || results_count == -1) {
+ if (search_text->get_text().is_empty() || results_count == -1) {
matches_label->hide();
} else {
matches_label->show();