2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "currentprojectfind.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectexplorer.h"
|
2011-09-07 20:28:04 +02:00
|
|
|
#include "project.h"
|
2011-12-13 10:50:57 +01:00
|
|
|
#include "session.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2013-03-26 12:32:52 +01:00
|
|
|
#include <utils/filesearch.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QSettings>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace Find;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
2013-09-05 11:46:07 +02:00
|
|
|
CurrentProjectFind::CurrentProjectFind()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-09-05 11:46:07 +02:00
|
|
|
connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
|
2011-12-14 15:55:05 +01:00
|
|
|
this, SLOT(handleProjectChanged()));
|
2013-09-05 11:46:07 +02:00
|
|
|
connect(SessionManager::instance(), SIGNAL(projectRemoved(ProjectExplorer::Project*)),
|
2013-02-12 18:37:14 +01:00
|
|
|
this, SLOT(handleProjectChanged()));
|
2013-09-05 11:46:07 +02:00
|
|
|
connect(SessionManager::instance(), SIGNAL(projectAdded(ProjectExplorer::Project*)),
|
2013-02-12 18:37:14 +01:00
|
|
|
this, SLOT(handleProjectChanged()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-04-03 15:53:29 +02:00
|
|
|
QString CurrentProjectFind::id() const
|
|
|
|
|
{
|
2010-02-01 12:43:56 +01:00
|
|
|
return QLatin1String("Current Project");
|
2009-04-03 15:53:29 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:06:15 +02:00
|
|
|
QString CurrentProjectFind::displayName() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return tr("Current Project");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CurrentProjectFind::isEnabled() const
|
|
|
|
|
{
|
2012-01-24 18:57:39 +01:00
|
|
|
return ProjectExplorerPlugin::currentProject() != 0 && BaseFileFind::isEnabled();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-12-13 10:50:57 +01:00
|
|
|
QVariant CurrentProjectFind::additionalParameters() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-01-24 18:57:39 +01:00
|
|
|
Project *project = ProjectExplorerPlugin::currentProject();
|
2012-02-14 16:43:51 +01:00
|
|
|
if (project && project->document())
|
2013-07-23 12:30:17 +02:00
|
|
|
return qVariantFromValue(project->projectFilePath());
|
2011-12-13 10:50:57 +01:00
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::FileIterator *CurrentProjectFind::files(const QStringList &nameFilters,
|
|
|
|
|
const QVariant &additionalParameters) const
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(additionalParameters.isValid(), return new Utils::FileIterator());
|
|
|
|
|
QString projectFile = additionalParameters.toString();
|
2013-09-05 11:46:07 +02:00
|
|
|
foreach (Project *project, SessionManager::projects()) {
|
2013-07-23 12:30:17 +02:00
|
|
|
if (project->document() && projectFile == project->projectFilePath())
|
2011-12-13 10:50:57 +01:00
|
|
|
return filesForProjects(nameFilters, QList<Project *>() << project);
|
|
|
|
|
}
|
|
|
|
|
return new Utils::FileIterator();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-07 20:28:04 +02:00
|
|
|
QString CurrentProjectFind::label() const
|
|
|
|
|
{
|
2012-01-24 18:57:39 +01:00
|
|
|
QTC_ASSERT(ProjectExplorerPlugin::currentProject(), return QString());
|
|
|
|
|
return tr("Project '%1':").arg(ProjectExplorerPlugin::currentProject()->displayName());
|
2011-09-07 20:28:04 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-14 15:55:05 +01:00
|
|
|
void CurrentProjectFind::handleProjectChanged()
|
|
|
|
|
{
|
|
|
|
|
emit enabledChanged(isEnabled());
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-12 18:37:14 +01:00
|
|
|
void CurrentProjectFind::recheckEnabled()
|
|
|
|
|
{
|
|
|
|
|
SearchResult *search = qobject_cast<SearchResult *>(sender());
|
|
|
|
|
if (!search)
|
|
|
|
|
return;
|
|
|
|
|
QString projectFile = getAdditionalParameters(search).toString();
|
2013-09-05 11:46:07 +02:00
|
|
|
foreach (Project *project, SessionManager::projects()) {
|
2013-07-23 12:30:17 +02:00
|
|
|
if (projectFile == project->projectFilePath()) {
|
2013-02-12 18:37:14 +01:00
|
|
|
search->setSearchAgainEnabled(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
search->setSearchAgainEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void CurrentProjectFind::writeSettings(QSettings *settings)
|
|
|
|
|
{
|
2010-02-01 12:43:56 +01:00
|
|
|
settings->beginGroup(QLatin1String("CurrentProjectFind"));
|
2008-12-02 12:01:29 +01:00
|
|
|
writeCommonSettings(settings);
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CurrentProjectFind::readSettings(QSettings *settings)
|
|
|
|
|
{
|
2010-02-01 12:43:56 +01:00
|
|
|
settings->beginGroup(QLatin1String("CurrentProjectFind"));
|
|
|
|
|
readCommonSettings(settings, QString(QLatin1Char('*')));
|
2008-12-02 12:01:29 +01:00
|
|
|
settings->endGroup();
|
|
|
|
|
}
|