summaryrefslogtreecommitdiff
path: root/editor/editor_node.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-11-10 09:57:23 +0100
committerGitHub <noreply@github.com>2017-11-10 09:57:23 +0100
commit346b4b5a1c099203c3b23d72042ea5fd844059d7 (patch)
treec2a19f675ec55c769dcd37135ed2efd8fbbce59f /editor/editor_node.cpp
parent94a915135df8bb6a4fa0af27edccf6290d830228 (diff)
parentf6ca9d34a2f7111b2d1359ef517e44e3e257469d (diff)
Merge pull request #12390 from MillionOstrich/filesystem-folder-drag
Improved file/folder drag preview for filesystem dock
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r--editor/editor_node.cpp84
1 files changed, 38 insertions, 46 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 3d171b692c..97a3497210 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -4226,61 +4226,53 @@ Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) {
return drag_data;
}
-Variant EditorNode::drag_files(const Vector<String> &p_files, Control *p_from) {
-
- VBoxContainer *files = memnew(VBoxContainer);
-
- int max_files = 6;
-
- for (int i = 0; i < MIN(max_files, p_files.size()); i++) {
-
+Variant EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from) {
+ bool has_folder = false;
+ bool has_file = false;
+ for (int i = 0; i < p_paths.size(); i++) {
+ bool is_folder = p_paths[i].ends_with("/");
+ has_folder |= is_folder;
+ has_file |= !is_folder;
+ }
+
+ int max_rows = 6;
+ int num_rows = p_paths.size() > max_rows ? max_rows - 1 : p_paths.size(); //Don't waste a row to say "1 more file" - list it instead.
+ VBoxContainer *vbox = memnew(VBoxContainer);
+ for (int i = 0; i < num_rows; i++) {
+ HBoxContainer *hbox = memnew(HBoxContainer);
+ TextureRect *icon = memnew(TextureRect);
Label *label = memnew(Label);
- label->set_text(p_files[i].get_file());
- files->add_child(label);
- }
-
- if (p_files.size() > max_files) {
- Label *label = memnew(Label);
- label->set_text(vformat(TTR("%d more file(s)"), p_files.size() - max_files));
- files->add_child(label);
+ if (p_paths[i].ends_with("/")) {
+ label->set_text(p_paths[i].substr(0, p_paths[i].length() - 1).get_file());
+ icon->set_texture(gui_base->get_icon("Folder", "EditorIcons"));
+ } else {
+ label->set_text(p_paths[i].get_file());
+ icon->set_texture(gui_base->get_icon("File", "EditorIcons"));
+ }
+ icon->set_size(Size2(16, 16));
+ hbox->add_child(icon);
+ hbox->add_child(label);
+ vbox->add_child(hbox);
}
- Dictionary drag_data;
- drag_data["type"] = "files";
- drag_data["files"] = p_files;
- drag_data["from"] = p_from;
-
- p_from->set_drag_preview(files); //wait until it enters scene
-
- return drag_data;
-}
-
-Variant EditorNode::drag_files_and_dirs(const Vector<String> &p_files, Control *p_from) {
-
- VBoxContainer *files = memnew(VBoxContainer);
-
- int max_files = 6;
-
- for (int i = 0; i < MIN(max_files, p_files.size()); i++) {
+ if (p_paths.size() > num_rows) {
Label *label = memnew(Label);
- label->set_text(p_files[i].get_file());
- files->add_child(label);
+ if (has_file && has_folder) {
+ label->set_text(vformat(TTR("%d more files or folders"), p_paths.size() - num_rows));
+ } else if (has_folder) {
+ label->set_text(vformat(TTR("%d more folders"), p_paths.size() - num_rows));
+ } else {
+ label->set_text(vformat(TTR("%d more files"), p_paths.size() - num_rows));
+ }
+ vbox->add_child(label);
}
+ p_from->set_drag_preview(vbox); //wait until it enters scene
- if (p_files.size() > max_files) {
-
- Label *label = memnew(Label);
- label->set_text(vformat(TTR("%d more file(s) or folder(s)"), p_files.size() - max_files));
- files->add_child(label);
- }
Dictionary drag_data;
- drag_data["type"] = "files_and_dirs";
- drag_data["files"] = p_files;
+ drag_data["type"] = has_folder ? "files_and_dirs" : "files";
+ drag_data["files"] = p_paths;
drag_data["from"] = p_from;
-
- p_from->set_drag_preview(files); //wait until it enters scene
-
return drag_data;
}