Fix bugs with find in (open) files.

Ensure goto line is visible

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@231 f5eea248-9336-0410-98b8-ebc06183d4e3
pull/343/head^2
harrybharry 17 years ago
parent 73a6500e63
commit 26287e2f08

@ -1424,15 +1424,28 @@ bool Notepad_plus::findInFiles(bool isRecursive, bool isInHiddenDir)
vector<string> fileNames; vector<string> fileNames;
getMatchedFileNames(dir2Search, patterns2Match, fileNames, isRecursive, isInHiddenDir); getMatchedFileNames(dir2Search, patterns2Match, fileNames, isRecursive, isInHiddenDir);
bool dontClose = false;
for (size_t i = 0 ; i < fileNames.size() ; i++) for (size_t i = 0 ; i < fileNames.size() ; i++)
{ {
BufferID id = MainFileManager->loadFile(fileNames.at(i).c_str()); BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str());
if (id != BUFFER_INVALID) { if (id != BUFFER_INVALID) {
dontClose = true;
} else {
MainFileManager->loadFile(fileNames.at(i).c_str());
dontClose = false;
}
if (id != BUFFER_INVALID) {
Buffer * pBuf = MainFileManager->getBufferByID(id);
bool oldLex = pBuf->getNeedsLexing();
pBuf->setNeedsLexing(false);
MainFileManager->addBufferReference(id, _pEditView); MainFileManager->addBufferReference(id, _pEditView);
_pEditView->activateBuffer(id); _pEditView->activateBuffer(id);
nbTotal += _findReplaceDlg.processAll(ProcessFindAll, NULL, NULL, true, fileNames.at(i).c_str()); nbTotal += _findReplaceDlg.processAll(ProcessFindAll, NULL, NULL, true, fileNames.at(i).c_str());
_pEditView->activateBuffer(oldBufID); _pEditView->activateBuffer(oldBufID);
MainFileManager->closeBuffer(id, _pEditView); if (!dontClose)
MainFileManager->closeBuffer(id, _pEditView);
else
pBuf->setNeedsLexing(oldLex);
} }
} }
@ -1443,8 +1456,9 @@ bool Notepad_plus::findInFiles(bool isRecursive, bool isInHiddenDir)
bool Notepad_plus::findInOpenedFiles() { bool Notepad_plus::findInOpenedFiles() {
BufferID mainID = _mainEditView.getCurrentBufferID(); BufferID mainID = _mainEditView.getCurrentBufferID();
BufferID subID = _subEditView.getCurrentBufferID();
ScintillaEditView * pOldView = _pEditView; ScintillaEditView * pOldView = _pEditView;
_pEditView = &_mainEditView; Buffer * pBuf = NULL;
int nbTotal = 0; int nbTotal = 0;
const bool isEntireDoc = true; const bool isEntireDoc = true;
@ -1454,30 +1468,39 @@ bool Notepad_plus::findInOpenedFiles() {
_findReplaceDlg.setSearchWord2Finder(); _findReplaceDlg.setSearchWord2Finder();
_pEditView = &_mainEditView;
if (_mainWindowStatus & WindowMainActive) if (_mainWindowStatus & WindowMainActive)
{ {
for (int i = 0 ; i < _mainDocTab.nbItem() ; i++) for (int i = 0 ; i < _mainDocTab.nbItem() ; i++)
{ {
_mainEditView.activateBuffer(_mainDocTab.getBufferByIndex(i)); pBuf = MainFileManager->getBufferByID(_mainDocTab.getBufferByIndex(i));
bool oldStyle = pBuf->getNeedsLexing();
pBuf->setNeedsLexing(false);
_mainEditView.activateBuffer(pBuf->getID());
_mainEditView.execute(SCI_BEGINUNDOACTION); _mainEditView.execute(SCI_BEGINUNDOACTION);
nbTotal += _findReplaceDlg.processAll(ProcessFindAll, NULL, NULL, isEntireDoc, _pEditView->getCurrentBuffer()->getFilePath()); nbTotal += _findReplaceDlg.processAll(ProcessFindAll, NULL, NULL, isEntireDoc, pBuf->getFilePath());
_mainEditView.execute(SCI_ENDUNDOACTION); _mainEditView.execute(SCI_ENDUNDOACTION);
pBuf->setNeedsLexing(oldStyle);
} }
} }
_mainEditView.activateBuffer(mainID);
_pEditView = &_subEditView;
if (_mainWindowStatus & WindowSubActive) if (_mainWindowStatus & WindowSubActive)
{ {
for (int i = 0 ; i < _subDocTab.nbItem() ; i++) for (int i = 0 ; i < _subDocTab.nbItem() ; i++)
{ {
_mainEditView.activateBuffer(_mainDocTab.getBufferByIndex(i)); pBuf = MainFileManager->getBufferByID(_subDocTab.getBufferByIndex(i));
_mainEditView.execute(SCI_BEGINUNDOACTION); bool oldStyle = pBuf->getNeedsLexing();
nbTotal += _findReplaceDlg.processAll(ProcessFindAll, NULL, NULL, isEntireDoc, _pEditView->getCurrentBuffer()->getFilePath()); pBuf->setNeedsLexing(false);
_mainEditView.execute(SCI_ENDUNDOACTION); _subEditView.activateBuffer(pBuf->getID());
_subEditView.execute(SCI_BEGINUNDOACTION);
nbTotal += _findReplaceDlg.processAll(ProcessFindAll, NULL, NULL, isEntireDoc, pBuf->getFilePath());
_subEditView.execute(SCI_ENDUNDOACTION);
pBuf->setNeedsLexing(oldStyle);
} }
} }
_mainEditView.activateBuffer(mainID); _subEditView.activateBuffer(subID);
_pEditView = pOldView; _pEditView = pOldView;

@ -44,10 +44,14 @@ BOOL CALLBACK GoToLineDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara
{ {
display(false); display(false);
cleanLineEdit(); cleanLineEdit();
if (_mode == go2line) if (_mode == go2line) {
(*_ppEditView)->execute(SCI_GOTOLINE, line-1); (*_ppEditView)->execute(SCI_GOTOLINE, line-1);
else (*_ppEditView)->execute(SCI_ENSUREVISIBLE, line-1);
} else {
int sci_line = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, line);
(*_ppEditView)->execute(SCI_GOTOPOS, line); (*_ppEditView)->execute(SCI_GOTOPOS, line);
(*_ppEditView)->execute(SCI_ENSUREVISIBLE, sci_line);
}
} }
(*_ppEditView)->getFocus(); (*_ppEditView)->getFocus();
return TRUE; return TRUE;

Loading…
Cancel
Save