2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-01-23 11:49:14 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2012-01-23 11:49:14 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-01-23 11:49:14 +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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2012-01-23 11:49:14 +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
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2012-01-23 11:49:14 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-01-23 11:49:14 +01:00
|
|
|
|
|
|
|
|
#include "findinopenfiles.h"
|
2014-09-26 09:14:03 +02:00
|
|
|
#include "textdocument.h"
|
|
|
|
|
#include "texteditor.h"
|
2012-01-23 11:49:14 +01:00
|
|
|
|
2013-03-26 12:32:52 +01:00
|
|
|
#include <utils/filesearch.h>
|
2012-01-23 11:49:14 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2013-07-05 16:08:38 +02:00
|
|
|
#include <coreplugin/editormanager/documentmodel.h>
|
2012-01-23 11:49:14 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
2012-01-23 11:49:14 +01:00
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
using namespace TextEditor::Internal;
|
|
|
|
|
|
|
|
|
|
FindInOpenFiles::FindInOpenFiles()
|
|
|
|
|
{
|
2015-12-13 01:18:33 +02:00
|
|
|
connect(Core::EditorManager::instance(), &Core::EditorManager::editorOpened,
|
|
|
|
|
this, &FindInOpenFiles::updateEnabledState);
|
|
|
|
|
connect(Core::EditorManager::instance(), &Core::EditorManager::editorsClosed,
|
|
|
|
|
this, &FindInOpenFiles::updateEnabledState);
|
2012-01-23 11:49:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FindInOpenFiles::id() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("Open Files");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FindInOpenFiles::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return tr("Open Documents");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::FileIterator *FindInOpenFiles::files(const QStringList &nameFilters,
|
|
|
|
|
const QVariant &additionalParameters) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(nameFilters)
|
|
|
|
|
Q_UNUSED(additionalParameters)
|
2014-01-14 10:16:57 +01:00
|
|
|
QMap<QString, QTextCodec *> openEditorEncodings
|
2014-09-22 18:43:31 +02:00
|
|
|
= TextDocument::openedTextDocumentEncodings();
|
2012-01-23 11:49:14 +01:00
|
|
|
QStringList fileNames;
|
|
|
|
|
QList<QTextCodec *> codecs;
|
2013-07-05 16:08:38 +02:00
|
|
|
foreach (Core::DocumentModel::Entry *entry,
|
2014-06-13 16:21:25 +02:00
|
|
|
Core::DocumentModel::entries()) {
|
2015-02-15 15:57:21 +02:00
|
|
|
QString fileName = entry->fileName().toString();
|
2012-01-23 11:49:14 +01:00
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
|
fileNames.append(fileName);
|
|
|
|
|
QTextCodec *codec = openEditorEncodings.value(fileName);
|
|
|
|
|
if (!codec)
|
2013-08-29 15:46:04 +02:00
|
|
|
codec = Core::EditorManager::defaultTextCodec();
|
2012-01-23 11:49:14 +01:00
|
|
|
codecs.append(codec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 15:19:42 +01:00
|
|
|
return new Utils::FileListIterator(fileNames, codecs);
|
2012-01-23 11:49:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant FindInOpenFiles::additionalParameters() const
|
|
|
|
|
{
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FindInOpenFiles::label() const
|
|
|
|
|
{
|
2012-10-01 10:18:23 +02:00
|
|
|
return tr("Open documents:");
|
2012-01-23 11:49:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FindInOpenFiles::toolTip() const
|
|
|
|
|
{
|
|
|
|
|
// %1 is filled by BaseFileFind::runNewSearch
|
|
|
|
|
return tr("Open Documents\n%1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FindInOpenFiles::isEnabled() const
|
|
|
|
|
{
|
2014-06-13 16:21:25 +02:00
|
|
|
return Core::DocumentModel::entryCount() > 0;
|
2012-01-23 11:49:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindInOpenFiles::writeSettings(QSettings *settings)
|
|
|
|
|
{
|
|
|
|
|
settings->beginGroup(QLatin1String("FindInOpenFiles"));
|
|
|
|
|
writeCommonSettings(settings);
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindInOpenFiles::readSettings(QSettings *settings)
|
|
|
|
|
{
|
|
|
|
|
settings->beginGroup(QLatin1String("FindInOpenFiles"));
|
|
|
|
|
readCommonSettings(settings, QLatin1String("*"));
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindInOpenFiles::updateEnabledState()
|
|
|
|
|
{
|
|
|
|
|
emit enabledChanged(isEnabled());
|
|
|
|
|
}
|