VCS: Simplify editor/command connections

* Move all the connections to setCommand()
* Move gotoLine logic to reportCommandFinished

Change-Id: I67ad74820b3d20b2b5fa97edad92f0f30111166f
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2016-03-28 23:13:59 +03:00
committed by Orgad Shaneh
parent 706fc6c00d
commit a63681c1d2
2 changed files with 10 additions and 21 deletions

View File

@@ -51,17 +51,6 @@
#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
@@ -131,12 +120,8 @@ VcsCommand *VcsBaseClientImpl::createCommand(const QString &workingDirectory,
{
auto cmd = new VcsCommand(workingDirectory, processEnvironment());
cmd->setDefaultTimeoutS(vcsTimeoutS());
if (editor) {
if (editor)
editor->setCommand(cmd);
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

View File

@@ -1199,10 +1199,15 @@ DiffChunk VcsBaseEditorWidget::diffChunk(QTextCursor cursor) const
void VcsBaseEditorWidget::reportCommandFinished(bool ok, int exitCode, const QVariant &data)
{
Q_UNUSED(exitCode);
Q_UNUSED(data);
if (!ok)
hideProgressIndicator();
if (!ok) {
textDocument()->setPlainText(tr("Failed to retrieve data."));
} else if (data.type() == QVariant::Int) {
const int line = data.toInt();
if (line >= 0)
gotoLine(line);
}
}
const VcsBaseEditorParameters *VcsBaseEditor::findType(const VcsBaseEditorParameters *array,
@@ -1385,11 +1390,10 @@ void VcsBaseEditorWidget::setCommand(VcsCommand *command)
hideProgressIndicator();
}
d->m_command = command;
if (d->m_command) {
if (command) {
d->m_progressIndicator = new Utils::ProgressIndicator(Utils::ProgressIndicator::Large);
d->m_progressIndicator->attachToWidget(this);
connect(d->m_command.data(), &VcsCommand::finished,
this, &VcsBaseEditorWidget::hideProgressIndicator);
connect(command, &VcsCommand::finished, this, &VcsBaseEditorWidget::reportCommandFinished);
QTimer::singleShot(100, this, &VcsBaseEditorWidget::showProgressIndicator);
}
}