diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index b7a74f0035b..0d6f4638626 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1494,8 +1494,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++) { @@ -1513,7 +1520,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) { @@ -1652,8 +1659,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("/"))); } @@ -1690,9 +1698,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); @@ -2205,12 +2214,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(); @@ -2229,7 +2242,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 cc5ba94b48f..561a4eba813 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);