forked from qt-creator/qt-creator
Git: Hook grep into Find In File System dialog
Change-Id: I0fc77ad61c8874a21afd5b5135df4d30fa795a8e Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
1b9b1541d3
commit
558c08e2c5
@@ -27,24 +27,21 @@
|
|||||||
#include "gitclient.h"
|
#include "gitclient.h"
|
||||||
#include "gitplugin.h"
|
#include "gitplugin.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
|
||||||
#include <coreplugin/find/findplugin.h>
|
|
||||||
#include <coreplugin/vcsmanager.h>
|
#include <coreplugin/vcsmanager.h>
|
||||||
|
#include <texteditor/findinfiles.h>
|
||||||
#include <vcsbase/vcsbaseconstants.h>
|
#include <vcsbase/vcsbaseconstants.h>
|
||||||
|
|
||||||
#include <utils/filesearch.h>
|
#include <utils/filesearch.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/pathchooser.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/runextensions.h>
|
#include <utils/runextensions.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QCheckBox>
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
#include <QGridLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -54,18 +51,10 @@ namespace Internal {
|
|||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
|
||||||
QString GitGrep::id() const
|
|
||||||
{
|
|
||||||
return QLatin1String("Git Grep");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString GitGrep::displayName() const
|
|
||||||
{
|
|
||||||
return tr("Git Grep");
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
const char EnableGitGrep[] = "EnableGitGrep";
|
||||||
|
|
||||||
class GitGrepRunner : public QObject
|
class GitGrepRunner : public QObject
|
||||||
{
|
{
|
||||||
using FutureInterfaceType = QFutureInterface<FileSearchResultList>;
|
using FutureInterfaceType = QFutureInterface<FileSearchResultList>;
|
||||||
@@ -180,117 +169,72 @@ private:
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
static bool validateDirectory(const QString &path)
|
||||||
|
{
|
||||||
|
static IVersionControl *gitVc = VcsManager::versionControl(VcsBase::Constants::VCS_ID_GIT);
|
||||||
|
QTC_ASSERT(gitVc, return false);
|
||||||
|
return gitVc == VcsManager::findVersionControlForDirectory(path, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GitGrep::GitGrep()
|
||||||
|
{
|
||||||
|
m_widget = new QCheckBox(tr("&Use Git Grep"));
|
||||||
|
m_widget->setToolTip(tr("Use Git Grep for searching. This includes only files "
|
||||||
|
"that are managed by source control."));
|
||||||
|
TextEditor::FindInFiles *findInFiles = TextEditor::FindInFiles::instance();
|
||||||
|
QTC_ASSERT(findInFiles, return);
|
||||||
|
QObject::connect(findInFiles, &TextEditor::FindInFiles::pathChanged,
|
||||||
|
m_widget.data(), [this](const QString &path) {
|
||||||
|
m_widget->setEnabled(validateDirectory(path));
|
||||||
|
});
|
||||||
|
findInFiles->setFindExtension(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
GitGrep::~GitGrep()
|
||||||
|
{
|
||||||
|
delete m_widget.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GitGrep::title() const
|
||||||
|
{
|
||||||
|
return tr("Git Grep");
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *GitGrep::widget() const
|
||||||
|
{
|
||||||
|
return m_widget.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GitGrep::isEnabled() const
|
||||||
|
{
|
||||||
|
return m_widget->isEnabled() && m_widget->isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GitGrep::isEnabled(const TextEditor::FileFindParameters ¶meters) const
|
||||||
|
{
|
||||||
|
return parameters.extensionParameters.toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant GitGrep::parameters() const
|
||||||
|
{
|
||||||
|
return isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GitGrep::readSettings(QSettings *settings)
|
||||||
|
{
|
||||||
|
m_widget->setChecked(settings->value(QLatin1String(EnableGitGrep), false).toBool());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GitGrep::writeSettings(QSettings *settings) const
|
||||||
|
{
|
||||||
|
settings->setValue(QLatin1String(EnableGitGrep), m_widget->isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
QFuture<FileSearchResultList> GitGrep::executeSearch(
|
QFuture<FileSearchResultList> GitGrep::executeSearch(
|
||||||
const TextEditor::FileFindParameters ¶meters)
|
const TextEditor::FileFindParameters ¶meters)
|
||||||
{
|
{
|
||||||
return Utils::runAsync<FileSearchResultList>(GitGrepRunner::run, parameters);
|
return Utils::runAsync<FileSearchResultList>(GitGrepRunner::run, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileIterator *GitGrep::files(const QStringList &, const QVariant &) const
|
|
||||||
{
|
|
||||||
QTC_ASSERT(false, return 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant GitGrep::additionalParameters() const
|
|
||||||
{
|
|
||||||
return qVariantFromValue(path().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString GitGrep::label() const
|
|
||||||
{
|
|
||||||
const QChar slash = QLatin1Char('/');
|
|
||||||
const QStringList &nonEmptyComponents = path().toFileInfo().absoluteFilePath()
|
|
||||||
.split(slash, QString::SkipEmptyParts);
|
|
||||||
return tr("Git Grep \"%1\":").arg(nonEmptyComponents.isEmpty() ? QString(slash)
|
|
||||||
: nonEmptyComponents.last());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString GitGrep::toolTip() const
|
|
||||||
{
|
|
||||||
//: %3 is filled by BaseFileFind::runNewSearch
|
|
||||||
return tr("Path: %1\nFilter: %2\n%3")
|
|
||||||
.arg(path().toUserOutput(), fileNameFilters().join(QLatin1Char(',')));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GitGrep::validateDirectory(FancyLineEdit *edit, QString *errorMessage) const
|
|
||||||
{
|
|
||||||
static IVersionControl *gitVc =
|
|
||||||
VcsManager::versionControl(VcsBase::Constants::VCS_ID_GIT);
|
|
||||||
QTC_ASSERT(gitVc, return false);
|
|
||||||
if (!m_directory->defaultValidationFunction()(edit, errorMessage))
|
|
||||||
return false;
|
|
||||||
const QString path = m_directory->path();
|
|
||||||
IVersionControl *vc = VcsManager::findVersionControlForDirectory(path, 0);
|
|
||||||
if (vc == gitVc)
|
|
||||||
return true;
|
|
||||||
if (errorMessage)
|
|
||||||
*errorMessage = tr("The path \"%1\" is not managed by Git").arg(path);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *GitGrep::createConfigWidget()
|
|
||||||
{
|
|
||||||
if (!m_configWidget) {
|
|
||||||
m_configWidget = new QWidget;
|
|
||||||
QGridLayout * const gridLayout = new QGridLayout(m_configWidget);
|
|
||||||
gridLayout->setMargin(0);
|
|
||||||
m_configWidget->setLayout(gridLayout);
|
|
||||||
|
|
||||||
QLabel *dirLabel = new QLabel(tr("Director&y:"));
|
|
||||||
gridLayout->addWidget(dirLabel, 0, 0, Qt::AlignRight);
|
|
||||||
m_directory = new PathChooser;
|
|
||||||
m_directory->setExpectedKind(PathChooser::ExistingDirectory);
|
|
||||||
m_directory->setHistoryCompleter(QLatin1String("Git.Grep.History"), true);
|
|
||||||
m_directory->setPromptDialogTitle(tr("Directory to search"));
|
|
||||||
m_directory->setValidationFunction([this](FancyLineEdit *edit, QString *errorMessage) {
|
|
||||||
return validateDirectory(edit, errorMessage);
|
|
||||||
});
|
|
||||||
connect(m_directory.data(), &PathChooser::validChanged,
|
|
||||||
this, &GitGrep::enabledChanged);
|
|
||||||
dirLabel->setBuddy(m_directory);
|
|
||||||
gridLayout->addWidget(m_directory, 0, 1, 1, 2);
|
|
||||||
|
|
||||||
QLabel * const filePatternLabel = new QLabel(tr("Fi&le pattern:"));
|
|
||||||
filePatternLabel->setMinimumWidth(80);
|
|
||||||
filePatternLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
|
||||||
filePatternLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
||||||
QWidget *patternWidget = createPatternWidget();
|
|
||||||
filePatternLabel->setBuddy(patternWidget);
|
|
||||||
gridLayout->addWidget(filePatternLabel, 1, 0);
|
|
||||||
gridLayout->addWidget(patternWidget, 1, 1, 1, 2);
|
|
||||||
m_configWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
|
||||||
}
|
|
||||||
return m_configWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileName GitGrep::path() const
|
|
||||||
{
|
|
||||||
return m_directory->fileName();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GitGrep::writeSettings(QSettings *settings)
|
|
||||||
{
|
|
||||||
settings->beginGroup(QLatin1String("GitGrep"));
|
|
||||||
writeCommonSettings(settings);
|
|
||||||
settings->endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GitGrep::readSettings(QSettings *settings)
|
|
||||||
{
|
|
||||||
settings->beginGroup(QLatin1String("GitGrep"));
|
|
||||||
readCommonSettings(settings, QLatin1String("*"));
|
|
||||||
settings->endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GitGrep::isValid() const
|
|
||||||
{
|
|
||||||
return m_directory->isValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GitGrep::setDirectory(const FileName &directory)
|
|
||||||
{
|
|
||||||
m_directory->setFileName(directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
} // Git
|
} // Git
|
||||||
|
|||||||
@@ -33,43 +33,30 @@
|
|||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
|
|
||||||
namespace Utils {
|
QT_FORWARD_DECLARE_CLASS(QCheckBox)
|
||||||
class FancyLineEdit;
|
|
||||||
class PathChooser;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Git {
|
namespace Git {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class GitGrep : public TextEditor::BaseFileFind
|
class GitGrep : public TextEditor::FileFindExtension
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_DECLARE_TR_FUNCTIONS(GitGrep)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QString id() const override;
|
GitGrep();
|
||||||
QString displayName() const override;
|
~GitGrep() override;
|
||||||
|
QString title() const override;
|
||||||
|
QWidget *widget() const override;
|
||||||
|
bool isEnabled() const override;
|
||||||
|
bool isEnabled(const TextEditor::FileFindParameters ¶meters) const override;
|
||||||
|
QVariant parameters() const override;
|
||||||
|
void readSettings(QSettings *settings) override;
|
||||||
|
void writeSettings(QSettings *settings) const override;
|
||||||
QFuture<Utils::FileSearchResultList> executeSearch(
|
QFuture<Utils::FileSearchResultList> executeSearch(
|
||||||
const TextEditor::FileFindParameters ¶meters) override;
|
const TextEditor::FileFindParameters ¶meters) override;
|
||||||
QWidget *createConfigWidget() override;
|
|
||||||
void writeSettings(QSettings *settings) override;
|
|
||||||
void readSettings(QSettings *settings) override;
|
|
||||||
bool isValid() const override;
|
|
||||||
|
|
||||||
void setDirectory(const Utils::FileName &directory);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Utils::FileIterator *files(const QStringList &nameFilters,
|
|
||||||
const QVariant &additionalParameters) const override;
|
|
||||||
QVariant additionalParameters() const override;
|
|
||||||
QString label() const override;
|
|
||||||
QString toolTip() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Utils::FileName path() const;
|
QPointer<QCheckBox> m_widget;
|
||||||
bool validateDirectory(Utils::FancyLineEdit *edit, QString *errorMessage) const;
|
|
||||||
|
|
||||||
QPointer<QWidget> m_configWidget;
|
|
||||||
QPointer<Utils::PathChooser> m_directory;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -68,15 +68,14 @@ public:
|
|||||||
class BaseFileFindPrivate
|
class BaseFileFindPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BaseFileFindPrivate() : m_resultLabel(0), m_filterCombo(0) {}
|
|
||||||
|
|
||||||
QMap<QFutureWatcher<FileSearchResultList> *, QPointer<SearchResult> > m_watchers;
|
QMap<QFutureWatcher<FileSearchResultList> *, QPointer<SearchResult> > m_watchers;
|
||||||
QPointer<IFindSupport> m_currentFindSupport;
|
QPointer<IFindSupport> m_currentFindSupport;
|
||||||
|
|
||||||
QLabel *m_resultLabel;
|
QLabel *m_resultLabel = 0;
|
||||||
QStringListModel m_filterStrings;
|
QStringListModel m_filterStrings;
|
||||||
QString m_filterSetting;
|
QString m_filterSetting;
|
||||||
QPointer<QComboBox> m_filterCombo;
|
QPointer<QComboBox> m_filterCombo;
|
||||||
|
QPointer<FileFindExtension> m_extension;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
@@ -130,6 +129,11 @@ QStringList BaseFileFind::fileNameFilters() const
|
|||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileFindExtension *BaseFileFind::extension() const
|
||||||
|
{
|
||||||
|
return d->m_extension.data();
|
||||||
|
}
|
||||||
|
|
||||||
void BaseFileFind::runNewSearch(const QString &txt, FindFlags findFlags,
|
void BaseFileFind::runNewSearch(const QString &txt, FindFlags findFlags,
|
||||||
SearchResultWindow::SearchMode searchMode)
|
SearchResultWindow::SearchMode searchMode)
|
||||||
{
|
{
|
||||||
@@ -147,6 +151,8 @@ void BaseFileFind::runNewSearch(const QString &txt, FindFlags findFlags,
|
|||||||
parameters.flags = findFlags;
|
parameters.flags = findFlags;
|
||||||
parameters.nameFilters = fileNameFilters();
|
parameters.nameFilters = fileNameFilters();
|
||||||
parameters.additionalParameters = additionalParameters();
|
parameters.additionalParameters = additionalParameters();
|
||||||
|
if (d->m_extension)
|
||||||
|
parameters.extensionParameters = d->m_extension->parameters();
|
||||||
search->setUserData(qVariantFromValue(parameters));
|
search->setUserData(qVariantFromValue(parameters));
|
||||||
connect(search, &SearchResult::activated, this, &BaseFileFind::openEditor);
|
connect(search, &SearchResult::activated, this, &BaseFileFind::openEditor);
|
||||||
if (searchMode == SearchResultWindow::SearchAndReplace)
|
if (searchMode == SearchResultWindow::SearchAndReplace)
|
||||||
@@ -192,6 +198,12 @@ void BaseFileFind::replaceAll(const QString &txt, FindFlags findFlags)
|
|||||||
runNewSearch(txt, findFlags, SearchResultWindow::SearchAndReplace);
|
runNewSearch(txt, findFlags, SearchResultWindow::SearchAndReplace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseFileFind::setFindExtension(FileFindExtension *extension)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(!d->m_extension, return);
|
||||||
|
d->m_extension = extension;
|
||||||
|
}
|
||||||
|
|
||||||
void BaseFileFind::doReplace(const QString &text,
|
void BaseFileFind::doReplace(const QString &text,
|
||||||
const QList<SearchResultItem> &items,
|
const QList<SearchResultItem> &items,
|
||||||
bool preserveCase)
|
bool preserveCase)
|
||||||
@@ -263,6 +275,8 @@ void BaseFileFind::writeCommonSettings(QSettings *settings)
|
|||||||
settings->setValue(QLatin1String("filters"), d->m_filterStrings.stringList());
|
settings->setValue(QLatin1String("filters"), d->m_filterStrings.stringList());
|
||||||
if (d->m_filterCombo)
|
if (d->m_filterCombo)
|
||||||
settings->setValue(QLatin1String("currentFilter"), d->m_filterCombo->currentText());
|
settings->setValue(QLatin1String("currentFilter"), d->m_filterCombo->currentText());
|
||||||
|
if (d->m_extension)
|
||||||
|
d->m_extension->writeSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseFileFind::readCommonSettings(QSettings *settings, const QString &defaultFilter)
|
void BaseFileFind::readCommonSettings(QSettings *settings, const QString &defaultFilter)
|
||||||
@@ -276,6 +290,8 @@ void BaseFileFind::readCommonSettings(QSettings *settings, const QString &defaul
|
|||||||
d->m_filterStrings.setStringList(filters);
|
d->m_filterStrings.setStringList(filters);
|
||||||
if (d->m_filterCombo)
|
if (d->m_filterCombo)
|
||||||
syncComboWithSettings(d->m_filterCombo, d->m_filterSetting);
|
syncComboWithSettings(d->m_filterCombo, d->m_filterSetting);
|
||||||
|
if (d->m_extension)
|
||||||
|
d->m_extension->readSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseFileFind::syncComboWithSettings(QComboBox *combo, const QString &setting)
|
void BaseFileFind::syncComboWithSettings(QComboBox *combo, const QString &setting)
|
||||||
@@ -425,6 +441,9 @@ QVariant BaseFileFind::getAdditionalParameters(SearchResult *search)
|
|||||||
|
|
||||||
QFuture<FileSearchResultList> BaseFileFind::executeSearch(const FileFindParameters ¶meters)
|
QFuture<FileSearchResultList> BaseFileFind::executeSearch(const FileFindParameters ¶meters)
|
||||||
{
|
{
|
||||||
|
if (d->m_extension && d->m_extension->isEnabled(parameters))
|
||||||
|
return d->m_extension->executeSearch(parameters);
|
||||||
|
|
||||||
auto func = parameters.flags & FindRegularExpression
|
auto func = parameters.flags & FindRegularExpression
|
||||||
? Utils::findInFilesRegExp
|
? Utils::findInFilesRegExp
|
||||||
: Utils::findInFiles;
|
: Utils::findInFiles;
|
||||||
|
|||||||
@@ -57,6 +57,22 @@ public:
|
|||||||
Core::FindFlags flags;
|
Core::FindFlags flags;
|
||||||
QStringList nameFilters;
|
QStringList nameFilters;
|
||||||
QVariant additionalParameters;
|
QVariant additionalParameters;
|
||||||
|
QVariant extensionParameters;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TEXTEDITOR_EXPORT FileFindExtension : public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~FileFindExtension() {}
|
||||||
|
virtual QString title() const = 0;
|
||||||
|
virtual QWidget *widget() const = 0;
|
||||||
|
virtual bool isEnabled() const = 0;
|
||||||
|
virtual bool isEnabled(const FileFindParameters ¶meters) const = 0;
|
||||||
|
virtual QVariant parameters() const = 0;
|
||||||
|
virtual void readSettings(QSettings *settings) = 0;
|
||||||
|
virtual void writeSettings(QSettings *settings) const = 0;
|
||||||
|
virtual QFuture<Utils::FileSearchResultList> executeSearch(
|
||||||
|
const FileFindParameters ¶meters) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT BaseFileFind : public Core::IFindFilter
|
class TEXTEDITOR_EXPORT BaseFileFind : public Core::IFindFilter
|
||||||
@@ -71,6 +87,7 @@ public:
|
|||||||
bool isReplaceSupported() const { return true; }
|
bool isReplaceSupported() const { return true; }
|
||||||
void findAll(const QString &txt, Core::FindFlags findFlags);
|
void findAll(const QString &txt, Core::FindFlags findFlags);
|
||||||
void replaceAll(const QString &txt, Core::FindFlags findFlags);
|
void replaceAll(const QString &txt, Core::FindFlags findFlags);
|
||||||
|
void setFindExtension(FileFindExtension *extension);
|
||||||
|
|
||||||
/* returns the list of unique files that were passed in items */
|
/* returns the list of unique files that were passed in items */
|
||||||
static QStringList replaceAll(const QString &txt,
|
static QStringList replaceAll(const QString &txt,
|
||||||
@@ -94,6 +111,7 @@ protected:
|
|||||||
void syncComboWithSettings(QComboBox *combo, const QString &setting);
|
void syncComboWithSettings(QComboBox *combo, const QString &setting);
|
||||||
void updateComboEntries(QComboBox *combo, bool onTop);
|
void updateComboEntries(QComboBox *combo, bool onTop);
|
||||||
QStringList fileNameFilters() const;
|
QStringList fileNameFilters() const;
|
||||||
|
FileFindExtension *extension() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void displayResult(int index);
|
void displayResult(int index);
|
||||||
|
|||||||
@@ -92,10 +92,17 @@ QVariant FindInFiles::additionalParameters() const
|
|||||||
|
|
||||||
QString FindInFiles::label() const
|
QString FindInFiles::label() const
|
||||||
{
|
{
|
||||||
|
QString title = tr("Directory");
|
||||||
|
if (FileFindExtension *ext = extension()) {
|
||||||
|
if (ext->isEnabled())
|
||||||
|
title = ext->title();
|
||||||
|
}
|
||||||
const QChar slash = QLatin1Char('/');
|
const QChar slash = QLatin1Char('/');
|
||||||
const QStringList &nonEmptyComponents = path().toFileInfo().absoluteFilePath()
|
const QStringList &nonEmptyComponents = path().toFileInfo().absoluteFilePath()
|
||||||
.split(slash, QString::SkipEmptyParts);
|
.split(slash, QString::SkipEmptyParts);
|
||||||
return tr("Directory \"%1\":").arg(nonEmptyComponents.isEmpty() ? QString(slash) : nonEmptyComponents.last());
|
return tr("%1 \"%2\":")
|
||||||
|
.arg(title)
|
||||||
|
.arg(nonEmptyComponents.isEmpty() ? QString(slash) : nonEmptyComponents.last());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FindInFiles::toolTip() const
|
QString FindInFiles::toolTip() const
|
||||||
@@ -114,15 +121,21 @@ QWidget *FindInFiles::createConfigWidget()
|
|||||||
gridLayout->setMargin(0);
|
gridLayout->setMargin(0);
|
||||||
m_configWidget->setLayout(gridLayout);
|
m_configWidget->setLayout(gridLayout);
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
if (FileFindExtension *ext = extension())
|
||||||
|
gridLayout->addWidget(ext->widget(), row++, 1, 1, 2);
|
||||||
|
|
||||||
QLabel *dirLabel = new QLabel(tr("Director&y:"));
|
QLabel *dirLabel = new QLabel(tr("Director&y:"));
|
||||||
gridLayout->addWidget(dirLabel, 0, 0, Qt::AlignRight);
|
gridLayout->addWidget(dirLabel, row, 0, Qt::AlignRight);
|
||||||
m_directory = new PathChooser;
|
m_directory = new PathChooser;
|
||||||
m_directory->setExpectedKind(PathChooser::ExistingDirectory);
|
m_directory->setExpectedKind(PathChooser::ExistingDirectory);
|
||||||
m_directory->setHistoryCompleter(QLatin1String(HistoryKey),
|
|
||||||
/*restoreLastItemFromHistory=*/ true);
|
|
||||||
m_directory->setPromptDialogTitle(tr("Directory to Search"));
|
m_directory->setPromptDialogTitle(tr("Directory to Search"));
|
||||||
|
connect(m_directory.data(), &PathChooser::pathChanged,
|
||||||
|
this, &FindInFiles::pathChanged);
|
||||||
connect(m_directory.data(), &PathChooser::validChanged,
|
connect(m_directory.data(), &PathChooser::validChanged,
|
||||||
this, &FindInFiles::enabledChanged);
|
this, &FindInFiles::enabledChanged);
|
||||||
|
m_directory->setHistoryCompleter(QLatin1String(HistoryKey),
|
||||||
|
/*restoreLastItemFromHistory=*/ true);
|
||||||
if (!HistoryCompleter::historyExistsFor(QLatin1String(HistoryKey))) {
|
if (!HistoryCompleter::historyExistsFor(QLatin1String(HistoryKey))) {
|
||||||
auto completer = static_cast<HistoryCompleter *>(m_directory->lineEdit()->completer());
|
auto completer = static_cast<HistoryCompleter *>(m_directory->lineEdit()->completer());
|
||||||
const QStringList legacyHistory = Core::ICore::settings()->value(
|
const QStringList legacyHistory = Core::ICore::settings()->value(
|
||||||
@@ -131,7 +144,7 @@ QWidget *FindInFiles::createConfigWidget()
|
|||||||
completer->addEntry(dir);
|
completer->addEntry(dir);
|
||||||
}
|
}
|
||||||
dirLabel->setBuddy(m_directory);
|
dirLabel->setBuddy(m_directory);
|
||||||
gridLayout->addWidget(m_directory, 0, 1, 1, 2);
|
gridLayout->addWidget(m_directory, row++, 1, 1, 2);
|
||||||
|
|
||||||
QLabel * const filePatternLabel = new QLabel(tr("Fi&le pattern:"));
|
QLabel * const filePatternLabel = new QLabel(tr("Fi&le pattern:"));
|
||||||
filePatternLabel->setMinimumWidth(80);
|
filePatternLabel->setMinimumWidth(80);
|
||||||
@@ -139,8 +152,8 @@ QWidget *FindInFiles::createConfigWidget()
|
|||||||
filePatternLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
filePatternLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
QWidget *patternWidget = createPatternWidget();
|
QWidget *patternWidget = createPatternWidget();
|
||||||
filePatternLabel->setBuddy(patternWidget);
|
filePatternLabel->setBuddy(patternWidget);
|
||||||
gridLayout->addWidget(filePatternLabel, 1, 0);
|
gridLayout->addWidget(filePatternLabel, row, 0);
|
||||||
gridLayout->addWidget(patternWidget, 1, 1, 1, 2);
|
gridLayout->addWidget(patternWidget, row++, 1, 1, 2);
|
||||||
m_configWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
m_configWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||||
}
|
}
|
||||||
return m_configWidget;
|
return m_configWidget;
|
||||||
@@ -170,6 +183,11 @@ void FindInFiles::setDirectory(const FileName &directory)
|
|||||||
m_directory->setFileName(directory);
|
m_directory->setFileName(directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileName FindInFiles::directory() const
|
||||||
|
{
|
||||||
|
return m_directory->fileName();
|
||||||
|
}
|
||||||
|
|
||||||
void FindInFiles::findOnFileSystem(const QString &path)
|
void FindInFiles::findOnFileSystem(const QString &path)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_instance, return);
|
QTC_ASSERT(m_instance, return);
|
||||||
@@ -178,3 +196,8 @@ void FindInFiles::findOnFileSystem(const QString &path)
|
|||||||
m_instance->setDirectory(FileName::fromString(folder));
|
m_instance->setDirectory(FileName::fromString(folder));
|
||||||
FindPlugin::instance()->openFindDialog(m_instance);
|
FindPlugin::instance()->openFindDialog(m_instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FindInFiles *FindInFiles::instance()
|
||||||
|
{
|
||||||
|
return m_instance;
|
||||||
|
}
|
||||||
|
|||||||
@@ -55,7 +55,12 @@ public:
|
|||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
void setDirectory(const Utils::FileName &directory);
|
void setDirectory(const Utils::FileName &directory);
|
||||||
|
Utils::FileName directory() const;
|
||||||
static void findOnFileSystem(const QString &path);
|
static void findOnFileSystem(const QString &path);
|
||||||
|
static FindInFiles *instance();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void pathChanged(const QString &directory);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Utils::FileIterator *files(const QStringList &nameFilters,
|
Utils::FileIterator *files(const QStringList &nameFilters,
|
||||||
|
|||||||
@@ -129,6 +129,10 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
|
|||||||
|
|
||||||
m_baseTextMarkRegistry = new TextMarkRegistry(this);
|
m_baseTextMarkRegistry = new TextMarkRegistry(this);
|
||||||
|
|
||||||
|
addAutoReleasedObject(new FindInFiles);
|
||||||
|
addAutoReleasedObject(new FindInCurrentFile);
|
||||||
|
addAutoReleasedObject(new FindInOpenFiles);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,10 +150,6 @@ void TextEditorPlugin::extensionsInitialized()
|
|||||||
|
|
||||||
updateSearchResultsTabWidth(m_settings->codeStyle()->currentTabSettings());
|
updateSearchResultsTabWidth(m_settings->codeStyle()->currentTabSettings());
|
||||||
|
|
||||||
addAutoReleasedObject(new FindInFiles);
|
|
||||||
addAutoReleasedObject(new FindInCurrentFile);
|
|
||||||
addAutoReleasedObject(new FindInOpenFiles);
|
|
||||||
|
|
||||||
Utils::MacroExpander *expander = Utils::globalMacroExpander();
|
Utils::MacroExpander *expander = Utils::globalMacroExpander();
|
||||||
|
|
||||||
expander->registerVariable(kCurrentDocumentSelection,
|
expander->registerVariable(kCurrentDocumentSelection,
|
||||||
|
|||||||
Reference in New Issue
Block a user