[ENHANCE] Find dialog always scrolls text into view,
The option where to display text is removed (poor behaviour), view doesnt scroll or scrolls (attempts to) to center, Find dialog shows searched text in messagebox when not found. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@175 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
4a6ca982e1
commit
9a38619187
@ -539,10 +539,6 @@ BOOL CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
|
||||
case IDDIRECTIONUP :
|
||||
case IDDIRECTIONDOWN :
|
||||
_options._whichDirection = (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, IDDIRECTIONDOWN), BM_GETCHECK, BST_CHECKED, 0));
|
||||
::EnableWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_STATIC), (BOOL)(_options._whichDirection == DIR_DOWN));
|
||||
::EnableWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_TOP), (BOOL)(_options._whichDirection == DIR_DOWN));
|
||||
::EnableWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_MIDDLE), (BOOL)(_options._whichDirection == DIR_DOWN));
|
||||
::EnableWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_BOTTOM), (BOOL)(_options._whichDirection == DIR_DOWN));
|
||||
return TRUE;
|
||||
|
||||
case IDC_PURGE_CHECK :
|
||||
@ -680,11 +676,13 @@ bool FindReplaceDlg::processFindNext(const char *txt2find, FindOption *options)
|
||||
int docLength = int((*_ppEditView)->execute(SCI_GETLENGTH));
|
||||
CharacterRange cr = (*_ppEditView)->getSelection();
|
||||
|
||||
//The search "zone" is relative to the selection, so search happens 'outside'
|
||||
int startPosition = cr.cpMax;
|
||||
int endPosition = docLength;
|
||||
|
||||
if (pOptions->_whichDirection == DIR_UP)
|
||||
{
|
||||
//When searching upwards, start is the lower part, end the upper, for backwards search
|
||||
startPosition = cr.cpMin - 1;
|
||||
endPosition = 0;
|
||||
}
|
||||
@ -703,22 +701,12 @@ bool FindReplaceDlg::processFindNext(const char *txt2find, FindOption *options)
|
||||
(*_ppEditView)->execute(SCI_SETTARGETEND, endPosition);
|
||||
(*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags);
|
||||
|
||||
|
||||
//char translatedText[FIND_REPLACE_STR_MAX];
|
||||
|
||||
/*
|
||||
if (_isRegExp)
|
||||
{
|
||||
formatType f = (*_ppEditView)->getCurrentBuffer().getFormat();
|
||||
pText = translate2SlashN(translatedText, f);
|
||||
}
|
||||
*/
|
||||
|
||||
int posFind = int((*_ppEditView)->execute(SCI_SEARCHINTARGET, strlen(pText), (LPARAM)pText));
|
||||
if (posFind == -1) //return;
|
||||
int posFind = int((*_ppEditView)->execute(SCI_SEARCHINTARGET, strlen(pText), (LPARAM)pText));
|
||||
if (posFind == -1) //no match found in target, check if a new target should be used
|
||||
{
|
||||
if (pOptions->_isWrapAround)
|
||||
{
|
||||
//when wrapping, use the rest of the document (entire document is usable)
|
||||
if (pOptions->_whichDirection == DIR_DOWN)
|
||||
{
|
||||
startPosition = 0;
|
||||
@ -730,36 +718,25 @@ bool FindReplaceDlg::processFindNext(const char *txt2find, FindOption *options)
|
||||
endPosition = 0;
|
||||
}
|
||||
|
||||
//new target, search again
|
||||
(*_ppEditView)->execute(SCI_SETTARGETSTART, startPosition);
|
||||
(*_ppEditView)->execute(SCI_SETTARGETEND, endPosition);
|
||||
int posFind = int((*_ppEditView)->execute(SCI_SEARCHINTARGET, strlen(pText), (LPARAM)pText));
|
||||
if (posFind == -1)
|
||||
{
|
||||
if (pOptions->_isIncremental)
|
||||
return false;
|
||||
|
||||
::MessageBox(_hSelf, "Can't find the word", "Find", MB_OK);
|
||||
// if the dialog is not shown, pass the focus to his parent(ie. Notepad++)
|
||||
if (!::IsWindowVisible(_hSelf))
|
||||
::SetFocus((*_ppEditView)->getHSelf());
|
||||
|
||||
return false;
|
||||
}
|
||||
int start = int((*_ppEditView)->execute(SCI_GETTARGETSTART));
|
||||
int end = int((*_ppEditView)->execute(SCI_GETTARGETEND));
|
||||
(*_ppEditView)->execute(SCI_SETSEL, start, end);
|
||||
|
||||
// to make sure the found result is visible
|
||||
int lineno = (*_ppEditView)->getCurrentLineNumber();
|
||||
(*_ppEditView)->execute(SCI_ENSUREVISIBLEENFORCEPOLICY, lineno);
|
||||
posFind = int((*_ppEditView)->execute(SCI_SEARCHINTARGET, strlen(pText), (LPARAM)pText));
|
||||
}
|
||||
else
|
||||
if (posFind == -1)
|
||||
{
|
||||
if (pOptions->_isIncremental)
|
||||
//failed, or failed twice with wrap
|
||||
if (pOptions->_isIncremental) //incremental search doesnt trigger messages
|
||||
return false;
|
||||
|
||||
::MessageBox(_hSelf, "Can't find the word", "Find", MB_OK);
|
||||
|
||||
|
||||
const char stringSize = 12;
|
||||
char message[30 + stringSize + 5]; //message, string, dots
|
||||
strcpy(message, "Can't find the text:\r\n");
|
||||
strncat(message, txt2find, stringSize);
|
||||
if (strlen(txt2find) > stringSize) {
|
||||
strcat(message, "...");
|
||||
}
|
||||
::MessageBox(_hSelf, message, "Find", MB_OK);
|
||||
// if the dialog is not shown, pass the focus to his parent(ie. Notepad++)
|
||||
if (!::IsWindowVisible(_hSelf))
|
||||
::SetFocus((*_ppEditView)->getHSelf());
|
||||
@ -768,30 +745,43 @@ bool FindReplaceDlg::processFindNext(const char *txt2find, FindOption *options)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int start = int((*_ppEditView)->execute(SCI_GETTARGETSTART));
|
||||
int end = int((*_ppEditView)->execute(SCI_GETTARGETEND));
|
||||
|
||||
int displayPos = getDisplayPos();
|
||||
(*_ppEditView)->execute(SCI_SETSEL, start, end);
|
||||
int start = posFind;//int((*_ppEditView)->execute(SCI_GETTARGETSTART));
|
||||
int end = int((*_ppEditView)->execute(SCI_GETTARGETEND));
|
||||
|
||||
// to make sure the found result is visible
|
||||
int lineno = (*_ppEditView)->getCurrentLineNumber();
|
||||
(*_ppEditView)->execute(SCI_ENSUREVISIBLEENFORCEPOLICY, lineno);
|
||||
//When searching up, the beginning of the (possible multiline) result is important, when scrolling down the end
|
||||
int testPos = (_options._whichDirection == DIR_DOWN)?end:start;
|
||||
(*_ppEditView)->execute(SCI_SETCURRENTPOS, testPos);
|
||||
int currentlineNumberDoc = (int)(*_ppEditView)->execute(SCI_LINEFROMPOSITION, testPos);
|
||||
int currentlineNumberVis = (int)(*_ppEditView)->execute(SCI_VISIBLEFROMDOCLINE, currentlineNumberDoc);
|
||||
(*_ppEditView)->execute(SCI_ENSUREVISIBLE, currentlineNumberDoc);
|
||||
|
||||
if ((displayPos != DISPLAY_POS_BOTTOM) && (_options._whichDirection == DIR_DOWN))
|
||||
int firstVisibleLineVis = (int)(*_ppEditView)->execute(SCI_GETFIRSTVISIBLELINE);
|
||||
int linesVisible = (int)(*_ppEditView)->execute(SCI_LINESONSCREEN) - 1; //-1 for the scrollbar
|
||||
int lastVisibleLineVis = (int)linesVisible + firstVisibleLineVis;
|
||||
|
||||
//if out of view vertically, scroll line into (center of) view
|
||||
int linesToScroll = 0;
|
||||
if (currentlineNumberVis < firstVisibleLineVis)
|
||||
{
|
||||
int firstVisibleLine = (*_ppEditView)->execute(EM_GETFIRSTVISIBLELINE);
|
||||
int currentlineNumber = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, posFind);
|
||||
int nbColumn2Scroll;
|
||||
|
||||
if (displayPos == DISPLAY_POS_TOP)
|
||||
nbColumn2Scroll = currentlineNumber-firstVisibleLine;
|
||||
else //(displayPos == DISPLAY_POS_MIDDLE)
|
||||
nbColumn2Scroll = (currentlineNumber-firstVisibleLine)/2;
|
||||
|
||||
(*_ppEditView)->scroll(0, nbColumn2Scroll);
|
||||
linesToScroll = currentlineNumberVis - firstVisibleLineVis;
|
||||
//use center
|
||||
linesToScroll -= linesVisible/2;
|
||||
}
|
||||
else if (currentlineNumberVis > lastVisibleLineVis)
|
||||
{
|
||||
linesToScroll = currentlineNumberVis - lastVisibleLineVis;
|
||||
//use center
|
||||
linesToScroll += linesVisible/2;
|
||||
}
|
||||
(*_ppEditView)->scroll(0, linesToScroll);
|
||||
|
||||
//Make sure the caret is visible, scroll horizontally (this will also fix wrapping problems)
|
||||
(*_ppEditView)->execute(SCI_GOTOPOS, start);
|
||||
(*_ppEditView)->execute(SCI_GOTOPOS, end);
|
||||
//(*_ppEditView)->execute(SCI_SETSEL, start, end);
|
||||
//(*_ppEditView)->execute(SCI_SETCURRENTPOS, end);
|
||||
(*_ppEditView)->execute(SCI_SETANCHOR, start);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1171,10 +1161,6 @@ void FindReplaceDlg::enableReplaceFunc(bool isEnable)
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_PURGE_CHECK),!hideOrShow);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_CLEAR_ALL),!hideOrShow);
|
||||
//::ShowWindow(::GetDlgItem(_hSelf, IDC_FINDINFILES),!hideOrShow);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_STATIC),!hideOrShow);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_TOP),!hideOrShow);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_MIDDLE),!hideOrShow);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_BOTTOM),!hideOrShow);
|
||||
|
||||
gotoCorrectTab();
|
||||
|
||||
@ -1210,11 +1196,6 @@ void FindReplaceDlg::enableFindInFilesControls(bool isEnable)
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_REPLACEINSELECTION), isEnable?SW_HIDE:SW_SHOW);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDREPLACEALL), isEnable?SW_HIDE:SW_SHOW);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_REPLACE_OPENEDFILES), isEnable?SW_HIDE:SW_SHOW);
|
||||
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_STATIC), SW_HIDE);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_TOP), SW_HIDE);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_MIDDLE), SW_HIDE);
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_BOTTOM), SW_HIDE);
|
||||
|
||||
// Show Items
|
||||
::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_FILTERS_STATIC), isEnable?SW_SHOW:SW_HIDE);
|
||||
|
@ -202,7 +202,6 @@ public :
|
||||
_doStyleFoundToken = isCheckedOrNot(IDC_STYLEFOUND_CHECK);
|
||||
|
||||
::EnableWindow(::GetDlgItem(_hSelf, IDCMARKALL), (_doMarkLine || _doStyleFoundToken));
|
||||
::SendMessage(::GetDlgItem(_hSelf, IDC_DISPLAYPOS_BOTTOM), BM_SETCHECK, BST_CHECKED, 0);
|
||||
};
|
||||
|
||||
void doDialog(DIALOG_TYPE whichType, bool isRTL = false) {
|
||||
@ -351,15 +350,6 @@ private :
|
||||
bool isCheckedOrNot(int checkControlID) const {
|
||||
return (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, checkControlID), BM_GETCHECK, 0, 0));
|
||||
};
|
||||
|
||||
int getDisplayPos() const {
|
||||
if (isCheckedOrNot(IDC_DISPLAYPOS_TOP))
|
||||
return DISPLAY_POS_TOP;
|
||||
else if (isCheckedOrNot(IDC_DISPLAYPOS_MIDDLE))
|
||||
return DISPLAY_POS_MIDDLE;
|
||||
else //IDC_DISPLAYPOS_BOTTOM
|
||||
return DISPLAY_POS_BOTTOM;
|
||||
};
|
||||
|
||||
void updateCombos();
|
||||
void updateCombo(int comboID) {
|
||||
|
@ -57,11 +57,7 @@ BEGIN
|
||||
CONTROL "&Up",IDDIRECTIONUP,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,155,94,45,12
|
||||
CONTROL "&Down",IDDIRECTIONDOWN,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,155,106,45,12
|
||||
GROUPBOX "Direction",IDC_DIR_STATIC,150,86,60,34,WS_GROUP
|
||||
CONTROL "Top",IDC_DISPLAYPOS_TOP,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,156,137,28,10
|
||||
CONTROL "Middle",IDC_DISPLAYPOS_MIDDLE,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,156,149,36,10
|
||||
CONTROL "Bottom",IDC_DISPLAYPOS_BOTTOM,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,156,161,39,10
|
||||
GROUPBOX "Display Position",IDC_DISPLAYPOS_STATIC,150,125,60,48
|
||||
|
||||
|
||||
PUSHBUTTON "Find Next",IDOK,217,20,90,14,WS_GROUP | WS_TABSTOP
|
||||
PUSHBUTTON "Count",IDCCOUNTALL,217,38,90,14, WS_TABSTOP
|
||||
PUSHBUTTON "Find all in all opened documents",IDC_FINDALL_OPENEDFILES,217,56,90,21,BS_MULTILINE | WS_TABSTOP
|
||||
|
@ -26,11 +26,6 @@
|
||||
#define IDC_PERCENTAGE_SLIDER 1622
|
||||
#define IDC_TRANSPARENT_GRPBOX 1623
|
||||
|
||||
#define IDC_DISPLAYPOS_STATIC 1624
|
||||
#define IDC_DISPLAYPOS_TOP 1625
|
||||
#define IDC_DISPLAYPOS_MIDDLE 1626
|
||||
#define IDC_DISPLAYPOS_BOTTOM 1627
|
||||
|
||||
#define IDC_FIND_IN_STATIC 1628
|
||||
//#define IDC_CURRENT_FILE_RADIO 1629
|
||||
//#define IDC_OPENED_FILES_RADIO 1630
|
||||
|
Loading…
Reference in New Issue
Block a user