From ddd055e5a23ef4d1694120489f5a1e55e31794f0 Mon Sep 17 00:00:00 2001 From: donho Date: Tue, 30 Sep 2008 23:02:47 +0000 Subject: [PATCH] [NEW_FEATURE] Find in Files in thread. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@334 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 54 ++++++++++++++++--- PowerEditor/src/Notepad_plus.h | 3 +- PowerEditor/src/Parameters.h | 2 - .../src/ScitillaComponent/FindReplaceDlg.cpp | 19 ++++--- .../src/ScitillaComponent/FindReplaceDlg.h | 17 +++--- 5 files changed, 65 insertions(+), 30 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 858956a7b..b089c52fa 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1525,8 +1525,10 @@ void Notepad_plus::getMatchedFileNames(const TCHAR *dir, const vector fileNames; + + _findReplaceDlg.putFindResultStr(TEXT("Scanning files to search...")); + _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); + bool dontClose = false; for (size_t i = 0 ; i < fileNames.size() ; i++) { BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str()); - if (id != BUFFER_INVALID) { + if (id != BUFFER_INVALID) + { dontClose = true; - } else { + } + else + { id = MainFileManager->loadFile(fileNames.at(i).c_str()); dontClose = false; } - if (id != BUFFER_INVALID) { + + if (id != BUFFER_INVALID) + { Buffer * pBuf = MainFileManager->getBufferByID(id); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); + + generic_string str = TEXT("File: "); + str += fileNames.at(i); + _findReplaceDlg.putFindResultStr(str.c_str()); + nbTotal += _findReplaceDlg.processAll(ProcessFindAll, NULL, NULL, true, fileNames.at(i).c_str()); if (!dontClose) MainFileManager->closeBuffer(id, _pEditView); @@ -1569,11 +1592,22 @@ bool Notepad_plus::findInFiles(bool isRecursive, bool isInHiddenDir) _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); _pEditView = pOldView; + + ::KillTimer(_hSelf, pTimer); - _findReplaceDlg.putFindResult(nbTotal); + wsprintf(msg, TEXT("%d hits"), nbTotal); + _findReplaceDlg.putFindResultStr((const TCHAR *)&msg); + _findReplaceDlg.Refresh(); return true; } +DWORD WINAPI AsyncFindInFiles(LPVOID iValue) +{ + Notepad_plus* npp = (Notepad_plus*)iValue; + npp->findInFiles(); + return 0; +} + bool Notepad_plus::findInOpenedFiles() { int nbTotal = 0; ScintillaEditView *pOldView = _pEditView; @@ -6685,9 +6719,8 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case WM_FINDINFILES : { - bool isRecursive = (lParam & FIND_RECURSIVE) != FALSE; - bool isInHiddenFolder = (lParam & FIND_INHIDDENDIR) != FALSE; - findInFiles(isRecursive, isInHiddenFolder); + DWORD dwTnum; + ::CreateThread(NULL,0,AsyncFindInFiles, this, 0, &dwTnum); return TRUE; } @@ -7828,6 +7861,11 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa return TRUE; } + case WM_TIMER: + { + _findReplaceDlg.Refresh(); + } + case NPPM_DMMHIDE: { _dockingManager.showDockableDlg((HWND)lParam, SW_HIDE); diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 553673bbf..b91bd9f08 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -185,8 +185,8 @@ public: winVer getWinVersion() const {return _winVersion;}; bool emergency(); - void notifyBufferChanged(Buffer * buffer, int mask); + bool findInFiles(); private: static const TCHAR _className[32]; @@ -675,7 +675,6 @@ private: void changeStyleCtrlsLang(HWND hDlg, int *idArray, const TCHAR **translatedText); bool replaceAllFiles(); bool findInOpenedFiles(); - bool findInFiles(bool isRecursive, bool isInHiddenDir); bool matchInList(const TCHAR *fileName, const vector & patterns); void getMatchedFileNames(const TCHAR *dir, const vector & patterns, vector & fileNames, bool isRecursive, bool isInHiddenDir); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 1fe0296a0..41ea7d4f7 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -746,8 +746,6 @@ public : const TCHAR * getName() {return _name.c_str();}; private: - //TCHAR _name[langNameLenMax]; - //TCHAR _ext[extsLenMax]; generic_string _name; generic_string _ext; diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index 191c9d172..b6ee4522c 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -1292,13 +1292,18 @@ void FindReplaceDlg::findAllIn(InWhat op) ::SendMessage(_pFinder->getHSelf(), WM_SIZE, 0, 0); - int finInFileOpt = _isRecursive?FIND_RECURSIVE:0; - if (_isRecursive) - finInFileOpt |= _isInHiddenDir?FIND_INHIDDENDIR:0; - - ::SendMessage(_hParent, (op==ALL_OPEN_DOCS)?WM_FINDALL_INOPENEDDOC:WM_FINDINFILES, 0, (op!=ALL_OPEN_DOCS)?finInFileOpt:0); - //TCHAR *pDataToWrite = _findAllResultStr + lstrlen(FIND_RESULT_DEFAULT_TITLE); - wsprintf(_findAllResultStr, TEXT("%d hits"), _findAllResult); + ::SendMessage(_hParent, (op==ALL_OPEN_DOCS)?WM_FINDALL_INOPENEDDOC:WM_FINDINFILES, 0, 0); + + Refresh(); +} + +void FindReplaceDlg::putFindResultStr(const TCHAR *text) +{ + wsprintf(_findAllResultStr, TEXT("%s"), text); +} + +void FindReplaceDlg::Refresh() +{ ::SendMessage(_hParent, NPPM_DMMSHOW, 0, (LPARAM)_pFinder->getHSelf()); } diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h index f525e5d3b..76caf62e2 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h @@ -193,11 +193,8 @@ friend class FindIncrementDlg; public : FindReplaceDlg() : StaticDialog(), _pFinder(NULL), _isRTL(false), _isRecursive(true),_isInHiddenDir(false),\ _fileNameLenMax(1024) { - //_line = new TCHAR[_maxNbCharAllocated + 3]; - //_uniCharLine = new char[(_maxNbCharAllocated + 3) * 2]; _uniFileName = new char[(_fileNameLenMax + 3) * 2]; _winVer = (NppParameters::getInstance())->getWinVersion(); - //lstrcpy(_findAllResultStr, FIND_RESULT_DEFAULT_TITLE); }; ~FindReplaceDlg() { _tab.destroy(); @@ -275,6 +272,9 @@ public : void putFindResult(int result) { _findAllResult = result; }; + void putFindResultStr(const TCHAR *text); + + void Refresh(); void setSearchWord2Finder(){ generic_string str2Search = getText2search(); @@ -309,6 +309,8 @@ public : const generic_string & getFilters() const {return _filters;}; const generic_string & getDirectory() const {return _directory;}; const FindOption & getCurrentOptions() const {return _options;}; + bool isRecursive() { return _isRecursive; } + bool isInHiddenDir() { return _isInHiddenDir; } protected : virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); @@ -329,22 +331,17 @@ private : ScintillaEditView **_ppEditView; Finder *_pFinder; - //StatusBar _statusBar; bool _isRTL; - //FindInFilesDlg _findInFilesDlg; int _findAllResult; - TCHAR _findAllResultStr[128]; + TCHAR _findAllResultStr[1024]; generic_string _filters; generic_string _directory; bool _isRecursive; bool _isInHiddenDir; - //int _maxNbCharAllocated; int _fileNameLenMax; - //TCHAR *_line; - //char *_uniCharLine; char *_uniFileName; TabBar _tab; @@ -355,8 +352,6 @@ private : void enableFindInFilesFunc() { enableFindInFilesControls(); - //::EnableWindow(::GetDlgItem(_hSelf, IDOK), FALSE); - _currentStatus = FINDINFILES_DLG; gotoCorrectTab(); ::MoveWindow(::GetDlgItem(_hSelf, IDCANCEL), _findInFilesClosePos.left, _findInFilesClosePos.top, _findInFilesClosePos.right, _findInFilesClosePos.bottom, TRUE);