From b38453e287961a56cd837e71d26cbad77692fe6b Mon Sep 17 00:00:00 2001 From: Lars Pettersson Date: Wed, 25 Dec 2024 03:52:07 +0100 Subject: [PATCH] Show tooltips for UID strings in ScriptEditor --- editor/editor_help.cpp | 46 +++++++++++++++++++++++++++ editor/editor_help.h | 1 + editor/plugins/script_text_editor.cpp | 15 ++++++--- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index dd8628b113f2..361d39bbae3b 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -46,6 +46,7 @@ #include "editor/editor_property_name_processor.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" +#include "editor/filesystem_dock.h" #include "editor/plugins/script_editor_plugin.h" #include "editor/themes/editor_scale.h" #include "scene/gui/line_edit.h" @@ -3812,6 +3813,17 @@ void EditorHelpBit::_update_labels() { title->pop(); // font_size title->pop(); // font } break; + case SYMBOL_HINT_RESOURCE_PATH: { + title->push_font(doc_source); + title->push_font_size(doc_source_size * 0.9); + title->push_color(value_color); + + title->add_text(nbsp + help_data.value); + + title->pop(); // color + title->pop(); // font_size + title->pop(); // font + } break; } title->show(); @@ -3857,6 +3869,20 @@ void EditorHelpBit::_update_labels() { _add_text_to_rt(help_data.experimental_message, content, this, symbol_class_name); } + if (symbol_hint == SYMBOL_HINT_RESOURCE_PATH && !help_data.value.is_empty()) { + help_data.description = ""; + content->push_meta("open " + help_data.value, RichTextLabel::META_UNDERLINE_ON_HOVER); + content->add_image(get_editor_theme_icon(SNAME("Load"))); + content->add_text(" " + TTR("Open")); + content->pop(); // meta + + content->add_newline(); + content->push_meta("show " + help_data.value, RichTextLabel::META_UNDERLINE_ON_HOVER); + content->add_image(get_editor_theme_icon(SNAME("Filesystem"))); + content->add_text(" " + TTR("Show in FileSystem")); + content->pop(); // meta + } + if (!help_data.description.is_empty()) { if (has_prev_text) { content->add_newline(); @@ -3949,6 +3975,14 @@ void EditorHelpBit::_meta_clicked(const String &p_select) { } else { _go_to_help(topic + ":" + symbol_class_name + ":" + link); } + } else if (p_select.begins_with("open res://")) { + if (symbol_type == "PackedScene") { + EditorNode::get_singleton()->load_scene(p_select.substr(5)); + } else { + EditorNode::get_singleton()->load_resource(p_select.substr(5)); + } + } else if (p_select.begins_with("show res://")) { + FileSystemDock::get_singleton()->navigate_to_path(p_select.substr(5)); } else if (p_select.begins_with("http:") || p_select.begins_with("https:")) { OS::get_singleton()->shell_open(p_select); } else if (p_select.begins_with("^")) { // Copy button. @@ -4072,6 +4106,18 @@ void EditorHelpBit::parse_symbol(const String &p_symbol, const String &p_prologu help_data.doc_type.enumeration = item_data.get("enumeration", ""); help_data.doc_type.is_bitfield = item_data.get("is_bitfield", false); help_data.value = item_data.get("value", ""); + } else if (item_type == "uid") { + if (ResourceUID::get_singleton()->has_id(ResourceUID::get_singleton()->text_to_id(item_name))) { + String path = ResourceUID::uid_to_path(item_name); + symbol_type = ResourceLoader::get_resource_type(path); + symbol_hint = SYMBOL_HINT_RESOURCE_PATH; + symbol_name = path.get_file(); + help_data.value = path; + } else { + symbol_type = TTR("Invalid UID"); + symbol_name = ""; + help_data.description = "[color=][i]" + TTR("This UID does not point to any valid Resource.") + "[/i][/color]"; + } } else { ERR_FAIL_MSG("Invalid doc id: Unknown item type " + item_type.quote() + "."); } diff --git a/editor/editor_help.h b/editor/editor_help.h index eb687e9c5687..8f89d64432b1 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -255,6 +255,7 @@ class EditorHelpBit : public VBoxContainer { SYMBOL_HINT_INHERITANCE, // [ < ParentClass[ < ...]] SYMBOL_HINT_ASSIGNABLE, // [: Type][ = value] SYMBOL_HINT_SIGNATURE, // (arguments)[ -> Type][ qualifiers] + SYMBOL_HINT_RESOURCE_PATH, // [value] }; struct DocType { diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index ac8b4a414c79..680d615e4bdd 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1106,14 +1106,19 @@ void ScriptTextEditor::_show_symbol_tooltip(const String &p_symbol, int p_row, i base = _find_node_for_script(base, base, script); } + String doc_symbol; ScriptLanguage::LookupResult result; - const String code_text = code_editor->get_text_editor()->get_text_with_cursor_char(p_row, p_column); - const Error lc_error = script->get_language()->lookup_code(code_text, p_symbol, script->get_path(), base, result); - if (lc_error != OK) { - return; + + if (p_symbol.begins_with("uid://")) { + doc_symbol = "uid||" + p_symbol; + } else { + const String code_text = code_editor->get_text_editor()->get_text_with_cursor_char(p_row, p_column); + const Error lc_error = script->get_language()->lookup_code(code_text, p_symbol, script->get_path(), base, result); + if (lc_error != OK) { + return; + } } - String doc_symbol; switch (result.type) { case ScriptLanguage::LOOKUP_RESULT_CLASS: { doc_symbol = "class|" + result.class_name + "|";