diff options
Diffstat (limited to 'src/plugins/vcsbase')
-rw-r--r-- | src/plugins/vcsbase/vcsbaseclient.cpp | 62 | ||||
-rw-r--r-- | src/plugins/vcsbase/vcsbaseclient.h | 3 |
2 files changed, 23 insertions, 42 deletions
diff --git a/src/plugins/vcsbase/vcsbaseclient.cpp b/src/plugins/vcsbase/vcsbaseclient.cpp index 36df6fb2f0..750e7f96c3 100644 --- a/src/plugins/vcsbase/vcsbaseclient.cpp +++ b/src/plugins/vcsbase/vcsbaseclient.cpp @@ -56,6 +56,17 @@ #include <QVariant> #include <QProcessEnvironment> +static void commandFinished(VcsBase::VcsBaseEditorWidget *editor, VcsBase::VcsCommand *cmd) +{ + if (!cmd->lastExecutionSuccess()) { + editor->reportCommandFinished(false, cmd->lastExecutionExitCode(), cmd->cookie()); + } else if (cmd->cookie().type() == QVariant::Int) { + const int line = cmd->cookie().toInt(); + if (line >= 0) + editor->gotoLine(line); + } +} + /*! \class VcsBase::VcsBaseClient @@ -80,27 +91,14 @@ namespace VcsBase { class VcsBaseClientImplPrivate { public: - VcsBaseClientImplPrivate(VcsBaseClientImpl *client, VcsBaseClientSettings *settings); + VcsBaseClientImplPrivate(VcsBaseClientSettings *settings); ~VcsBaseClientImplPrivate(); - void bindCommandToEditor(VcsCommand *cmd, VcsBaseEditorWidget *editor); - VcsBaseClientSettings *m_clientSettings; - QSignalMapper *m_cmdFinishedMapper; }; -void VcsBaseClientImplPrivate::bindCommandToEditor(VcsCommand *cmd, VcsBaseEditorWidget *editor) -{ - editor->setCommand(cmd); - QObject::connect(cmd, &VcsCommand::finished, - m_cmdFinishedMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); - m_cmdFinishedMapper->setMapping(cmd, editor); -} - -VcsBaseClientImplPrivate::VcsBaseClientImplPrivate(VcsBaseClientImpl *client, - VcsBaseClientSettings *settings) : - m_clientSettings(settings), - m_cmdFinishedMapper(new QSignalMapper(client)) +VcsBaseClientImplPrivate::VcsBaseClientImplPrivate(VcsBaseClientSettings *settings) : + m_clientSettings(settings) { m_clientSettings->readSettings(Core::ICore::settings()); } @@ -110,14 +108,11 @@ VcsBaseClientImplPrivate::~VcsBaseClientImplPrivate() delete m_clientSettings; } -VcsBaseClientImpl::VcsBaseClientImpl(VcsBaseClientImpl *client, VcsBaseClientSettings *settings) : - d(new VcsBaseClientImplPrivate(client, settings)) +VcsBaseClientImpl::VcsBaseClientImpl(VcsBaseClientSettings *settings) : + d(new VcsBaseClientImplPrivate(settings)) { connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested, this, &VcsBaseClientImpl::saveSettings); - - connect(d->m_cmdFinishedMapper, static_cast<void (QSignalMapper::*)(QWidget*)>(&QSignalMapper::mapped), - this, &VcsBaseClientImpl::commandFinishedGotoLine); } VcsBaseClientImpl::~VcsBaseClientImpl() @@ -141,8 +136,11 @@ VcsCommand *VcsBaseClientImpl::createCommand(const QString &workingDirectory, { auto cmd = new VcsCommand(workingDirectory, processEnvironment()); cmd->setDefaultTimeoutS(vcsTimeoutS()); - if (editor) - d->bindCommandToEditor(cmd, editor); + if (editor) { + connect(editor, &QObject::destroyed, cmd, &VcsCommand::abort); + connect(cmd, &VcsCommand::finished, + editor, [editor, cmd]() { commandFinished(editor, cmd); }); + } if (mode == VcsWindowOutputBind) { cmd->addFlags(VcsCommand::ShowStdOut); if (editor) // assume that the commands output is the important thing @@ -278,22 +276,6 @@ void VcsBaseClientImpl::saveSettings() settings().writeSettings(Core::ICore::settings()); } -void VcsBaseClientImpl::commandFinishedGotoLine(QWidget *editorObject) -{ - VcsBaseEditorWidget *editor = qobject_cast<VcsBaseEditorWidget *>(editorObject); - VcsCommand *cmd = qobject_cast<VcsCommand *>(d->m_cmdFinishedMapper->mapping(editor)); - if (editor && cmd) { - if (!cmd->lastExecutionSuccess()) { - editor->reportCommandFinished(false, cmd->lastExecutionExitCode(), cmd->cookie()); - } else if (cmd->cookie().type() == QVariant::Int) { - const int line = cmd->cookie().toInt(); - if (line >= 0) - editor->gotoLine(line); - } - d->m_cmdFinishedMapper->removeMappings(cmd); - } -} - class VcsBaseClientPrivate { public: @@ -319,7 +301,7 @@ VcsBaseClient::StatusItem::StatusItem(const QString &s, const QString &f) : { } VcsBaseClient::VcsBaseClient(VcsBaseClientSettings *settings) : - VcsBaseClientImpl(this, settings), + VcsBaseClientImpl(settings), d(new VcsBaseClientPrivate) { qRegisterMetaType<QVariant>(); diff --git a/src/plugins/vcsbase/vcsbaseclient.h b/src/plugins/vcsbase/vcsbaseclient.h index 50827a1384..03a87ea458 100644 --- a/src/plugins/vcsbase/vcsbaseclient.h +++ b/src/plugins/vcsbase/vcsbaseclient.h @@ -68,7 +68,7 @@ class VCSBASE_EXPORT VcsBaseClientImpl : public QObject Q_OBJECT public: - explicit VcsBaseClientImpl(VcsBaseClientImpl *client, VcsBaseClientSettings *settings); + explicit VcsBaseClientImpl(VcsBaseClientSettings *settings); ~VcsBaseClientImpl(); VcsBaseClientSettings &settings() const; @@ -130,7 +130,6 @@ protected: private: void saveSettings(); - void commandFinishedGotoLine(QWidget*); VcsBaseClientImplPrivate *d; }; |