diff options
author | MillionOstrich <31486600+MillionOstrich@users.noreply.github.com> | 2017-10-24 23:09:04 +0100 |
---|---|---|
committer | MillionOstrich <31486600+MillionOstrich@users.noreply.github.com> | 2017-11-03 21:39:53 +0000 |
commit | f6ca9d34a2f7111b2d1359ef517e44e3e257469d (patch) | |
tree | bcf8bd8292959db866161cd6bc5f67da1517359c /editor/filesystem_dock.cpp | |
parent | acd193b62e3972d6dd1e4b2aa115948658f85e9b (diff) |
Improve file/folder drag preview on filesystem dock
Added icons for files/folders in drag preview
Fixed folders getting an empty string label
Don't show "1 more file(s)" label instead of the file
Added "more folders" case if moving folders exclusively
Merged drag_files and drag_files_and_dirs to reduce code duplication
Simplified get_drag_data_fw and removed commented out code
Diffstat (limited to 'editor/filesystem_dock.cpp')
-rw-r--r-- | editor/filesystem_dock.cpp | 72 |
1 files changed, 15 insertions, 57 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 00cbd9bb72..96fa9773ad 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1186,78 +1186,36 @@ void FileSystemDock::set_display_mode(int p_mode) { } Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) { + bool is_favorite = false; + Vector<String> paths; if (p_from == tree) { - TreeItem *selected = tree->get_selected(); if (!selected) return Variant(); - String fpath = selected->get_metadata(0); - if (fpath == String()) + String folder = selected->get_metadata(0); + if (folder == String()) return Variant(); - if (!fpath.ends_with("/")) - fpath = fpath + "/"; - Vector<String> paths; - paths.push_back(fpath); - Dictionary d = EditorNode::get_singleton()->drag_files(paths, p_from); - - if (selected->get_parent() && tree->get_root()->get_children() == selected->get_parent()) { - //a favorite.. treat as such - d["type"] = "favorite"; - } - - return d; - } - - if (p_from == files) { - - List<int> seldirs; - List<int> selfiles; + paths.push_back(folder.ends_with("/") ? folder : (folder + "/")); + is_favorite = selected->get_parent() != NULL && tree->get_root()->get_children() == selected->get_parent(); + } else if (p_from == files) { for (int i = 0; i < files->get_item_count(); i++) { if (files->is_selected(i)) { - String fpath = files->get_item_metadata(i); - if (fpath.ends_with("/")) - seldirs.push_back(i); - else - selfiles.push_back(i); + paths.push_back(files->get_item_metadata(i)); } } + } - if (seldirs.empty() && selfiles.empty()) - return Variant(); - /* - if (seldirs.size() && selfiles.size()) - return Variant(); //can't really mix files and dirs (i think?) - yes you can, commenting - */ - - /*if (selfiles.size()==1) { - Ref<Resource> resource = ResourceLoader::load(files->get_item_metadata(selfiles.front()->get())); - if (resource.is_valid()) { - return EditorNode::get_singleton()->drag_resource(resource,p_from); - } - }*/ - - Vector<String> fnames; - if (selfiles.size() > 0 || seldirs.size() > 0) { - if (selfiles.size() > 0) { - for (List<int>::Element *E = selfiles.front(); E; E = E->next()) { - fnames.push_back(files->get_item_metadata(E->get())); - } - if (seldirs.size() == 0) - return EditorNode::get_singleton()->drag_files(fnames, p_from); - } - - for (List<int>::Element *E = seldirs.front(); E; E = E->next()) { - fnames.push_back(files->get_item_metadata(E->get())); - } + if (paths.empty()) + return Variant(); - return EditorNode::get_singleton()->drag_files_and_dirs(fnames, p_from); - } + Dictionary drag_data = EditorNode::get_singleton()->drag_files_and_dirs(paths, p_from); + if (is_favorite) { + drag_data["type"] = "favorite"; } - - return Variant(); + return drag_data; } bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { |