2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-05-29 14:14:08 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-05-29 14:14:08 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-05-29 14:14:08 +02: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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2009-05-29 14:14:08 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-05-29 14:14:08 +02:00
|
|
|
|
|
|
|
|
#include "findincurrentfile.h"
|
2014-09-26 09:14:03 +02:00
|
|
|
#include "texteditor.h"
|
2015-02-26 13:22:35 +01:00
|
|
|
#include "textdocument.h"
|
2009-05-29 14:14:08 +02:00
|
|
|
|
2013-03-26 12:32:52 +01:00
|
|
|
#include <utils/filesearch.h>
|
2015-01-10 23:40:32 +02:00
|
|
|
#include <utils/fileutils.h>
|
2009-05-29 14:14:08 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2013-03-26 15:56:33 +01:00
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2009-05-29 14:14:08 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
2009-05-29 14:14:08 +02:00
|
|
|
|
2010-10-11 11:34:17 +02:00
|
|
|
using namespace TextEditor;
|
2009-05-29 14:14:08 +02:00
|
|
|
using namespace TextEditor::Internal;
|
|
|
|
|
|
2011-09-02 11:51:31 +02:00
|
|
|
FindInCurrentFile::FindInCurrentFile()
|
2009-05-29 14:14:08 +02:00
|
|
|
{
|
2015-12-13 01:18:33 +02:00
|
|
|
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
|
|
|
|
this, &FindInCurrentFile::handleFileChange);
|
2012-05-08 09:43:14 +02:00
|
|
|
handleFileChange(Core::EditorManager::currentEditor());
|
2009-05-29 14:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FindInCurrentFile::id() const
|
|
|
|
|
{
|
2012-01-05 11:05:28 +01:00
|
|
|
return QLatin1String("Current File");
|
2009-05-29 14:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:06:15 +02:00
|
|
|
QString FindInCurrentFile::displayName() const
|
2009-05-29 14:14:08 +02:00
|
|
|
{
|
|
|
|
|
return tr("Current File");
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-13 10:50:57 +01:00
|
|
|
Utils::FileIterator *FindInCurrentFile::files(const QStringList &nameFilters,
|
2016-12-09 13:33:12 +01:00
|
|
|
const QStringList &exclusionFilters,
|
2011-12-13 10:50:57 +01:00
|
|
|
const QVariant &additionalParameters) const
|
2009-05-29 14:14:08 +02:00
|
|
|
{
|
2011-12-13 10:50:57 +01:00
|
|
|
Q_UNUSED(nameFilters)
|
2016-12-09 13:33:12 +01:00
|
|
|
Q_UNUSED(exclusionFilters)
|
2011-12-13 10:50:57 +01:00
|
|
|
QString fileName = additionalParameters.toString();
|
2014-09-22 18:43:31 +02:00
|
|
|
QMap<QString, QTextCodec *> openEditorEncodings = TextDocument::openedTextDocumentEncodings();
|
2010-10-11 11:34:17 +02:00
|
|
|
QTextCodec *codec = openEditorEncodings.value(fileName);
|
|
|
|
|
if (!codec)
|
2013-08-29 15:46:04 +02:00
|
|
|
codec = Core::EditorManager::defaultTextCodec();
|
2019-01-18 20:25:30 +01:00
|
|
|
return new Utils::FileListIterator({fileName}, {codec});
|
2009-05-29 14:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-13 10:50:57 +01:00
|
|
|
QVariant FindInCurrentFile::additionalParameters() const
|
|
|
|
|
{
|
2019-05-27 13:32:20 +02:00
|
|
|
return QVariant::fromValue(m_currentDocument->filePath().toString());
|
2011-12-13 10:50:57 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-07 20:28:04 +02:00
|
|
|
QString FindInCurrentFile::label() const
|
|
|
|
|
{
|
2015-01-10 23:40:32 +02:00
|
|
|
return tr("File \"%1\":").arg(m_currentDocument->filePath().fileName());
|
2011-09-07 20:28:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FindInCurrentFile::toolTip() const
|
|
|
|
|
{
|
2011-09-16 09:28:20 +02:00
|
|
|
// %2 is filled by BaseFileFind::runNewSearch
|
2014-12-21 21:54:30 +02:00
|
|
|
return tr("File path: %1\n%2").arg(m_currentDocument->filePath().toUserOutput());
|
2011-09-07 20:28:04 +02:00
|
|
|
}
|
|
|
|
|
|
2009-05-29 14:14:08 +02:00
|
|
|
bool FindInCurrentFile::isEnabled() const
|
|
|
|
|
{
|
2013-07-04 13:30:26 +02:00
|
|
|
return m_currentDocument && !m_currentDocument->filePath().isEmpty();
|
2009-08-25 12:30:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindInCurrentFile::handleFileChange(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (!editor) {
|
2021-12-08 13:25:25 +01:00
|
|
|
m_currentDocument = nullptr;
|
|
|
|
|
emit enabledChanged(isEnabled());
|
2009-08-25 12:30:47 +02:00
|
|
|
} else {
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::IDocument *document = editor->document();
|
|
|
|
|
if (document != m_currentDocument) {
|
|
|
|
|
m_currentDocument = document;
|
2011-12-14 15:55:05 +01:00
|
|
|
emit enabledChanged(isEnabled());
|
2009-08-25 12:30:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
2009-05-29 14:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-25 12:30:47 +02:00
|
|
|
|
2009-05-29 14:14:08 +02:00
|
|
|
void FindInCurrentFile::writeSettings(QSettings *settings)
|
|
|
|
|
{
|
2012-01-05 11:05:28 +01:00
|
|
|
settings->beginGroup(QLatin1String("FindInCurrentFile"));
|
2009-05-29 14:14:08 +02:00
|
|
|
writeCommonSettings(settings);
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindInCurrentFile::readSettings(QSettings *settings)
|
|
|
|
|
{
|
2012-01-05 11:05:28 +01:00
|
|
|
settings->beginGroup(QLatin1String("FindInCurrentFile"));
|
2016-12-09 13:33:12 +01:00
|
|
|
readCommonSettings(settings, "*", "");
|
2009-05-29 14:14:08 +02:00
|
|
|
settings->endGroup();
|
|
|
|
|
}
|