Merge pull request #2707 from RaiKoHoff/Dev_NewFeatures

grepWinNP3: Export search result list (NP3 enhancements)
This commit is contained in:
Rainer Kottenhoff 2020-08-24 14:47:29 +02:00 committed by GitHub
commit cba56d8c00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 30 deletions

View File

@ -1459,6 +1459,15 @@ LRESULT CSearchDlg::DoCommand(int id, int msg)
if (FailedShowMessage(hr))
break;
COMDLG_FILTERSPEC const aFileTypes[] = { {L"Text files", L"*.txt; *.lst"}, {L"All types", L"*.*"} };
hr = pfd->SetFileTypes(_countof(aFileTypes), aFileTypes);
if (FailedShowMessage(hr))
break;
hr = pfd->SetFileName(L"gw_search_results.txt");
if (FailedShowMessage(hr))
break;
IFileDialogCustomizePtr pfdCustomize;
hr = pfd.QueryInterface(IID_PPV_ARGS(&pfdCustomize));
if (SUCCEEDED(hr))
@ -1538,14 +1547,17 @@ LRESULT CSearchDlg::DoCommand(int id, int msg)
bool needSeparator = false;
if (includePaths)
{
file << CUnicodeUtils::StdGetUTF8(item.filepath);
std::string fpath = CUnicodeUtils::StdGetUTF8(item.filepath);
std::transform(fpath.begin(), fpath.end(), fpath.begin(), [](char c) { return (c == '\\' ? '/' : c); });
file << std::string("file://");
file << fpath;
needSeparator = true;
}
if (includeMatchLineNumbers)
{
if (needSeparator)
file << separator;
file << CStringUtils::Format("%lld", item.matchlinesnumbers[i]);
file << CStringUtils::Format("(%lld)", item.matchlinesnumbers[i]);
needSeparator = true;
}
if (includeMatchLineTexts)
@ -1571,19 +1583,41 @@ LRESULT CSearchDlg::DoCommand(int id, int msg)
}
else
{
auto exportpaths = CRegStdDWORD(L"Software\\grepWin\\export_paths");
auto exportlinenumbers = CRegStdDWORD(L"Software\\grepWin\\export_linenumbers");
auto exportlinecontent = CRegStdDWORD(L"Software\\grepWin\\export_linecontent");
auto exportpaths = CRegStdDWORD(L"Software\\grepWinNP3\\export_paths");
auto exportlinenumbers = CRegStdDWORD(L"Software\\grepWinNP3\\export_linenumbers");
auto exportlinecontent = CRegStdDWORD(L"Software\\grepWinNP3\\export_linecontent");
exportpaths = includePaths ? 1 : 0;
exportlinenumbers = includeMatchLineNumbers ? 1 : 0;
exportlinecontent = includeMatchLineTexts ? 1 : 0;
}
SHELLEXECUTEINFO sei = {0};
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.lpVerb = TEXT("open");
sei.lpFile = path.c_str();
sei.nShow = SW_SHOWNORMAL;
ShellExecuteEx(&sei);
// open file
std::wstring cmd = bPortable ? g_iniFile.GetValue(L"global", L"editorcmd", L"") :
(std::wstring)CRegStdString(L"Software\\grepWinNP3\\editorcmd", L"");
if (!cmd.empty())
{
SearchReplace(cmd, L"%mode%", L"mb");
SearchReplace(cmd, L"%pattern%", L"");
SearchReplace(cmd, L"%line%", L"0");
SearchReplace(cmd, L"%path%", path.c_str());
STARTUPINFO startupInfo;
PROCESS_INFORMATION processInfo;
SecureZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(STARTUPINFO);
SecureZeroMemory(&processInfo, sizeof(processInfo));
CreateProcess(NULL, const_cast<wchar_t*>(cmd.c_str()), NULL, NULL, FALSE, 0, 0, NULL, &startupInfo, &processInfo);
CloseHandle(processInfo.hThread);
CloseHandle(processInfo.hProcess);
}
else
{
SHELLEXECUTEINFO sei = {0};
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.lpVerb = TEXT("open");
sei.lpFile = path.c_str();
sei.nShow = SW_SHOWNORMAL;
ShellExecuteEx(&sei);
}
}
}
}
@ -2328,10 +2362,8 @@ void CSearchDlg::OpenFileAtListIndex(int listIndex)
if (dotPos != std::wstring::npos)
ext = inf.filepath.substr(dotPos);
CRegStdString regEditorCmd(L"Software\\grepWinNP3\\editorcmd");
std::wstring cmd = regEditorCmd;
if (bPortable)
cmd = g_iniFile.GetValue(L"global", L"editorcmd", L"");
std::wstring cmd = bPortable ? g_iniFile.GetValue(L"global", L"editorcmd", L"") :
(std::wstring)CRegStdString(L"Software\\grepWinNP3\\editorcmd", L"");
if (!cmd.empty())
{
bool filelist = (IsDlgButtonChecked(*this, IDC_RESULTFILES) == BST_CHECKED);
@ -3333,7 +3365,8 @@ int CSearchDlg::SearchFile(std::shared_ptr<CSearchInfo> sinfoPtr, const std::wst
else
{
ProfileTimer profile((L"file load and parse: " + sinfoPtr->filepath).c_str());
auto nNullCount = bPortable ? _wtoi(g_iniFile.GetValue(L"settings", L"nullbytes", L"0")) : int(DWORD(CRegStdDWORD(L"Software\\grepWin\\nullbytes", 0)));
auto nNullCount = bPortable ? int(g_iniFile.GetLongValue(L"settings", L"nullbytes", 0)) :
int(DWORD(CRegStdDWORD(L"Software\\grepWinNP3\\nullbytes", 0)));
if (nNullCount > 0)
{
constexpr __int64 oneMB = 1024 * 1024;

View File

@ -6,13 +6,13 @@
//#pragma message(__LOC__"Run the NAnt script to get proper version info")
#define FILEVER 2, 1, 3, 26
#define PRODUCTVER 2, 1, 3, 26
#define STRFILEVER "2.1.3.26\0"
#define STRPRODUCTVER "2.1.3.26\0"
#define FILEVER 2, 1, 3, 27
#define PRODUCTVER 2, 1, 3, 27
#define STRFILEVER "2.1.3.27\0"
#define STRPRODUCTVER "2.1.3.27\0"
#define GREPWIN_VERMAJOR 2
#define GREPWIN_VERMINOR 1
#define GREPWIN_VERMICRO 3
#define GREPWIN_VERBUILD 26
#define GREPWIN_VERDATE "2020-08-17"
#define GREPWIN_VERBUILD 27
#define GREPWIN_VERDATE "2020-08-24"

View File

@ -3755,12 +3755,12 @@ void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern)
}
if (lngIdx >= 0) {
IniSectionGetString(L"global", L"languagefile", grepWinLangResName[lngIdx].filename, tchTemp, COUNTOF(tchTemp));
IniSectionSetString(L"global", L"languagefile", tchTemp);
IniSectionGetString(globalSection, L"languagefile", grepWinLangResName[lngIdx].filename, tchTemp, COUNTOF(tchTemp));
IniSectionSetString(globalSection, L"languagefile", tchTemp);
} else {
IniSectionGetString(L"global", L"languagefile", L"", tchTemp, COUNTOF(tchTemp));
IniSectionGetString(globalSection, L"languagefile", L"", tchTemp, COUNTOF(tchTemp));
if (StrIsEmpty(tchTemp)) {
IniSectionDelete(L"global", L"languagefile", false);
IniSectionDelete(globalSection, L"languagefile", false);
}
}
@ -3768,10 +3768,22 @@ void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern)
IniSectionSetString(globalSection, L"editorcmd", tchTemp);
// [settings]
bool const bEscClose = IniSectionGetBool(L"settings", L"escclose", (Settings.EscFunction == 2));
IniSectionSetBool(L"settings", L"escclose", bEscClose);
bool const bBackupInFolder = IniSectionGetBool(L"settings", L"backupinfolder", true);
IniSectionSetBool(L"settings", L"backupinfolder", bBackupInFolder);
const WCHAR *const settingsSection = L"settings";
bool const bEscClose = IniSectionGetBool(settingsSection, L"escclose", (Settings.EscFunction == 2));
IniSectionSetBool(settingsSection, L"escclose", bEscClose);
bool const bBackupInFolder = IniSectionGetBool(settingsSection, L"backupinfolder", true);
IniSectionSetBool(settingsSection, L"backupinfolder", bBackupInFolder);
// [export]
const WCHAR *const exportSection = L"export";
bool const bExpPaths = IniSectionGetBool(exportSection, L"paths", true);
IniSectionSetBool(exportSection, L"paths", bExpPaths);
bool const bExpLnNums = IniSectionGetBool(exportSection, L"linenumbers", true);
IniSectionSetBool(exportSection, L"linenumbers", bExpLnNums);
bool const bExpContent = IniSectionGetBool(exportSection, L"linecontent", true);
IniSectionSetBool(exportSection, L"linecontent", bExpContent);
// search directory
WCHAR tchSearchDir[MAX_PATH] = { L'\0' };