[BUG_FIXED] Make Find in files threadless to improve the performance and to avoid the crash.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@360 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
4e51f83fea
commit
c62bfed96c
|
@ -1537,6 +1537,13 @@ void Notepad_plus::getMatchedFileNames(const TCHAR *dir, const vector<generic_st
|
|||
::FindClose(hFile);
|
||||
}
|
||||
|
||||
DWORD WINAPI AsyncCancelFindInFiles(LPVOID NppHWND)
|
||||
{
|
||||
MessageBox((HWND) NULL, TEXT("Searching...\nPress Enter to Cancel"), TEXT("Find In Files"), MB_OK);
|
||||
PostMessage((HWND) NppHWND, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Notepad_plus::findInFiles()
|
||||
{
|
||||
bool isRecursive = _findReplaceDlg.isRecursive();
|
||||
|
@ -1555,6 +1562,9 @@ bool Notepad_plus::findInFiles()
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
HANDLE CancelThreadHandle = ::CreateThread(NULL, 0, AsyncCancelFindInFiles, _hSelf, 0, NULL);
|
||||
|
||||
vector<generic_string> patterns2Match;
|
||||
if (_findReplaceDlg.getFilters() == TEXT(""))
|
||||
_findReplaceDlg.setFindInFilesDirFilter(NULL, TEXT("*.*"));
|
||||
|
@ -1562,24 +1572,20 @@ bool Notepad_plus::findInFiles()
|
|||
vector<generic_string> fileNames;
|
||||
|
||||
_findReplaceDlg.putFindResultStr(TEXT("Scanning files to search..."));
|
||||
//_findReplaceDlg.refresh();
|
||||
_findReplaceDlg.refresh();
|
||||
|
||||
getMatchedFileNames(dir2Search, patterns2Match, fileNames, isRecursive, isInHiddenDir);
|
||||
|
||||
TCHAR msg[128];
|
||||
wsprintf(msg, TEXT("Found %d matching files"), fileNames.size());
|
||||
_findReplaceDlg.putFindResultStr((const TCHAR*)msg);
|
||||
//_findReplaceDlg.refresh();
|
||||
|
||||
//UINT_PTR pTimer = ::SetTimer(_hSelf, 12614, 500, NULL);
|
||||
_findReplaceDlg.refresh();
|
||||
|
||||
bool dontClose = false;
|
||||
for (size_t i = 0 ; i < fileNames.size() ; i++)
|
||||
{
|
||||
if (!_findReplaceDlg.isFindingInFiles())
|
||||
{
|
||||
break;
|
||||
}
|
||||
MSG msg;
|
||||
if (PeekMessage(&msg, _hSelf, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, PM_REMOVE)) break;
|
||||
|
||||
BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str());
|
||||
if (id != BUFFER_INVALID)
|
||||
|
@ -1607,23 +1613,16 @@ bool Notepad_plus::findInFiles()
|
|||
}
|
||||
}
|
||||
|
||||
TerminateThread(CancelThreadHandle, 0);
|
||||
|
||||
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc);
|
||||
_pEditView = pOldView;
|
||||
|
||||
//::KillTimer(_hSelf, pTimer);
|
||||
|
||||
wsprintf(msg, TEXT("%d hits"), nbTotal);
|
||||
_findReplaceDlg.putFindResultStr((const TCHAR *)&msg);
|
||||
//_findReplaceDlg.refresh();
|
||||
_findReplaceDlg.reachEnd();
|
||||
return true;
|
||||
}
|
||||
_findReplaceDlg.refresh();
|
||||
|
||||
DWORD WINAPI AsyncFindInFiles(LPVOID iValue)
|
||||
{
|
||||
Notepad_plus* npp = (Notepad_plus*)iValue;
|
||||
npp->findInFiles();
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Notepad_plus::findInOpenedFiles()
|
||||
|
@ -6778,8 +6777,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
|
|||
|
||||
case WM_FINDINFILES :
|
||||
{
|
||||
DWORD dwTnum;
|
||||
::CreateThread(NULL,0,AsyncFindInFiles, this, 0, &dwTnum);
|
||||
findInFiles();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -7990,12 +7988,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
|
|||
_dockingManager.showDockableDlg((HWND)lParam, SW_SHOW);
|
||||
return TRUE;
|
||||
}
|
||||
/*
|
||||
case WM_TIMER:
|
||||
{
|
||||
_findReplaceDlg.refresh();
|
||||
}
|
||||
*/
|
||||
|
||||
case NPPM_DMMHIDE:
|
||||
{
|
||||
_dockingManager.showDockableDlg((HWND)lParam, SW_HIDE);
|
||||
|
|
|
@ -634,8 +634,6 @@ BOOL CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
|
|||
|
||||
case IDD_FINDINFILES_FIND_BUTTON :
|
||||
{
|
||||
_isFindingInFiles = true;
|
||||
showFindInFilesButton();
|
||||
const int filterSize = 256;
|
||||
TCHAR filters[filterSize];
|
||||
TCHAR directory[MAX_PATH];
|
||||
|
@ -655,13 +653,6 @@ BOOL CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
|
|||
}
|
||||
return TRUE;
|
||||
|
||||
case IDD_FINDINFILES_FINDSTOP_BUTTON :
|
||||
{
|
||||
_isFindingInFiles = false;
|
||||
showFindInFilesButton();
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
case IDC_REPLACE_OPENEDFILES :
|
||||
{
|
||||
if (_currentStatus == REPLACE_DLG)
|
||||
|
@ -1384,21 +1375,18 @@ void FindReplaceDlg::findAllIn(InWhat op)
|
|||
|
||||
::SendMessage(_hParent, (op==ALL_OPEN_DOCS)?WM_FINDALL_INOPENEDDOC:WM_FINDINFILES, 0, 0);
|
||||
|
||||
//refresh();
|
||||
refresh();
|
||||
}
|
||||
|
||||
void FindReplaceDlg::putFindResultStr(const TCHAR *text)
|
||||
{
|
||||
wsprintf(_findAllResultStr, TEXT("%s"), text);
|
||||
::SendMessage(_hParent, NPPM_DMMSHOW, 0, (LPARAM)_pFinder->getHSelf());
|
||||
}
|
||||
|
||||
/*
|
||||
void FindReplaceDlg::refresh()
|
||||
{
|
||||
//::SendMessage(_hParent, NPPM_DMMSHOW, 0, (LPARAM)_pFinder->getHSelf());
|
||||
::SendMessage(_hParent, NPPM_DMMSHOW, 0, (LPARAM)_pFinder->getHSelf());
|
||||
}
|
||||
*/
|
||||
|
||||
void FindReplaceDlg::enableReplaceFunc(bool isEnable)
|
||||
{
|
||||
|
@ -1469,8 +1457,7 @@ void FindReplaceDlg::enableFindInFilesControls(bool isEnable)
|
|||
::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_STATIC), isEnable?SW_SHOW:SW_HIDE);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO), isEnable?SW_SHOW:SW_HIDE);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_BROWSE_BUTTON), isEnable?SW_SHOW:SW_HIDE);
|
||||
//::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_FIND_BUTTON), isEnable?SW_SHOW:SW_HIDE);
|
||||
showFindInFilesButton(isEnable);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_FIND_BUTTON), isEnable?SW_SHOW:SW_HIDE);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_GOBACK_BUTTON), isEnable?SW_SHOW:SW_HIDE);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_RECURSIVE_CHECK), isEnable?SW_SHOW:SW_HIDE);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_INHIDDENDIR_CHECK), isEnable?SW_SHOW:SW_HIDE);
|
||||
|
|
|
@ -192,7 +192,7 @@ class FindReplaceDlg : public StaticDialog
|
|||
friend class FindIncrementDlg;
|
||||
public :
|
||||
FindReplaceDlg() : StaticDialog(), _pFinder(NULL), _isRTL(false), _isRecursive(true),_isInHiddenDir(false),\
|
||||
_fileNameLenMax(1024), _isFindingInFiles(false) {
|
||||
_fileNameLenMax(1024) {
|
||||
_uniFileName = new char[(_fileNameLenMax + 3) * 2];
|
||||
_winVer = (NppParameters::getInstance())->getWinVersion();
|
||||
};
|
||||
|
@ -311,25 +311,6 @@ public :
|
|||
const FindOption & getCurrentOptions() const {return _options;};
|
||||
bool isRecursive() const { return _isRecursive; };
|
||||
bool isInHiddenDir() const { return _isInHiddenDir; };
|
||||
void showFindInFilesButton(bool shouldBeShown = true) {
|
||||
bool fif, fifStop;
|
||||
if (shouldBeShown)
|
||||
{
|
||||
fif = !_isFindingInFiles;
|
||||
fifStop = _isFindingInFiles;
|
||||
}
|
||||
else
|
||||
{
|
||||
fif = fifStop = false;
|
||||
}
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_FIND_BUTTON), fif?SW_SHOW:SW_HIDE);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_FINDSTOP_BUTTON), fifStop?SW_SHOW:SW_HIDE);
|
||||
};
|
||||
bool isFindingInFiles() const {return _isFindingInFiles;};
|
||||
void reachEnd() {
|
||||
_isFindingInFiles = false;
|
||||
showFindInFilesButton();
|
||||
};
|
||||
void saveFindHistory();
|
||||
|
||||
protected :
|
||||
|
@ -345,7 +326,6 @@ private :
|
|||
bool _doMarkLine;
|
||||
bool _doStyleFoundToken;
|
||||
bool _isInSelection;
|
||||
bool _isFindingInFiles;
|
||||
|
||||
|
||||
RECT _findClosePos, _replaceClosePos, _findInFilesClosePos;
|
||||
|
|
|
@ -71,7 +71,6 @@ BEGIN
|
|||
PUSHBUTTON "Replace &All",IDREPLACEALL,217,56,90,14, WS_TABSTOP
|
||||
PUSHBUTTON "Replace all in all opened documents",IDC_REPLACE_OPENEDFILES,217,74,90,21,BS_MULTILINE | WS_TABSTOP
|
||||
PUSHBUTTON "Find them all",IDD_FINDINFILES_FIND_BUTTON,217,20,90,14,WS_GROUP
|
||||
PUSHBUTTON "Stop searching",IDD_FINDINFILES_FINDSTOP_BUTTON,217,20,90,14,WS_GROUP
|
||||
PUSHBUTTON "Close",IDCANCEL,217,99,90,14, WS_TABSTOP
|
||||
|
||||
GROUPBOX "Transparency",IDC_TRANSPARENT_GRPBOX,227,123,83,49
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
#define IDD_FINDINFILES_GOBACK_BUTTON 1657
|
||||
#define IDD_FINDINFILES_RECURSIVE_CHECK 1658
|
||||
#define IDD_FINDINFILES_INHIDDENDIR_CHECK 1659
|
||||
#define IDD_FINDINFILES_FINDSTOP_BUTTON 1660
|
||||
|
||||
#define IDD_FINDRESULT 1670
|
||||
|
||||
|
|
|
@ -297,8 +297,9 @@
|
|||
#define NPPM_INTERNAL_SETCARETBLINKRATE (NOTEPADPLUS_USER_INTERNAL + 19)
|
||||
#define NPPM_INTERNAL_CLEARINDICATORTAGMATCH (NOTEPADPLUS_USER_INTERNAL + 20)
|
||||
#define NPPM_INTERNAL_CLEARINDICATORTAGATTR (NOTEPADPLUS_USER_INTERNAL + 21)
|
||||
#define NPPM_INTERNAL_SWITCHVIEWFROMHWND (NOTEPADPLUS_USER_INTERNAL + 22)
|
||||
#define NPPM_INTERNAL_UPDATETITLEBAR (NOTEPADPLUS_USER_INTERNAL + 23)
|
||||
#define NPPM_INTERNAL_SWITCHVIEWFROMHWND (NOTEPADPLUS_USER_INTERNAL + 22)
|
||||
#define NPPM_INTERNAL_UPDATETITLEBAR (NOTEPADPLUS_USER_INTERNAL + 23)
|
||||
#define NPPM_INTERNAL_CANCEL_FIND_IN_FILES (NOTEPADPLUS_USER_INTERNAL + 24)
|
||||
|
||||
// See Notepad_plus_msgs.h
|
||||
//#define NOTEPADPLUS_USER (WM_USER + 1000)
|
||||
|
|
Loading…
Reference in New Issue