diff --git a/assets/data/icons/RemixIcon/file-copy-line.svg b/assets/data/icons/RemixIcon/file-copy-line.svg new file mode 100644 index 0000000..9e82aa2 --- /dev/null +++ b/assets/data/icons/RemixIcon/file-copy-line.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Screens/FileSelectScreen.cpp b/src/Screens/FileSelectScreen.cpp index 9203eed..33e9b5d 100644 --- a/src/Screens/FileSelectScreen.cpp +++ b/src/Screens/FileSelectScreen.cpp @@ -234,6 +234,33 @@ void FileSelectScreen::move_selected_files(const std::filesystem::path& fromPath } } +void FileSelectScreen::duplicate_selected_files(const std::filesystem::path& inPath) { + std::vector toFolderListNames; + + int globCount; + char** filesInPath = SDL_GlobDirectory(inPath.c_str(), "*", 0, &globCount); + if(filesInPath) { + for(int i = 0; i < globCount; i++) { + std::filesystem::path p(filesInPath[i]); + toFolderListNames.emplace_back(p.filename().stem()); + } + } + else + SDL_CreateDirectory(inPath.string().c_str()); + + for(const FileInfo& f : fileList) { + if(f.selected) { + std::string newFileName = ensure_string_unique(toFolderListNames, f.fileName); + std::filesystem::path filePath = inPath / (f.fileName + World::DOT_FILE_EXTENSION); + std::filesystem::path thumbnailPath = inPath / (f.fileName + ".jpg"); + std::filesystem::path newFilePath = inPath / (newFileName + "." + World::FILE_EXTENSION); + std::filesystem::path newThumbnailPath = inPath / (newFileName + ".jpg"); + SDL_CopyFile(filePath.string().c_str(), newFilePath.string().c_str()); + SDL_CopyFile(thumbnailPath.string().c_str(), newThumbnailPath.string().c_str()); + } + } +} + void FileSelectScreen::delete_selected_files_in_trash() { for(const FileInfo& f : fileList) { if(f.selected) { @@ -263,6 +290,11 @@ void FileSelectScreen::edit_action_bar() { update_file_list(fileList, savePath, false); editMode = false; }); + edit_action_bar_button("duplicate", "data/icons/RemixIcon/file-copy-line.svg", "Duplicate", [&] { + duplicate_selected_files(savePath); + update_file_list(fileList, savePath, false); + editMode = false; + }); } else if(selectedMenu == SelectedMenu::TRASH) { edit_action_bar_button("restore", "data/icons/RemixIcon/refresh-line.svg", "Restore", [&] { diff --git a/src/Screens/FileSelectScreen.hpp b/src/Screens/FileSelectScreen.hpp index 0169c16..7b3608e 100644 --- a/src/Screens/FileSelectScreen.hpp +++ b/src/Screens/FileSelectScreen.hpp @@ -56,6 +56,7 @@ class FileSelectScreen : public Screen { MOVE_OUT_OF_TRASH }; void move_selected_files(const std::filesystem::path& fromPath, const std::filesystem::path& toPath, TrashMoveType trashMoveType); + void duplicate_selected_files(const std::filesystem::path& inPath); void delete_selected_files_in_trash(); enum class FileViewType {