forked from qt-creator/qt-creator
VCS: Enable canceling a command
Change-Id: Ifdaf901611e2b780defacb95f2b579d706e0343b Reviewed-by: Petar Perisin <petar.perisin@gmail.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
367cfc8419
commit
d15c6bba28
@@ -132,7 +132,7 @@ void CheckoutProgressWizardPage::slotError(const QString &text)
|
|||||||
void CheckoutProgressWizardPage::terminate()
|
void CheckoutProgressWizardPage::terminate()
|
||||||
{
|
{
|
||||||
if (m_command)
|
if (m_command)
|
||||||
m_command->terminate();
|
m_command->cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckoutProgressWizardPage::isComplete() const
|
bool CheckoutProgressWizardPage::isComplete() const
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
|
#include <QFutureWatcher>
|
||||||
#include <QtConcurrentRun>
|
#include <QtConcurrentRun>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
@@ -101,6 +102,8 @@ public:
|
|||||||
ProgressParser *m_progressParser;
|
ProgressParser *m_progressParser;
|
||||||
VcsBase::VcsBaseOutputWindow *m_outputWindow;
|
VcsBase::VcsBaseOutputWindow *m_outputWindow;
|
||||||
bool m_progressiveOutput;
|
bool m_progressiveOutput;
|
||||||
|
bool m_hadOutput;
|
||||||
|
QFutureWatcher<void> m_watcher;
|
||||||
|
|
||||||
QList<Job> m_jobs;
|
QList<Job> m_jobs;
|
||||||
|
|
||||||
@@ -121,6 +124,7 @@ CommandPrivate::CommandPrivate(const QString &binary,
|
|||||||
m_progressParser(0),
|
m_progressParser(0),
|
||||||
m_outputWindow(VcsBase::VcsBaseOutputWindow::instance()),
|
m_outputWindow(VcsBase::VcsBaseOutputWindow::instance()),
|
||||||
m_progressiveOutput(false),
|
m_progressiveOutput(false),
|
||||||
|
m_hadOutput(false),
|
||||||
m_lastExecSuccess(false),
|
m_lastExecSuccess(false),
|
||||||
m_lastExecExitCode(-1)
|
m_lastExecExitCode(-1)
|
||||||
{
|
{
|
||||||
@@ -210,6 +214,8 @@ void Command::execute()
|
|||||||
|
|
||||||
// For some reason QtConcurrent::run() only works on this
|
// For some reason QtConcurrent::run() only works on this
|
||||||
QFuture<void> task = QtConcurrent::run(&Command::run, this);
|
QFuture<void> task = QtConcurrent::run(&Command::run, this);
|
||||||
|
d->m_watcher.setFuture(task);
|
||||||
|
connect(&d->m_watcher, SIGNAL(canceled()), this, SLOT(cancel()));
|
||||||
QString binary = QFileInfo(d->m_binaryPath).baseName();
|
QString binary = QFileInfo(d->m_binaryPath).baseName();
|
||||||
if (!binary.isEmpty())
|
if (!binary.isEmpty())
|
||||||
binary = binary.replace(0, 1, binary[0].toUpper()); // Upper the first letter
|
binary = binary.replace(0, 1, binary[0].toUpper()); // Upper the first letter
|
||||||
@@ -219,9 +225,9 @@ void Command::execute()
|
|||||||
Core::Id::fromString(binary + QLatin1String(".action")));
|
Core::Id::fromString(binary + QLatin1String(".action")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command::terminate()
|
void Command::cancel()
|
||||||
{
|
{
|
||||||
emit doTerminate();
|
emit terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Command::lastExecutionSuccess() const
|
bool Command::lastExecutionSuccess() const
|
||||||
@@ -247,6 +253,8 @@ void Command::run(QFutureInterface<void> &future)
|
|||||||
|
|
||||||
if (d->m_progressParser)
|
if (d->m_progressParser)
|
||||||
d->m_progressParser->setFuture(&future);
|
d->m_progressParser->setFuture(&future);
|
||||||
|
else
|
||||||
|
future.setProgressRange(0, 1);
|
||||||
const int count = d->m_jobs.size();
|
const int count = d->m_jobs.size();
|
||||||
d->m_lastExecExitCode = -1;
|
d->m_lastExecExitCode = -1;
|
||||||
d->m_lastExecSuccess = true;
|
d->m_lastExecSuccess = true;
|
||||||
@@ -265,18 +273,24 @@ void Command::run(QFutureInterface<void> &future)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!future.isCanceled()) {
|
const QString canceledMessage = tr("Canceled");
|
||||||
if (!d->m_progressiveOutput) {
|
if (d->m_progressiveOutput) {
|
||||||
|
if (!d->m_hadOutput && future.isCanceled())
|
||||||
|
emit output(canceledMessage);
|
||||||
|
} else {
|
||||||
|
if (stdOut.isEmpty() && future.isCanceled())
|
||||||
|
emit output(canceledMessage);
|
||||||
|
else
|
||||||
emit output(stdOut);
|
emit output(stdOut);
|
||||||
if (!stdErr.isEmpty())
|
if (!stdErr.isEmpty())
|
||||||
emit errorText(stdErr);
|
emit errorText(stdErr);
|
||||||
}
|
|
||||||
|
|
||||||
emit finished(d->m_lastExecSuccess, d->m_lastExecExitCode, cookie());
|
|
||||||
if (d->m_lastExecSuccess)
|
|
||||||
emit success(cookie());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit finished(d->m_lastExecSuccess, d->m_lastExecExitCode, cookie());
|
||||||
|
if (d->m_lastExecSuccess)
|
||||||
|
emit success(cookie());
|
||||||
|
future.setProgressValue(future.progressMaximum());
|
||||||
|
|
||||||
if (d->m_progressParser)
|
if (d->m_progressParser)
|
||||||
d->m_progressParser->setFuture(0);
|
d->m_progressParser->setFuture(0);
|
||||||
// As it is used asynchronously, we need to delete ourselves
|
// As it is used asynchronously, we need to delete ourselves
|
||||||
@@ -362,7 +376,7 @@ Utils::SynchronousProcessResponse Command::runVcs(const QStringList &arguments,
|
|||||||
} else {
|
} else {
|
||||||
Utils::SynchronousProcess process;
|
Utils::SynchronousProcess process;
|
||||||
process.setExitCodeInterpreter(interpreter);
|
process.setExitCodeInterpreter(interpreter);
|
||||||
connect(this, SIGNAL(doTerminate()), &process, SLOT(terminate()));
|
connect(this, SIGNAL(terminate()), &process, SLOT(terminate()));
|
||||||
if (!d->m_workingDirectory.isEmpty())
|
if (!d->m_workingDirectory.isEmpty())
|
||||||
process.setWorkingDirectory(d->m_workingDirectory);
|
process.setWorkingDirectory(d->m_workingDirectory);
|
||||||
|
|
||||||
@@ -535,8 +549,10 @@ void Command::bufferedOutput(const QString &text)
|
|||||||
d->m_progressParser->parseProgress(text);
|
d->m_progressParser->parseProgress(text);
|
||||||
if (d->m_flags & VcsBasePlugin::ShowStdOutInLogWindow)
|
if (d->m_flags & VcsBasePlugin::ShowStdOutInLogWindow)
|
||||||
d->m_outputWindow->append(text);
|
d->m_outputWindow->append(text);
|
||||||
if (d->m_progressiveOutput)
|
if (d->m_progressiveOutput) {
|
||||||
emit output(text);
|
emit output(text);
|
||||||
|
d->m_hadOutput = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command::bufferedError(const QString &text)
|
void Command::bufferedError(const QString &text)
|
||||||
|
|||||||
@@ -80,7 +80,6 @@ public:
|
|||||||
void addJob(const QStringList &arguments, Utils::ExitCodeInterpreter *interpreter = 0);
|
void addJob(const QStringList &arguments, Utils::ExitCodeInterpreter *interpreter = 0);
|
||||||
void addJob(const QStringList &arguments, int timeout, Utils::ExitCodeInterpreter *interpreter = 0);
|
void addJob(const QStringList &arguments, int timeout, Utils::ExitCodeInterpreter *interpreter = 0);
|
||||||
void execute();
|
void execute();
|
||||||
void terminate();
|
|
||||||
bool lastExecutionSuccess() const;
|
bool lastExecutionSuccess() const;
|
||||||
int lastExecutionExitCode() const;
|
int lastExecutionExitCode() const;
|
||||||
|
|
||||||
@@ -114,16 +113,21 @@ private:
|
|||||||
Utils::SynchronousProcessResponse runSynchronous(const QStringList &arguments, int timeoutMS,
|
Utils::SynchronousProcessResponse runSynchronous(const QStringList &arguments, int timeoutMS,
|
||||||
Utils::ExitCodeInterpreter *interpreter = 0);
|
Utils::ExitCodeInterpreter *interpreter = 0);
|
||||||
|
|
||||||
private slots:
|
public slots:
|
||||||
void bufferedOutput(const QString &text);
|
void cancel();
|
||||||
void bufferedError(const QString &text);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void output(const QString &);
|
void output(const QString &);
|
||||||
void errorText(const QString &);
|
void errorText(const QString &);
|
||||||
void finished(bool ok, int exitCode, const QVariant &cookie);
|
void finished(bool ok, int exitCode, const QVariant &cookie);
|
||||||
void success(const QVariant &cookie);
|
void success(const QVariant &cookie);
|
||||||
void doTerminate();
|
|
||||||
|
private slots:
|
||||||
|
void bufferedOutput(const QString &text);
|
||||||
|
void bufferedError(const QString &text);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void terminate(); // Internal
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Internal::CommandPrivate *const d;
|
class Internal::CommandPrivate *const d;
|
||||||
|
|||||||
Reference in New Issue
Block a user