MCPcopy Create free account
hub / github.com/clechasseur/pathcopycopy / ActOnFiles

Method ActOnFiles

PathCopyCopy/src/PathCopyCopyContextMenuExt.cpp:1073–1144  ·  view source on GitHub ↗

Performs the plugin's default action on our saved files. Call this when user picks a plugin from the menu, for instance. @param p_spPlugin Plugin to apply. @param p_hWnd Handle to parent window, that can be used for message boxes, etc. @return Result code.

Source from the content-addressed store, hash-verified

1071// @return Result code.
1072//
1073HRESULT CPathCopyCopyContextMenuExt::ActOnFiles(const PCC::PluginSP& p_spPlugin,
1074 HWND const p_hWnd)
1075{
1076 using namespace coveo::linq;
1077
1078 HRESULT hRes = E_FAIL;
1079
1080 if (p_spPlugin != nullptr) {
1081 // Loop through files and compute filenames using plugin.
1082 const bool addQuotes = GetSettings().GetAddQuotesAroundPaths();
1083 const bool areQuotesOptional = GetSettings().GetAreQuotesOptional();
1084 const bool makeEmailLinks = GetSettings().GetMakePathsIntoEmailLinks();
1085 const StringUtils::EncodeParam encodeParam = GetSettings().GetEncodeParam();
1086 const bool recursively = p_spPlugin->CopyPathsRecursively() || GetSettings().GetCopyPathsRecursively();
1087 std::wstring pathsSeparator = p_spPlugin->PathsSeparator();
1088 if (pathsSeparator.empty()) {
1089 pathsSeparator = GetSettings().GetPathsSeparator();
1090 if (pathsSeparator.empty()) {
1091 pathsSeparator = DEFAULT_PATHS_SEPARATOR;
1092 }
1093 }
1094 PCC::FilesV vNewFiles;
1095 PCC::FilesV vFiles = GetFilesToActOn(recursively);
1096 for (const auto& oldName : vFiles) {
1097 // Ask plugin to compute filename using its scheme and save it.
1098 std::wstring newFile;
1099 if (makeEmailLinks) {
1100 newFile += L"<";
1101 }
1102 std::wstring newName = p_spPlugin->GetPath(oldName);
1103 StringUtils::EncodeURICharacters(newName, encodeParam);
1104 if (addQuotes) {
1105 AddQuotes(newName, areQuotesOptional);
1106 }
1107 newFile += newName;
1108 if (makeEmailLinks) {
1109 newFile += L">";
1110 }
1111 vNewFiles.emplace_back(std::move(newFile));
1112 }
1113
1114 // Sort files alphabetically (case-insensitively).
1115 vNewFiles = from(vNewFiles)
1116 | order_by([](auto&& file) { return StringUtils::ToUppercase(file); })
1117 | to_vector();
1118
1119 // Convert vector of filenames to a string using path separator.
1120 std::wstring newFiles;
1121 if (!vNewFiles.empty()) {
1122 auto newFilesIt = vNewFiles.cbegin();
1123 newFiles += *newFilesIt;
1124 for (++newFilesIt; newFilesIt != vNewFiles.cend(); ++newFilesIt) {
1125 newFiles += pathsSeparator;
1126 newFiles += *newFilesIt;
1127 }
1128 }
1129
1130 // Get action to perform on the filenames.

Callers

nothing calls this directly

Calls 15

fromFunction · 0.85
order_byFunction · 0.85
to_vectorFunction · 0.85
GetAreQuotesOptionalMethod · 0.80
GetEncodeParamMethod · 0.80
emptyMethod · 0.80
GetPathsSeparatorMethod · 0.80
CopyPathsRecursivelyMethod · 0.45
PathsSeparatorMethod · 0.45

Tested by

no test coverage detected