forked from qt-creator/qt-creator
ShellCommandPage: Merge with VcsCommandPage
Change-Id: Ib8975ddaf9790d80b9784d63ddcfc32ab3c7c9c8 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -68,122 +68,6 @@ static char JOB_ARGUMENTS[] = "arguments";
|
|||||||
static char JOB_TIME_OUT[] = "timeoutFactor";
|
static char JOB_TIME_OUT[] = "timeoutFactor";
|
||||||
static char JOB_ENABLED[] = "enabled";
|
static char JOB_ENABLED[] = "enabled";
|
||||||
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\class VcsBase::ShellCommandPage
|
|
||||||
|
|
||||||
\brief The ShellCommandPage implements a page showing the
|
|
||||||
progress of a \c ShellCommand.
|
|
||||||
|
|
||||||
Turns complete when the command succeeds.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ShellCommandPage::ShellCommandPage(QWidget *parent) :
|
|
||||||
WizardPage(parent),
|
|
||||||
m_startedStatus(tr("Command started..."))
|
|
||||||
{
|
|
||||||
resize(264, 200);
|
|
||||||
auto verticalLayout = new QVBoxLayout(this);
|
|
||||||
m_logPlainTextEdit = new QPlainTextEdit;
|
|
||||||
m_formatter = new OutputFormatter;
|
|
||||||
m_logPlainTextEdit->setReadOnly(true);
|
|
||||||
m_formatter->setPlainTextEdit(m_logPlainTextEdit);
|
|
||||||
|
|
||||||
verticalLayout->addWidget(m_logPlainTextEdit);
|
|
||||||
|
|
||||||
m_statusLabel = new QLabel;
|
|
||||||
verticalLayout->addWidget(m_statusLabel);
|
|
||||||
setTitle(tr("Run Command"));
|
|
||||||
}
|
|
||||||
|
|
||||||
ShellCommandPage::~ShellCommandPage()
|
|
||||||
{
|
|
||||||
QTC_ASSERT(m_state != Running, QApplication::restoreOverrideCursor());
|
|
||||||
delete m_formatter;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShellCommandPage::setStartedStatus(const QString &startedStatus)
|
|
||||||
{
|
|
||||||
m_startedStatus = startedStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShellCommandPage::start(VcsCommand *command)
|
|
||||||
{
|
|
||||||
if (!command) {
|
|
||||||
m_logPlainTextEdit->setPlainText(tr("No job running, please abort."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTC_ASSERT(m_state != Running, return);
|
|
||||||
m_command = command;
|
|
||||||
command->setProgressiveOutput(true);
|
|
||||||
connect(command, &VcsCommand::stdOutText, this, [this](const QString &text) {
|
|
||||||
m_formatter->appendMessage(text, StdOutFormat);
|
|
||||||
});
|
|
||||||
connect(command, &VcsCommand::stdErrText, this, [this](const QString &text) {
|
|
||||||
m_formatter->appendMessage(text, StdErrFormat);
|
|
||||||
});
|
|
||||||
connect(command, &VcsCommand::finished, this, &ShellCommandPage::slotFinished);
|
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
||||||
m_logPlainTextEdit->clear();
|
|
||||||
m_overwriteOutput = false;
|
|
||||||
m_statusLabel->setText(m_startedStatus);
|
|
||||||
m_statusLabel->setPalette(QPalette());
|
|
||||||
m_state = Running;
|
|
||||||
command->execute();
|
|
||||||
|
|
||||||
wizard()->button(QWizard::BackButton)->setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShellCommandPage::slotFinished(bool success, const QVariant &)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(m_state == Running, return);
|
|
||||||
|
|
||||||
QString message;
|
|
||||||
QPalette palette;
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
m_state = Succeeded;
|
|
||||||
message = tr("Succeeded.");
|
|
||||||
palette.setColor(QPalette::WindowText, creatorTheme()->color(Theme::TextColorNormal).name());
|
|
||||||
} else {
|
|
||||||
m_state = Failed;
|
|
||||||
message = tr("Failed.");
|
|
||||||
palette.setColor(QPalette::WindowText, creatorTheme()->color(Theme::TextColorError).name());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_statusLabel->setText(message);
|
|
||||||
m_statusLabel->setPalette(palette);
|
|
||||||
|
|
||||||
QApplication::restoreOverrideCursor();
|
|
||||||
wizard()->button(QWizard::BackButton)->setEnabled(true);
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
emit completeChanged();
|
|
||||||
emit finished(success);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShellCommandPage::terminate()
|
|
||||||
{
|
|
||||||
if (m_command)
|
|
||||||
m_command->cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShellCommandPage::handleReject()
|
|
||||||
{
|
|
||||||
if (!isRunning())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
terminate();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShellCommandPage::isComplete() const
|
|
||||||
{
|
|
||||||
return m_state == Succeeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// VcsCommandPageFactory:
|
// VcsCommandPageFactory:
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
@@ -336,11 +220,39 @@ bool VcsCommandPageFactory::validateData(Id typeId, const QVariant &data, QStrin
|
|||||||
// VcsCommandPage:
|
// VcsCommandPage:
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\class VcsBase::VcsCommandPage
|
||||||
|
|
||||||
|
\brief The VcsCommandPage implements a page showing the
|
||||||
|
progress of a \c VcsCommand.
|
||||||
|
|
||||||
|
Turns complete when the command succeeds.
|
||||||
|
*/
|
||||||
|
|
||||||
VcsCommandPage::VcsCommandPage()
|
VcsCommandPage::VcsCommandPage()
|
||||||
|
: m_startedStatus(tr("Command started..."))
|
||||||
{
|
{
|
||||||
|
resize(264, 200);
|
||||||
|
auto verticalLayout = new QVBoxLayout(this);
|
||||||
|
m_logPlainTextEdit = new QPlainTextEdit;
|
||||||
|
m_formatter = new OutputFormatter;
|
||||||
|
m_logPlainTextEdit->setReadOnly(true);
|
||||||
|
m_formatter->setPlainTextEdit(m_logPlainTextEdit);
|
||||||
|
|
||||||
|
verticalLayout->addWidget(m_logPlainTextEdit);
|
||||||
|
|
||||||
|
m_statusLabel = new QLabel;
|
||||||
|
verticalLayout->addWidget(m_statusLabel);
|
||||||
setTitle(tr("Checkout"));
|
setTitle(tr("Checkout"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VcsCommandPage::~VcsCommandPage()
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_state != Running, QApplication::restoreOverrideCursor());
|
||||||
|
delete m_formatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void VcsCommandPage::initializePage()
|
void VcsCommandPage::initializePage()
|
||||||
{
|
{
|
||||||
// Delay real initialization till after QWizard is done with its setup.
|
// Delay real initialization till after QWizard is done with its setup.
|
||||||
@@ -348,6 +260,21 @@ void VcsCommandPage::initializePage()
|
|||||||
QTimer::singleShot(0, this, &VcsCommandPage::delayedInitialize);
|
QTimer::singleShot(0, this, &VcsCommandPage::delayedInitialize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VcsCommandPage::isComplete() const
|
||||||
|
{
|
||||||
|
return m_state == Succeeded;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VcsCommandPage::handleReject()
|
||||||
|
{
|
||||||
|
if (m_state != Running)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (m_command)
|
||||||
|
m_command->cancel();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void VcsCommandPage::delayedInitialize()
|
void VcsCommandPage::delayedInitialize()
|
||||||
{
|
{
|
||||||
auto wiz = qobject_cast<JsonWizard *>(wizard());
|
auto wiz = qobject_cast<JsonWizard *>(wizard());
|
||||||
@@ -401,7 +328,7 @@ void VcsCommandPage::delayedInitialize()
|
|||||||
|
|
||||||
const QString runMessage = wiz->expander()->expand(m_runMessage);
|
const QString runMessage = wiz->expander()->expand(m_runMessage);
|
||||||
if (!runMessage.isEmpty())
|
if (!runMessage.isEmpty())
|
||||||
setStartedStatus(runMessage);
|
m_startedStatus = runMessage;
|
||||||
|
|
||||||
QStringList extraArgs;
|
QStringList extraArgs;
|
||||||
for (const QString &in : qAsConst(m_arguments)) {
|
for (const QString &in : qAsConst(m_arguments)) {
|
||||||
@@ -442,6 +369,61 @@ void VcsCommandPage::delayedInitialize()
|
|||||||
start(command);
|
start(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VcsCommandPage::start(VcsCommand *command)
|
||||||
|
{
|
||||||
|
if (!command) {
|
||||||
|
m_logPlainTextEdit->setPlainText(tr("No job running, please abort."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTC_ASSERT(m_state != Running, return);
|
||||||
|
m_command = command;
|
||||||
|
command->setProgressiveOutput(true);
|
||||||
|
connect(command, &VcsCommand::stdOutText, this, [this](const QString &text) {
|
||||||
|
m_formatter->appendMessage(text, StdOutFormat);
|
||||||
|
});
|
||||||
|
connect(command, &VcsCommand::stdErrText, this, [this](const QString &text) {
|
||||||
|
m_formatter->appendMessage(text, StdErrFormat);
|
||||||
|
});
|
||||||
|
connect(command, &VcsCommand::finished, this, &VcsCommandPage::finished);
|
||||||
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
|
m_logPlainTextEdit->clear();
|
||||||
|
m_overwriteOutput = false;
|
||||||
|
m_statusLabel->setText(m_startedStatus);
|
||||||
|
m_statusLabel->setPalette(QPalette());
|
||||||
|
m_state = Running;
|
||||||
|
command->execute();
|
||||||
|
|
||||||
|
wizard()->button(QWizard::BackButton)->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VcsCommandPage::finished(bool success, const QVariant &)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_state == Running, return);
|
||||||
|
|
||||||
|
QString message;
|
||||||
|
QPalette palette;
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
m_state = Succeeded;
|
||||||
|
message = tr("Succeeded.");
|
||||||
|
palette.setColor(QPalette::WindowText, creatorTheme()->color(Theme::TextColorNormal).name());
|
||||||
|
} else {
|
||||||
|
m_state = Failed;
|
||||||
|
message = tr("Failed.");
|
||||||
|
palette.setColor(QPalette::WindowText, creatorTheme()->color(Theme::TextColorError).name());
|
||||||
|
}
|
||||||
|
|
||||||
|
m_statusLabel->setText(message);
|
||||||
|
m_statusLabel->setPalette(palette);
|
||||||
|
|
||||||
|
QApplication::restoreOverrideCursor();
|
||||||
|
wizard()->button(QWizard::BackButton)->setEnabled(true);
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
emit completeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void VcsCommandPage::setCheckoutData(const QString &repo, const QString &baseDir, const QString &name,
|
void VcsCommandPage::setCheckoutData(const QString &repo, const QString &baseDir, const QString &name,
|
||||||
const QStringList &args)
|
const QStringList &args)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,10 +39,7 @@ class QPlainTextEdit;
|
|||||||
class QLabel;
|
class QLabel;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils { class OutputFormatter; }
|
||||||
class FilePath;
|
|
||||||
class OutputFormatter;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace VcsBase {
|
namespace VcsBase {
|
||||||
|
|
||||||
@@ -62,51 +59,17 @@ public:
|
|||||||
bool validateData(Utils::Id typeId, const QVariant &data, QString *errorMessage) override;
|
bool validateData(Utils::Id typeId, const QVariant &data, QString *errorMessage) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ShellCommandPage : public Utils::WizardPage
|
class VcsCommandPage : public Utils::WizardPage
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum State { Idle, Running, Failed, Succeeded };
|
|
||||||
|
|
||||||
explicit ShellCommandPage(QWidget *parent = nullptr);
|
|
||||||
~ShellCommandPage() override;
|
|
||||||
|
|
||||||
void setStartedStatus(const QString &startedStatus);
|
|
||||||
void start(VcsCommand *command);
|
|
||||||
|
|
||||||
bool isComplete() const override;
|
|
||||||
bool isRunning() const{ return m_state == Running; }
|
|
||||||
|
|
||||||
void terminate();
|
|
||||||
|
|
||||||
bool handleReject() override;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void finished(bool success);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void slotFinished(bool success, const QVariant &cookie);
|
|
||||||
|
|
||||||
QPlainTextEdit *m_logPlainTextEdit;
|
|
||||||
Utils::OutputFormatter *m_formatter;
|
|
||||||
QLabel *m_statusLabel;
|
|
||||||
|
|
||||||
VcsCommand *m_command = nullptr;
|
|
||||||
QString m_startedStatus;
|
|
||||||
bool m_overwriteOutput = false;
|
|
||||||
|
|
||||||
State m_state = Idle;
|
|
||||||
};
|
|
||||||
|
|
||||||
class VcsCommandPage : public ShellCommandPage
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VcsCommandPage();
|
VcsCommandPage();
|
||||||
|
~VcsCommandPage() override;
|
||||||
|
|
||||||
void initializePage() override;
|
void initializePage() override;
|
||||||
|
bool isComplete() const override;
|
||||||
|
bool handleReject() override;
|
||||||
|
|
||||||
void setCheckoutData(const QString &repo, const QString &baseDir, const QString &name,
|
void setCheckoutData(const QString &repo, const QString &baseDir, const QString &name,
|
||||||
const QStringList &args);
|
const QStringList &args);
|
||||||
@@ -115,10 +78,13 @@ public:
|
|||||||
void setVersionControlId(const QString &id);
|
void setVersionControlId(const QString &id);
|
||||||
void setRunMessage(const QString &msg);
|
void setRunMessage(const QString &msg);
|
||||||
|
|
||||||
private slots:
|
|
||||||
void delayedInitialize();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void delayedInitialize();
|
||||||
|
void start(VcsCommand *command);
|
||||||
|
void finished(bool success, const QVariant &cookie);
|
||||||
|
|
||||||
|
enum State { Idle, Running, Failed, Succeeded };
|
||||||
|
|
||||||
struct JobData
|
struct JobData
|
||||||
{
|
{
|
||||||
bool skipEmptyArguments = false;
|
bool skipEmptyArguments = false;
|
||||||
@@ -128,6 +94,15 @@ private:
|
|||||||
int timeOutFactor;
|
int timeOutFactor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QPlainTextEdit *m_logPlainTextEdit = nullptr;
|
||||||
|
Utils::OutputFormatter *m_formatter = nullptr;
|
||||||
|
QLabel *m_statusLabel = nullptr;
|
||||||
|
|
||||||
|
VcsCommand *m_command = nullptr;
|
||||||
|
QString m_startedStatus;
|
||||||
|
bool m_overwriteOutput = false;
|
||||||
|
|
||||||
|
State m_state = Idle;
|
||||||
QString m_vcsId;
|
QString m_vcsId;
|
||||||
QString m_repository;
|
QString m_repository;
|
||||||
QString m_directory;
|
QString m_directory;
|
||||||
|
|||||||
Reference in New Issue
Block a user