basefilefind.h 3.78 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
hjk's avatar
hjk committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
hjk's avatar
hjk committed
32

con's avatar
con committed
33
34
35
36
37
38
#ifndef BASEFILEFIND_H
#define BASEFILEFIND_H

#include "texteditor_global.h"

#include <find/ifindfilter.h>
39
#include <find/searchresultwindow.h>
con's avatar
con committed
40
41
#include <utils/filesearch.h>

42
43
#include <QtGui/QStringListModel>

con's avatar
con committed
44
45
#include <QtCore/QFutureWatcher>
#include <QtCore/QPointer>
46
47
48
49
50
51

QT_BEGIN_NAMESPACE
class QLabel;
class QComboBox;
QT_END_NAMESPACE

52
53
54
namespace Utils {
class FileIterator;
}
55
namespace Find {
56
struct SearchResultItem;
57
class IFindSupport;
58
}
con's avatar
con committed
59
60
61
62
63
64
65
66

namespace TextEditor {

class TEXTEDITOR_EXPORT BaseFileFind : public Find::IFindFilter
{
    Q_OBJECT

public:
Eike Ziller's avatar
Eike Ziller committed
67
    BaseFileFind();
68
    ~BaseFileFind();
con's avatar
con committed
69
70

    bool isEnabled() const;
dt's avatar
dt committed
71
72
    bool canCancel() const;
    void cancel();
73
    bool isReplaceSupported() const { return true; }
74
75
    void findAll(const QString &txt, Find::FindFlags findFlags);
    void replaceAll(const QString &txt, Find::FindFlags findFlags);
con's avatar
con committed
76

77
78
79
    /* returns the list of unique files that were passed in items */
    static QStringList replaceAll(const QString &txt,
                                  const QList<Find::SearchResultItem> &items);
80

con's avatar
con committed
81
protected:
82
    virtual Utils::FileIterator *files() const = 0;
83
84
85
86
    virtual QString label() const = 0; // see Find::SearchResult::setInfo
    virtual QString toolTip() const = 0; // see Find::SearchResult::setInfo,
                                         // add %1 placeholder where the find flags should be put

con's avatar
con committed
87
88
89
90
91
92
93
94
95
96
    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;

private slots:
    void displayResult(int index);
    void searchFinished();
97
    void openEditor(const Find::SearchResultItem &item);
98
99
    void doReplace(const QString &txt,
                    const QList<Find::SearchResultItem> &items);
100
    void hideHighlightAll(bool visible);
con's avatar
con committed
101
102
103

private:
    QWidget *createProgressWidget();
104
105
    void runNewSearch(const QString &txt, Find::FindFlags findFlags,
                      Find::SearchResultWindow::SearchMode searchMode);
con's avatar
con committed
106

107
108
    Find::SearchResult *m_currentSearch;
    int m_currentSearchCount;
109

110
    QFutureWatcher<Utils::FileSearchResultList> m_watcher;
con's avatar
con committed
111
    bool m_isSearching;
112
113
    QPointer<Find::IFindSupport> m_currentFindSupport;

con's avatar
con committed
114
115
116
117
118
119
120
121
122
    QLabel *m_resultLabel;
    QStringListModel m_filterStrings;
    QString m_filterSetting;
    QPointer<QComboBox> m_filterCombo;
};

} // namespace TextEditor

#endif // BASEFILEFIND_H