Skip to content

Commit 591e70f

Browse files
committed
Merge pull request #106750 from KoBeWi/path_guesser
Assign base path when creating Resource
2 parents 79f39b2 + e7d9df3 commit 591e70f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

editor/editor_resource_picker.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "editor/audio_stream_preview.h"
3434
#include "editor/editor_help.h"
35+
#include "editor/editor_inspector.h"
3536
#include "editor/editor_node.h"
3637
#include "editor/editor_resource_preview.h"
3738
#include "editor/editor_settings.h"
@@ -496,6 +497,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
496497

497498
Resource *resp = Object::cast_to<Resource>(obj);
498499
ERR_BREAK(!resp);
500+
resp->set_path(_get_owner_path() + "::"); // Assign a base path for built-in Resources.
499501

500502
EditorNode::get_editor_data().instantiate_object_properties(obj);
501503

@@ -589,6 +591,32 @@ void EditorResourcePicker::_button_input(const Ref<InputEvent> &p_event) {
589591
}
590592
}
591593

594+
String EditorResourcePicker::_get_owner_path() const {
595+
EditorProperty *property = Object::cast_to<EditorProperty>(get_parent());
596+
if (!property) {
597+
return String();
598+
}
599+
Object *obj = property->get_edited_object();
600+
601+
Node *node = Object::cast_to<Node>(obj);
602+
if (node) {
603+
if (node->get_scene_file_path().is_empty()) {
604+
node = node->get_owner();
605+
}
606+
if (node) {
607+
return node->get_scene_file_path();
608+
}
609+
return String();
610+
}
611+
612+
Resource *res = Object::cast_to<Resource>(obj);
613+
if (res && !res->is_built_in()) {
614+
return res->get_path();
615+
}
616+
// TODO: It would be nice to handle deeper Resource nesting.
617+
return String();
618+
}
619+
592620
String EditorResourcePicker::_get_resource_type(const Ref<Resource> &p_resource) const {
593621
if (p_resource.is_null()) {
594622
return String();

editor/editor_resource_picker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class EditorResourcePicker : public HBoxContainer {
101101
void _button_draw();
102102
void _button_input(const Ref<InputEvent> &p_event);
103103

104+
String _get_owner_path() const;
104105
String _get_resource_type(const Ref<Resource> &p_resource) const;
105106
void _ensure_allowed_types() const;
106107
bool _is_drop_valid(const Dictionary &p_drag_data) const;

0 commit comments

Comments
 (0)