basefilefind.h 5.42 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12
13
14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16
17
18
19
20
21
22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
hjk's avatar
hjk committed
25

hjk's avatar
hjk committed
26
#pragma once
con's avatar
con committed
27
28

#include "texteditor_global.h"
Orgad Shaneh's avatar
Orgad Shaneh committed
29
#include "utils/filesearch.h"
con's avatar
con committed
30

31
32
#include <coreplugin/find/ifindfilter.h>
#include <coreplugin/find/searchresultwindow.h>
33

Orgad Shaneh's avatar
Orgad Shaneh committed
34
35
#include <QFuture>

36
37
38
39
40
QT_BEGIN_NAMESPACE
class QLabel;
class QComboBox;
QT_END_NAMESPACE

41
namespace Utils { class FileIterator; }
42
namespace Core {
43
44
class IEditor;
class IFindSupport;
45
class SearchResult;
46
class SearchResultItem;
47
} // namespace Core
con's avatar
con committed
48
49

namespace TextEditor {
Orgad Shaneh's avatar
Orgad Shaneh committed
50

51
52
53
54
namespace Internal {
class BaseFileFindPrivate;
class SearchEnginePrivate;
} // Internal
con's avatar
con committed
55

Orgad Shaneh's avatar
Orgad Shaneh committed
56
57
58
59
60
61
62
class TEXTEDITOR_EXPORT FileFindParameters
{
public:
    QString text;
    Core::FindFlags flags;
    QStringList nameFilters;
    QVariant additionalParameters;
63
64
    int searchEngineIndex;
    QVariant searchEngineParameters;
65
66
};

67
68
69
class BaseFileFind;

class TEXTEDITOR_EXPORT SearchEngine : public QObject
70
{
71
    Q_OBJECT
72
public:
73
74
    SearchEngine();
    ~SearchEngine();
75
    virtual QString title() const = 0;
76
    virtual QString toolTip() const = 0; // add %1 placeholder where the find flags should be put
77
78
79
80
81
    virtual QWidget *widget() const = 0;
    virtual QVariant parameters() const = 0;
    virtual void readSettings(QSettings *settings) = 0;
    virtual void writeSettings(QSettings *settings) const = 0;
    virtual QFuture<Utils::FileSearchResultList> executeSearch(
82
            const FileFindParameters &parameters, BaseFileFind *baseFileFind) = 0;
83
84
    virtual Core::IEditor *openEditor(const Core::SearchResultItem &item,
                                      const FileFindParameters &parameters) = 0;
85
86
87
88
89
    bool isEnabled() const;
    void setEnabled(bool enabled);

signals:
    void enabledChanged(bool enabled);
90

91
92
private:
    Internal::SearchEnginePrivate *d;
Orgad Shaneh's avatar
Orgad Shaneh committed
93
94
};

95
class TEXTEDITOR_EXPORT BaseFileFind : public Core::IFindFilter
con's avatar
con committed
96
97
98
99
{
    Q_OBJECT

public:
Eike Ziller's avatar
Eike Ziller committed
100
    BaseFileFind();
101
    ~BaseFileFind();
con's avatar
con committed
102
103

    bool isEnabled() const;
104
    bool isReplaceSupported() const { return true; }
105
106
    void findAll(const QString &txt, Core::FindFlags findFlags);
    void replaceAll(const QString &txt, Core::FindFlags findFlags);
107
    void addSearchEngine(SearchEngine *searchEngine);
con's avatar
con committed
108

109
110
    /* returns the list of unique files that were passed in items */
    static QStringList replaceAll(const QString &txt,
111
                                  const QList<Core::SearchResultItem> &items,
112
                                  bool preserveCase = false);
113
114
    virtual Utils::FileIterator *files(const QStringList &nameFilters,
                                       const QVariant &additionalParameters) const = 0;
115
116

protected:
117
    virtual QVariant additionalParameters() const = 0;
118
119
120
    QVariant getAdditionalParameters(Core::SearchResult *search);
    virtual QString label() const = 0; // see Core::SearchResultWindow::startNewSearch
    virtual QString toolTip() const = 0; // see Core::SearchResultWindow::startNewSearch,
121
                                         // add %1 placeholder where the find flags should be put
122
    QFuture<Utils::FileSearchResultList> executeSearch(const FileFindParameters &parameters);
123

con's avatar
con committed
124
125
126
127
128
129
    void writeCommonSettings(QSettings *settings);
    void readCommonSettings(QSettings *settings, const QString &defaultFilter);
    QWidget *createPatternWidget();
    void syncComboWithSettings(QComboBox *combo, const QString &setting);
    void updateComboEntries(QComboBox *combo, bool onTop);
    QStringList fileNameFilters() const;
130
131
132
133
134

    SearchEngine *currentSearchEngine() const;
    QVector<SearchEngine *> searchEngines() const;
    void setCurrentSearchEngine(int index);
    virtual void syncSearchEngineCombo(int /*selectedSearchEngineIndex*/) {}
con's avatar
con committed
135

136
137
138
signals:
    void currentSearchEngineChanged();

139
private:
con's avatar
con committed
140
141
    void displayResult(int index);
    void searchFinished();
142
    void cancel();
143
    void setPaused(bool paused);
144
    void openEditor(const Core::SearchResultItem &item);
145
    void doReplace(const QString &txt,
146
                   const QList<Core::SearchResultItem> &items,
147
                   bool preserveCase);
148
    void hideHighlightAll(bool visible);
149
    void searchAgain();
150
    void recheckEnabled();
con's avatar
con committed
151

152
153
154
    void runNewSearch(const QString &txt, Core::FindFlags findFlags,
                      Core::SearchResultWindow::SearchMode searchMode);
    void runSearch(Core::SearchResult *search);
con's avatar
con committed
155

156
    Internal::BaseFileFindPrivate *d;
con's avatar
con committed
157
158
159
160
};

} // namespace TextEditor

Orgad Shaneh's avatar
Orgad Shaneh committed
161
Q_DECLARE_METATYPE(TextEditor::FileFindParameters)