mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-11 21:03:05 +08:00
+upd: current grepWin dev
This commit is contained in:
parent
4e46cf666e
commit
3d73eed105
@ -521,16 +521,16 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<Import Project="..\packages\boost.1.81.0\build\boost.targets" Condition="Exists('..\packages\boost.1.81.0\build\boost.targets')" />
|
||||
<Import Project="..\packages\boost_iostreams-vc143.1.81.0\build\boost_iostreams-vc143.targets" Condition="Exists('..\packages\boost_iostreams-vc143.1.81.0\build\boost_iostreams-vc143.targets')" />
|
||||
<Import Project="..\packages\boost_regex-vc143.1.81.0\build\boost_regex-vc143.targets" Condition="Exists('..\packages\boost_regex-vc143.1.81.0\build\boost_regex-vc143.targets')" />
|
||||
<Import Project="..\packages\boost.1.82.0\build\boost.targets" Condition="Exists('..\packages\boost.1.82.0\build\boost.targets')" />
|
||||
<Import Project="..\packages\boost_iostreams-vc143.1.82.0\build\boost_iostreams-vc143.targets" Condition="Exists('..\packages\boost_iostreams-vc143.1.82.0\build\boost_iostreams-vc143.targets')" />
|
||||
<Import Project="..\packages\boost_regex-vc143.1.82.0\build\boost_regex-vc143.targets" Condition="Exists('..\packages\boost_regex-vc143.1.82.0\build\boost_regex-vc143.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\boost.1.81.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.81.0\build\boost.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_iostreams-vc143.1.81.0\build\boost_iostreams-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_iostreams-vc143.1.81.0\build\boost_iostreams-vc143.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_regex-vc143.1.81.0\build\boost_regex-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_regex-vc143.1.81.0\build\boost_regex-vc143.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost.1.82.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost.1.82.0\build\boost.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_iostreams-vc143.1.82.0\build\boost_iostreams-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_iostreams-vc143.1.82.0\build\boost_iostreams-vc143.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\boost_regex-vc143.1.82.0\build\boost_regex-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_regex-vc143.1.82.0\build\boost_regex-vc143.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="boost" version="1.81.0" targetFramework="native" />
|
||||
<package id="boost_iostreams-vc143" version="1.81.0" targetFramework="native" />
|
||||
<package id="boost_regex-vc143" version="1.81.0" targetFramework="native" />
|
||||
<package id="boost" version="1.82.0" targetFramework="native" />
|
||||
<package id="boost_iostreams-vc143" version="1.82.0" targetFramework="native" />
|
||||
<package id="boost_regex-vc143" version="1.82.0" targetFramework="native" />
|
||||
</packages>
|
||||
@ -26,7 +26,7 @@
|
||||
|
||||
static HWND g_hDlgCurrent = nullptr;
|
||||
|
||||
INT_PTR CDialog::DoModal(HINSTANCE hInstance, int resID, HWND hWndParent)
|
||||
INT_PTR CDialog::DoModal(HINSTANCE hInstance, int resID, HWND hWndParent)
|
||||
{
|
||||
m_bPseudoModal = false;
|
||||
hResource = hInstance;
|
||||
@ -142,7 +142,7 @@ void CDialog::InitDialog(HWND hwndDlg, UINT iconID, bool bPosition /* = true*/)
|
||||
WINDOWPLACEMENT placement;
|
||||
placement.length = sizeof(WINDOWPLACEMENT);
|
||||
|
||||
HWND hwndOwner = ::GetParent(hwndDlg);
|
||||
HWND hwndOwner = ::GetParent(hwndDlg);
|
||||
GetWindowPlacement(hwndOwner, &placement);
|
||||
if ((hwndOwner == nullptr) || (placement.showCmd == SW_SHOWMINIMIZED) || (placement.showCmd == SW_SHOWMINNOACTIVE))
|
||||
hwndOwner = ::GetDesktopWindow();
|
||||
@ -204,8 +204,8 @@ INT_PTR CALLBACK CDialog::stDlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPAR
|
||||
{
|
||||
// get the pointer to the window from lpCreateParams
|
||||
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
|
||||
pWnd = reinterpret_cast<CDialog*>(lParam);
|
||||
pWnd->m_hwnd = hwndDlg;
|
||||
pWnd = reinterpret_cast<CDialog*>(lParam);
|
||||
pWnd->m_hwnd = hwndDlg;
|
||||
// create the tooltip control
|
||||
pWnd->m_hToolTips = CreateWindowEx(0,
|
||||
TOOLTIPS_CLASS, nullptr,
|
||||
@ -242,7 +242,7 @@ INT_PTR CALLBACK CDialog::stDlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPAR
|
||||
bInDlgProc = true;
|
||||
DefDlgProc(hwndDlg, uMsg, wParam, lParam);
|
||||
bInDlgProc = false;
|
||||
HDC hdc = reinterpret_cast<HDC>(wParam);
|
||||
HDC hdc = reinterpret_cast<HDC>(wParam);
|
||||
// draw the frame margins in black
|
||||
RECT rc;
|
||||
GetClientRect(hwndDlg, &rc);
|
||||
@ -539,7 +539,7 @@ BOOL CDialog::IsDialogMessage(LPMSG lpMsg)
|
||||
|
||||
void CDialog::AdjustControlSize(UINT nID)
|
||||
{
|
||||
HWND hwndDlgItem = GetDlgItem(*this, nID);
|
||||
HWND hwndDlgItem = GetDlgItem(*this, nID);
|
||||
// adjust the size of the control to fit its content
|
||||
auto sControlText = GetDlgItemText(nID);
|
||||
// next step: find the rectangle the control text needs to
|
||||
@ -553,11 +553,11 @@ void CDialog::AdjustControlSize(UINT nID)
|
||||
RECT controlRectOrig = controlRect;
|
||||
if (hDC)
|
||||
{
|
||||
HFONT hFont = GetWindowFont(hwndDlgItem);
|
||||
HFONT hFont = GetWindowFont(hwndDlgItem);
|
||||
HFONT hOldFont = static_cast<HFONT>(SelectObject(hDC, hFont));
|
||||
OffsetRect(&controlRect, -controlRect.left, -controlRect.top);
|
||||
if (DrawText(hDC, sControlText.get(), -1, &controlRect, DT_WORDBREAK | DT_EXPANDTABS | DT_LEFT | DT_CALCRECT))
|
||||
{
|
||||
{
|
||||
// we're dealing with radio buttons and check boxes,
|
||||
// which means we have to add a little space for the checkbox
|
||||
const int checkWidth = GetSystemMetrics(SM_CXMENUCHECK) + 2 * GetSystemMetrics(SM_CXEDGE) + CDPIAware::Instance().Scale(*this, 3);
|
||||
@ -565,7 +565,7 @@ void CDialog::AdjustControlSize(UINT nID)
|
||||
// now we have the rectangle the control really needs
|
||||
if ((controlRectOrig.right - controlRectOrig.left) > (controlRect.right - controlRect.left))
|
||||
{
|
||||
controlRectOrig.right = controlRectOrig.left + (controlRect.right - controlRect.left);
|
||||
controlRectOrig.right = controlRectOrig.left + (controlRect.right - controlRect.left);
|
||||
MoveWindow(hwndDlgItem, controlRectOrig.left, controlRectOrig.top, controlRectOrig.right - controlRectOrig.left, controlRectOrig.bottom - controlRectOrig.top, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ private:
|
||||
#ifdef _DEBUG
|
||||
m_bActive = true;
|
||||
#else
|
||||
m_bActive = !!CRegStdDWORD(DEBUGOUTPUTREGPATH, FALSE);
|
||||
m_bActive = !!CRegStdDWORD(DEBUGOUTPUTREGPATH, FALSE);
|
||||
#endif
|
||||
}
|
||||
~CTraceToOutputDebugString()
|
||||
@ -186,7 +186,7 @@ private:
|
||||
static CTraceToOutputDebugString* m_pInstance;
|
||||
|
||||
// Non Unicode output helper
|
||||
void TraceV(PCSTR pszFormat, va_list args) const
|
||||
void TraceV(PCSTR pszFormat, va_list args) const
|
||||
{
|
||||
// Format the output buffer
|
||||
char szBuffer[1024];
|
||||
|
||||
@ -78,7 +78,7 @@ bool CLanguage::LoadFile(const std::wstring& path)
|
||||
file.getline(line.get(), 2 * MAX_STRING_LENGTH);
|
||||
if (line.get()[0] == 0)
|
||||
{
|
||||
//empty line means end of entry!
|
||||
// empty line means end of entry!
|
||||
std::wstring msgId;
|
||||
std::wstring msgStr;
|
||||
int type = 0;
|
||||
@ -86,24 +86,24 @@ bool CLanguage::LoadFile(const std::wstring& path)
|
||||
{
|
||||
if (wcsncmp(I->c_str(), L"# ", 2) == 0)
|
||||
{
|
||||
//user comment
|
||||
// user comment
|
||||
type = 0;
|
||||
}
|
||||
if (wcsncmp(I->c_str(), L"#.", 2) == 0)
|
||||
{
|
||||
//automatic comments
|
||||
// automatic comments
|
||||
type = 0;
|
||||
}
|
||||
if (wcsncmp(I->c_str(), L"#,", 2) == 0)
|
||||
{
|
||||
//flag
|
||||
// flag
|
||||
type = 0;
|
||||
}
|
||||
if (wcsncmp(I->c_str(), L"msgid", 5) == 0)
|
||||
{
|
||||
//message id
|
||||
msgId = I->c_str();
|
||||
msgId = std::wstring(msgId.substr(7, msgId.size() - 8));
|
||||
// message id
|
||||
msgId = I->c_str();
|
||||
msgId = std::wstring(msgId.substr(7, msgId.size() - 8));
|
||||
|
||||
std::wstring s = msgId;
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](wint_t c) { return !iswspace(c); }));
|
||||
@ -273,7 +273,7 @@ BOOL CALLBACK CLanguage::TranslateWindowProc(HWND hwnd, LPARAM lParam)
|
||||
// now we have the rectangle the control really needs
|
||||
if ((controlRectOrig.right - controlRectOrig.left) > (controlRect.right - controlRect.left))
|
||||
{
|
||||
controlRectOrig.right = controlRectOrig.left + (controlRect.right - controlRect.left);
|
||||
controlRectOrig.right = controlRectOrig.left + (controlRect.right - controlRect.left);
|
||||
MoveWindow(hwnd, controlRectOrig.left, controlRectOrig.top, controlRectOrig.right - controlRectOrig.left, controlRectOrig.bottom - controlRectOrig.top, TRUE);
|
||||
}
|
||||
}
|
||||
@ -303,7 +303,7 @@ BOOL CALLBACK CLanguage::TranslateWindowProc(HWND hwnd, LPARAM lParam)
|
||||
{
|
||||
// translate hint texts in edit controls
|
||||
constexpr int bufCount = 4096;
|
||||
auto buf = std::make_unique<wchar_t[]>(bufCount);
|
||||
auto buf = std::make_unique<wchar_t[]>(bufCount);
|
||||
SecureZeroMemory(buf.get(), bufCount * sizeof(wchar_t));
|
||||
Edit_GetCueBannerText(hwnd, buf.get(), bufCount);
|
||||
auto sTranslated = GetTranslatedString(buf.get(), pLangMap);
|
||||
@ -312,8 +312,8 @@ BOOL CALLBACK CLanguage::TranslateWindowProc(HWND hwnd, LPARAM lParam)
|
||||
else if (wcscmp(className, TOOLTIPS_CLASS) == 0)
|
||||
{
|
||||
constexpr int bufCount = 4096;
|
||||
auto buf = std::make_unique<wchar_t[]>(bufCount);
|
||||
auto toolCount = static_cast<int>(SendMessage(hwnd, TTM_GETTOOLCOUNT, 0, 0));
|
||||
auto buf = std::make_unique<wchar_t[]>(bufCount);
|
||||
auto toolCount = static_cast<int>(SendMessage(hwnd, TTM_GETTOOLCOUNT, 0, 0));
|
||||
for (int i = 0; i < toolCount; ++i)
|
||||
{
|
||||
SecureZeroMemory(buf.get(), bufCount * sizeof(wchar_t));
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// sktoolslib - common files for SK tools
|
||||
|
||||
// Copyright (C) 2013-2015, 2017, 2020-2022 - Stefan Kueng
|
||||
// Copyright (C) 2013-2015, 2017, 2020-2023 - Stefan Kueng
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
@ -121,6 +121,17 @@ std::wstring CPathUtils::GetLongPathname(const std::wstring& path)
|
||||
}
|
||||
if (ret == 0)
|
||||
return path;
|
||||
if (sRet.starts_with('\\'))
|
||||
{
|
||||
ret = GetFullPathName(sRet.c_str(), 0, nullptr, nullptr);
|
||||
if (ret)
|
||||
{
|
||||
auto fullPath = std::make_unique<wchar_t[]>(ret + 2);
|
||||
ret = GetFullPathName(sRet.c_str(), ret + 1, fullPath.get(), nullptr);
|
||||
if (ret)
|
||||
sRet = std::wstring(fullPath.get(), ret);
|
||||
}
|
||||
}
|
||||
return sRet;
|
||||
}
|
||||
|
||||
|
||||
@ -47,9 +47,9 @@
|
||||
* not found
|
||||
* @endcode
|
||||
*/
|
||||
int strwildcmp(const char* wild, const char* string);
|
||||
int wcswildcmp(const wchar_t* wild, const wchar_t* string);
|
||||
int wcswildicmp(const wchar_t* wild, const wchar_t* string);
|
||||
int strwildcmp(const char* wild, const char* string);
|
||||
int wcswildcmp(const wchar_t* wild, const wchar_t* string);
|
||||
int wcswildicmp(const wchar_t* wild, const wchar_t* string);
|
||||
|
||||
bool WriteAsciiStringToClipboard(const wchar_t* sClipdata, HWND hOwningWnd);
|
||||
void SearchReplace(std::wstring& str, const std::wstring& toreplace, const std::wstring& replacewith);
|
||||
@ -274,13 +274,13 @@ std::wstring to_bit_wstring(T number, bool trimSignificantClearBits)
|
||||
{
|
||||
// Unsigned version of type given.
|
||||
using UT = typename std::make_unsigned<T>::type;
|
||||
UT one = 1;
|
||||
UT zero = 0;
|
||||
UT uNumber;
|
||||
uNumber = UT(number);
|
||||
UT one = 1;
|
||||
UT zero = 0;
|
||||
UT uNumber;
|
||||
uNumber = UT(number);
|
||||
constexpr int nBits = std::numeric_limits<UT>::digits;
|
||||
std::wstring bs;
|
||||
bool seenSetBit = false;
|
||||
std::wstring bs;
|
||||
bool seenSetBit = false;
|
||||
for (int bn = nBits - 1; bn >= 0; --bn)
|
||||
{
|
||||
UT mask = one << bn;
|
||||
@ -300,9 +300,9 @@ std::string to_bit_string(T number, bool trimSignificantClearBits)
|
||||
{
|
||||
// Unsigned version of type given.
|
||||
using UT = typename std::make_unsigned<T>::type;
|
||||
UT one = 1;
|
||||
UT zero = 0;
|
||||
UT uNumber;
|
||||
UT one = 1;
|
||||
UT zero = 0;
|
||||
UT uNumber;
|
||||
uNumber = UT(number);
|
||||
const int nBits = std::numeric_limits<UT>::digits;
|
||||
std::string bs;
|
||||
|
||||
@ -21,7 +21,6 @@
|
||||
#include "TextFile.h"
|
||||
#include "PathUtils.h"
|
||||
#include "maxpath.h"
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
static wchar_t WideCharSwap(wchar_t nValue)
|
||||
@ -86,7 +85,7 @@ bool CTextFile::Save(LPCWSTR path, bool keepFileDate) const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CTextFile::Load(LPCWSTR path, UnicodeType &type, bool bUTF8, std::atomic_bool& bCancelled)
|
||||
bool CTextFile::Load(LPCWSTR path, UnicodeType &type, bool bUTF8, std::atomic_bool &bCancelled)
|
||||
{
|
||||
encoding = AutoType;
|
||||
type = AutoType;
|
||||
@ -284,7 +283,7 @@ bool CTextFile::Load(LPCWSTR path, UnicodeType &type, bool bUTF8, std::atomic_bo
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else //if (encoding == ANSI)
|
||||
else // if (encoding == ANSI)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -436,12 +435,12 @@ CTextFile::UnicodeType CTextFile::CheckUnicodeType(BYTE *pBuffer, int cb) const
|
||||
{
|
||||
if (cb < 2)
|
||||
return Ansi;
|
||||
UINT16 *pVal16 = reinterpret_cast<UINT16 *>(pBuffer);
|
||||
UINT8 * pVal8 = reinterpret_cast<UINT8 *>(pVal16 + 1);
|
||||
UINT16 *pVal16 = reinterpret_cast<UINT16 *>(pBuffer);
|
||||
UINT8 *pVal8 = reinterpret_cast<UINT8 *>(pVal16 + 1);
|
||||
// scan the whole buffer for a 0x0000 sequence
|
||||
// if found, we assume a binary file
|
||||
int nNull = 0;
|
||||
int nDblNull = 0;
|
||||
int nNull = 0;
|
||||
int nDblNull = 0;
|
||||
for (int i = 0; i < (cb - 2); i = i + 2)
|
||||
{
|
||||
if (0x0000 == *pVal16++)
|
||||
@ -523,7 +522,7 @@ CTextFile::UnicodeType CTextFile::CheckUnicodeType(BYTE *pBuffer, int cb) const
|
||||
return Ansi;
|
||||
}
|
||||
|
||||
bool CTextFile::CalculateLines(std::atomic_bool& bCancelled)
|
||||
bool CTextFile::CalculateLines(std::atomic_bool &bCancelled)
|
||||
{
|
||||
// fill an array with starting positions for every line in the loaded file
|
||||
if (pFileBuf == nullptr)
|
||||
|
||||
@ -59,17 +59,17 @@ public:
|
||||
* \param newLen length of the new file content in bytes
|
||||
* \note the old buffer is automatically freed.
|
||||
*/
|
||||
bool ContentsModified(std::unique_ptr<BYTE[]> pBuf, DWORD newLen);
|
||||
bool ContentsModified(std::unique_ptr<BYTE[]> pBuf, DWORD newLen);
|
||||
|
||||
/**
|
||||
* Returns the line number from a given character position inside the file.
|
||||
*/
|
||||
long LineFromPosition(long pos) const;
|
||||
long LineFromPosition(long pos) const;
|
||||
|
||||
/**
|
||||
* Returns the line from a given line number
|
||||
*/
|
||||
std::wstring GetLineString(long lineNumber) const;
|
||||
std::wstring GetLineString(long lineNumber) const;
|
||||
|
||||
/**
|
||||
* Returns the file content as a text string.
|
||||
@ -81,17 +81,17 @@ public:
|
||||
* Returns a pointer to the file contents. Call GetFileLength() to get
|
||||
* the size in number of bytes of this buffer.
|
||||
*/
|
||||
LPVOID GetFileContent() const { return pFileBuf.get(); }
|
||||
LPVOID GetFileContent() const { return pFileBuf.get(); }
|
||||
|
||||
/**
|
||||
* Returns the size of the file in bytes
|
||||
*/
|
||||
long GetFileLength() const { return fileLen; }
|
||||
long GetFileLength() const { return fileLen; }
|
||||
|
||||
/**
|
||||
* Returns the encoding of the file
|
||||
*/
|
||||
UnicodeType GetEncoding() const { return encoding; }
|
||||
UnicodeType GetEncoding() const { return encoding; }
|
||||
|
||||
/**
|
||||
* Returns a string representation of the encoding
|
||||
@ -106,26 +106,26 @@ public:
|
||||
/**
|
||||
* Returns the filename without the extension (if any)
|
||||
*/
|
||||
std::wstring GetFileNameWithoutExtension() const;
|
||||
std::wstring GetFileNameWithoutExtension() const;
|
||||
|
||||
/**
|
||||
* Returns the filename extension (if any)
|
||||
*/
|
||||
std::wstring GetFileNameExtension() const;
|
||||
std::wstring GetFileNameExtension() const;
|
||||
|
||||
/**
|
||||
* Replaces the file content.
|
||||
*/
|
||||
void SetFileContent(const std::wstring& content);
|
||||
void SetFileContent(const std::wstring& content);
|
||||
|
||||
bool HasBOM() const { return hasBOM; }
|
||||
bool HasBOM() const { return hasBOM; }
|
||||
|
||||
/**
|
||||
* Sets the number of null bytes that are allowed for
|
||||
* a file to still be considered text instead of binary
|
||||
* in the encoding detection. Default is 2.
|
||||
*/
|
||||
void SetNullbyteCountForBinary(int count) { nullByteCount = count; }
|
||||
void SetNullbyteCountForBinary(int count) { nullByteCount = count; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// grepWin - regex search and replace for Windows
|
||||
|
||||
// Copyright (C) 2007-2009, 2012-2013, 2017, 2020-2022 - Stefan Kueng
|
||||
// Copyright (C) 2007-2009, 2012-2013, 2017, 2020-2023 - Stefan Kueng
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
@ -33,7 +33,7 @@ CBookmarks::~CBookmarks()
|
||||
{
|
||||
}
|
||||
|
||||
void CBookmarks::Load()
|
||||
void CBookmarks::InitPath()
|
||||
{
|
||||
auto path = std::make_unique<wchar_t[]>(MAX_PATH_NEW);
|
||||
GetModuleFileName(nullptr, path.get(), MAX_PATH_NEW);
|
||||
@ -50,6 +50,12 @@ void CBookmarks::Load()
|
||||
}
|
||||
CreateDirectory(m_iniPath.c_str(), nullptr);
|
||||
m_iniPath += L"\\bookmarks";
|
||||
}
|
||||
|
||||
void CBookmarks::Load()
|
||||
{
|
||||
if (m_iniPath.empty())
|
||||
InitPath();
|
||||
SetUnicode();
|
||||
SetMultiLine();
|
||||
SetSpaces(false);
|
||||
@ -58,22 +64,8 @@ void CBookmarks::Load()
|
||||
|
||||
void CBookmarks::Save()
|
||||
{
|
||||
auto path = std::make_unique<wchar_t[]>(MAX_PATH_NEW);
|
||||
GetModuleFileName(nullptr, path.get(), MAX_PATH_NEW);
|
||||
if (bPortable)
|
||||
{
|
||||
m_iniPath = path.get();
|
||||
m_iniPath = m_iniPath.substr(0, m_iniPath.rfind('\\'));
|
||||
}
|
||||
else
|
||||
{
|
||||
SHGetFolderPath(nullptr, CSIDL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, path.get());
|
||||
m_iniPath = path.get();
|
||||
m_iniPath += L"\\grepWinNP3";
|
||||
}
|
||||
CreateDirectory(m_iniPath.c_str(), nullptr);
|
||||
m_iniPath += L"\\bookmarks";
|
||||
|
||||
if (m_iniPath.empty())
|
||||
InitPath();
|
||||
SaveFile(m_iniPath.c_str(), true);
|
||||
}
|
||||
|
||||
@ -158,7 +150,26 @@ Bookmark CBookmarks::GetBookmark(const std::wstring& name) const
|
||||
bk.FileMatch = GetValue(name.c_str(), L"filematch", L"");
|
||||
bk.FileMatchRegex = wcscmp(GetValue(name.c_str(), L"filematchregex", L"false"), L"true") == 0;
|
||||
bk.Path = GetValue(name.c_str(), L"searchpath", L"");
|
||||
|
||||
RemoveQuotes(bk.Search);
|
||||
RemoveQuotes(bk.Replace);
|
||||
RemoveQuotes(bk.ExcludeDirs);
|
||||
RemoveQuotes(bk.FileMatch);
|
||||
}
|
||||
|
||||
return bk;
|
||||
}
|
||||
|
||||
void CBookmarks::RemoveQuotes(std::wstring& str)
|
||||
{
|
||||
if (!str.empty())
|
||||
{
|
||||
if (str[0] == '"')
|
||||
str = str.substr(1);
|
||||
if (!str.empty())
|
||||
{
|
||||
if (str[str.size() - 1] == '"')
|
||||
str = str.substr(0, str.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// grepWin - regex search and replace for Windows
|
||||
|
||||
// Copyright (C) 2007-2008, 2012-2013, 2020-2022 - Stefan Kueng
|
||||
// Copyright (C) 2007-2008, 2012-2013, 2020-2023 - Stefan Kueng
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
@ -72,11 +72,13 @@ public:
|
||||
CBookmarks();
|
||||
~CBookmarks();
|
||||
|
||||
void Load();
|
||||
void Save();
|
||||
void AddBookmark(const Bookmark& bm);
|
||||
void RemoveBookmark(const std::wstring& name);
|
||||
Bookmark GetBookmark(const std::wstring& name) const;
|
||||
void InitPath();
|
||||
void Load();
|
||||
void Save();
|
||||
void AddBookmark(const Bookmark& bm);
|
||||
void RemoveBookmark(const std::wstring& name);
|
||||
Bookmark GetBookmark(const std::wstring& name) const;
|
||||
static void RemoveQuotes(std::wstring& str);
|
||||
|
||||
protected:
|
||||
std::wstring m_iniPath;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// grepWin - regex search and replace for Windows
|
||||
|
||||
// Copyright (C) 2007-2010, 2012-2017, 2019-2022 - Stefan Kueng
|
||||
// Copyright (C) 2007-2010, 2012-2017, 2019-2023 - Stefan Kueng
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
@ -246,9 +246,7 @@ LRESULT CBookmarksDlg::DoCommand(int id, int /*msg*/)
|
||||
if (nameDlg.GetName().compare(buf.get()))
|
||||
{
|
||||
Bookmark bk = m_bookmarks.GetBookmark(buf.get());
|
||||
RemoveQuotes(bk.Search);
|
||||
RemoveQuotes(bk.Replace);
|
||||
bk.Name = nameDlg.GetName();
|
||||
bk.Name = nameDlg.GetName();
|
||||
m_bookmarks.AddBookmark(bk);
|
||||
m_bookmarks.RemoveBookmark(buf.get());
|
||||
m_bookmarks.Save();
|
||||
@ -298,8 +296,8 @@ void CBookmarksDlg::InitBookmarks()
|
||||
{
|
||||
std::wstring searchString = m_bookmarks.GetValue(section.pItem, L"searchString", L"");
|
||||
std::wstring replaceString = m_bookmarks.GetValue(section.pItem, L"replaceString", L"");
|
||||
RemoveQuotes(searchString);
|
||||
RemoveQuotes(replaceString);
|
||||
CBookmarks::RemoveQuotes(searchString);
|
||||
CBookmarks::RemoveQuotes(replaceString);
|
||||
|
||||
LVITEM lv = {0};
|
||||
lv.mask = LVIF_TEXT;
|
||||
@ -329,20 +327,6 @@ void CBookmarksDlg::InitBookmarks()
|
||||
ListView_SetColumnWidth(hListControl, 2, LVSCW_AUTOSIZE_USEHEADER);
|
||||
}
|
||||
|
||||
void CBookmarksDlg::RemoveQuotes(std::wstring& str)
|
||||
{
|
||||
if (!str.empty())
|
||||
{
|
||||
if (str[0] == '"')
|
||||
str = str.substr(1);
|
||||
if (!str.empty())
|
||||
{
|
||||
if (str[str.size()-1] == '"')
|
||||
str = str.substr(0, str.size()-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CBookmarksDlg::PrepareSelected()
|
||||
{
|
||||
m_bookmarks.Save();
|
||||
@ -360,11 +344,11 @@ void CBookmarksDlg::PrepareSelected()
|
||||
m_path = m_bookmarks.GetValue(buf.get(), L"searchpath", L"");
|
||||
m_replaceString = m_bookmarks.GetValue(buf.get(), L"replaceString", L"");
|
||||
m_sExcludeDirs = m_bookmarks.GetValue(buf.get(), L"excludedirs", L"");
|
||||
m_sFileMatch = m_bookmarks.GetValue(buf.get(), L"filematch", L"");
|
||||
RemoveQuotes(m_searchString);
|
||||
RemoveQuotes(m_replaceString);
|
||||
RemoveQuotes(m_sExcludeDirs);
|
||||
RemoveQuotes(m_sFileMatch);
|
||||
m_sFileMatch = m_bookmarks.GetValue(buf.get(), L"filematch", L"");
|
||||
CBookmarks::RemoveQuotes(m_searchString);
|
||||
CBookmarks::RemoveQuotes(m_replaceString);
|
||||
CBookmarks::RemoveQuotes(m_sExcludeDirs);
|
||||
CBookmarks::RemoveQuotes(m_sFileMatch);
|
||||
m_bUseRegex = wcscmp(m_bookmarks.GetValue(buf.get(), L"useregex", L"false"), L"true") == 0;
|
||||
m_bCaseSensitive = wcscmp(m_bookmarks.GetValue(buf.get(), L"casesensitive", L"false"), L"true") == 0;
|
||||
m_bDotMatchesNewline = wcscmp(m_bookmarks.GetValue(buf.get(), L"dotmatchesnewline", L"false"), L"true") == 0;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// grepWin - regex search and replace for Windows
|
||||
|
||||
// Copyright (C) 2007-2009, 2012-2013, 2016, 2019-2022 - Stefan Kueng
|
||||
// Copyright (C) 2007-2009, 2012-2013, 2016, 2019-2023 - Stefan Kueng
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
@ -58,7 +58,6 @@ public:
|
||||
protected:
|
||||
LRESULT CALLBACK DlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) override;
|
||||
LRESULT DoCommand(int id, int msg);
|
||||
static void RemoveQuotes(std::wstring& str);
|
||||
void PrepareSelected();
|
||||
|
||||
private:
|
||||
|
||||
@ -2457,13 +2457,22 @@ void CSearchDlg::DoListNotify(LPNMITEMACTIVATE lpNMItemActivate)
|
||||
OpenFileAtListIndex(lpNMItemActivate->iItem);
|
||||
}
|
||||
}
|
||||
if (lpNMItemActivate->hdr.code == LVN_ODSTATECHANGED)
|
||||
{
|
||||
if (!m_bBlockUpdate)
|
||||
{
|
||||
HWND hListControl = lpNMItemActivate->hdr.hwndFrom;
|
||||
m_selectedItems = ListView_GetSelectedCount(hListControl);
|
||||
UpdateInfoLabel();
|
||||
}
|
||||
}
|
||||
if (lpNMItemActivate->hdr.code == LVN_ITEMCHANGED)
|
||||
{
|
||||
if ((lpNMItemActivate->uOldState & LVIS_SELECTED) || (lpNMItemActivate->uNewState & LVIS_SELECTED))
|
||||
{
|
||||
if (!m_bBlockUpdate)
|
||||
{
|
||||
HWND hListControl = GetDlgItem(*this, IDC_RESULTLIST);
|
||||
HWND hListControl = lpNMItemActivate->hdr.hwndFrom;
|
||||
m_selectedItems = ListView_GetSelectedCount(hListControl);
|
||||
UpdateInfoLabel();
|
||||
}
|
||||
@ -3319,7 +3328,7 @@ DWORD CSearchDlg::SearchThread()
|
||||
}
|
||||
found = s.find_first_of('\\', found + 1);
|
||||
}
|
||||
CStringUtils::rtrim(s, L"\\/");
|
||||
CStringUtils::rtrim(s, L"\\/ ");
|
||||
pathVector.push_back(s);
|
||||
}
|
||||
pBufSearchPath += pos;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// grepWin - regex search and replace for Windows
|
||||
|
||||
// Copyright (C) 2007-2008, 2010-2022 - Stefan Kueng
|
||||
// Copyright (C) 2007-2008, 2010-2023 - Stefan Kueng
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
@ -178,7 +178,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
|
||||
CCmdLineParser parser(lpCmdLine);
|
||||
|
||||
//MessageBox(NULL, L"", L"", MB_OK);
|
||||
// MessageBox(NULL, L"", L"", MB_OK);
|
||||
|
||||
if (parser.HasKey(L"register"))
|
||||
{
|
||||
@ -253,46 +253,35 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
{
|
||||
bool bOnlyOne = bPortable ? g_iniFile.GetBoolValue(L"global", L"onlyone", L"false") :
|
||||
!!DWORD(CRegStdDWORD(L"Software\\grepWinNP3\\onlyone", 0));
|
||||
bool bCopyData = false;
|
||||
|
||||
//auto searchfor = parser.HasVal(L"searchfor") ? parser.GetVal(L"searchfor") :
|
||||
// (bPortable ? g_iniFile.GetValue(L"global", L"searchfor", L"") : L"");
|
||||
|
||||
auto sPath = parser.HasVal(L"searchpath") ? parser.GetVal(L"searchpath") :
|
||||
(bPortable ? g_iniFile.GetValue(L"global", L"searchpath", L"") : CPathUtils::GetCWD());
|
||||
sPath = SanitizeSearchPaths(sPath);
|
||||
SearchReplace(sPath, L"/", L"\\");
|
||||
sPath = SanitizeSearchPaths(sPath);
|
||||
|
||||
if (SendMessage(hWnd, GREPWIN_STARTUPMSG, 1, 0)) // check if grepWin was started moments ago
|
||||
{
|
||||
SendMessage(hWnd, GREPWIN_STARTUPMSG, 0, 0); // reset the timer
|
||||
bCopyData = true;
|
||||
bQuit = true;
|
||||
}
|
||||
else if (bOnlyOne)
|
||||
{
|
||||
bCopyData = true;
|
||||
bQuit = true;
|
||||
}
|
||||
if (bCopyData) {
|
||||
|
||||
//CopyData_t data2copy = {0};
|
||||
//StringCchCopyW(data2copy.searchFor, _countof(data2copy.searchFor), searchfor.c_str());
|
||||
//StringCchCopyW(data2copy.searchPath, _countof(data2copy.searchPath), sPath.c_str());
|
||||
|
||||
// grepWin was started just moments ago:
|
||||
// add the new path to the existing search path in that grepWin instance
|
||||
std::wstring searchfor = parser.HasVal(L"searchfor") ?
|
||||
parser.GetVal(L"searchfor") :
|
||||
(bPortable ? g_iniFile.GetValue(L"global", L"searchfor", L"") : L"");
|
||||
|
||||
std::wstring sPath = parser.HasVal(L"searchpath") ? parser.GetVal(L"searchpath") :
|
||||
(bPortable ? g_iniFile.GetValue(L"global", L"searchpath", L"") : L"");
|
||||
SearchReplace(sPath, L"/", L"\\");
|
||||
sPath = SanitizeSearchPaths(sPath);
|
||||
|
||||
CopyData_t data2copy = {0};
|
||||
StringCchCopyW(data2copy.searchFor, _countof(data2copy.searchFor), searchfor.c_str());
|
||||
StringCchCopyW(data2copy.searchPath, _countof(data2copy.searchPath), sPath.c_str());
|
||||
|
||||
COPYDATASTRUCT copyData = {0};
|
||||
copyData.lpData = static_cast<LPVOID>(const_cast<LPWSTR>(sPath.c_str()));
|
||||
copyData.cbData = static_cast<DWORD>(sPath.size()) * sizeof(wchar_t);
|
||||
SendMessage(hWnd, WM_COPYDATA, 0, reinterpret_cast<LPARAM>(©Data));
|
||||
SetForegroundWindow(hWnd); //set the window to front
|
||||
SetForegroundWindow(hWnd); // set the window to front
|
||||
bQuit = true;
|
||||
}
|
||||
else if (bOnlyOne)
|
||||
{
|
||||
std::wstring sPath = parser.HasVal(L"searchpath") ? parser.GetVal(L"searchpath") : L"";
|
||||
SearchReplace(sPath, L"/", L"\\");
|
||||
sPath = SanitizeSearchPaths(sPath);
|
||||
COPYDATASTRUCT copyData = {0};
|
||||
copyData.lpData = static_cast<LPVOID>(const_cast<LPWSTR>(sPath.c_str()));
|
||||
copyData.cbData = static_cast<DWORD>(sPath.size()) * sizeof(wchar_t);
|
||||
@ -338,6 +327,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
}
|
||||
else
|
||||
{
|
||||
bool searchPathSet = false;
|
||||
CSearchDlg searchDlg(nullptr);
|
||||
if (parser.HasVal(L"searchini"))
|
||||
{
|
||||
@ -354,6 +344,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
std::wstring sPath = searchIni.GetValue(section.c_str(), L"searchpath");
|
||||
sPath = SanitizeSearchPaths(sPath);
|
||||
searchDlg.SetSearchPath(sPath);
|
||||
searchPathSet = true;
|
||||
}
|
||||
if (searchIni.GetValue(section.c_str(), L"searchfor"))
|
||||
searchDlg.SetSearchString(searchIni.GetValue(section.c_str(), L"searchfor"));
|
||||
@ -448,6 +439,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
(bPortable ? g_iniFile.GetValue(L"global", L"searchpath", L"") : L"");
|
||||
sPath = SanitizeSearchPaths(sPath);
|
||||
searchDlg.SetSearchPath(sPath);
|
||||
searchPathSet = true;
|
||||
}
|
||||
if (parser.HasKey(L"searchfor"))
|
||||
searchDlg.SetSearchString(parser.GetVal(L"searchfor") ? parser.GetVal(L"searchfor") :
|
||||
@ -539,7 +531,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
searchDlg.SetDateLimit(parser.GetLongVal(L"datelimit"), date1, date2);
|
||||
}
|
||||
|
||||
if (!parser.HasKey(L"searchpath"))
|
||||
if (!searchPathSet)
|
||||
{
|
||||
auto cmdLineSize = wcslen(lpCmdLine);
|
||||
auto cmdLinePath = std::make_unique<wchar_t[]>(cmdLineSize + 1);
|
||||
@ -551,6 +543,12 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
sPath = SanitizeSearchPaths(sPath);
|
||||
searchDlg.SetSearchPath(sPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto sPath = CPathUtils::GetCWD();
|
||||
sPath = SanitizeSearchPaths(sPath);
|
||||
searchDlg.SetSearchPath(sPath);
|
||||
}
|
||||
}
|
||||
if (parser.HasKey(L"nosavesettings"))
|
||||
searchDlg.SetNoSaveSettings(true);
|
||||
|
||||
@ -238,7 +238,7 @@
|
||||
#endif // SI_SUPPORT_IOSTREAMS
|
||||
|
||||
#if (defined(_DEBUG) || defined(DEBUG)) && !defined(NDEBUG)
|
||||
#ifndef assert
|
||||
# ifndef assert
|
||||
# include <cassert>
|
||||
# endif
|
||||
# define SI_ASSERT(x) assert(x)
|
||||
@ -256,13 +256,13 @@
|
||||
//constexpr int SI_NOMEM = -2; //!< Out of memory error
|
||||
//constexpr int SI_FILE = -3; //!< File error (see errno for detail error)
|
||||
enum class SI_Error : int {
|
||||
SI_OK = 0, //!< No error
|
||||
SI_UPDATED = 1, //!< An existing value was updated
|
||||
SI_INSERTED = 2, //!< A new value was inserted
|
||||
SI_OK = 0, //!< No error
|
||||
SI_UPDATED = 1, //!< An existing value was updated
|
||||
SI_INSERTED = 2, //!< A new value was inserted
|
||||
// note: test for any error with (retval < 0)
|
||||
SI_FAIL = -1, //!< Generic failure
|
||||
SI_NOMEM = -2, //!< Out of memory error
|
||||
SI_FILE = -3 //!< File error (see errno for detail error)
|
||||
SI_FAIL = -1, //!< Generic failure
|
||||
SI_NOMEM = -2, //!< Out of memory error
|
||||
SI_FILE = -3 //!< File error (see errno for detail error)
|
||||
};
|
||||
|
||||
#define SI_UTF8_SIGNATURE "\xEF\xBB\xBF"
|
||||
@ -2954,10 +2954,10 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::Save(
|
||||
|
||||
// write the value as long
|
||||
if (*iValue->pItem || !m_bAllowKeyOnly) {
|
||||
if (!convert.ConvertToStore(iValue->pItem)) {
|
||||
return SI_Error::SI_FAIL;
|
||||
}
|
||||
a_oOutput.Write(m_bSpaces ? " = " : "=");
|
||||
if (!convert.ConvertToStore(iValue->pItem)) {
|
||||
return SI_Error::SI_FAIL;
|
||||
}
|
||||
a_oOutput.Write(m_bSpaces ? " = " : "=");
|
||||
if (m_bParseQuotes && IsSingleLineQuotedValue(iValue->pItem)) {
|
||||
// the only way to preserve external whitespace on a value (i.e. before or after)
|
||||
// is to quote it. This is simple quoting, we don't escape quotes within the data.
|
||||
@ -2966,21 +2966,21 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::Save(
|
||||
a_oOutput.Write("\"");
|
||||
}
|
||||
else if (m_bAllowMultiLine && IsMultiLineData(iValue->pItem)) {
|
||||
// multi-line data needs to be processed specially to ensure
|
||||
// that we use the correct newline format for the current system
|
||||
a_oOutput.Write("<<<END_OF_TEXT" SI_NEWLINE_A);
|
||||
if (!OutputMultiLineText(a_oOutput, convert, iValue->pItem)) {
|
||||
return SI_Error::SI_FAIL;
|
||||
}
|
||||
a_oOutput.Write("END_OF_TEXT");
|
||||
}
|
||||
else {
|
||||
a_oOutput.Write(convert.Data());
|
||||
// multi-line data needs to be processed specially to ensure
|
||||
// that we use the correct newline format for the current system
|
||||
a_oOutput.Write("<<<END_OF_TEXT" SI_NEWLINE_A);
|
||||
if (!OutputMultiLineText(a_oOutput, convert, iValue->pItem)) {
|
||||
return SI_Error::SI_FAIL;
|
||||
}
|
||||
a_oOutput.Write("END_OF_TEXT");
|
||||
}
|
||||
else {
|
||||
a_oOutput.Write(convert.Data());
|
||||
}
|
||||
}
|
||||
a_oOutput.Write(SI_NEWLINE_A);
|
||||
bNeedNewLine = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//???bNeedNewLine = true;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user