diff options
Diffstat (limited to 'editor/editor_help.cpp')
-rw-r--r-- | editor/editor_help.cpp | 112 |
1 files changed, 82 insertions, 30 deletions
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 569a28215c..c049db8ef6 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -30,6 +30,7 @@ #include "editor_help.h" +#include "core/core_constants.h" #include "core/input/input.h" #include "core/os/keyboard.h" #include "doc_data_compressed.gen.h" @@ -116,7 +117,7 @@ void EditorHelp::_class_desc_select(const String &p_select) { } else { if (table->has(link)) { // Found in the current page - class_desc->scroll_to_line((*table)[link]); + class_desc->scroll_to_paragraph((*table)[link]); } else { if (topic == "class_enum") { // Try to find the enum in @GlobalScope @@ -170,7 +171,7 @@ void EditorHelp::_add_type(const String &p_type, const String &p_enum) { if (t.is_empty()) { t = "void"; } - bool can_ref = (t != "void") || !p_enum.is_empty(); + bool can_ref = (t != "void" && t.find("*") == -1) || !p_enum.is_empty(); if (!p_enum.is_empty()) { if (p_enum.get_slice_count(".") > 1) { @@ -393,8 +394,8 @@ void EditorHelp::_update_doc() { 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) { + for (const KeyValue<String, DocData::ClassDoc> &E : doc->class_list) { + if (E.value.inherits == cd.name) { if (!found) { class_desc->push_color(title_color); class_desc->add_text(TTR("Inherited by:") + " "); @@ -405,7 +406,7 @@ void EditorHelp::_update_doc() { class_desc->add_text(" , "); } - _add_type(E->get().name); + _add_type(E.value.name); prev = true; } } @@ -479,7 +480,7 @@ void EditorHelp::_update_doc() { } class_desc->push_color(symbol_color); - class_desc->append_bbcode("[url=" + link + "]" + linktxt + "[/url]"); + class_desc->append_text("[url=" + link + "]" + linktxt + "[/url]"); class_desc->pop(); class_desc->add_newline(); } @@ -632,8 +633,8 @@ void EditorHelp::_update_doc() { continue; } } - // Ignore undocumented private. - if (cd.methods[i].name.begins_with("_") && cd.methods[i].description.is_empty()) { + // Ignore undocumented non virtual private. + if (cd.methods[i].name.begins_with("_") && cd.methods[i].description.is_empty() && cd.methods[i].qualifiers.find("virtual") == -1) { continue; } methods.push_back(cd.methods[i]); @@ -695,7 +696,7 @@ void EditorHelp::_update_doc() { class_desc->pop(); //cell } - if (m[i].description != "") { + if (m[i].description != "" || m[i].errors_returned.size() > 0) { method_descr = true; } @@ -758,8 +759,8 @@ void EditorHelp::_update_doc() { if (cd.theme_properties[i].description != "") { class_desc->push_font(doc_font); - class_desc->add_text(" "); class_desc->push_color(comment_color); + class_desc->add_text(U" – "); _add_text(DTR(cd.theme_properties[i].description)); class_desc->pop(); class_desc->pop(); @@ -875,14 +876,14 @@ void EditorHelp::_update_doc() { class_desc->add_newline(); - for (Map<String, Vector<DocData::ConstantDoc>>::Element *E = enums.front(); E; E = E->next()) { - enum_line[E->key()] = class_desc->get_line_count() - 2; + for (KeyValue<String, Vector<DocData::ConstantDoc>> &E : enums) { + 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(); - String e = E->key(); + String e = E.key; if ((e.get_slice_count(".") > 1) && (e.get_slice(".", 0) == edited_class)) { e = e.get_slice(".", 1); } @@ -912,10 +913,10 @@ void EditorHelp::_update_doc() { } class_desc->push_indent(1); - Vector<DocData::ConstantDoc> enum_list = E->get(); + Vector<DocData::ConstantDoc> enum_list = E.value; Map<String, int> enumValuesContainer; - int enumStartingLine = enum_line[E->key()]; + int enumStartingLine = enum_line[E.key]; for (int i = 0; i < enum_list.size(); i++) { if (cd.name == "@GlobalScope") { @@ -941,8 +942,7 @@ void EditorHelp::_update_doc() { if (enum_list[i].description != "") { class_desc->push_font(doc_font); class_desc->push_color(comment_color); - static const char32_t dash[6] = { ' ', ' ', 0x2013 /* en dash */, ' ', ' ', 0 }; - class_desc->add_text(String(dash)); + class_desc->add_text(U" – "); _add_text(DTR(enum_list[i].description)); class_desc->pop(); class_desc->pop(); @@ -955,7 +955,7 @@ void EditorHelp::_update_doc() { } if (cd.name == "@GlobalScope") { - enum_values_line[E->key()] = enumValuesContainer; + enum_values_line[E.key] = enumValuesContainer; } class_desc->pop(); @@ -1011,8 +1011,7 @@ void EditorHelp::_update_doc() { if (constants[i].description != "") { class_desc->push_font(doc_font); class_desc->push_color(comment_color); - static const char32_t dash[6] = { ' ', ' ', 0x2013 /* en dash */, ' ', ' ', 0 }; - class_desc->add_text(String(dash)); + class_desc->add_text(U" – "); _add_text(DTR(constants[i].description)); class_desc->pop(); class_desc->pop(); @@ -1181,9 +1180,9 @@ void EditorHelp::_update_doc() { class_desc->add_text(" "); class_desc->push_color(comment_color); if (cd.is_script_doc) { - class_desc->append_bbcode(TTR("There is currently no description for this property.")); + class_desc->append_text(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->append_text(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(); } @@ -1229,6 +1228,31 @@ 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].errors_returned.size()) { + class_desc->append_text(TTR("Error codes returned:")); + class_desc->add_newline(); + class_desc->push_list(0, RichTextLabel::LIST_DOTS, false); + for (int j = 0; j < methods_filtered[i].errors_returned.size(); j++) { + if (j > 0) { + class_desc->add_newline(); + } + int val = methods_filtered[i].errors_returned[j]; + String text = itos(val); + for (int k = 0; k < CoreConstants::get_global_constant_count(); k++) { + if (CoreConstants::get_global_constant_value(k) == val && CoreConstants::get_global_constant_enum(k) == SNAME("Error")) { + text = CoreConstants::get_global_constant_name(k); + break; + } + } + + class_desc->push_bold(); + class_desc->append_text(text); + class_desc->pop(); + } + class_desc->pop(); + class_desc->add_newline(); + class_desc->add_newline(); + } if (!methods_filtered[i].description.strip_edges().is_empty()) { _add_text(DTR(methods_filtered[i].description)); } else { @@ -1236,9 +1260,9 @@ void EditorHelp::_update_doc() { class_desc->add_text(" "); class_desc->push_color(comment_color); if (cd.is_script_doc) { - class_desc->append_bbcode(TTR("There is currently no description for this method.")); + class_desc->append_text(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->append_text(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(); } @@ -1304,6 +1328,8 @@ void EditorHelp::_help_callback(const String &p_topic) { } else if (what == "class_global") { if (constant_line.has(name)) { line = constant_line[name]; + } else if (method_line.has(name)) { + line = method_line[name]; } else { Map<String, Map<String, int>>::Element *iter = enum_values_line.front(); while (true) { @@ -1319,7 +1345,7 @@ void EditorHelp::_help_callback(const String &p_topic) { } } - class_desc->call_deferred(SNAME("scroll_to_line"), line); + class_desc->call_deferred(SNAME("scroll_to_paragraph"), line); } static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { @@ -1586,6 +1612,11 @@ void EditorHelp::generate_doc() { doc->merge_from(compdoc); //ensure all is up to date } +void EditorHelp::_toggle_scripts_pressed() { + ScriptEditor::get_singleton()->toggle_scripts_panel(); + update_toggle_scripts_button(); +} + void EditorHelp::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: @@ -1596,7 +1627,11 @@ void EditorHelp::_notification(int p_what) { if (is_inside_tree()) { _class_desc_resized(); } + update_toggle_scripts_button(); } break; + case NOTIFICATION_VISIBILITY_CHANGED: + update_toggle_scripts_button(); + break; default: break; } @@ -1627,7 +1662,7 @@ Vector<Pair<String, int>> EditorHelp::get_sections() { void EditorHelp::scroll_to_section(int p_section_index) { int line = section_line[p_section_index].second; - class_desc->scroll_to_line(line); + class_desc->scroll_to_paragraph(line); } void EditorHelp::popup_search() { @@ -1650,6 +1685,15 @@ void EditorHelp::set_scroll(int p_scroll) { class_desc->get_v_scroll()->set_value(p_scroll); } +void EditorHelp::update_toggle_scripts_button() { + if (is_layout_rtl()) { + toggle_scripts_button->set_icon(get_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Forward") : SNAME("Back"), SNAME("EditorIcons"))); + } else { + toggle_scripts_button->set_icon(get_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Back") : SNAME("Forward"), SNAME("EditorIcons"))); + } + toggle_scripts_button->set_tooltip(vformat("%s (%s)", TTR("Toggle Scripts Panel"), ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text())); +} + void EditorHelp::_bind_methods() { ClassDB::bind_method("_class_list_select", &EditorHelp::_class_list_select); ClassDB::bind_method("_request_help", &EditorHelp::_request_help); @@ -1680,6 +1724,16 @@ EditorHelp::EditorHelp() { find_bar->hide(); find_bar->set_rich_text_label(class_desc); + status_bar = memnew(HBoxContainer); + add_child(status_bar); + status_bar->set_h_size_flags(SIZE_EXPAND_FILL); + status_bar->set_custom_minimum_size(Size2(0, 24 * EDSCALE)); + + toggle_scripts_button = memnew(Button); + toggle_scripts_button->set_flat(true); + toggle_scripts_button->connect("pressed", callable_mp(this, &EditorHelp::_toggle_scripts_pressed)); + status_bar->add_child(toggle_scripts_button); + class_desc->set_selection_enabled(true); scroll_locked = false; @@ -1827,8 +1881,6 @@ void FindBar::_notification(int p_what) { } void FindBar::_bind_methods() { - ClassDB::bind_method("_unhandled_input", &FindBar::_unhandled_input); - ADD_SIGNAL(MethodInfo("search")); } @@ -1870,7 +1922,7 @@ void FindBar::_update_results_count() { return; } - String full_text = rich_text_label->get_text(); + String full_text = rich_text_label->get_parsed_text(); int from_pos = 0; @@ -1904,7 +1956,7 @@ void FindBar::_hide_bar() { hide(); } -void FindBar::_unhandled_input(const Ref<InputEvent> &p_event) { +void FindBar::unhandled_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventKey> k = p_event; |