Allow toggling UID display in path properties

This commit is contained in:
kobewi 2025-05-22 14:21:24 +02:00
parent 46c495ca21
commit a6d4faf9b4
3 changed files with 31 additions and 6 deletions

View file

@ -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<String> &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 /////////////////////////

View file

@ -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;

1
editor/icons/UID.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="12"><path fill="#41ec80" d="M 5,10 V 4 H 3 V 8 C 2.4477153,8 2,7.5522847 2,7 V 4 H 0 v 3 c 0,1.6568542 1.3431458,3 3,3 z" transform="translate(1)"/><path fill="#41ec80" d="m 6.9999479,2 v 2 h 2 V 2 Z m 7.0000001,0 v 2 h -1 c -3.9999981,0 -3.9999981,6 0,6 h 3 V 2 Z M 6.9999479,6 v 4 h 2 V 6 Z m 6.0000001,0 h 1 v 2 h -1 c -1.333333,0 -1.333333,-2 0,-2 z"/></svg>

After

Width:  |  Height:  |  Size: 443 B