allprojectsfind.cpp 5.24 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
#include "allprojectsfind.h"
hjk's avatar
hjk committed
34

con's avatar
con committed
35
#include "project.h"
36
#include "session.h"
hjk's avatar
hjk committed
37
#include "projectexplorer.h"
38
#include "editorconfiguration.h"
hjk's avatar
hjk committed
39
40

#include <utils/qtcassert.h>
41
42
#include <texteditor/itexteditor.h>
#include <coreplugin/editormanager/editormanager.h>
con's avatar
con committed
43

44
#include <QtCore/QSettings>
con's avatar
con committed
45
#include <QtCore/QRegExp>
46

con's avatar
con committed
47
#include <QtGui/QGridLayout>
48
#include <QtGui/QLabel>
49
#include <QtGui/QHBoxLayout>
con's avatar
con committed
50
51
52
53
54
55

using namespace Find;
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
using namespace TextEditor;

56
57
58
AllProjectsFind::AllProjectsFind(ProjectExplorerPlugin *plugin)
    : m_plugin(plugin),
      m_configWidget(0)
con's avatar
con committed
59
60
61
62
{
    connect(m_plugin, SIGNAL(fileListChanged()), this, SIGNAL(changed()));
}

63
64
QString AllProjectsFind::id() const
{
65
    return QLatin1String("All Projects");
66
67
}

68
QString AllProjectsFind::displayName() const
con's avatar
con committed
69
70
71
72
73
74
75
76
77
78
79
{
    return tr("All Projects");
}

bool AllProjectsFind::isEnabled() const
{
    return BaseFileFind::isEnabled()
            && m_plugin->session() != 0
            && m_plugin->session()->projects().count() > 0;
}

80
QList<Project *> AllProjectsFind::projects() const
con's avatar
con committed
81
{
dt's avatar
dt committed
82
    Q_ASSERT(m_plugin->session());
83
84
85
86
87
    return m_plugin->session()->projects();
}

Utils::FileIterator *AllProjectsFind::files() const
{
con's avatar
con committed
88
89
90
91
92
    QList<QRegExp> filterRegs;
    QStringList nameFilters = fileNameFilters();
    foreach (const QString &filter, nameFilters) {
        filterRegs << QRegExp(filter, Qt::CaseInsensitive, QRegExp::Wildcard);
    }
93
94
    QMap<QString, QTextCodec *> openEditorEncodings = TextEditor::ITextEditor::openedTextEditorsEncodings();
    QMap<QString, QTextCodec *> encodings;
95
    foreach (const Project *project, projects()) {
96
97
        QStringList projectFiles = project->files(Project::AllFiles);
        QStringList filteredFiles;
con's avatar
con committed
98
99
100
        if (!filterRegs.isEmpty()) {
            foreach (const QString &file, projectFiles) {
                foreach (const QRegExp &reg, filterRegs) {
101
                    if (reg.exactMatch(file) || reg.exactMatch(QFileInfo(file).fileName())) {
102
                        filteredFiles.append(file);
con's avatar
con committed
103
104
105
106
107
                        break;
                    }
                }
            }
        } else {
108
109
110
111
112
            filteredFiles = projectFiles;
        }
        foreach (const QString &fileName, filteredFiles) {
            QTextCodec *codec = openEditorEncodings.value(fileName);
            if (!codec)
113
                codec = project->editorConfiguration()->textCodec();
114
            encodings.insert(fileName, codec);
con's avatar
con committed
115
116
        }
    }
117
    return new Utils::FileIterator(encodings.keys(), encodings.values());
con's avatar
con committed
118
119
}

120
121
122
123
124
125
126
127
128
129
QString AllProjectsFind::label() const
{
    return tr("All Projects:");
}

QString AllProjectsFind::toolTip() const
{
    return tr("Filter: %1\n%2").arg(fileNameFilters().join(QLatin1String(",")));
}

con's avatar
con committed
130
131
132
133
134
135
136
QWidget *AllProjectsFind::createConfigWidget()
{
    if (!m_configWidget) {
        m_configWidget = new QWidget;
        QGridLayout * const gridLayout = new QGridLayout(m_configWidget);
        gridLayout->setMargin(0);
        m_configWidget->setLayout(gridLayout);
137
        QLabel * const filePatternLabel = new QLabel(tr("File &pattern:"));
con's avatar
con committed
138
139
140
        filePatternLabel->setMinimumWidth(80);
        filePatternLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
        filePatternLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
141
142
        QWidget *patternWidget = createPatternWidget();
        filePatternLabel->setBuddy(patternWidget);
143
144
        gridLayout->addWidget(filePatternLabel, 0, 0, Qt::AlignRight);
        gridLayout->addWidget(patternWidget, 0, 1);
con's avatar
con committed
145
146
147
148
149
150
151
        m_configWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    }
    return m_configWidget;
}

void AllProjectsFind::writeSettings(QSettings *settings)
{
152
    settings->beginGroup(QLatin1String("AllProjectsFind"));
con's avatar
con committed
153
154
155
156
157
158
    writeCommonSettings(settings);
    settings->endGroup();
}

void AllProjectsFind::readSettings(QSettings *settings)
{
159
160
    settings->beginGroup(QLatin1String("AllProjectsFind"));
    readCommonSettings(settings, QString(QLatin1Char('*')));
con's avatar
con committed
161
162
    settings->endGroup();
}