From cafa64cd2752c471d3fb464e6530ce2bbb7fbc93 Mon Sep 17 00:00:00 2001 From: Gaktan Date: Sat, 20 Apr 2024 18:16:14 +0200 Subject: [PATCH] Add option to open online doc for selected native class in script editor --- editor/plugins/script_editor_plugin.cpp | 42 +++++++++++++++++++++++-- editor/plugins/script_editor_plugin.h | 2 ++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 6cb49bbfa657..eb6282ca0c10 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -731,6 +731,7 @@ void ScriptEditor::_go_to_tab(int p_idx) { _update_members_overview(); _update_help_overview(); _update_selected_editor_menu(); + _update_online_doc(); _update_members_overview_visibility(); _update_help_overview_visibility(); } @@ -903,6 +904,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { _go_to_tab(idx); } else { _update_selected_editor_menu(); + _update_online_doc(); } _update_history_arrows(); @@ -1350,7 +1352,21 @@ void ScriptEditor::_menu_option(int p_option) { help_search_dialog->popup_dialog(); } break; case SEARCH_WEBSITE: { - OS::get_singleton()->shell_open(VERSION_DOCS_URL "/"); + Control *tab = tab_container->get_current_tab_control(); + + EditorHelp *eh = Object::cast_to(tab); + bool native_class_doc = false; + if (eh) { + const HashMap::ConstIterator E = EditorHelp::get_doc_data()->class_list.find(eh->get_class()); + native_class_doc = E && !E->value.is_script_doc; + } + if (native_class_doc) { + String name = eh->get_class().to_lower(); + String doc_url = vformat(VERSION_DOCS_URL "/classes/class_%s.html", name); + OS::get_singleton()->shell_open(doc_url); + } else { + OS::get_singleton()->shell_open(VERSION_DOCS_URL "/"); + } } break; case WINDOW_NEXT: { _history_forward(); @@ -2029,6 +2045,26 @@ void ScriptEditor::_update_help_overview() { } } +void ScriptEditor::_update_online_doc() { + Node *current = tab_container->get_tab_control(tab_container->get_current_tab()); + + EditorHelp *eh = Object::cast_to(current); + bool native_class_doc = false; + if (eh) { + const HashMap::ConstIterator E = EditorHelp::get_doc_data()->class_list.find(eh->get_class()); + native_class_doc = E && !E->value.is_script_doc; + } + if (native_class_doc) { + String name = eh->get_class(); + String tooltip = vformat(TTR("Open '%s' in Godot online documentation."), name); + site_search->set_text(TTR("Open in Online Docs")); + site_search->set_tooltip_text(tooltip); + } else { + site_search->set_text(TTR("Online Docs")); + site_search->set_tooltip_text(TTR("Open Godot online documentation.")); + } +} + void ScriptEditor::_update_script_colors() { bool script_temperature_enabled = EDITOR_GET("text_editor/script_list/script_temperature_enabled"); @@ -4147,10 +4183,8 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { site_search = memnew(Button); site_search->set_flat(true); - site_search->set_text(TTR("Online Docs")); site_search->connect(SceneStringName(pressed), callable_mp(this, &ScriptEditor::_menu_option).bind(SEARCH_WEBSITE)); menu_hb->add_child(site_search); - site_search->set_tooltip_text(TTR("Open Godot online documentation.")); help_search = memnew(Button); help_search->set_flat(true); @@ -4271,6 +4305,8 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { Ref json_syntax_highlighter; json_syntax_highlighter.instantiate(); register_syntax_highlighter(json_syntax_highlighter); + + _update_online_doc(); } ScriptEditor::~ScriptEditor() { diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index e6bb8f14a9b8..6f8e71ce75be 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -450,6 +450,8 @@ class ScriptEditor : public PanelContainer { void _update_help_overview(); void _help_overview_selected(int p_idx); + void _update_online_doc(); + void _find_scripts(Node *p_base, Node *p_current, HashSet> &used); void _tree_changed();