From 2b8d65761ceabecaba0f5e1d71111997c5bf8b69 Mon Sep 17 00:00:00 2001 From: iwek7 Date: Sat, 10 Aug 2019 01:15:25 +0200 Subject: Improvements and fixes of filesystem dock --- editor/filesystem_dock.cpp | 35 ++++++++++++++++++++++++----------- editor/filesystem_dock.h | 1 + 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index e4823c7745..406593800e 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1484,8 +1484,15 @@ Vector FileSystemDock::_tree_get_selected(bool remove_self_inclusion) { selected = tree->get_next_selected(selected); } + if (remove_self_inclusion) { + selected_strings = _remove_self_included_paths(selected_strings); + } + return selected_strings; +} + +Vector FileSystemDock::_remove_self_included_paths(Vector selected_strings) { // Remove paths or files that are included into another - if (remove_self_inclusion && selected_strings.size() > 1) { + if (selected_strings.size() > 1) { selected_strings.sort_custom(); String last_path = ""; for (int i = 0; i < selected_strings.size(); i++) { @@ -1503,7 +1510,7 @@ Vector FileSystemDock::_tree_get_selected(bool remove_self_inclusion) { void FileSystemDock::_tree_rmb_option(int p_option) { - Vector selected_strings = _tree_get_selected(); + Vector selected_strings = _tree_get_selected(false); // Execute the current option switch (p_option) { @@ -1642,8 +1649,9 @@ void FileSystemDock::_file_option(int p_option, const Vector &p_selected case FILE_MOVE: { // Move the files to a given location to_move.clear(); - for (int i = 0; i < p_selected.size(); i++) { - String fpath = p_selected[i]; + Vector collapsed_paths = _remove_self_included_paths(p_selected); + for (int i = collapsed_paths.size() - 1; i >= 0; i--) { + String fpath = collapsed_paths[i]; if (fpath != "res://") { to_move.push_back(FileOrFolder(fpath, !fpath.ends_with("/"))); } @@ -1680,9 +1688,10 @@ void FileSystemDock::_file_option(int p_option, const Vector &p_selected // Remove the selected files Vector remove_files; Vector remove_folders; + Vector collapsed_paths = _remove_self_included_paths(p_selected); - for (int i = 0; i < p_selected.size(); i++) { - String fpath = p_selected[i]; + for (int i = 0; i < collapsed_paths.size(); i++) { + String fpath = collapsed_paths[i]; if (fpath != "res://") { if (fpath.ends_with("/")) { remove_folders.push_back(fpath); @@ -2195,12 +2204,16 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vectoradd_item(TTR("Copy Path"), FILE_COPY_PATH); - p_popup->add_item(TTR("Rename..."), FILE_RENAME); - p_popup->add_item(TTR("Duplicate..."), FILE_DUPLICATE); + if (p_paths[0] != "res://") { + p_popup->add_item(TTR("Rename..."), FILE_RENAME); + p_popup->add_item(TTR("Duplicate..."), FILE_DUPLICATE); + } } - p_popup->add_item(TTR("Move To..."), FILE_MOVE); - p_popup->add_item(TTR("Delete"), FILE_REMOVE); + if (p_paths.size() > 1 || p_paths[0] != "res://") { + p_popup->add_item(TTR("Move To..."), FILE_MOVE); + p_popup->add_item(TTR("Delete"), FILE_REMOVE); + } if (p_paths.size() == 1) { p_popup->add_separator(); @@ -2219,7 +2232,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector paths = _tree_get_selected(); + Vector paths = _tree_get_selected(false); if (paths.size() == 1) { if (paths[0].ends_with("/")) { diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index cc5ba94b48..561a4eba81 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -279,6 +279,7 @@ private: bool _is_file_type_disabled_by_feature_profile(const StringName &p_class); void _feature_profile_changed(); + Vector _remove_self_included_paths(Vector selected_strings); protected: void _notification(int p_what); -- cgit v1.2.3