forked from qt-creator/qt-creator
Git: Add grep and pickaxe filters
Fixes: QTCREATORBUG-22512 Change-Id: I98eed9a7f9da15e163804a0fd81713149a06c5b0 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
Orgad Shaneh
parent
1ebb72b47f
commit
1b2aa56f15
@@ -999,8 +999,9 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName,
|
||||
const QString title = tr("Git Log \"%1\"").arg(msgArg);
|
||||
const Id editorId = Git::Constants::GIT_LOG_EDITOR_ID;
|
||||
const QString sourceFile = VcsBaseEditor::getSource(workingDir, fileName);
|
||||
VcsBaseEditorWidget *editor = createVcsEditor(editorId, title, sourceFile,
|
||||
codecFor(CodecLogOutput), "logTitle", msgArg);
|
||||
GitEditorWidget *editor = static_cast<GitEditorWidget *>(
|
||||
createVcsEditor(editorId, title, sourceFile,
|
||||
codecFor(CodecLogOutput), "logTitle", msgArg));
|
||||
VcsBaseEditorConfig *argWidget = editor->editorConfig();
|
||||
if (!argWidget) {
|
||||
argWidget = new GitLogArgumentsWidget(settings(), !fileName.isEmpty(), editor->toolBar());
|
||||
@@ -1018,6 +1019,13 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName,
|
||||
arguments << "-n" << QString::number(logCount);
|
||||
|
||||
arguments << argWidget->arguments();
|
||||
const QString grepValue = editor->grepValue();
|
||||
if (!grepValue.isEmpty())
|
||||
arguments << "--grep=" + grepValue;
|
||||
|
||||
const QString pickaxeValue = editor->pickaxeValue();
|
||||
if (!pickaxeValue.isEmpty())
|
||||
arguments << "-S" << pickaxeValue;
|
||||
|
||||
if (!fileName.isEmpty())
|
||||
arguments << "--" << fileName;
|
||||
|
@@ -35,10 +35,11 @@
|
||||
#include "githighlighters.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <vcsbase/vcsoutputwindow.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <vcsbase/vcsbaseeditorconfig.h>
|
||||
#include <vcsbase/vcsoutputwindow.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/temporaryfile.h>
|
||||
|
||||
#include <QMenu>
|
||||
@@ -380,5 +381,45 @@ QString GitEditorWidget::sourceWorkingDirectory() const
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
void GitEditorWidget::lineEditChanged()
|
||||
{
|
||||
if (VcsBaseEditorConfig *config = editorConfig())
|
||||
config->handleArgumentsChanged();
|
||||
}
|
||||
|
||||
void GitEditorWidget::refreshOnLineEdit(Utils::FancyLineEdit *lineEdit)
|
||||
{
|
||||
connect(lineEdit, &QLineEdit::returnPressed,
|
||||
this, &GitEditorWidget::lineEditChanged);
|
||||
connect(lineEdit, &Utils::FancyLineEdit::rightButtonClicked,
|
||||
this, &GitEditorWidget::lineEditChanged);
|
||||
}
|
||||
|
||||
void GitEditorWidget::setGrepLineEdit(Utils::FancyLineEdit *lineEdit)
|
||||
{
|
||||
m_grepLineEdit = lineEdit;
|
||||
refreshOnLineEdit(lineEdit);
|
||||
}
|
||||
|
||||
void GitEditorWidget::setPickaxeLineEdit(Utils::FancyLineEdit *lineEdit)
|
||||
{
|
||||
m_pickaxeLineEdit = lineEdit;
|
||||
refreshOnLineEdit(lineEdit);
|
||||
}
|
||||
|
||||
QString GitEditorWidget::grepValue() const
|
||||
{
|
||||
if (!m_grepLineEdit)
|
||||
return QString();
|
||||
return m_grepLineEdit->text();
|
||||
}
|
||||
|
||||
QString GitEditorWidget::pickaxeValue() const
|
||||
{
|
||||
if (!m_pickaxeLineEdit)
|
||||
return QString();
|
||||
return m_pickaxeLineEdit->text();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Git
|
||||
|
@@ -29,6 +29,8 @@
|
||||
|
||||
#include <QRegExp>
|
||||
|
||||
namespace Utils { class FancyLineEdit; }
|
||||
|
||||
namespace Git {
|
||||
namespace Internal {
|
||||
|
||||
@@ -40,6 +42,10 @@ public:
|
||||
GitEditorWidget();
|
||||
|
||||
void setPlainText(const QString &text) override;
|
||||
void setGrepLineEdit(Utils::FancyLineEdit *lineEdit);
|
||||
void setPickaxeLineEdit(Utils::FancyLineEdit *lineEdit);
|
||||
QString grepValue() const;
|
||||
QString pickaxeValue() const;
|
||||
|
||||
private:
|
||||
void applyDiffChunk(const VcsBase::DiffChunk& chunk, bool revert);
|
||||
@@ -59,9 +65,13 @@ private:
|
||||
bool supportChangeLinks() const override;
|
||||
QString fileNameForLine(int line) const override;
|
||||
QString sourceWorkingDirectory() const;
|
||||
void refreshOnLineEdit(Utils::FancyLineEdit *lineEdit);
|
||||
void lineEditChanged();
|
||||
|
||||
mutable QRegExp m_changeNumberPattern;
|
||||
QString m_currentChange;
|
||||
Utils::FancyLineEdit *m_grepLineEdit = nullptr;
|
||||
Utils::FancyLineEdit *m_pickaxeLineEdit = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Git
|
||||
|
@@ -54,11 +54,13 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/locator/commandlocator.h>
|
||||
#include <coreplugin/messagebox.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <coreplugin/navigationwidget.h>
|
||||
#include <coreplugin/vcsmanager.h>
|
||||
|
||||
#include <coreplugin/messagebox.h>
|
||||
#include <aggregation/aggregate.h>
|
||||
#include <utils/fancylineedit.h>
|
||||
#include <utils/parameteraction.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -83,7 +85,9 @@
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QFileDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QMenu>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
#include <QTest>
|
||||
@@ -125,6 +129,52 @@ private:
|
||||
GitClient *m_client;
|
||||
};
|
||||
|
||||
class GitLogEditorWidget : public QWidget
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Git::Internal::GitLogEditorWidget);
|
||||
public:
|
||||
GitLogEditorWidget()
|
||||
{
|
||||
auto gitEditor = new GitEditorWidget;
|
||||
auto vlayout = new QVBoxLayout;
|
||||
auto hlayout = new QHBoxLayout;
|
||||
vlayout->setSpacing(0);
|
||||
vlayout->setContentsMargins(0, 0, 0, 0);
|
||||
auto grepLineEdit = addLineEdit(tr("Filter by message"),
|
||||
tr("Filter log entries by text in the commit message."));
|
||||
auto pickaxeLineEdit = addLineEdit(tr("Filter by content"),
|
||||
tr("Filter log entries by added or removed string."));
|
||||
hlayout->setSpacing(20);
|
||||
hlayout->setContentsMargins(0, 0, 0, 0);
|
||||
hlayout->addWidget(new QLabel(tr("Filter:")));
|
||||
hlayout->addWidget(grepLineEdit);
|
||||
hlayout->addWidget(pickaxeLineEdit);
|
||||
hlayout->addStretch();
|
||||
vlayout->addLayout(hlayout);
|
||||
vlayout->addWidget(gitEditor);
|
||||
setLayout(vlayout);
|
||||
gitEditor->setGrepLineEdit(grepLineEdit);
|
||||
gitEditor->setPickaxeLineEdit(pickaxeLineEdit);
|
||||
|
||||
auto textAgg = Aggregation::Aggregate::parentAggregate(gitEditor);
|
||||
auto agg = textAgg ? textAgg : new Aggregation::Aggregate;
|
||||
agg->add(this);
|
||||
agg->add(gitEditor);
|
||||
setFocusProxy(gitEditor);
|
||||
}
|
||||
|
||||
private:
|
||||
FancyLineEdit *addLineEdit(const QString &placeholder, const QString &tooltip)
|
||||
{
|
||||
auto lineEdit = new FancyLineEdit;
|
||||
lineEdit->setFiltering(true);
|
||||
lineEdit->setToolTip(tooltip);
|
||||
lineEdit->setPlaceholderText(placeholder);
|
||||
lineEdit->setMaximumWidth(200);
|
||||
return lineEdit;
|
||||
}
|
||||
};
|
||||
|
||||
const unsigned minimumRequiredVersion = 0x010900;
|
||||
|
||||
const VcsBaseSubmitEditorParameters submitParameters {
|
||||
@@ -346,7 +396,7 @@ public:
|
||||
|
||||
VcsEditorFactory logEditorFactory {
|
||||
&logEditorParameters,
|
||||
[] { return new GitEditorWidget; },
|
||||
[] { return new GitLogEditorWidget; },
|
||||
std::bind(&GitPluginPrivate::describe, this, _1, _2)
|
||||
};
|
||||
|
||||
|
@@ -71,10 +71,11 @@ VcsEditorFactory::VcsEditorFactory(const VcsBaseEditorParameters *parameters,
|
||||
return document;
|
||||
});
|
||||
|
||||
setEditorWidgetCreator([parameters, editorWidgetCreator, describeFunc]() -> TextEditorWidget * {
|
||||
auto widget = qobject_cast<VcsBaseEditorWidget *>(editorWidgetCreator());
|
||||
widget->setDescribeFunc(describeFunc);
|
||||
widget->setParameters(parameters);
|
||||
setEditorWidgetCreator([parameters, editorWidgetCreator, describeFunc]() {
|
||||
auto widget = editorWidgetCreator();
|
||||
auto editorWidget = Aggregation::query<VcsBaseEditorWidget>(widget);
|
||||
editorWidget->setDescribeFunc(describeFunc);
|
||||
editorWidget->setParameters(parameters);
|
||||
return widget;
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user