Merge pull request #3526 from RaiKoHoff/Dev_DM_STD

Update: grepWin(NP3) - allow multiple search paths
This commit is contained in:
Pairi Daiza 2021-07-26 14:16:14 +02:00 committed by GitHub
commit 3ffbe1a425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 141 additions and 15 deletions

View File

@ -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<std::wstring>& 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<LPITEMIDLIST>(lParam), szDir))
{
SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, reinterpret_cast<LPARAM>(szDir));

View File

@ -20,6 +20,7 @@
#pragma once
#include <string>
#include <vector>
/**
* \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<std::wstring>& paths, std::wstring sDefaultPath = {});
/**
* If this is set to true, then the second checkbox gets disabled as soon as the first

View File

@ -1303,13 +1303,22 @@ LRESULT CSearchDlg::DoCommand(int id, int msg)
break;
}
auto pathBuf = std::make_unique<wchar_t[]>(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<std::wstring> 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;

View File

@ -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"