From a6d4faf9b4d5c4ef54cf567d78e565fa6dda030c Mon Sep 17 00:00:00 2001 From: kobewi Date: Thu, 22 May 2025 14:21:24 +0200 Subject: [PATCH] Allow toggling UID display in path properties --- editor/editor_properties.cpp | 29 ++++++++++++++++++++++++----- editor/editor_properties.h | 7 ++++++- editor/icons/UID.svg | 1 + 3 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 editor/icons/UID.svg diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 1960101cbaa..652e06fb502 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -579,9 +579,9 @@ void EditorPropertyPath::_path_selected(const String &p_path) { update_property(); } -String EditorPropertyPath::_get_path_text() { +String EditorPropertyPath::_get_path_text(bool p_allow_uid) { String full_path = get_edited_property_value(); - if (full_path.begins_with("uid://")) { + if (!p_allow_uid && full_path.begins_with("uid://")) { full_path = ResourceUID::uid_to_path(full_path); } @@ -624,9 +624,11 @@ void EditorPropertyPath::_path_pressed() { } void EditorPropertyPath::update_property() { - String full_path = _get_path_text(); + String full_path = _get_path_text(display_uid); path->set_text(full_path); path->set_tooltip_text(full_path); + + toggle_uid->set_visible(get_edited_property_value().operator String().begins_with("uid://")); } void EditorPropertyPath::setup(const Vector &p_extensions, bool p_folder, bool p_global, bool p_enable_uid) { @@ -648,6 +650,7 @@ void EditorPropertyPath::_notification(int p_what) { } else { path_edit->set_button_icon(get_editor_theme_icon(SNAME("FileBrowse"))); } + _update_uid_icon(); } break; } } @@ -656,6 +659,16 @@ void EditorPropertyPath::_path_focus_exited() { _path_selected(path->get_text()); } +void EditorPropertyPath::_toggle_uid_display() { + display_uid = !display_uid; + _update_uid_icon(); + update_property(); +} + +void EditorPropertyPath::_update_uid_icon() { + toggle_uid->set_button_icon(get_editor_theme_icon(display_uid ? SNAME("UID") : SNAME("NodePath"))); +} + void EditorPropertyPath::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { const Dictionary drag_data = p_data; if (!drag_data.has("type")) { @@ -708,11 +721,17 @@ EditorPropertyPath::EditorPropertyPath() { path_edit = memnew(Button); path_edit->set_accessibility_name(TTRC("Edit")); - path_edit->set_clip_text(true); path_hb->add_child(path_edit); add_focusable(path); - dialog = nullptr; path_edit->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyPath::_path_pressed)); + + toggle_uid = memnew(Button); + toggle_uid->set_accessibility_name(TTRC("Toggle Display UID")); + toggle_uid->set_tooltip_text(TTRC("Toggles displaying between path and UID.\nThe UID is the actual value of this property.")); + toggle_uid->set_pressed(false); + path_hb->add_child(toggle_uid); + add_focusable(toggle_uid); + toggle_uid->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyPath::_toggle_uid_display)); } ///////////////////// CLASS NAME ///////////////////////// diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 20e38dbc506..256ab56aa19 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -162,15 +162,20 @@ class EditorPropertyPath : public EditorProperty { bool global = false; bool save_mode = false; bool enable_uid = false; + bool display_uid = true; + EditorFileDialog *dialog = nullptr; LineEdit *path = nullptr; Button *path_edit = nullptr; + Button *toggle_uid = nullptr; - String _get_path_text(); + String _get_path_text(bool p_allow_uid = false); void _path_selected(const String &p_path); void _path_pressed(); void _path_focus_exited(); + void _toggle_uid_display(); + void _update_uid_icon(); void _drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); bool _can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; diff --git a/editor/icons/UID.svg b/editor/icons/UID.svg new file mode 100644 index 00000000000..4a9d2c503cc --- /dev/null +++ b/editor/icons/UID.svg @@ -0,0 +1 @@ +