From 36706f13a4d345be8ec156c82618d58c4f4bd6bc Mon Sep 17 00:00:00 2001 From: donho Date: Sat, 26 Apr 2008 03:07:18 +0000 Subject: [PATCH] [NEW_FEATURE] Refine the "HighLight all" feature in incremental search dialog. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@190 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 36 -------- .../src/ScitillaComponent/FindReplaceDlg.cpp | 88 +++++++++++-------- .../src/ScitillaComponent/FindReplaceDlg.h | 5 +- .../ScitillaComponent/ScintillaEditView.cpp | 1 - PowerEditor/src/resource.h | 2 +- 5 files changed, 57 insertions(+), 75 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 2e27a074..8c7904f4 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -7390,12 +7390,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa return _toReduceTabBar?TRUE:FALSE; } - case NPPM_INTERNAL_MARKALL : - { - markSelectedTextInc(bool(wParam)); - return TRUE; - } - // ADD: success->hwnd; failure->NULL // REMOVE: success->NULL; failure->hwnd case NPPM_MODELESSDIALOG : @@ -8304,33 +8298,3 @@ void Notepad_plus::markSelectedText() _findReplaceDlg.markAll2(text2Find); } -void Notepad_plus::markSelectedTextInc(bool enable) -{ - if (!enable) - {//printStr("out"); - _pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_INC); - return; - } - - //Get selection - CharacterRange range = _pEditView->getSelection(); - //Dont mark if the selection has not changed. - if (range.cpMin == _prevSelectedRange.cpMin && range.cpMax == _prevSelectedRange.cpMax) - { - _pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_INC); - return; - } - - //Clear marks - _pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_INC); - - //If nothing selected, dont mark anything - if (range.cpMin == range.cpMax) - { - return; - } - char text2Find[MAX_PATH]; - _pEditView->getSelectedText(text2Find, sizeof(text2Find), false); //do not expand selection (false) - _findReplaceDlg.markAllInc(text2Find); -} - diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index 0c275227..b639a2a1 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -959,17 +959,20 @@ int FindReplaceDlg::markAll(const char *txt2find) int FindReplaceDlg::markAll2(const char *txt2find) { - int nbFound = processAll(ProcessMarkAll_2, txt2find, NULL, true, NULL); + FindOption opt; + opt._isMatchCase = false; + opt._isWholeWord = true; + int nbFound = processAll(ProcessMarkAll_2, txt2find, NULL, true, NULL, &opt); return nbFound; } -int FindReplaceDlg::markAllInc(const char *txt2find) +int FindReplaceDlg::markAllInc(const char *txt2find, FindOption *opt) { - int nbFound = processAll(ProcessMarkAll_IncSearch, txt2find, NULL, true, NULL); + int nbFound = processAll(ProcessMarkAll_IncSearch, txt2find, NULL, true, NULL, opt); return nbFound; } -int FindReplaceDlg::processAll(ProcessOperation op, const char *txt2find, const char *txt2replace, bool isEntire, const char *fileName) +int FindReplaceDlg::processAll(ProcessOperation op, const char *txt2find, const char *txt2replace, bool isEntire, const char *fileName, FindOption *opt) { int nbReplaced = 0; @@ -982,7 +985,7 @@ int FindReplaceDlg::processAll(ProcessOperation op, const char *txt2find, const if (!fileName) fileName = ""; - FindOption *pOptions = &_options; + FindOption *pOptions = opt?opt:&_options; bool isUnicode = (*_ppEditView)->getCurrentBuffer().getUnicodeMode() != uni8Bit; int stringSizeFind = 0; @@ -1024,12 +1027,12 @@ int FindReplaceDlg::processAll(ProcessOperation op, const char *txt2find, const bool isRegExp = pOptions->_searchType == FindRegex; int flags = Searching::buildSearchFlags(pOptions); - +/* if (op == ProcessMarkAll_2) flags = SCFIND_WHOLEWORD; else if (op == ProcessMarkAll_IncSearch) flags ^= SCFIND_WHOLEWORD; - +*/ CharacterRange cr = (*_ppEditView)->getSelection(); int docLength = int((*_ppEditView)->execute(SCI_GETLENGTH)); @@ -1500,37 +1503,33 @@ BOOL CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM } return TRUE; + case IDC_INCFINDMATCHCASE: case IDC_INCFINDTEXT : - { - if (HIWORD(wParam) == EN_CHANGE) - { - if (_doSearchFromBegin) - { - FindOption fo; - fo._isWholeWord = false; - fo._isIncremental = true; - fo._isMatchCase = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDMATCHCASE, BM_GETCHECK, 0, 0)); - bool isHiLieAll = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDHILITEALL, BM_GETCHECK, 0, 0)); - - string str2Search = _pFRDlg->getTextFromCombo(::GetDlgItem(_hSelf, IDC_INCFINDTEXT), isUnicode); - _pFRDlg->processFindNext(str2Search.c_str(), &fo); - - if (isHiLieAll) - { - ::SendMessage(_hParent, NPPM_INTERNAL_MARKALL, TRUE, 0); - } - } - else - _doSearchFromBegin = true; - } - } - return TRUE; - case IDC_INCFINDHILITEALL : { - bool isHiLieAll = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDHILITEALL, BM_GETCHECK, 0, 0)); - //printStr(isHiLieAll?"yes":"no"); - ::SendMessage(_hParent, NPPM_INTERNAL_MARKALL, (BOOL)isHiLieAll, 0); + if (_doSearchFromBegin) + { + FindOption fo; + fo._isWholeWord = false; + fo._isIncremental = true; + fo._isMatchCase = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDMATCHCASE, BM_GETCHECK, 0, 0)); + + string str2Search = _pFRDlg->getTextFromCombo(::GetDlgItem(_hSelf, IDC_INCFINDTEXT), isUnicode); + bool isFound = _pFRDlg->processFindNext(str2Search.c_str(), &fo); + if (!isFound) + { + CharacterRange range = (*(_pFRDlg->_ppEditView))->getSelection(); + (*(_pFRDlg->_ppEditView))->execute(SCI_SETSEL, -1, range.cpMin); + } + + bool isHiLieAll = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDHILITEALL, BM_GETCHECK, 0, 0)); + if (str2Search == "") + isHiLieAll = false; + + markSelectedTextInc(isHiLieAll, &fo); + } + else + _doSearchFromBegin = true; } return TRUE; @@ -1561,6 +1560,25 @@ BOOL CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM return FALSE; } +void FindIncrementDlg::markSelectedTextInc(bool enable, FindOption *opt) +{ + (*(_pFRDlg->_ppEditView))->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_INC); + + if (!enable) + return; + + //Get selection + CharacterRange range = (*(_pFRDlg->_ppEditView))->getSelection(); + + //If nothing selected, dont mark anything + if (range.cpMin == range.cpMax) + return; + + char text2Find[MAX_PATH]; + (*(_pFRDlg->_ppEditView))->getSelectedText(text2Find, sizeof(text2Find), false); //do not expand selection (false) + _pFRDlg->markAllInc(text2Find, opt); +} + void FindIncrementDlg::addToRebar(ReBar * rebar) { if(_pRebar) return; diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h index 1916f9bd..2e88f095 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h @@ -237,9 +237,9 @@ public : int markAll(const char *str2find); int markAll2(const char *str2find); - int markAllInc(const char *str2find); + int markAllInc(const char *str2find, FindOption *opt); - int processAll(ProcessOperation op, const char *txt2find, const char *txt2replace, bool isEntire = false, const char *fileName = NULL); + int processAll(ProcessOperation op, const char *txt2find, const char *txt2replace, bool isEntire = false, const char *fileName = NULL, FindOption *opt = NULL); void replaceAllInOpenedDocs(); void findAllIn(InWhat op); void setSearchText(const char * txt2find, bool isUTF8 = false) { @@ -413,6 +413,7 @@ private : bool _doSearchFromBegin; virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + void markSelectedTextInc(bool enable, FindOption *opt = NULL); }; #endif //FIND_REPLACE_DLG_H diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 922ec896..bd8f56ab 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -684,7 +684,6 @@ void ScintillaEditView::defineDocType(LangType typeDoc) { if (getCurrentBuffer()._unicodeMode == uni8Bit) execute(SCI_SETCODEPAGE, _codepage); - } execute(SCI_SETSTYLEBITS, 5); diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index 8963efca..230df079 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -284,7 +284,7 @@ #define NPPM_INTERNAL_ISTABBARREDUCED (NOTEPADPLUS_USER_INTERNAL + 12) #define NPPM_INTERNAL_ISFOCUSEDTAB (NOTEPADPLUS_USER_INTERNAL + 13) #define NPPM_INTERNAL_GETMENU (NOTEPADPLUS_USER_INTERNAL + 14) - #define NPPM_INTERNAL_MARKALL (NOTEPADPLUS_USER_INTERNAL + 15) + //#define NPPM_INTERNAL_MARKALL (NOTEPADPLUS_USER_INTERNAL + 15) // See Notepad_plus_msgs.h //#define NOTEPADPLUS_USER (WM_USER + 1000)