Skip to content

Commit

Permalink
Show tooltips for UID strings in ScriptEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
larspet committed Dec 25, 2024
1 parent 0f95e9f commit b38453e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
46 changes: 46 additions & 0 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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=<EditorHelpBitCommentColor>][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() + ".");
}
Expand Down
1 change: 1 addition & 0 deletions editor/editor_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 10 additions & 5 deletions editor/plugins/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "|";
Expand Down

0 comments on commit b38453e

Please sign in to comment.