summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorMillionOstrich <31486600+MillionOstrich@users.noreply.github.com>2017-10-25 15:27:35 +0100
committerMillionOstrich <31486600+MillionOstrich@users.noreply.github.com>2017-11-03 20:49:36 +0000
commit9c65924b3db7c61da2045f0ea14e56fdde71e628 (patch)
tree02caadf8e402f4ad04b8d786e4b2802c7027004f /editor
parentacd193b62e3972d6dd1e4b2aa115948658f85e9b (diff)
Don't try to move if dragging a folder into itself
If a folder would be moved to an invalid location disallow the drag Don't treat dragging a file/folder to its current location as invalid Allow dragging onto empty space / files in the files list Fix dragging a folder onto "Favourites" starting an invalid move
Diffstat (limited to 'editor')
-rw-r--r--editor/filesystem_dock.cpp75
-rw-r--r--editor/filesystem_dock.h1
2 files changed, 32 insertions, 44 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 00cbd9bb72..19a8068c9a 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -1292,32 +1292,20 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da
}
if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) {
+ String to_dir = _get_drag_target_folder(p_point, p_from);
+ if (to_dir.empty())
+ return false;
+ //Attempting to move a folder into itself will fail later
+ //Rather than bring up a message don't try to do it in the first place
+ to_dir = to_dir.ends_with("/") ? to_dir : (to_dir + "/");
Vector<String> fnames = drag_data["files"];
-
- if (p_from == files) {
-
- int at_pos = files->get_item_at_position(p_point);
- if (at_pos != -1) {
-
- String dir = files->get_item_metadata(at_pos);
- if (dir.ends_with("/"))
- return true;
- }
- }
-
- if (p_from == tree) {
-
- TreeItem *ti = tree->get_item_at_position(p_point);
- if (!ti)
- return false;
-
- String fpath = ti->get_metadata(0);
- if (fpath == String())
+ for (int i = 0; i < fnames.size(); ++i) {
+ if (fnames[i].ends_with("/") && to_dir.begins_with(fnames[i]))
return false;
-
- return true;
}
+
+ return true;
}
return false;
@@ -1431,28 +1419,8 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
}
if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) {
-
- if (p_from == files || p_from == tree) {
-
- String to_dir;
-
- if (p_from == files) {
-
- int at_pos = files->get_item_at_position(p_point);
- ERR_FAIL_COND(at_pos == -1);
- to_dir = files->get_item_metadata(at_pos);
- } else {
- TreeItem *ti = tree->get_item_at_position(p_point);
- if (!ti)
- return;
- to_dir = ti->get_metadata(0);
- ERR_FAIL_COND(to_dir == String());
- }
-
- if (to_dir != "res://" && to_dir.ends_with("/")) {
- to_dir = to_dir.substr(0, to_dir.length() - 1);
- }
-
+ String to_dir = _get_drag_target_folder(p_point, p_from);
+ if (!to_dir.empty()) {
Vector<String> fnames = drag_data["files"];
to_move.clear();
for (int i = 0; i < fnames.size(); i++) {
@@ -1463,6 +1431,25 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
}
}
+String FileSystemDock::_get_drag_target_folder(const Point2 &p_point, Control *p_from) const {
+ if (p_from == files) {
+ int pos = files->get_item_at_position(p_point, true);
+ if (pos == -1)
+ return path;
+
+ String target = files->get_item_metadata(pos);
+ return target.ends_with("/") ? target : path;
+ }
+
+ if (p_from == tree) {
+ TreeItem *ti = tree->get_item_at_position(p_point);
+ if (ti && ti != tree->get_root()->get_children())
+ return ti->get_metadata(0);
+ }
+
+ return String();
+}
+
void FileSystemDock::_files_list_rmb_select(int p_item, const Vector2 &p_pos) {
//Right clicking ".." should clear current selection
diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h
index 2cb0573a3d..249621564d 100644
--- a/editor/filesystem_dock.h
+++ b/editor/filesystem_dock.h
@@ -209,6 +209,7 @@ private:
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
+ String _get_drag_target_folder(const Point2 &p_point, Control *p_from) const;
void _preview_invalidated(const String &p_path);
void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);