You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-12 13:20:55 +00:00
Merge pull request #62089 from Step-an/add_drag_and_drop_to_EditorPropertyPath
This commit is contained in:
@@ -507,13 +507,55 @@ void EditorPropertyPath::_path_focus_exited() {
|
|||||||
_path_selected(path->get_text());
|
_path_selected(path->get_text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (String(drag_data["type"]) != "files") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const Vector<String> filesPaths = drag_data["files"];
|
||||||
|
if (filesPaths.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit_changed(get_edited_property(), filesPaths[0]);
|
||||||
|
update_property();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EditorPropertyPath::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
|
||||||
|
const Dictionary drag_data = p_data;
|
||||||
|
if (!drag_data.has("type")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (String(drag_data["type"]) != "files") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const Vector<String> filesPaths = drag_data["files"];
|
||||||
|
if (filesPaths.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const String &extension : extensions) {
|
||||||
|
if (filesPaths[0].ends_with(extension.substr(1, extension.size() - 1))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void EditorPropertyPath::_bind_methods() {
|
void EditorPropertyPath::_bind_methods() {
|
||||||
|
ClassDB::bind_method(D_METHOD("_can_drop_data_fw", "position", "data", "from"), &EditorPropertyPath::_can_drop_data_fw);
|
||||||
|
ClassDB::bind_method(D_METHOD("_drop_data_fw", "position", "data", "from"), &EditorPropertyPath::_drop_data_fw);
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorPropertyPath::EditorPropertyPath() {
|
EditorPropertyPath::EditorPropertyPath() {
|
||||||
HBoxContainer *path_hb = memnew(HBoxContainer);
|
HBoxContainer *path_hb = memnew(HBoxContainer);
|
||||||
add_child(path_hb);
|
add_child(path_hb);
|
||||||
path = memnew(LineEdit);
|
path = memnew(LineEdit);
|
||||||
|
path->set_drag_forwarding(this);
|
||||||
path->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
|
path->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
|
||||||
path_hb->add_child(path);
|
path_hb->add_child(path);
|
||||||
path->connect("text_submitted", callable_mp(this, &EditorPropertyPath::_path_selected));
|
path->connect("text_submitted", callable_mp(this, &EditorPropertyPath::_path_selected));
|
||||||
|
|||||||
@@ -142,6 +142,8 @@ class EditorPropertyPath : public EditorProperty {
|
|||||||
void _path_selected(const String &p_path);
|
void _path_selected(const String &p_path);
|
||||||
void _path_pressed();
|
void _path_pressed();
|
||||||
void _path_focus_exited();
|
void _path_focus_exited();
|
||||||
|
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;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void _set_read_only(bool p_read_only) override;
|
virtual void _set_read_only(bool p_read_only) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user