Merge pull request #96371 from KoBeWi/mentos

Improve dropping code in script editor
This commit is contained in:
Rémi Verschelde 2024-09-03 16:14:02 +02:00
commit d0a7dcd8c0
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 11 additions and 13 deletions

View File

@ -1843,7 +1843,8 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
const String &line = te->get_line(drop_at_line);
const bool is_empty_line = line_will_be_empty || line.is_empty() || te->get_first_non_whitespace_column(drop_at_line) == line.length();
if (d.has("type") && String(d["type"]) == "resource") {
const String type = d.get("type", "");
if (type == "resource") {
Ref<Resource> resource = d["resource"];
if (resource.is_null()) {
return;
@ -1868,11 +1869,11 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
}
}
if (d.has("type") && (String(d["type"]) == "files" || String(d["type"]) == "files_and_dirs")) {
Array files = d["files"];
for (int i = 0; i < files.size(); i++) {
const String &path = String(files[i]);
if (type == "files" || type == "files_and_dirs") {
const PackedStringArray files = d["files"];
PackedStringArray parts;
for (const String &path : files) {
if (drop_modifier_pressed && ResourceLoader::exists(path)) {
Ref<Resource> resource = ResourceLoader::load(path);
if (resource.is_null()) {
@ -1880,18 +1881,15 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
resource.instantiate();
resource->set_path_cache(path);
}
text_to_drop += _get_dropped_resource_line(resource, is_empty_line);
parts.append(_get_dropped_resource_line(resource, is_empty_line));
} else {
text_to_drop += _quote_drop_data(path);
}
if (i < files.size() - 1) {
text_to_drop += is_empty_line ? "\n" : ", ";
parts.append(_quote_drop_data(path));
}
}
text_to_drop = String(is_empty_line ? "\n" : ", ").join(parts);
}
if (d.has("type") && String(d["type"]) == "nodes") {
if (type == "nodes") {
Node *scene_root = get_tree()->get_edited_scene_root();
if (!scene_root) {
EditorNode::get_singleton()->show_warning(TTR("Can't drop nodes without an open scene."));
@ -1982,7 +1980,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
}
}
if (d.has("type") && String(d["type"]) == "obj_property") {
if (type == "obj_property") {
bool add_literal = EDITOR_GET("text_editor/completion/add_node_path_literals");
text_to_drop = add_literal ? "^" : "";
// It is unclear whether properties may contain single or double quotes.