From c76136fd1847c7b1d7abf586ceb954286c900a49 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Mon, 26 Jul 2021 10:33:53 +0200 Subject: [PATCH] +upd: grepWinNP3 (current grepWin dev) allow multiple search paths --- grepWinNP3/sktoolslib_mod/BrowseFolder.cpp | 121 ++++++++++++++++++++- grepWinNP3/sktoolslib_mod/BrowseFolder.h | 2 + grepWinNP3/src/SearchDlg.cpp | 21 +++- grepWinNP3/src/last/version.h | 12 +- 4 files changed, 141 insertions(+), 15 deletions(-) diff --git a/grepWinNP3/sktoolslib_mod/BrowseFolder.cpp b/grepWinNP3/sktoolslib_mod/BrowseFolder.cpp index 4c39e1fa6..e6a23e7b3 100644 --- a/grepWinNP3/sktoolslib_mod/BrowseFolder.cpp +++ b/grepWinNP3/sktoolslib_mod/BrowseFolder.cpp @@ -60,6 +60,121 @@ CBrowseFolder::RetVal CBrowseFolder::Show(HWND parent, LPWSTR path, size_t pathL wcscpy_s(path, pathLen, temp.c_str()); return ret; } +CBrowseFolder::RetVal CBrowseFolder::Show(HWND parent, std::vector& paths, std::wstring sDefaultPath) +{ + RetVal ret = RetVal::Ok; //assume OK + m_sDefaultPath = sDefaultPath; + if (m_sDefaultPath.empty() && !paths.empty()) + { + // if the result path already contains a path, use that as the default path + m_sDefaultPath = paths[0]; + } + if (!PathFileExists(m_sDefaultPath.c_str())) + m_sDefaultPath.clear(); + paths.clear(); + + // Create a new common open file dialog + IFileOpenDialog* pfd = nullptr; + HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd)); + if (SUCCEEDED(hr)) + { + // Set the dialog as a folder picker + DWORD dwOptions; + if (SUCCEEDED(hr = pfd->GetOptions(&dwOptions))) + { + hr = pfd->SetOptions(dwOptions | FOS_ALLOWMULTISELECT | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST); + } + + // Set a title + if (SUCCEEDED(hr)) + { + wchar_t* nl = wcschr(m_title, '\n'); + if (nl) + *nl = 0; + pfd->SetTitle(m_title); + } + + // set the default folder + if (SUCCEEDED(hr) && !m_sDefaultPath.empty()) + { + IShellItem* psiDefault = nullptr; + hr = SHCreateItemFromParsingName(m_sDefaultPath.c_str(), nullptr, IID_PPV_ARGS(&psiDefault)); + if (SUCCEEDED(hr)) + { + hr = pfd->SetFolder(psiDefault); + psiDefault->Release(); + } + } + } + + if (wcslen(m_checkText)) + { + IFileDialogCustomize* pfdCustomize = nullptr; + hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize)); + if (SUCCEEDED(hr)) + { + pfdCustomize->StartVisualGroup(100, L""); + pfdCustomize->AddCheckButton(101, m_checkText, FALSE); + if (wcslen(m_checkText2)) + { + pfdCustomize->AddCheckButton(102, m_checkText2, FALSE); + } + pfdCustomize->EndVisualGroup(); + pfdCustomize->Release(); + } + } + + // Show the open file dialog + if (SUCCEEDED(hr) && SUCCEEDED(hr = pfd->Show(parent))) + { + IShellItemArray* psiResults = nullptr; + hr = pfd->GetResults(&psiResults); + // Get the selection from the user + if (SUCCEEDED(hr)) + { + DWORD resultCount = 0; + hr = psiResults->GetCount(&resultCount); + if (SUCCEEDED(hr)) + { + for (DWORD i = 0; i < resultCount; ++i) + { + IShellItem* psiResult = nullptr; + hr = psiResults->GetItemAt(i, &psiResult); + if (SUCCEEDED(hr)) + { + PWSTR pszPath = nullptr; + hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszPath); + if (SUCCEEDED(hr)) + { + paths.push_back(pszPath); + CoTaskMemFree(pszPath); + } + psiResult->Release(); + + IFileDialogCustomize* pfdCustomize; + hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize)); + if (SUCCEEDED(hr)) + { + pfdCustomize->GetCheckButtonState(101, &m_bCheck); + pfdCustomize->GetCheckButtonState(102, &m_bCheck2); + pfdCustomize->Release(); + } + } + } + psiResults->Release(); + } + } + else + ret = RetVal::Cancel; + } + else + ret = RetVal::Cancel; + + pfd->Release(); + + return ret; +} + CBrowseFolder::RetVal CBrowseFolder::Show(HWND parent, std::wstring& path, const std::wstring& sDefaultPath /* = std::wstring() */) { RetVal ret = RetVal::Ok; //assume OK @@ -94,7 +209,7 @@ CBrowseFolder::RetVal CBrowseFolder::Show(HWND parent, std::wstring& path, const // set the default folder if (SUCCEEDED(hr)) { - using SHCIFPN = HRESULT(WINAPI * )(PCWSTR pszPath, IBindCtx * pbc, REFIID riid, void** ppv); + using SHCIFPN = HRESULT(WINAPI*)(PCWSTR pszPath, IBindCtx * pbc, REFIID riid, void** ppv); HMODULE hLib = LoadLibrary(L"shell32.dll"); if (hLib) @@ -248,7 +363,7 @@ void CBrowseFolder::SetFont(HWND hwnd, LPCWSTR fontName, int fontSize) int CBrowseFolder::BrowseCallBackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM /*lpData*/) { - RECT listViewRect, dialog; + RECT listViewRect{}, dialog{}; //Initialization callback message if (uMsg == BFFM_INITIALIZED) { @@ -365,7 +480,7 @@ int CBrowseFolder::BrowseCallBackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARA if (uMsg == BFFM_SELCHANGED) { // Set the status window to the currently selected path. - wchar_t szDir[MAX_PATH]; + wchar_t szDir[MAX_PATH]{}; if (SHGetPathFromIDList(reinterpret_cast(lParam), szDir)) { SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, reinterpret_cast(szDir)); diff --git a/grepWinNP3/sktoolslib_mod/BrowseFolder.h b/grepWinNP3/sktoolslib_mod/BrowseFolder.h index 135f35f16..ce9a158ae 100644 --- a/grepWinNP3/sktoolslib_mod/BrowseFolder.h +++ b/grepWinNP3/sktoolslib_mod/BrowseFolder.h @@ -20,6 +20,7 @@ #pragma once #include +#include /** * \ingroup Utils @@ -61,6 +62,7 @@ public: */ CBrowseFolder::RetVal Show(HWND parent, std::wstring& path, const std::wstring& sDefaultPath = std::wstring()); CBrowseFolder::RetVal Show(HWND parent, LPWSTR path, size_t pathLen, LPCWSTR szDefaultPath = nullptr); + CBrowseFolder::RetVal Show(HWND parent, std::vector& paths, std::wstring sDefaultPath = {}); /** * If this is set to true, then the second checkbox gets disabled as soon as the first diff --git a/grepWinNP3/src/SearchDlg.cpp b/grepWinNP3/src/SearchDlg.cpp index 0af1915c0..b11d2bc8c 100644 --- a/grepWinNP3/src/SearchDlg.cpp +++ b/grepWinNP3/src/SearchDlg.cpp @@ -1303,13 +1303,22 @@ LRESULT CSearchDlg::DoCommand(int id, int msg) break; } - auto pathBuf = std::make_unique(MAX_PATH_NEW); - wcscpy_s(pathBuf.get(), MAX_PATH_NEW, path.get()); - browse.SetInfo(TranslatedString(hResource, IDS_SELECTPATHTOSEARCH).c_str()); - if (browse.Show(*this, pathBuf.get(), MAX_PATH_NEW, m_searchPath.c_str()) == CBrowseFolder::RetVal::Ok) + std::vector paths; + if (browse.Show(*this, paths, m_searchPath) == CBrowseFolder::RetVal::Ok) { - SetDlgItemText(*this, IDC_SEARCHPATH, pathBuf.get()); - m_searchPath = pathBuf.get(); + std::wstring pathString; + for (const auto& selPath : paths) + { + if (pathString.empty()) + pathString = selPath; + else + { + pathString += L"|"; + pathString += selPath; + } + } + SetDlgItemText(*this, IDC_SEARCHPATH, pathString.c_str()); + m_searchPath = pathString; } } break; diff --git a/grepWinNP3/src/last/version.h b/grepWinNP3/src/last/version.h index 9b82d133b..626f06e8c 100644 --- a/grepWinNP3/src/last/version.h +++ b/grepWinNP3/src/last/version.h @@ -6,13 +6,13 @@ //#pragma message(__LOC__"Run the NAnt script to get proper version info") -#define FILEVER 2, 1, 8, 38 -#define PRODUCTVER 2, 1, 8, 38 -#define STRFILEVER "2.1.8.38\0" -#define STRPRODUCTVER "2.1.8.38\0" +#define FILEVER 2, 1, 8, 39 +#define PRODUCTVER 2, 1, 8, 39 +#define STRFILEVER "2.1.8.39\0" +#define STRPRODUCTVER "2.1.8.39\0" #define GREPWIN_VERMAJOR 2 #define GREPWIN_VERMINOR 1 #define GREPWIN_VERMICRO 8 -#define GREPWIN_VERBUILD 38 -#define GREPWIN_VERDATE "2021-07-02" +#define GREPWIN_VERBUILD 39 +#define GREPWIN_VERDATE "2021-07-26"