forked from qt-creator/qt-creator
Vcs: in VcsBaseClient use functors to create log/diff parameter widgets
Also API of VcsBaseEditorParameterWidget was changed to take benefit of C++11 lambdas. Slot executeCommand() is no longer virtual and only fires signal commandExecutionRequested(). The Vcs client just has to bind a lambda to this signal instead of some boiler-plate code like keeping track of the arguments of diff/log with "struct XxxDiffParameters", etc. Change-Id: I347c97d84a8324e9c661df4e6d9a6075980b020f Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -89,9 +89,15 @@ public:
|
||||
void bindCommandToEditor(VcsCommand *cmd, VcsBaseEditorWidget *editor);
|
||||
void commandFinishedGotoLine(QWidget *editorObject);
|
||||
|
||||
VcsBaseEditorParameterWidget *createDiffEditor();
|
||||
VcsBaseEditorParameterWidget *createLogEditor();
|
||||
|
||||
VcsBaseClientSettings *m_clientSettings;
|
||||
QSignalMapper *m_cmdFinishedMapper;
|
||||
|
||||
VcsBaseClient::ParameterWidgetCreator m_diffParamWidgetCreator;
|
||||
VcsBaseClient::ParameterWidgetCreator m_logParamWidgetCreator;
|
||||
|
||||
private:
|
||||
VcsBaseClient *m_client;
|
||||
};
|
||||
@@ -157,6 +163,16 @@ void VcsBaseClientPrivate::commandFinishedGotoLine(QWidget *editorObject)
|
||||
}
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget *VcsBaseClientPrivate::createDiffEditor()
|
||||
{
|
||||
return m_diffParamWidgetCreator ? m_diffParamWidgetCreator() : 0;
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget *VcsBaseClientPrivate::createLogEditor()
|
||||
{
|
||||
return m_logParamWidgetCreator ? m_logParamWidgetCreator() : 0;
|
||||
}
|
||||
|
||||
VcsBaseClient::StatusItem::StatusItem(const QString &s, const QString &f) :
|
||||
flags(s), file(f)
|
||||
{
|
||||
@@ -350,10 +366,12 @@ void VcsBaseClient::diff(const QString &workingDir, const QStringList &files,
|
||||
editor->setWorkingDirectory(workingDir);
|
||||
|
||||
VcsBaseEditorParameterWidget *paramWidget = editor->configurationWidget();
|
||||
if (!paramWidget && (paramWidget = createDiffEditor(workingDir, files, extraOptions))) {
|
||||
if (!paramWidget && (paramWidget = d->createDiffEditor())) {
|
||||
// editor has been just created, createVcsEditor() didn't set a configuration widget yet
|
||||
connect(editor, &VcsBaseEditorWidget::diffChunkReverted,
|
||||
paramWidget, &VcsBaseEditorParameterWidget::executeCommand);
|
||||
connect(paramWidget, &VcsBaseEditorParameterWidget::commandExecutionRequested,
|
||||
[=] { diff(workingDir, files, extraOptions); } );
|
||||
editor->setConfigurationWidget(paramWidget);
|
||||
}
|
||||
|
||||
@@ -380,8 +398,10 @@ void VcsBaseClient::log(const QString &workingDir, const QStringList &files,
|
||||
editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);
|
||||
|
||||
VcsBaseEditorParameterWidget *paramWidget = editor->configurationWidget();
|
||||
if (!paramWidget && (paramWidget = createLogEditor(workingDir, files, extraOptions))) {
|
||||
if (!paramWidget && (paramWidget = d->createLogEditor())) {
|
||||
// editor has been just created, createVcsEditor() didn't set a configuration widget yet
|
||||
connect(paramWidget, &VcsBaseEditorParameterWidget::commandExecutionRequested,
|
||||
[=] { log(workingDir, files, extraOptions, enableAnnotationContextMenu); } );
|
||||
editor->setConfigurationWidget(paramWidget);
|
||||
}
|
||||
|
||||
@@ -467,6 +487,16 @@ Utils::ExitCodeInterpreter *VcsBaseClient::exitCodeInterpreter(VcsCommandTag cmd
|
||||
return 0;
|
||||
}
|
||||
|
||||
void VcsBaseClient::setDiffParameterWidgetCreator(ParameterWidgetCreator creator)
|
||||
{
|
||||
d->m_diffParamWidgetCreator = std::move(creator);
|
||||
}
|
||||
|
||||
void VcsBaseClient::setLogParameterWidgetCreator(ParameterWidgetCreator creator)
|
||||
{
|
||||
d->m_logParamWidgetCreator = std::move(creator);
|
||||
}
|
||||
|
||||
void VcsBaseClient::import(const QString &repositoryRoot, const QStringList &files,
|
||||
const QStringList &extraOptions)
|
||||
{
|
||||
@@ -527,26 +557,6 @@ VcsBaseClientSettings *VcsBaseClient::settings() const
|
||||
return d->m_clientSettings;
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget *VcsBaseClient::createDiffEditor(const QString &workingDir,
|
||||
const QStringList &files,
|
||||
const QStringList &extraOptions)
|
||||
{
|
||||
Q_UNUSED(workingDir);
|
||||
Q_UNUSED(files);
|
||||
Q_UNUSED(extraOptions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
VcsBaseEditorParameterWidget *VcsBaseClient::createLogEditor(const QString &workingDir,
|
||||
const QStringList &files,
|
||||
const QStringList &extraOptions)
|
||||
{
|
||||
Q_UNUSED(workingDir);
|
||||
Q_UNUSED(files);
|
||||
Q_UNUSED(extraOptions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString VcsBaseClient::vcsEditorTitle(const QString &vcsCmd, const QString &sourceId) const
|
||||
{
|
||||
const Utils::FileName binary = settings()->binaryPath();
|
||||
|
Reference in New Issue
Block a user