void SearchOpenFiles::doSearchNextFile(int startLine) { if (m_cancelSearch) { m_nextIndex = -1; m_cancelSearch = true; emit searchDone(); return; } // NOTE The document managers signal documentWillBeDeleted() must be connected to // cancelSearch(). A closed file could lead to a crash if it is not handled. int line = searchOpenFile(m_docList[m_nextIndex], m_regExp, startLine); if (line == 0) { // file searched go to next m_nextIndex++; if (m_nextIndex == m_docList.size()) { m_nextIndex = -1; m_cancelSearch = true; emit searchDone(); } else { emit searchNextFile(0); } } else { emit searchNextFile(line); } }
void SearchOpenFiles::startSearch(const QList<KTextEditor::Document*> &list, const QRegExp ®exp) { if (m_nextIndex != -1) return; m_docList = list; m_nextIndex = 0; m_regExp = regexp; m_cancelSearch = false; emit searchNextFile(); }
void SearchOpenFiles::doSearchNextFile() { if (m_cancelSearch) { m_nextIndex = -1; emit searchDone(); return; } int column; // NOTE The document managers signal documentWillBeDeleted() must be connected to // cancelSearch(). A closed file could lead to a crash if it is not handled. for (int line =0; line < m_docList[m_nextIndex]->lines(); line++) { column = m_regExp.indexIn(m_docList[m_nextIndex]->line(line)); while (column != -1) { if (m_docList[m_nextIndex]->url().isLocalFile() ) { emit matchFound(m_docList[m_nextIndex]->url().path(), line, column, m_docList[m_nextIndex]->line(line), m_regExp.matchedLength()); } else { emit matchFound(m_docList[m_nextIndex]->url().prettyUrl(), line, column, m_docList[m_nextIndex]->line(line), m_regExp.matchedLength()); } column = m_regExp.indexIn(m_docList[m_nextIndex]->line(line), column + 1); } } m_nextIndex++; if (m_nextIndex == m_docList.size()) { m_nextIndex = -1; emit searchDone(); } else { emit searchNextFile(); } }
SearchOpenFiles::SearchOpenFiles(QObject *parent) : QObject(parent), m_nextIndex(-1) { connect(this, SIGNAL(searchNextFile()), this, SLOT(doSearchNextFile()), Qt::QueuedConnection); }