mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-23 13:54:54 +02:00
Make FindInFiles progress window behave like modal
This commit is contained in:
parent
4409277180
commit
df7ddabff0
@ -1458,7 +1458,7 @@ bool Notepad_plus::replaceInFiles()
|
|||||||
{
|
{
|
||||||
if (filesCount >= 200)
|
if (filesCount >= 200)
|
||||||
filesPerPercent = filesCount / 100;
|
filesPerPercent = filesCount / 100;
|
||||||
progress.open(NULL, TEXT("Replace In Files progress..."));
|
progress.open(_findReplaceDlg.getHSelf(), TEXT("Replace In Files progress..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0, updateOnCount = filesPerPercent; i < filesCount; ++i)
|
for (size_t i = 0, updateOnCount = filesPerPercent; i < filesCount; ++i)
|
||||||
@ -1496,6 +1496,7 @@ bool Notepad_plus::replaceInFiles()
|
|||||||
{
|
{
|
||||||
updateOnCount += filesPerPercent;
|
updateOnCount += filesPerPercent;
|
||||||
progress.setPercent((i * 100) / filesCount, fileNames.at(i).c_str());
|
progress.setPercent((i * 100) / filesCount, fileNames.at(i).c_str());
|
||||||
|
progress.flushCallerUserInput();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1504,6 +1505,7 @@ bool Notepad_plus::replaceInFiles()
|
|||||||
}
|
}
|
||||||
|
|
||||||
progress.close();
|
progress.close();
|
||||||
|
progress.flushCallerUserInput();
|
||||||
|
|
||||||
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc);
|
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc);
|
||||||
_invisibleEditView.setCurrentBuffer(oldBuf);
|
_invisibleEditView.setCurrentBuffer(oldBuf);
|
||||||
@ -1553,7 +1555,7 @@ bool Notepad_plus::findInFiles()
|
|||||||
{
|
{
|
||||||
if (filesCount >= 200)
|
if (filesCount >= 200)
|
||||||
filesPerPercent = filesCount / 100;
|
filesPerPercent = filesCount / 100;
|
||||||
progress.open(NULL, TEXT("Find In Files progress..."));
|
progress.open(_findReplaceDlg.getHSelf(), TEXT("Find In Files progress..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0, updateOnCount = filesPerPercent; i < filesCount; ++i)
|
for (size_t i = 0, updateOnCount = filesPerPercent; i < filesCount; ++i)
|
||||||
@ -1583,6 +1585,7 @@ bool Notepad_plus::findInFiles()
|
|||||||
{
|
{
|
||||||
updateOnCount += filesPerPercent;
|
updateOnCount += filesPerPercent;
|
||||||
progress.setPercent((i * 100) / filesCount, fileNames.at(i).c_str());
|
progress.setPercent((i * 100) / filesCount, fileNames.at(i).c_str());
|
||||||
|
progress.flushCallerUserInput();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1591,6 +1594,7 @@ bool Notepad_plus::findInFiles()
|
|||||||
}
|
}
|
||||||
|
|
||||||
progress.close();
|
progress.close();
|
||||||
|
progress.flushCallerUserInput();
|
||||||
|
|
||||||
_findReplaceDlg.finishFilesSearch(nbTotal);
|
_findReplaceDlg.finishFilesSearch(nbTotal);
|
||||||
|
|
||||||
|
@ -2917,7 +2917,7 @@ const int Progress::cBTNheight = 25;
|
|||||||
volatile LONG Progress::refCount = 0;
|
volatile LONG Progress::refCount = 0;
|
||||||
|
|
||||||
|
|
||||||
Progress::Progress(HINSTANCE hInst) : _hwnd(NULL)
|
Progress::Progress(HINSTANCE hInst) : _hwnd(NULL), _hCallerWnd(NULL)
|
||||||
{
|
{
|
||||||
if (::InterlockedIncrement(&refCount) == 1)
|
if (::InterlockedIncrement(&refCount) == 1)
|
||||||
{
|
{
|
||||||
@ -2955,23 +2955,26 @@ Progress::~Progress()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HWND Progress::open(HWND hOwner, const TCHAR* header)
|
HWND Progress::open(HWND hCallerWnd, const TCHAR* header)
|
||||||
{
|
{
|
||||||
if (_hwnd)
|
if (_hwnd)
|
||||||
return _hwnd;
|
return _hwnd;
|
||||||
|
|
||||||
_hOwner = hOwner;
|
|
||||||
|
|
||||||
if (header)
|
|
||||||
_tcscpy_s(_header, _countof(_header), header);
|
|
||||||
else
|
|
||||||
_tcscpy_s(_header, _countof(_header), cDefaultHeader);
|
|
||||||
|
|
||||||
// Create manually reset non-signaled event
|
// Create manually reset non-signaled event
|
||||||
_hActiveState = ::CreateEvent(NULL, TRUE, FALSE, NULL);
|
_hActiveState = ::CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||||
if (!_hActiveState)
|
if (!_hActiveState)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
_hCallerWnd = hCallerWnd;
|
||||||
|
|
||||||
|
for (HWND hwnd = _hCallerWnd; hwnd; hwnd = ::GetParent(hwnd))
|
||||||
|
::UpdateWindow(hwnd);
|
||||||
|
|
||||||
|
if (header)
|
||||||
|
_tcscpy_s(_header, _countof(_header), header);
|
||||||
|
else
|
||||||
|
_tcscpy_s(_header, _countof(_header), cDefaultHeader);
|
||||||
|
|
||||||
_hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadFunc,
|
_hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadFunc,
|
||||||
(LPVOID)this, 0, NULL);
|
(LPVOID)this, 0, NULL);
|
||||||
if (!_hThread)
|
if (!_hThread)
|
||||||
@ -2995,24 +2998,6 @@ HWND Progress::open(HWND hOwner, const TCHAR* header)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Progress::isCancelled() const
|
|
||||||
{
|
|
||||||
if (_hwnd)
|
|
||||||
return (::WaitForSingleObject(_hActiveState, 0) != WAIT_OBJECT_0);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Progress::setPercent(unsigned percent, const TCHAR *fileName) const
|
|
||||||
{
|
|
||||||
if (_hwnd)
|
|
||||||
{
|
|
||||||
::SendNotifyMessage(_hPBar, PBM_SETPOS, (WPARAM)percent, 0);
|
|
||||||
::SendMessage(_hPText, WM_SETTEXT, 0, (LPARAM)fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Progress::close()
|
void Progress::close()
|
||||||
{
|
{
|
||||||
if (_hwnd)
|
if (_hwnd)
|
||||||
@ -3020,12 +3005,37 @@ void Progress::close()
|
|||||||
::SendMessage(_hwnd, WM_CLOSE, 0, 0);
|
::SendMessage(_hwnd, WM_CLOSE, 0, 0);
|
||||||
_hwnd = NULL;
|
_hwnd = NULL;
|
||||||
::WaitForSingleObject(_hThread, INFINITE);
|
::WaitForSingleObject(_hThread, INFINITE);
|
||||||
|
|
||||||
::CloseHandle(_hThread);
|
::CloseHandle(_hThread);
|
||||||
::CloseHandle(_hActiveState);
|
::CloseHandle(_hActiveState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Progress::setPercent(unsigned percent, const TCHAR *fileName) const
|
||||||
|
{
|
||||||
|
if (_hwnd)
|
||||||
|
{
|
||||||
|
::PostMessage(_hPBar, PBM_SETPOS, (WPARAM)percent, 0);
|
||||||
|
::SendMessage(_hPText, WM_SETTEXT, 0, (LPARAM)fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Progress::flushCallerUserInput() const
|
||||||
|
{
|
||||||
|
MSG msg;
|
||||||
|
for (HWND hwnd = _hCallerWnd; hwnd; hwnd = ::GetParent(hwnd))
|
||||||
|
{
|
||||||
|
if (::PeekMessage(&msg, hwnd, 0, 0, PM_QS_INPUT | PM_REMOVE))
|
||||||
|
{
|
||||||
|
while (::PeekMessage(&msg, hwnd, 0, 0, PM_QS_INPUT | PM_REMOVE));
|
||||||
|
::UpdateWindow(hwnd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DWORD Progress::threadFunc(LPVOID data)
|
DWORD Progress::threadFunc(LPVOID data)
|
||||||
{
|
{
|
||||||
Progress* pw = static_cast<Progress*>(data);
|
Progress* pw = static_cast<Progress*>(data);
|
||||||
@ -3054,14 +3064,11 @@ int Progress::thread()
|
|||||||
|
|
||||||
int Progress::createProgressWindow()
|
int Progress::createProgressWindow()
|
||||||
{
|
{
|
||||||
DWORD styleEx = WS_EX_OVERLAPPEDWINDOW;
|
_hwnd = ::CreateWindowEx(
|
||||||
if (_hOwner)
|
WS_EX_TOOLWINDOW | WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST,
|
||||||
styleEx |= WS_EX_TOOLWINDOW;
|
|
||||||
|
|
||||||
_hwnd = ::CreateWindowEx(styleEx,
|
|
||||||
cClassName, _header, WS_POPUP | WS_CAPTION,
|
cClassName, _header, WS_POPUP | WS_CAPTION,
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||||
_hOwner, NULL, _hInst, (LPVOID)this);
|
NULL, NULL, _hInst, (LPVOID)this);
|
||||||
if (!_hwnd)
|
if (!_hwnd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -3094,7 +3101,6 @@ int Progress::createProgressWindow()
|
|||||||
(width - cBTNwidth) / 2, height - cBTNheight - 5,
|
(width - cBTNwidth) / 2, height - cBTNheight - 5,
|
||||||
cBTNwidth, cBTNheight, _hwnd, NULL, _hInst, NULL);
|
cBTNwidth, cBTNheight, _hwnd, NULL, _hInst, NULL);
|
||||||
|
|
||||||
|
|
||||||
if (hf)
|
if (hf)
|
||||||
::SendMessage(_hBtn, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0));
|
::SendMessage(_hBtn, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0));
|
||||||
|
|
||||||
|
@ -410,15 +410,24 @@ public:
|
|||||||
Progress(HINSTANCE hInst);
|
Progress(HINSTANCE hInst);
|
||||||
~Progress();
|
~Progress();
|
||||||
|
|
||||||
HWND open(HWND hOwner = NULL, const TCHAR* header = NULL);
|
HWND open(HWND hCallerWnd = NULL, const TCHAR* header = NULL);
|
||||||
bool isCancelled() const;
|
void close();
|
||||||
void setPercent(unsigned percent, const TCHAR *fileName) const;
|
|
||||||
void setInfo(const TCHAR *info) const {
|
bool isCancelled() const
|
||||||
|
{
|
||||||
|
if (_hwnd)
|
||||||
|
return (::WaitForSingleObject(_hActiveState, 0) != WAIT_OBJECT_0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setInfo(const TCHAR *info) const
|
||||||
|
{
|
||||||
if (_hwnd)
|
if (_hwnd)
|
||||||
::SendMessage(_hPText, WM_SETTEXT, 0, (LPARAM)info);
|
::SendMessage(_hPText, WM_SETTEXT, 0, (LPARAM)info);
|
||||||
};
|
}
|
||||||
|
|
||||||
void close();
|
void setPercent(unsigned percent, const TCHAR *fileName) const;
|
||||||
|
void flushCallerUserInput() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const TCHAR cClassName[];
|
static const TCHAR cClassName[];
|
||||||
@ -444,7 +453,7 @@ private:
|
|||||||
|
|
||||||
HINSTANCE _hInst;
|
HINSTANCE _hInst;
|
||||||
volatile HWND _hwnd;
|
volatile HWND _hwnd;
|
||||||
HWND _hOwner;
|
HWND _hCallerWnd;
|
||||||
TCHAR _header[128];
|
TCHAR _header[128];
|
||||||
HANDLE _hThread;
|
HANDLE _hThread;
|
||||||
HANDLE _hActiveState;
|
HANDLE _hActiveState;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user