From 078371cfb64e573b614a86c21f8dd0c5ce917ba7 Mon Sep 17 00:00:00 2001 From: MillionOstrich <31486600+MillionOstrich@users.noreply.github.com> Date: Wed, 25 Oct 2017 15:40:33 +0100 Subject: [PATCH] Fix dragging a resource onto filesystem dock Call push_item before save_resource_as because the save button uses editor_history current. Reject the drop in can_drop_data if it isn't on a folder or the files list. Removed some duplicated code --- editor/filesystem_dock.cpp | 41 ++++++-------------------------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 19a8068c9a9..8f4100e856b 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1288,7 +1288,8 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da } if (drag_data.has("type") && String(drag_data["type"]) == "resource") { - return true; + String to_dir = _get_drag_target_folder(p_point, p_from); + return !to_dir.empty(); } if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) { @@ -1381,40 +1382,10 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, if (drag_data.has("type") && String(drag_data["type"]) == "resource") { Ref res = drag_data["resource"]; - - if (!res.is_valid()) { - return; - } - - if (p_from == tree) { - - TreeItem *ti = tree->get_item_at_position(p_point); - if (!ti) - return; - - String fpath = ti->get_metadata(0); - if (fpath == String()) - return; - - EditorNode::get_singleton()->save_resource_as(res, fpath); - return; - } - - if (p_from == files) { - String save_path = path; - - int at_pos = files->get_item_at_position(p_point); - if (at_pos != -1) { - String to_dir = files->get_item_metadata(at_pos); - if (to_dir.ends_with("/")) { - save_path = to_dir; - if (save_path != "res://") - save_path = save_path.substr(0, save_path.length() - 1); - } - } - - EditorNode::get_singleton()->save_resource_as(res, save_path); - return; + String to_dir = _get_drag_target_folder(p_point, p_from); + if (res.is_valid() && !to_dir.empty()) { + EditorNode::get_singleton()->push_item(res.ptr()); + EditorNode::get_singleton()->save_resource_as(res, to_dir); } }