From 1eb46eaca328b9cb9e8cd3486146bcf55c91ea3f Mon Sep 17 00:00:00 2001 From: donho Date: Fri, 25 Apr 2008 18:34:25 +0000 Subject: [PATCH] [NEW_FEATURE] Add hilite all in Incremental search. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@189 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 39 ++++++++++++++- PowerEditor/src/Notepad_plus.h | 1 + .../src/ScitillaComponent/FindReplaceDlg.cpp | 47 ++++++++++++++++--- .../src/ScitillaComponent/FindReplaceDlg.h | 5 +- .../src/ScitillaComponent/FindReplaceDlg.rc | 7 +-- .../src/ScitillaComponent/FindReplaceDlg_rc.h | 1 + .../ScitillaComponent/ScintillaEditView.cpp | 11 ++++- PowerEditor/src/resource.h | 1 + scintilla/include/SciLexer.h | 2 + 9 files changed, 99 insertions(+), 15 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 466f797a..2e27a074 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -7390,6 +7390,12 @@ 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 : @@ -8295,7 +8301,36 @@ void Notepad_plus::markSelectedText() return; } } - FindOption op; - op._isWholeWord = true; _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/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index dca3b42f..003590a3 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -684,6 +684,7 @@ private: void setFileOpenSaveDlgFilters(FileDialog & fDlg); void reloadOnSwitchBack(); void markSelectedText(); + void markSelectedTextInc(bool enable); bool isQualifiedWord(const char *str) { diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index 2d3f44e5..0c275227 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -963,6 +963,12 @@ int FindReplaceDlg::markAll2(const char *txt2find) return nbFound; } +int FindReplaceDlg::markAllInc(const char *txt2find) +{ + int nbFound = processAll(ProcessMarkAll_IncSearch, txt2find, NULL, true, NULL); + return nbFound; +} + int FindReplaceDlg::processAll(ProcessOperation op, const char *txt2find, const char *txt2replace, bool isEntire, const char *fileName) { int nbReplaced = 0; @@ -1017,8 +1023,13 @@ int FindReplaceDlg::processAll(ProcessOperation op, const char *txt2find, const } bool isRegExp = pOptions->_searchType == FindRegex; - int flags = (op == ProcessMarkAll_2)?SCFIND_WHOLEWORD:Searching::buildSearchFlags(pOptions); - + 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)); @@ -1186,7 +1197,14 @@ int FindReplaceDlg::processAll(ProcessOperation op, const char *txt2find, const startPosition = (direction == DIR_UP)?posFind - foundTextLen:posFind + foundTextLen; break; } + + case ProcessMarkAll_IncSearch: { + (*_ppEditView)->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_FOUND_STYLE_INC); + (*_ppEditView)->execute(SCI_INDICATORFILLRANGE, start, end - start); + startPosition = (direction == DIR_UP)?posFind - foundTextLen:posFind + foundTextLen; + break; } + case ProcessCountAll: { startPosition = posFind + foundTextLen; break; } @@ -1483,6 +1501,7 @@ BOOL CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM return TRUE; case IDC_INCFINDTEXT : + { if (HIWORD(wParam) == EN_CHANGE) { if (_doSearchFromBegin) @@ -1491,17 +1510,33 @@ BOOL CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM 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; + } + 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); + } + return TRUE; } } + case WM_ERASEBKGND: { HWND hParent = ::GetParent(_hSelf); @@ -1513,11 +1548,9 @@ BOOL CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM LRESULT lResult = SendMessage(hParent, WM_ERASEBKGND,(WPARAM)winDC, 0); ::SetWindowOrgEx(winDC, ptOrig.x, ptOrig.y, NULL); return (BOOL)lResult; - break; } - case WM_SIZE: - { - //Handle sizing (resize editbox?) + break; } + case WM_MOVE: { ::InvalidateRect(_hSelf, NULL, TRUE); //when moving, force background redraw diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h index 5a87a45d..1916f9bd 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h @@ -57,7 +57,7 @@ struct TargetRange { }; enum SearchType { FindNormal, FindExtended, FindRegex }; -enum ProcessOperation { ProcessFindAll, ProcessReplaceAll, ProcessCountAll, ProcessMarkAll, ProcessMarkAll_2 }; +enum ProcessOperation { ProcessFindAll, ProcessReplaceAll, ProcessCountAll, ProcessMarkAll, ProcessMarkAll_2, ProcessMarkAll_IncSearch }; struct FindOption { bool _isWholeWord; @@ -237,6 +237,7 @@ public : int markAll(const char *str2find); int markAll2(const char *str2find); + int markAllInc(const char *str2find); int processAll(ProcessOperation op, const char *txt2find, const char *txt2replace, bool isEntire = false, const char *fileName = NULL); void replaceAllInOpenedDocs(); @@ -408,7 +409,7 @@ private : ReBar * _pRebar; REBARBANDINFO _rbBand; - HWND _hEditBox, _hSearchPrev, _hSearchNext, _hCheckCase; + //HWND _hEditBox, _hSearchPrev, _hSearchNext, _hCheckCase, _hCheckHiLiteAll; bool _doSearchFromBegin; virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc index 7e5deb9d..0b59cdeb 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc @@ -79,17 +79,18 @@ BEGIN CONTROL "",IDC_PERCENTAGE_SLIDER,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | NOT WS_VISIBLE | WS_TABSTOP,240,161,53,10 END -IDD_INCREMENT_FIND DIALOGEX 0, 0, 330, 20 +IDD_INCREMENT_FIND DIALOGEX 0, 0, 400, 20 STYLE DS_SYSMODAL | DS_CONTROL | DS_FIXEDSYS | WS_CHILD | WS_CLIPCHILDREN //EXSTYLE WS_EX_TRANSPARENT FONT 8, "MS Shell Dlg" BEGIN PUSHBUTTON "X",IDCANCEL,2,3,16,14 - LTEXT "Find :",IDC_INCSTATIC,20,5,25,12 + RTEXT "Find :",IDC_INCSTATIC,20,6,25,12 EDITTEXT IDC_INCFINDTEXT,45,4,175,12,ES_AUTOHSCROLL | ES_WANTRETURN | NOT WS_BORDER,WS_EX_STATICEDGE PUSHBUTTON "<",IDC_INCFINDPREVOK,223,3,16,14 DEFPUSHBUTTON ">",IDC_INCFINDNXTOK,243,3,16,14 - CONTROL "Match case", IDC_INCFINDMATCHCASE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,270,5,60,12 + CONTROL "Highlight all", IDC_INCFINDHILITEALL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,270,5,65,12 + CONTROL "Match case", IDC_INCFINDMATCHCASE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,335,5,60,12 END IDD_FINDRESULT DIALOGEX 26, 41, 223, 67 diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h index 60961da7..bde4aa2b 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h @@ -63,6 +63,7 @@ #define IDC_INCFINDPREVOK 1683 #define IDC_INCFINDNXTOK 1684 #define IDC_INCFINDMATCHCASE 1685 +#define IDC_INCFINDHILITEALL 1686 #define IDC_TRANSPARENT_CHECK 1686 #define IDC_TRANSPARENT_LOSSFOCUS_RADIO 1687 diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index ed85866a..922ec896 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -113,7 +113,8 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) // smart hilighting execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_FOUND_STYLE_2, INDIC_ROUNDBOX); execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_FOUND_STYLE, INDIC_ROUNDBOX); - + execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_FOUND_STYLE_INC, INDIC_ROUNDBOX); + _pParameter = NppParameters::getInstance(); _codepage = ::GetACP(); @@ -653,6 +654,14 @@ void ScintillaEditView::defineDocType(LangType typeDoc) iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_2); if (iFind != -1) + { + Style & styleFind = stylers.getStyler(iFind); + //setSpecialStyle(styleFind); + setSpecialIndicator(styleFind); + } + + iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_INC); + if (iFind != -1) { Style & styleFind = stylers.getStyler(iFind); //setSpecialStyle(styleFind); diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index 2d8b9078..8963efca 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -284,6 +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) // See Notepad_plus_msgs.h //#define NOTEPADPLUS_USER (WM_USER + 1000) diff --git a/scintilla/include/SciLexer.h b/scintilla/include/SciLexer.h index 41a8579f..0f381802 100644 --- a/scintilla/include/SciLexer.h +++ b/scintilla/include/SciLexer.h @@ -110,6 +110,8 @@ #define SCE_UNIVERSAL_SELECT_STYLE 30 #define SCE_UNIVERSAL_FOUND_STYLE 31 #define SCE_UNIVERSAL_FOUND_STYLE_2 29 +#define SCE_UNIVERSAL_FOUND_STYLE_INC 28 + #define SCE_P_DEFAULT 0 #define SCE_P_COMMENTLINE 1 #define SCE_P_NUMBER 2