2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 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 "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>
|
2012-10-15 11:53:22 +02:00
|
|
|
#include <coreplugin/dialogs/readonlyfilesdialog.h>
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2014-01-13 16:17:34 +01:00
|
|
|
#include <coreplugin/find/ifindsupport.h>
|
2014-07-23 19:10:38 +02:00
|
|
|
#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-08-09 11:08:01 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2013-03-26 12:32:52 +01:00
|
|
|
#include <utils/filesearch.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QPair>
|
2013-03-26 12:32:52 +01:00
|
|
|
#include <QStringListModel>
|
|
|
|
|
#include <QFutureWatcher>
|
|
|
|
|
#include <QPointer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QComboBox>
|
2013-03-26 12:32:52 +01:00
|
|
|
#include <QLabel>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QLabel>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-03-26 12:32:52 +01:00
|
|
|
namespace TextEditor {
|
|
|
|
|
namespace Internal {
|
2014-01-13 16:17:34 +01:00
|
|
|
|
|
|
|
|
class BaseFileFindPrivate
|
|
|
|
|
{
|
2013-03-26 12:32:52 +01:00
|
|
|
public:
|
|
|
|
|
BaseFileFindPrivate() : m_resultLabel(0), m_filterCombo(0) {}
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
QMap<QFutureWatcher<Utils::FileSearchResultList> *, QPointer<Core::SearchResult> > m_watchers;
|
|
|
|
|
QPointer<Core::IFindSupport> m_currentFindSupport;
|
2013-03-26 12:32:52 +01:00
|
|
|
|
|
|
|
|
QLabel *m_resultLabel;
|
|
|
|
|
QStringListModel m_filterStrings;
|
|
|
|
|
QString m_filterSetting;
|
|
|
|
|
QPointer<QComboBox> m_filterCombo;
|
|
|
|
|
};
|
2014-01-13 16:17:34 +01:00
|
|
|
|
2013-03-26 12:32:52 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
using namespace Internal;
|
2009-10-05 11:06:05 +02:00
|
|
|
using namespace Utils;
|
2014-01-13 16:17:34 +01:00
|
|
|
using namespace Core;
|
2013-03-26 12:32:52 +01:00
|
|
|
|
|
|
|
|
BaseFileFind::BaseFileFind() : d(new BaseFileFindPrivate)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-18 14:23:06 +02:00
|
|
|
BaseFileFind::~BaseFileFind()
|
|
|
|
|
{
|
2013-03-26 12:32:52 +01:00
|
|
|
delete d;
|
2011-08-18 14:23:06 +02:00
|
|
|
}
|
|
|
|
|
|
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);
|
2013-03-26 12:32:52 +01:00
|
|
|
QFutureWatcher<FileSearchResultList> *watcher = d->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
|
|
|
}
|
|
|
|
|
|
2012-05-25 16:45:18 +02:00
|
|
|
void BaseFileFind::setPaused(bool paused)
|
|
|
|
|
{
|
|
|
|
|
SearchResult *search = qobject_cast<SearchResult *>(sender());
|
|
|
|
|
QTC_ASSERT(search, return);
|
2013-03-26 12:32:52 +01:00
|
|
|
QFutureWatcher<FileSearchResultList> *watcher = d->m_watchers.key(search);
|
2012-05-25 16:45:18 +02:00
|
|
|
QTC_ASSERT(watcher, return);
|
|
|
|
|
if (!paused || watcher->isRunning()) // guard against pausing when the search is finished
|
|
|
|
|
watcher->setPaused(paused);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QStringList BaseFileFind::fileNameFilters() const
|
|
|
|
|
{
|
|
|
|
|
QStringList filters;
|
2013-03-26 12:32:52 +01:00
|
|
|
if (d->m_filterCombo && !d->m_filterCombo->currentText().isEmpty()) {
|
|
|
|
|
const QStringList parts = d->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();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!filter.isEmpty())
|
2008-12-02 12:01:29 +01:00
|
|
|
filters << filter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return filters;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
void BaseFileFind::runNewSearch(const QString &txt, Core::FindFlags findFlags,
|
2011-08-09 11:08:01 +02:00
|
|
|
SearchResultWindow::SearchMode searchMode)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-03-26 12:32:52 +01:00
|
|
|
d->m_currentFindSupport = 0;
|
|
|
|
|
if (d->m_filterCombo)
|
|
|
|
|
updateComboEntries(d->m_filterCombo, true);
|
2014-01-13 16:17:34 +01:00
|
|
|
SearchResult *search = Core::SearchResultWindow::instance()->startNewSearch(label(),
|
|
|
|
|
toolTip().arg(Core::IFindFilter::descriptionForFindFlags(findFlags)),
|
2014-03-11 16:06:33 -03:00
|
|
|
txt, searchMode, Core::SearchResultWindow::PreserveCaseEnabled,
|
|
|
|
|
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));
|
2014-01-13 16:17:34 +01:00
|
|
|
connect(search, SIGNAL(activated(Core::SearchResultItem)), this, SLOT(openEditor(Core::SearchResultItem)));
|
2011-08-09 11:08:01 +02:00
|
|
|
if (searchMode == SearchResultWindow::SearchAndReplace) {
|
2014-01-13 16:17:34 +01:00
|
|
|
connect(search, SIGNAL(replaceButtonClicked(QString,QList<Core::SearchResultItem>,bool)),
|
|
|
|
|
this, SLOT(doReplace(QString,QList<Core::SearchResultItem>,bool)));
|
2011-08-09 11:08:01 +02:00
|
|
|
}
|
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()));
|
2012-05-25 16:45:18 +02:00
|
|
|
connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool)));
|
2011-12-13 10:50:57 +01:00
|
|
|
connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain()));
|
2013-02-12 18:37:14 +01:00
|
|
|
connect(this, SIGNAL(enabledChanged(bool)), search, SIGNAL(requestEnabledCheck()));
|
|
|
|
|
connect(search, SIGNAL(requestEnabledCheck()), this, SLOT(recheckEnabled()));
|
|
|
|
|
|
2011-12-13 10:50:57 +01:00
|
|
|
runSearch(search);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
void BaseFileFind::runSearch(Core::SearchResult *search)
|
2011-12-13 10:50:57 +01:00
|
|
|
{
|
|
|
|
|
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)));
|
2013-04-08 15:02:30 +02:00
|
|
|
CountingLabel *statusLabel = new CountingLabel;
|
|
|
|
|
connect(search, SIGNAL(countChanged(int)), statusLabel, SLOT(updateCount(int)));
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::SearchResultWindow::instance()->popup(IOutputPane::Flags(IOutputPane::ModeSwitch|IOutputPane::WithFocus));
|
2011-12-13 10:50:57 +01:00
|
|
|
QFutureWatcher<FileSearchResultList> *watcher = new QFutureWatcher<FileSearchResultList>();
|
2013-03-26 12:32:52 +01:00
|
|
|
d->m_watchers.insert(watcher, search);
|
2011-12-13 10:50:57 +01:00
|
|
|
watcher->setPendingResultsLimit(1);
|
|
|
|
|
connect(watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int)));
|
|
|
|
|
connect(watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
|
2014-01-13 16:17:34 +01:00
|
|
|
if (parameters.flags & FindRegularExpression) {
|
2011-12-13 10:50:57 +01:00
|
|
|
watcher->setFuture(Utils::findInFilesRegExp(parameters.text,
|
|
|
|
|
files(parameters.nameFilters, parameters.additionalParameters),
|
|
|
|
|
textDocumentFlagsForFindFlags(parameters.flags),
|
2014-09-22 18:43:31 +02:00
|
|
|
TextDocument::openedTextDocumentContents()));
|
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),
|
2014-09-22 18:43:31 +02:00
|
|
|
TextDocument::openedTextDocumentContents()));
|
2010-07-15 15:39:35 +02:00
|
|
|
}
|
2013-09-03 15:18:37 +02:00
|
|
|
FutureProgress *progress =
|
2014-04-17 15:14:14 +02:00
|
|
|
ProgressManager::addTask(watcher->future(), tr("Searching"), Constants::TASK_SEARCH);
|
2013-09-03 15:18:37 +02:00
|
|
|
progress->setWidget(label);
|
2013-04-08 15:02:30 +02:00
|
|
|
progress->setStatusBarWidget(statusLabel);
|
2012-05-25 16:45:18 +02:00
|
|
|
connect(progress, SIGNAL(clicked()), search, SLOT(popup()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
void BaseFileFind::findAll(const QString &txt, Core::FindFlags findFlags)
|
2011-08-09 11:08:01 +02:00
|
|
|
{
|
|
|
|
|
runNewSearch(txt, findFlags, SearchResultWindow::SearchOnly);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
void BaseFileFind::replaceAll(const QString &txt, Core::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,
|
2014-01-13 16:17:34 +01:00
|
|
|
const QList<Core::SearchResultItem> &items,
|
2012-11-30 16:15:07 +01:00
|
|
|
bool preserveCase)
|
2009-12-21 11:08:20 +01:00
|
|
|
{
|
2012-11-30 16:15:07 +01:00
|
|
|
QStringList files = replaceAll(text, items, preserveCase);
|
2009-12-21 11:08:20 +01:00
|
|
|
if (!files.isEmpty()) {
|
2013-08-30 09:22:42 +02:00
|
|
|
DocumentManager::notifyFilesChangedInternally(files);
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::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());
|
2013-03-26 12:32:52 +01:00
|
|
|
SearchResult *search = d->m_watchers.value(watcher);
|
2011-12-12 15:16:49 +01:00
|
|
|
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);
|
2014-01-13 16:17:34 +01:00
|
|
|
QList<Core::SearchResultItem> items;
|
2010-06-25 09:16:30 +02:00
|
|
|
foreach (const Utils::FileSearchResult &result, results) {
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::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;
|
|
|
|
|
}
|
2014-01-13 16:17:34 +01:00
|
|
|
search->addResults(items, Core::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());
|
2013-03-26 12:32:52 +01:00
|
|
|
SearchResult *search = d->m_watchers.value(watcher);
|
2011-12-12 15:16:49 +01:00
|
|
|
if (search)
|
2012-05-16 15:59:16 +02:00
|
|
|
search->finishSearch(watcher->isCanceled());
|
2013-03-26 12:32:52 +01:00
|
|
|
d->m_watchers.remove(watcher);
|
2011-12-12 15:16:49 +01:00
|
|
|
watcher->deleteLater();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *BaseFileFind::createPatternWidget()
|
|
|
|
|
{
|
|
|
|
|
QString filterToolTip = tr("List of comma separated wildcard filters");
|
2013-03-26 12:32:52 +01:00
|
|
|
d->m_filterCombo = new QComboBox;
|
|
|
|
|
d->m_filterCombo->setEditable(true);
|
|
|
|
|
d->m_filterCombo->setModel(&d->m_filterStrings);
|
|
|
|
|
d->m_filterCombo->setMaxCount(10);
|
|
|
|
|
d->m_filterCombo->setMinimumContentsLength(10);
|
|
|
|
|
d->m_filterCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
|
|
|
|
|
d->m_filterCombo->setInsertPolicy(QComboBox::InsertAtBottom);
|
|
|
|
|
d->m_filterCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
d->m_filterCombo->setToolTip(filterToolTip);
|
|
|
|
|
syncComboWithSettings(d->m_filterCombo, d->m_filterSetting);
|
|
|
|
|
return d->m_filterCombo;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseFileFind::writeCommonSettings(QSettings *settings)
|
|
|
|
|
{
|
2013-03-26 12:32:52 +01:00
|
|
|
settings->setValue(QLatin1String("filters"), d->m_filterStrings.stringList());
|
|
|
|
|
if (d->m_filterCombo)
|
|
|
|
|
settings->setValue(QLatin1String("currentFilter"), d->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();
|
2013-03-26 12:32:52 +01:00
|
|
|
d->m_filterSetting = settings->value(QLatin1String("currentFilter")).toString();
|
2008-12-02 12:01:29 +01:00
|
|
|
if (filters.isEmpty())
|
|
|
|
|
filters << defaultFilter;
|
2013-03-26 12:32:52 +01:00
|
|
|
if (d->m_filterSetting.isEmpty())
|
|
|
|
|
d->m_filterSetting = filters.first();
|
|
|
|
|
d->m_filterStrings.setStringList(filters);
|
|
|
|
|
if (d->m_filterCombo)
|
|
|
|
|
syncComboWithSettings(d->m_filterCombo, d->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) {
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (onTop)
|
2008-12-02 12:01:29 +01:00
|
|
|
combo->insertItem(0, combo->currentText());
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2008-12-02 12:01:29 +01:00
|
|
|
combo->addItem(combo->currentText());
|
|
|
|
|
combo->setCurrentIndex(combo->findText(combo->currentText()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
void BaseFileFind::openEditor(const Core::SearchResultItem &item)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-08-09 11:08:01 +02:00
|
|
|
SearchResult *result = qobject_cast<SearchResult *>(sender());
|
2013-08-30 09:22:42 +02:00
|
|
|
IEditor *openedEditor = 0;
|
2010-07-19 14:46:53 +02:00
|
|
|
if (item.path.size() > 0) {
|
2013-08-30 09:22:42 +02:00
|
|
|
openedEditor = EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
|
2013-05-30 17:26:51 +02:00
|
|
|
item.lineNumber,
|
2013-05-31 12:52:53 +02:00
|
|
|
item.textMarkPos);
|
2010-07-19 14:46:53 +02:00
|
|
|
} else {
|
2013-08-30 09:22:42 +02:00
|
|
|
openedEditor = EditorManager::openEditor(QDir::fromNativeSeparators(item.text));
|
2011-08-09 11:08:01 +02:00
|
|
|
}
|
2013-03-26 12:32:52 +01:00
|
|
|
if (d->m_currentFindSupport)
|
2014-07-02 13:43:31 +02:00
|
|
|
d->m_currentFindSupport->clearHighlights();
|
2013-03-26 12:32:52 +01:00
|
|
|
d->m_currentFindSupport = 0;
|
2011-08-09 11:08:01 +02:00
|
|
|
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>();
|
2013-03-26 12:32:52 +01:00
|
|
|
d->m_currentFindSupport = findSupport;
|
|
|
|
|
d->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)
|
|
|
|
|
{
|
2013-03-26 12:32:52 +01:00
|
|
|
if (!visible && d->m_currentFindSupport)
|
2014-07-02 13:43:31 +02:00
|
|
|
d->m_currentFindSupport->clearHighlights();
|
2011-08-09 11:08:01 +02:00
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-12 18:37:14 +01:00
|
|
|
void BaseFileFind::recheckEnabled()
|
|
|
|
|
{
|
|
|
|
|
SearchResult *search = qobject_cast<SearchResult *>(sender());
|
|
|
|
|
if (!search)
|
|
|
|
|
return;
|
|
|
|
|
search->setSearchAgainEnabled(isEnabled());
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-21 11:08:20 +01:00
|
|
|
QStringList BaseFileFind::replaceAll(const QString &text,
|
2014-01-13 16:17:34 +01:00
|
|
|
const QList<Core::SearchResultItem> &items,
|
2012-11-30 16:15:07 +01:00
|
|
|
bool preserveCase)
|
2009-12-21 11:08:20 +01:00
|
|
|
{
|
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
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
QHash<QString, QList<Core::SearchResultItem> > changes;
|
|
|
|
|
foreach (const Core::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
|
|
|
|
2012-10-15 11:53:22 +02:00
|
|
|
// Checking for files without write permissions
|
2014-01-13 16:17:34 +01:00
|
|
|
QHashIterator<QString, QList<Core::SearchResultItem> > it(changes);
|
2012-10-15 11:53:22 +02:00
|
|
|
QSet<QString> roFiles;
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
const QFileInfo fileInfo(it.key());
|
|
|
|
|
if (!fileInfo.isWritable())
|
|
|
|
|
roFiles.insert(it.key());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Query the user for permissions
|
|
|
|
|
if (!roFiles.isEmpty()) {
|
2013-09-20 23:17:22 +02:00
|
|
|
Core::Internal::ReadOnlyFilesDialog roDialog(roFiles.toList(), ICore::mainWindow());
|
2012-10-15 11:53:22 +02:00
|
|
|
roDialog.setShowFailWarning(true, tr("Aborting replace."));
|
|
|
|
|
if (roDialog.exec() == Core::Internal::ReadOnlyFilesDialog::RO_Cancel)
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it.toFront();
|
2009-12-21 11:08:20 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
const QString fileName = it.key();
|
2014-01-13 16:17:34 +01:00
|
|
|
const QList<Core::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;
|
2014-01-13 16:17:34 +01:00
|
|
|
foreach (const Core::SearchResultItem &item, changeItems) {
|
2011-10-17 10:37:22 +02:00
|
|
|
const QPair<int, int> &p = qMakePair(item.lineNumber, item.textMarkPos);
|
|
|
|
|
if (processed.contains(p))
|
|
|
|
|
continue;
|
|
|
|
|
processed.insert(p);
|
|
|
|
|
|
|
|
|
|
QString replacement;
|
2012-11-30 16:15:07 +01:00
|
|
|
if (item.userData.canConvert<QStringList>() && !item.userData.toStringList().isEmpty()) {
|
2011-10-17 10:37:22 +02:00
|
|
|
replacement = Utils::expandRegExpReplacement(text, item.userData.toStringList());
|
2012-11-30 16:15:07 +01:00
|
|
|
} else if (preserveCase) {
|
|
|
|
|
const QString originalText = (item.textMarkLength == 0) ? item.text
|
|
|
|
|
: item.text.mid(item.textMarkPos, item.textMarkLength);
|
|
|
|
|
replacement = Utils::matchCaseReplacement(originalText, text);
|
|
|
|
|
} else {
|
2011-10-17 10:37:22 +02:00
|
|
|
replacement = text;
|
2012-11-30 16:15:07 +01:00
|
|
|
}
|
2011-10-17 10:37:22 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-02-12 18:37:14 +01:00
|
|
|
QVariant BaseFileFind::getAdditionalParameters(SearchResult *search)
|
|
|
|
|
{
|
|
|
|
|
return search->userData().value<FileFindParameters>().additionalParameters;
|
|
|
|
|
}
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
2014-01-13 16:17:34 +01:00
|
|
|
|
|
|
|
|
} // namespace TextEditor
|