2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-08-02 21:58:39 +08:00
|
|
|
#ifndef SEARCHDIALOG_H
|
|
|
|
#define SEARCHDIALOG_H
|
|
|
|
|
|
|
|
#include <QDialog>
|
2022-09-26 14:54:28 +08:00
|
|
|
#include <qsynedit/SynEdit.h>
|
2021-08-05 19:58:32 +08:00
|
|
|
#include "../utils.h"
|
2021-08-02 21:58:39 +08:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class SearchDialog;
|
|
|
|
}
|
|
|
|
|
2021-08-05 12:31:53 +08:00
|
|
|
struct SearchResultTreeItem;
|
2021-08-02 23:42:10 +08:00
|
|
|
class QTabBar;
|
2021-08-03 23:55:57 +08:00
|
|
|
class Editor;
|
2021-08-02 21:58:39 +08:00
|
|
|
class SearchDialog : public QDialog
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2021-08-03 23:55:57 +08:00
|
|
|
enum class SearchAction {
|
|
|
|
Find,
|
|
|
|
FindFiles,
|
|
|
|
Replace,
|
|
|
|
ReplaceFiles
|
|
|
|
};
|
|
|
|
|
2021-08-02 21:58:39 +08:00
|
|
|
public:
|
|
|
|
explicit SearchDialog(QWidget *parent = nullptr);
|
|
|
|
~SearchDialog();
|
2021-08-02 23:42:10 +08:00
|
|
|
void find(const QString& text);
|
2021-08-04 00:17:38 +08:00
|
|
|
void findNext();
|
|
|
|
void findPrevious();
|
2021-08-02 23:42:10 +08:00
|
|
|
void findInFiles(const QString& text);
|
2022-09-25 09:55:18 +08:00
|
|
|
void findInFiles(const QString& keyword, SearchFileScope scope, QSynedit::SynSearchOptions options);
|
2021-08-02 23:42:10 +08:00
|
|
|
void replace(const QString& sFind, const QString& sReplace);
|
2022-09-25 09:55:18 +08:00
|
|
|
QSynedit::PSynSearchBase searchEngine() const;
|
2021-08-03 23:55:57 +08:00
|
|
|
|
2021-08-04 00:17:38 +08:00
|
|
|
QTabBar *tabBar() const;
|
|
|
|
|
2021-08-02 23:42:10 +08:00
|
|
|
private slots:
|
2021-08-03 23:55:57 +08:00
|
|
|
void onTabChanged();
|
2021-08-02 23:42:10 +08:00
|
|
|
void on_cbFind_currentTextChanged(const QString &arg1);
|
|
|
|
|
|
|
|
void on_btnCancel_clicked();
|
|
|
|
|
|
|
|
void on_btnExecute_clicked();
|
2021-08-03 23:55:57 +08:00
|
|
|
private:
|
2022-09-25 09:55:18 +08:00
|
|
|
int execute(QSynedit::SynEdit* editor, const QString& sSearch,
|
2022-01-24 18:03:35 +08:00
|
|
|
const QString& sReplace,
|
2022-09-25 09:55:18 +08:00
|
|
|
QSynedit::SynSearchMathedProc matchCallback = nullptr,
|
|
|
|
QSynedit::SynSearchConfirmAroundProc confirmAroundCallback = nullptr);
|
|
|
|
std::shared_ptr<SearchResultTreeItem> batchFindInEditor(QSynedit::SynEdit * editor,const QString& filename, const QString& keyword);
|
2021-08-02 21:58:39 +08:00
|
|
|
private:
|
|
|
|
Ui::SearchDialog *ui;
|
2021-08-02 23:42:10 +08:00
|
|
|
QTabBar *mTabBar;
|
2022-09-25 09:55:18 +08:00
|
|
|
QSynedit::SynSearchOptions mSearchOptions;
|
|
|
|
QSynedit::PSynSearchBase mSearchEngine;
|
|
|
|
QSynedit::PSynSearchBase mBasicSearchEngine;
|
|
|
|
QSynedit::PSynSearchBase mRegexSearchEngine;
|
2022-04-11 09:39:44 +08:00
|
|
|
|
|
|
|
// QWidget interface
|
|
|
|
protected:
|
|
|
|
void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
|
2021-08-02 21:58:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SEARCHDIALOG_H
|