1 | /* |
2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
3 | * |
4 | * This program is free software: you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation, either version 3 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | */ |
17 | #ifndef SEARCHDIALOG_H |
18 | #define SEARCHDIALOG_H |
19 | |
20 | #include <QDialog> |
21 | #include <qsynedit/SynEdit.h> |
22 | #include "../utils.h" |
23 | |
24 | namespace Ui { |
25 | class SearchDialog; |
26 | } |
27 | |
28 | struct SearchResultTreeItem; |
29 | class QTabBar; |
30 | class Editor; |
31 | class SearchDialog : public QDialog |
32 | { |
33 | Q_OBJECT |
34 | |
35 | enum class SearchAction { |
36 | Find, |
37 | FindFiles, |
38 | Replace, |
39 | ReplaceFiles |
40 | }; |
41 | |
42 | public: |
43 | explicit SearchDialog(QWidget *parent = nullptr); |
44 | ~SearchDialog(); |
45 | void find(const QString& text); |
46 | void findNext(); |
47 | void findPrevious(); |
48 | void findInFiles(const QString& text); |
49 | void findInFiles(const QString& keyword, SearchFileScope scope, QSynedit::SearchOptions options); |
50 | void replace(const QString& sFind, const QString& sReplace); |
51 | QSynedit::PSynSearchBase searchEngine() const; |
52 | |
53 | QTabBar *tabBar() const; |
54 | |
55 | private slots: |
56 | void onTabChanged(); |
57 | void on_cbFind_currentTextChanged(const QString &arg1); |
58 | |
59 | void on_btnCancel_clicked(); |
60 | |
61 | void on_btnExecute_clicked(); |
62 | private: |
63 | int execute(QSynedit::SynEdit* editor, const QString& sSearch, |
64 | const QString& sReplace, |
65 | QSynedit::SearchMathedProc matchCallback = nullptr, |
66 | QSynedit::SearchConfirmAroundProc confirmAroundCallback = nullptr); |
67 | std::shared_ptr<SearchResultTreeItem> batchFindInEditor(QSynedit::SynEdit * editor,const QString& filename, const QString& keyword); |
68 | private: |
69 | Ui::SearchDialog *ui; |
70 | QTabBar *mTabBar; |
71 | QSynedit::SearchOptions mSearchOptions; |
72 | QSynedit::PSynSearchBase mSearchEngine; |
73 | QSynedit::PSynSearchBase mBasicSearchEngine; |
74 | QSynedit::PSynSearchBase mRegexSearchEngine; |
75 | |
76 | // QWidget interface |
77 | protected: |
78 | void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; |
79 | }; |
80 | |
81 | #endif // SEARCHDIALOG_H |
82 | |