Skip to content

Commit db25c8f

Browse files
committed
Exposed path properties save UID if referencing a resource
Currently, if a user or some resource exposes a path in a script, if this references a resource path it will be saved as a full path. This will make refactoring not work if the resource pointed towards changes location or is renamed. This change makes it so an uid:// path is saved internally in case a path to a resource has been selected, effectively making it refactor proof.
1 parent db66bd3 commit db25c8f

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

editor/editor_properties.cpp

+20-5
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,26 @@ void EditorPropertyPath::_set_read_only(bool p_read_only) {
462462
}
463463

464464
void EditorPropertyPath::_path_selected(const String &p_path) {
465-
emit_changed(get_edited_property(), p_path);
465+
String full_path = p_path;
466+
ResourceUID::ID id = ResourceLoader::get_resource_uid(full_path);
467+
468+
if (id != ResourceUID::INVALID_ID) {
469+
full_path = ResourceUID::get_singleton()->id_to_text(id);
470+
}
471+
472+
emit_changed(get_edited_property(), full_path);
466473
update_property();
467474
}
468475

476+
String EditorPropertyPath::_get_path_text() {
477+
String full_path = get_edited_property_value();
478+
if (full_path.begins_with("uid://")) {
479+
full_path = ResourceUID::get_singleton()->get_id_path(ResourceUID::get_singleton()->text_to_id(full_path));
480+
}
481+
482+
return full_path;
483+
}
484+
469485
void EditorPropertyPath::_path_pressed() {
470486
if (!dialog) {
471487
dialog = memnew(EditorFileDialog);
@@ -474,7 +490,7 @@ void EditorPropertyPath::_path_pressed() {
474490
add_child(dialog);
475491
}
476492

477-
String full_path = get_edited_property_value();
493+
String full_path = _get_path_text();
478494

479495
dialog->clear_filters();
480496

@@ -502,7 +518,7 @@ void EditorPropertyPath::_path_pressed() {
502518
}
503519

504520
void EditorPropertyPath::update_property() {
505-
String full_path = get_edited_property_value();
521+
String full_path = _get_path_text();
506522
path->set_text(full_path);
507523
path->set_tooltip_text(full_path);
508524
}
@@ -547,8 +563,7 @@ void EditorPropertyPath::_drop_data_fw(const Point2 &p_point, const Variant &p_d
547563
return;
548564
}
549565

550-
emit_changed(get_edited_property(), filesPaths[0]);
551-
update_property();
566+
_path_selected(filesPaths[0]);
552567
}
553568

554569
bool EditorPropertyPath::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {

editor/editor_properties.h

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class EditorPropertyPath : public EditorProperty {
142142
LineEdit *path = nullptr;
143143
Button *path_edit = nullptr;
144144

145+
String _get_path_text();
146+
145147
void _path_selected(const String &p_path);
146148
void _path_pressed();
147149
void _path_focus_exited();

0 commit comments

Comments
 (0)