File indexing completed on 2024-04-28 05:49:12

0001 /*
0002     SPDX-FileCopyrightText: 2011-21 Kåre Särs <kare.sars@iki.fi>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QElapsedTimer>
0010 #include <QObject>
0011 #include <QRegularExpression>
0012 #include <QTimer>
0013 #include <ktexteditor/document.h>
0014 
0015 #include "MatchModel.h"
0016 
0017 class SearchOpenFiles : public QObject
0018 {
0019     Q_OBJECT
0020 
0021 public:
0022     SearchOpenFiles(QObject *parent = nullptr);
0023 
0024     void startSearch(const QList<KTextEditor::Document *> &list, const QRegularExpression &regexp);
0025     bool searching() const;
0026     void terminateSearch();
0027 
0028 public Q_SLOTS:
0029     void cancelSearch();
0030 
0031     /// return 0 on success or a line number where we stopped.
0032     int searchOpenFile(KTextEditor::Document *doc, const QRegularExpression &regExp, int startLine);
0033 
0034 private Q_SLOTS:
0035     void doSearchNextFile(int startLine);
0036 
0037 private:
0038     int searchSingleLineRegExp(KTextEditor::Document *doc, const QRegularExpression &regExp, int startLine);
0039     int searchMultiLineRegExp(KTextEditor::Document *doc, const QRegularExpression &regExp, int startLine);
0040 
0041 Q_SIGNALS:
0042     void matchesFound(const QUrl &url, const QList<KateSearchMatch> &searchMatches, KTextEditor::Document *doc);
0043     void searchDone();
0044     void searching(const QString &file);
0045 
0046 private:
0047     QList<KTextEditor::Document *> m_docList;
0048     int m_nextFileIndex = -1;
0049     QTimer m_nextRunTimer;
0050     int m_nextLine = -1;
0051     QRegularExpression m_regExp;
0052     bool m_cancelSearch = true;
0053     bool m_terminateSearch = false;
0054     QString m_fullDoc;
0055     QList<int> m_lineStart;
0056     QElapsedTimer m_statusTime;
0057 };