2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "basefilefind.h"
|
2011-12-12 15:16:49 +01:00
|
|
|
#include "basefilefind_p.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-08-09 11:08:01 +02:00
|
|
|
#include <aggregation/aggregate.h>
|
2009-01-21 18:30:45 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2009-01-13 14:16:36 +01:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/progressmanager/futureprogress.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2011-08-09 11:08:01 +02:00
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <find/textfindconstants.h>
|
|
|
|
|
#include <texteditor/itexteditor.h>
|
|
|
|
|
#include <texteditor/basetexteditor.h>
|
2011-10-17 10:37:22 +02:00
|
|
|
#include <texteditor/refactoringchanges.h>
|
2009-07-15 12:38:45 +02:00
|
|
|
#include <utils/stylehelper.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2011-08-09 11:08:01 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDirIterator>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QPair>
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QMainWindow>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QTextBlock>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
using namespace Utils;
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace Find;
|
|
|
|
|
using namespace TextEditor;
|
2011-12-12 15:16:49 +01:00
|
|
|
using namespace TextEditor::Internal;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-09-02 11:51:31 +02:00
|
|
|
BaseFileFind::BaseFileFind()
|
2011-12-12 15:16:49 +01:00
|
|
|
: m_resultLabel(0),
|
2010-07-15 16:40:05 +02:00
|
|
|
m_filterCombo(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-18 14:23:06 +02:00
|
|
|
BaseFileFind::~BaseFileFind()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool BaseFileFind::isEnabled() const
|
|
|
|
|
{
|
2011-12-12 15:16:49 +01:00
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-02 16:13:33 +02:00
|
|
|
void BaseFileFind::cancel()
|
|
|
|
|
{
|
2011-12-12 15:16:49 +01:00
|
|
|
SearchResult *search = qobject_cast<SearchResult *>(sender());
|
|
|
|
|
QTC_ASSERT(search, return);
|
2011-12-14 13:26:33 +01:00
|
|
|
QFutureWatcher<FileSearchResultList> *watcher = m_watchers.key(search);
|
2011-12-12 15:16:49 +01:00
|
|
|
QTC_ASSERT(watcher, return);
|
|
|
|
|
watcher->cancel();
|
2010-09-02 16:13:33 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QStringList BaseFileFind::fileNameFilters() const
|
|
|
|
|
{
|
|
|
|
|
QStringList filters;
|
|
|
|
|
if (m_filterCombo && !m_filterCombo->currentText().isEmpty()) {
|
2010-02-01 12:43:56 +01:00
|
|
|
const QStringList parts = m_filterCombo->currentText().split(QLatin1Char(','));
|
2008-12-02 12:01:29 +01:00
|
|
|
foreach (const QString &part, parts) {
|
2010-02-01 12:43:56 +01:00
|
|
|
const QString filter = part.trimmed();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!filter.isEmpty()) {
|
|
|
|
|
filters << filter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return filters;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-09 11:08:01 +02:00
|
|
|
void BaseFileFind::runNewSearch(const QString &txt, Find::FindFlags findFlags,
|
|
|
|
|
SearchResultWindow::SearchMode searchMode)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-08-09 11:08:01 +02:00
|
|
|
m_currentFindSupport = 0;
|
2009-05-29 14:14:08 +02:00
|
|
|
if (m_filterCombo)
|
2010-05-03 22:20:30 +02:00
|
|
|
updateComboEntries(m_filterCombo, true);
|
2011-12-12 15:16:49 +01:00
|
|
|
SearchResult *search = Find::SearchResultWindow::instance()->startNewSearch(label(),
|
2011-09-09 16:10:57 +02:00
|
|
|
toolTip().arg(Find::IFindFilter::descriptionForFindFlags(findFlags)),
|
|
|
|
|
txt, searchMode, QString::fromLatin1("TextEditor"));
|
2011-12-12 15:16:49 +01:00
|
|
|
search->setTextToReplace(txt);
|
2011-12-13 10:50:57 +01:00
|
|
|
search->setSearchAgainSupported(true);
|
|
|
|
|
FileFindParameters parameters;
|
|
|
|
|
parameters.text = txt;
|
|
|
|
|
parameters.flags = findFlags;
|
|
|
|
|
parameters.nameFilters = fileNameFilters();
|
|
|
|
|
parameters.additionalParameters = additionalParameters();
|
|
|
|
|
search->setUserData(qVariantFromValue(parameters));
|
2011-12-12 15:16:49 +01:00
|
|
|
connect(search, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem)));
|
2011-08-09 11:08:01 +02:00
|
|
|
if (searchMode == SearchResultWindow::SearchAndReplace) {
|
2011-12-12 15:16:49 +01:00
|
|
|
connect(search, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
|
2011-08-09 11:08:01 +02:00
|
|
|
this, SLOT(doReplace(QString,QList<Find::SearchResultItem>)));
|
|
|
|
|
}
|
2011-12-12 15:16:49 +01:00
|
|
|
connect(search, SIGNAL(visibilityChanged(bool)), this, SLOT(hideHighlightAll(bool)));
|
2011-12-13 10:50:57 +01:00
|
|
|
connect(search, SIGNAL(cancelled()), this, SLOT(cancel()));
|
|
|
|
|
connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain()));
|
2011-12-14 15:55:05 +01:00
|
|
|
connect(this, SIGNAL(enabledChanged(bool)), search, SLOT(setSearchAgainEnabled(bool)));
|
2011-12-13 10:50:57 +01:00
|
|
|
runSearch(search);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseFileFind::runSearch(Find::SearchResult *search)
|
|
|
|
|
{
|
|
|
|
|
FileFindParameters parameters = search->userData().value<FileFindParameters>();
|
2011-12-12 15:16:49 +01:00
|
|
|
CountingLabel *label = new CountingLabel;
|
|
|
|
|
connect(search, SIGNAL(countChanged(int)), label, SLOT(updateCount(int)));
|
2011-09-02 11:51:31 +02:00
|
|
|
Find::SearchResultWindow::instance()->popup(true);
|
2011-12-13 10:50:57 +01:00
|
|
|
QFutureWatcher<FileSearchResultList> *watcher = new QFutureWatcher<FileSearchResultList>();
|
|
|
|
|
m_watchers.insert(watcher, search);
|
|
|
|
|
watcher->setPendingResultsLimit(1);
|
|
|
|
|
connect(watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int)));
|
|
|
|
|
connect(watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
|
|
|
|
|
if (parameters.flags & Find::FindRegularExpression) {
|
|
|
|
|
watcher->setFuture(Utils::findInFilesRegExp(parameters.text,
|
|
|
|
|
files(parameters.nameFilters, parameters.additionalParameters),
|
|
|
|
|
textDocumentFlagsForFindFlags(parameters.flags),
|
|
|
|
|
ITextEditor::openedTextEditorsContents()));
|
2010-07-15 15:39:35 +02:00
|
|
|
} else {
|
2011-12-13 10:50:57 +01:00
|
|
|
watcher->setFuture(Utils::findInFiles(parameters.text,
|
|
|
|
|
files(parameters.nameFilters, parameters.additionalParameters),
|
|
|
|
|
textDocumentFlagsForFindFlags(parameters.flags),
|
|
|
|
|
ITextEditor::openedTextEditorsContents()));
|
2010-07-15 15:39:35 +02:00
|
|
|
}
|
2010-01-29 21:33:57 +01:00
|
|
|
Core::FutureProgress *progress =
|
2012-01-24 15:36:40 +01:00
|
|
|
Core::ICore::progressManager()->addTask(watcher->future(),
|
2011-07-25 20:52:07 +02:00
|
|
|
tr("Search"),
|
2012-01-05 11:05:28 +01:00
|
|
|
QLatin1String(Constants::TASK_SEARCH));
|
2011-12-12 15:16:49 +01:00
|
|
|
progress->setWidget(label);
|
2011-09-02 11:51:31 +02:00
|
|
|
connect(progress, SIGNAL(clicked()), Find::SearchResultWindow::instance(), SLOT(popup()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-09 11:08:01 +02:00
|
|
|
void BaseFileFind::findAll(const QString &txt, Find::FindFlags findFlags)
|
|
|
|
|
{
|
|
|
|
|
runNewSearch(txt, findFlags, SearchResultWindow::SearchOnly);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-15 15:39:35 +02:00
|
|
|
void BaseFileFind::replaceAll(const QString &txt, Find::FindFlags findFlags)
|
2009-12-21 11:08:20 +01:00
|
|
|
{
|
2011-08-09 11:08:01 +02:00
|
|
|
runNewSearch(txt, findFlags, SearchResultWindow::SearchAndReplace);
|
2009-12-21 11:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseFileFind::doReplace(const QString &text,
|
|
|
|
|
const QList<Find::SearchResultItem> &items)
|
|
|
|
|
{
|
|
|
|
|
QStringList files = replaceAll(text, items);
|
|
|
|
|
if (!files.isEmpty()) {
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::DocumentManager::notifyFilesChangedInternally(files);
|
2011-09-02 11:51:31 +02:00
|
|
|
Find::SearchResultWindow::instance()->hide();
|
2009-12-21 11:08:20 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void BaseFileFind::displayResult(int index) {
|
2011-12-12 15:16:49 +01:00
|
|
|
QFutureWatcher<FileSearchResultList> *watcher =
|
|
|
|
|
static_cast<QFutureWatcher<FileSearchResultList> *>(sender());
|
|
|
|
|
SearchResult *search = m_watchers.value(watcher);
|
|
|
|
|
if (!search) {
|
|
|
|
|
// search was removed from search history while the search is running
|
|
|
|
|
watcher->cancel();
|
2011-09-09 16:10:57 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2011-12-12 15:16:49 +01:00
|
|
|
Utils::FileSearchResultList results = watcher->resultAt(index);
|
2011-08-09 11:08:01 +02:00
|
|
|
QList<Find::SearchResultItem> items;
|
2010-06-25 09:16:30 +02:00
|
|
|
foreach (const Utils::FileSearchResult &result, results) {
|
|
|
|
|
Find::SearchResultItem item;
|
2010-07-19 14:46:53 +02:00
|
|
|
item.path = QStringList() << QDir::toNativeSeparators(result.fileName);
|
2010-06-25 09:16:30 +02:00
|
|
|
item.lineNumber = result.lineNumber;
|
2010-07-19 14:46:53 +02:00
|
|
|
item.text = result.matchingLine;
|
|
|
|
|
item.textMarkLength = result.matchLength;
|
|
|
|
|
item.textMarkPos = result.matchStart;
|
|
|
|
|
item.useTextEditorFont = true;
|
2010-06-25 09:16:30 +02:00
|
|
|
item.userData = result.regexpCapturedTexts;
|
|
|
|
|
items << item;
|
|
|
|
|
}
|
2011-12-12 15:16:49 +01:00
|
|
|
search->addResults(items, Find::SearchResult::AddOrdered);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseFileFind::searchFinished()
|
|
|
|
|
{
|
2011-12-12 15:16:49 +01:00
|
|
|
QFutureWatcher<FileSearchResultList> *watcher =
|
|
|
|
|
static_cast<QFutureWatcher<FileSearchResultList> *>(sender());
|
|
|
|
|
SearchResult *search = m_watchers.value(watcher);
|
|
|
|
|
if (search)
|
2012-05-16 15:59:16 +02:00
|
|
|
search->finishSearch(watcher->isCanceled());
|
2011-12-12 15:16:49 +01:00
|
|
|
m_watchers.remove(watcher);
|
|
|
|
|
watcher->deleteLater();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *BaseFileFind::createPatternWidget()
|
|
|
|
|
{
|
|
|
|
|
QString filterToolTip = tr("List of comma separated wildcard filters");
|
|
|
|
|
m_filterCombo = new QComboBox;
|
|
|
|
|
m_filterCombo->setEditable(true);
|
|
|
|
|
m_filterCombo->setModel(&m_filterStrings);
|
|
|
|
|
m_filterCombo->setMaxCount(10);
|
|
|
|
|
m_filterCombo->setMinimumContentsLength(10);
|
|
|
|
|
m_filterCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
|
|
|
|
|
m_filterCombo->setInsertPolicy(QComboBox::InsertAtBottom);
|
|
|
|
|
m_filterCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
m_filterCombo->setToolTip(filterToolTip);
|
|
|
|
|
syncComboWithSettings(m_filterCombo, m_filterSetting);
|
|
|
|
|
return m_filterCombo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseFileFind::writeCommonSettings(QSettings *settings)
|
|
|
|
|
{
|
2012-01-05 11:05:28 +01:00
|
|
|
settings->setValue(QLatin1String("filters"), m_filterStrings.stringList());
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_filterCombo)
|
2012-01-05 11:05:28 +01:00
|
|
|
settings->setValue(QLatin1String("currentFilter"), m_filterCombo->currentText());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseFileFind::readCommonSettings(QSettings *settings, const QString &defaultFilter)
|
|
|
|
|
{
|
2012-01-05 11:05:28 +01:00
|
|
|
QStringList filters = settings->value(QLatin1String("filters")).toStringList();
|
|
|
|
|
m_filterSetting = settings->value(QLatin1String("currentFilter")).toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (filters.isEmpty())
|
|
|
|
|
filters << defaultFilter;
|
|
|
|
|
if (m_filterSetting.isEmpty())
|
|
|
|
|
m_filterSetting = filters.first();
|
|
|
|
|
m_filterStrings.setStringList(filters);
|
2009-05-29 14:14:08 +02:00
|
|
|
if (m_filterCombo)
|
|
|
|
|
syncComboWithSettings(m_filterCombo, m_filterSetting);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseFileFind::syncComboWithSettings(QComboBox *combo, const QString &setting)
|
|
|
|
|
{
|
|
|
|
|
if (!combo)
|
|
|
|
|
return;
|
|
|
|
|
int index = combo->findText(setting);
|
|
|
|
|
if (index < 0)
|
|
|
|
|
combo->setEditText(setting);
|
|
|
|
|
else
|
|
|
|
|
combo->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseFileFind::updateComboEntries(QComboBox *combo, bool onTop)
|
|
|
|
|
{
|
|
|
|
|
int index = combo->findText(combo->currentText());
|
|
|
|
|
if (index < 0) {
|
|
|
|
|
if (onTop) {
|
|
|
|
|
combo->insertItem(0, combo->currentText());
|
|
|
|
|
} else {
|
|
|
|
|
combo->addItem(combo->currentText());
|
|
|
|
|
}
|
|
|
|
|
combo->setCurrentIndex(combo->findText(combo->currentText()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-05 16:01:50 +02:00
|
|
|
void BaseFileFind::openEditor(const Find::SearchResultItem &item)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-08-09 11:08:01 +02:00
|
|
|
SearchResult *result = qobject_cast<SearchResult *>(sender());
|
|
|
|
|
Core::IEditor *openedEditor = 0;
|
2010-07-19 14:46:53 +02:00
|
|
|
if (item.path.size() > 0) {
|
2011-08-09 11:08:01 +02:00
|
|
|
openedEditor = TextEditor::BaseTextEditorWidget::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
|
|
|
|
|
item.lineNumber,
|
|
|
|
|
item.textMarkPos,
|
2011-11-10 11:36:51 +01:00
|
|
|
Core::Id(),
|
2011-08-09 11:08:01 +02:00
|
|
|
Core::EditorManager::ModeSwitch);
|
2010-07-19 14:46:53 +02:00
|
|
|
} else {
|
2012-05-08 09:43:14 +02:00
|
|
|
openedEditor = Core::EditorManager::openEditor(QDir::fromNativeSeparators(item.text),
|
|
|
|
|
Core::Id(), Core::EditorManager::ModeSwitch);
|
2011-08-09 11:08:01 +02:00
|
|
|
}
|
|
|
|
|
if (m_currentFindSupport)
|
|
|
|
|
m_currentFindSupport->clearResults();
|
|
|
|
|
m_currentFindSupport = 0;
|
|
|
|
|
if (!openedEditor)
|
|
|
|
|
return;
|
|
|
|
|
// highlight results
|
|
|
|
|
if (IFindSupport *findSupport = Aggregation::query<IFindSupport>(openedEditor->widget())) {
|
|
|
|
|
if (result) {
|
2011-12-13 10:50:57 +01:00
|
|
|
FileFindParameters parameters = result->userData().value<FileFindParameters>();
|
2011-08-09 11:08:01 +02:00
|
|
|
m_currentFindSupport = findSupport;
|
2011-12-13 10:50:57 +01:00
|
|
|
m_currentFindSupport->highlightAll(parameters.text, parameters.flags);
|
2011-08-09 11:08:01 +02:00
|
|
|
}
|
2010-07-19 14:46:53 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-12-21 11:08:20 +01:00
|
|
|
|
2011-08-09 11:08:01 +02:00
|
|
|
void BaseFileFind::hideHighlightAll(bool visible)
|
|
|
|
|
{
|
|
|
|
|
if (!visible && m_currentFindSupport)
|
|
|
|
|
m_currentFindSupport->clearResults();
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-13 10:50:57 +01:00
|
|
|
void BaseFileFind::searchAgain()
|
|
|
|
|
{
|
|
|
|
|
SearchResult *search = qobject_cast<SearchResult *>(sender());
|
2012-02-07 15:44:12 +01:00
|
|
|
search->restart();
|
2011-12-13 10:50:57 +01:00
|
|
|
runSearch(search);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-21 11:08:20 +01:00
|
|
|
QStringList BaseFileFind::replaceAll(const QString &text,
|
|
|
|
|
const QList<Find::SearchResultItem> &items)
|
|
|
|
|
{
|
2010-12-01 13:25:08 +01:00
|
|
|
if (items.isEmpty())
|
2009-12-21 11:08:20 +01:00
|
|
|
return QStringList();
|
|
|
|
|
|
2011-10-17 10:37:22 +02:00
|
|
|
RefactoringChanges refactoring;
|
2009-12-21 11:08:20 +01:00
|
|
|
|
2011-10-17 10:37:22 +02:00
|
|
|
QHash<QString, QList<Find::SearchResultItem> > changes;
|
2009-12-21 11:08:20 +01:00
|
|
|
foreach (const Find::SearchResultItem &item, items)
|
2010-10-19 12:15:36 +02:00
|
|
|
changes[QDir::fromNativeSeparators(item.path.first())].append(item);
|
2009-12-21 11:08:20 +01:00
|
|
|
|
|
|
|
|
QHashIterator<QString, QList<Find::SearchResultItem> > it(changes);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
const QString fileName = it.key();
|
2010-06-11 13:35:22 +10:00
|
|
|
const QList<Find::SearchResultItem> changeItems = it.value();
|
2009-12-21 11:08:20 +01:00
|
|
|
|
2011-10-17 10:37:22 +02:00
|
|
|
ChangeSet changeSet;
|
|
|
|
|
RefactoringFilePtr file = refactoring.file(fileName);
|
|
|
|
|
QSet<QPair<int, int> > processed;
|
|
|
|
|
foreach (const Find::SearchResultItem &item, changeItems) {
|
|
|
|
|
const QPair<int, int> &p = qMakePair(item.lineNumber, item.textMarkPos);
|
|
|
|
|
if (processed.contains(p))
|
|
|
|
|
continue;
|
|
|
|
|
processed.insert(p);
|
|
|
|
|
|
|
|
|
|
QString replacement;
|
|
|
|
|
if (item.userData.canConvert<QStringList>() && !item.userData.toStringList().isEmpty())
|
|
|
|
|
replacement = Utils::expandRegExpReplacement(text, item.userData.toStringList());
|
|
|
|
|
else
|
|
|
|
|
replacement = text;
|
|
|
|
|
|
|
|
|
|
const int start = file->position(item.lineNumber, item.textMarkPos + 1);
|
|
|
|
|
const int end = file->position(item.lineNumber,
|
|
|
|
|
item.textMarkPos + item.textMarkLength + 1);
|
|
|
|
|
changeSet.replace(start, end, replacement);
|
2009-12-21 11:08:20 +01:00
|
|
|
}
|
2011-10-17 10:37:22 +02:00
|
|
|
file->setChangeSet(changeSet);
|
|
|
|
|
file->apply();
|
2009-12-21 11:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return changes.keys();
|
|
|
|
|
}
|
2011-12-12 15:16:49 +01:00
|
|
|
|
|
|
|
|
CountingLabel::CountingLabel()
|
|
|
|
|
{
|
|
|
|
|
setAlignment(Qt::AlignCenter);
|
|
|
|
|
// ### TODO this setup should be done by style
|
|
|
|
|
QFont f = font();
|
|
|
|
|
f.setBold(true);
|
|
|
|
|
f.setPointSizeF(StyleHelper::sidebarFontSize());
|
|
|
|
|
setFont(f);
|
|
|
|
|
setPalette(StyleHelper::sidebarFontPalette(palette()));
|
|
|
|
|
updateCount(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CountingLabel::updateCount(int count)
|
|
|
|
|
{
|
|
|
|
|
setText(tr("%1 found").arg(count));
|
|
|
|
|
}
|