QtSupport: Use TerminalAspect in CustomExecutableRunConfiguration

Change-Id: I4fddb145ed03b3bd28836cdd1d7b9f810a0ad111
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
hjk
2015-05-12 18:26:35 +02:00
parent aa78053974
commit 75784cd266
4 changed files with 33 additions and 32 deletions

View File

@@ -80,7 +80,8 @@ void TerminalAspect::addToMainConfigurationWidget(QWidget *parent, QFormLayout *
layout->addRow(QString(), m_checkBox); layout->addRow(QString(), m_checkBox);
connect(m_checkBox.data(), &QAbstractButton::clicked, this, [this] { connect(m_checkBox.data(), &QAbstractButton::clicked, this, [this] {
m_userSet = true; m_userSet = true;
setUseTerminal(true); m_useTerminal = m_checkBox->isChecked();
emit useTerminalChanged(m_useTerminal);
}); });
} }
@@ -121,6 +122,8 @@ ApplicationLauncher::Mode TerminalAspect::runMode() const
void TerminalAspect::setRunMode(ApplicationLauncher::Mode runMode) void TerminalAspect::setRunMode(ApplicationLauncher::Mode runMode)
{ {
setUseTerminal(runMode == ApplicationLauncher::Console); setUseTerminal(runMode == ApplicationLauncher::Console);
if (m_checkBox)
m_checkBox->setChecked(m_useTerminal);
} }
/*! /*!

View File

@@ -33,6 +33,7 @@
#include <coreplugin/variablechooser.h> #include <coreplugin/variablechooser.h>
#include <projectexplorer/environmentaspect.h> #include <projectexplorer/environmentaspect.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <utils/detailswidget.h> #include <utils/detailswidget.h>
@@ -45,12 +46,13 @@
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
using namespace ProjectExplorer;
namespace QtSupport { namespace QtSupport {
namespace Internal { namespace Internal {
CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomExecutableRunConfiguration *rc, ApplyMode mode) CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomExecutableRunConfiguration *rc, ApplyMode mode)
: m_ignoreChange(false), m_runConfiguration(rc) : m_ignoreChange(false), m_runConfiguration(rc), m_temporaryTerminalAspect(0)
{ {
QFormLayout *layout = new QFormLayout; QFormLayout *layout = new QFormLayout;
layout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); layout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
@@ -72,8 +74,15 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE
layout->addRow(tr("Working directory:"), m_workingDirectory); layout->addRow(tr("Working directory:"), m_workingDirectory);
m_useTerminalCheck = new QCheckBox(tr("Run in &terminal"), this); TerminalAspect *terminalAspect = rc->extraAspect<TerminalAspect>();
layout->addRow(QString(), m_useTerminalCheck); if (mode == InstantApply) {
terminalAspect->addToMainConfigurationWidget(this, layout);
} else {
m_temporaryTerminalAspect = terminalAspect->clone(rc);
m_temporaryTerminalAspect->addToMainConfigurationWidget(this, layout);
connect(m_temporaryTerminalAspect, &TerminalAspect::useTerminalChanged,
this, &CustomExecutableConfigurationWidget::validChanged);
}
QVBoxLayout *vbox = new QVBoxLayout(this); QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0); vbox->setMargin(0);
@@ -95,8 +104,6 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE
this, SLOT(argumentsEdited(QString))); this, SLOT(argumentsEdited(QString)));
connect(m_workingDirectory, SIGNAL(changed(QString)), connect(m_workingDirectory, SIGNAL(changed(QString)),
this, SLOT(workingDirectoryEdited())); this, SLOT(workingDirectoryEdited()));
connect(m_useTerminalCheck, SIGNAL(toggled(bool)),
this, SLOT(termToggled(bool)));
} else { } else {
connect(m_executableChooser, SIGNAL(changed(QString)), connect(m_executableChooser, SIGNAL(changed(QString)),
this, SIGNAL(validChanged())); this, SIGNAL(validChanged()));
@@ -104,8 +111,6 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE
this, SIGNAL(validChanged())); this, SIGNAL(validChanged()));
connect(m_workingDirectory, SIGNAL(changed(QString)), connect(m_workingDirectory, SIGNAL(changed(QString)),
this, SIGNAL(validChanged())); this, SIGNAL(validChanged()));
connect(m_useTerminalCheck, SIGNAL(toggled(bool)),
this, SIGNAL(validChanged()));
} }
ProjectExplorer::EnvironmentAspect *aspect = rc->extraAspect<ProjectExplorer::EnvironmentAspect>(); ProjectExplorer::EnvironmentAspect *aspect = rc->extraAspect<ProjectExplorer::EnvironmentAspect>();
@@ -123,6 +128,11 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE
Core::VariableChooser::addSupportForChildWidgets(this, m_runConfiguration->macroExpander()); Core::VariableChooser::addSupportForChildWidgets(this, m_runConfiguration->macroExpander());
} }
CustomExecutableConfigurationWidget::~CustomExecutableConfigurationWidget()
{
delete m_temporaryTerminalAspect;
}
void CustomExecutableConfigurationWidget::environmentWasChanged() void CustomExecutableConfigurationWidget::environmentWasChanged()
{ {
ProjectExplorer::EnvironmentAspect *aspect ProjectExplorer::EnvironmentAspect *aspect
@@ -151,14 +161,6 @@ void CustomExecutableConfigurationWidget::workingDirectoryEdited()
m_ignoreChange = false; m_ignoreChange = false;
} }
void CustomExecutableConfigurationWidget::termToggled(bool on)
{
m_ignoreChange = true;
m_runConfiguration->setRunMode(on ? ProjectExplorer::ApplicationLauncher::Console
: ProjectExplorer::ApplicationLauncher::Gui);
m_ignoreChange = false;
}
void CustomExecutableConfigurationWidget::changed() void CustomExecutableConfigurationWidget::changed()
{ {
// We triggered the change, don't update us // We triggered the change, don't update us
@@ -168,8 +170,6 @@ void CustomExecutableConfigurationWidget::changed()
m_executableChooser->setPath(m_runConfiguration->rawExecutable()); m_executableChooser->setPath(m_runConfiguration->rawExecutable());
m_commandLineArgumentsLineEdit->setText(m_runConfiguration->rawCommandLineArguments()); m_commandLineArgumentsLineEdit->setText(m_runConfiguration->rawCommandLineArguments());
m_workingDirectory->setPath(m_runConfiguration->baseWorkingDirectory()); m_workingDirectory->setPath(m_runConfiguration->baseWorkingDirectory());
m_useTerminalCheck->setChecked(m_runConfiguration->runMode()
== ProjectExplorer::ApplicationLauncher::Console);
} }
void CustomExecutableConfigurationWidget::apply() void CustomExecutableConfigurationWidget::apply()
@@ -178,8 +178,7 @@ void CustomExecutableConfigurationWidget::apply()
m_runConfiguration->setExecutable(m_executableChooser->rawPath()); m_runConfiguration->setExecutable(m_executableChooser->rawPath());
m_runConfiguration->setCommandLineArguments(m_commandLineArgumentsLineEdit->text()); m_runConfiguration->setCommandLineArguments(m_commandLineArgumentsLineEdit->text());
m_runConfiguration->setBaseWorkingDirectory(m_workingDirectory->rawPath()); m_runConfiguration->setBaseWorkingDirectory(m_workingDirectory->rawPath());
m_runConfiguration->setRunMode(m_useTerminalCheck->isChecked() ? ProjectExplorer::ApplicationLauncher::Console m_runConfiguration->setRunMode(m_temporaryTerminalAspect->runMode());
: ProjectExplorer::ApplicationLauncher::Gui);
m_ignoreChange = false; m_ignoreChange = false;
} }

View File

@@ -46,6 +46,10 @@ class DetailsWidget;
class PathChooser; class PathChooser;
} }
namespace ProjectExplorer {
class TerminalAspect;
}
namespace QtSupport { namespace QtSupport {
class CustomExecutableRunConfiguration; class CustomExecutableRunConfiguration;
@@ -58,6 +62,8 @@ class CustomExecutableConfigurationWidget : public QWidget
public: public:
enum ApplyMode { InstantApply, DelayedApply}; enum ApplyMode { InstantApply, DelayedApply};
CustomExecutableConfigurationWidget(CustomExecutableRunConfiguration *rc, ApplyMode mode); CustomExecutableConfigurationWidget(CustomExecutableRunConfiguration *rc, ApplyMode mode);
~CustomExecutableConfigurationWidget();
void apply(); // only used for DelayedApply void apply(); // only used for DelayedApply
bool isValid() const; bool isValid() const;
@@ -70,16 +76,15 @@ private slots:
void executableEdited(); void executableEdited();
void argumentsEdited(const QString &arguments); void argumentsEdited(const QString &arguments);
void workingDirectoryEdited(); void workingDirectoryEdited();
void termToggled(bool);
void environmentWasChanged(); void environmentWasChanged();
private: private:
bool m_ignoreChange; bool m_ignoreChange;
CustomExecutableRunConfiguration *m_runConfiguration; CustomExecutableRunConfiguration *m_runConfiguration;
ProjectExplorer::TerminalAspect *m_temporaryTerminalAspect;
Utils::PathChooser *m_executableChooser; Utils::PathChooser *m_executableChooser;
QLineEdit *m_commandLineArgumentsLineEdit; QLineEdit *m_commandLineArgumentsLineEdit;
Utils::PathChooser *m_workingDirectory; Utils::PathChooser *m_workingDirectory;
QCheckBox *m_useTerminalCheck;
Utils::DetailsWidget *m_detailsContainer; Utils::DetailsWidget *m_detailsContainer;
}; };

View File

@@ -35,6 +35,7 @@
#include <projectexplorer/buildconfiguration.h> #include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/localenvironmentaspect.h> #include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <projectexplorer/abi.h> #include <projectexplorer/abi.h>
@@ -61,7 +62,6 @@ const char CUSTOM_EXECUTABLE_ID[] = "ProjectExplorer.CustomExecutableRunConfigur
const char EXECUTABLE_KEY[] = "ProjectExplorer.CustomExecutableRunConfiguration.Executable"; const char EXECUTABLE_KEY[] = "ProjectExplorer.CustomExecutableRunConfiguration.Executable";
const char ARGUMENTS_KEY[] = "ProjectExplorer.CustomExecutableRunConfiguration.Arguments"; const char ARGUMENTS_KEY[] = "ProjectExplorer.CustomExecutableRunConfiguration.Arguments";
const char WORKING_DIRECTORY_KEY[] = "ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory"; const char WORKING_DIRECTORY_KEY[] = "ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory";
const char USE_TERMINAL_KEY[] = "ProjectExplorer.CustomExecutableRunConfiguration.UseTerminal";
} }
void CustomExecutableRunConfiguration::ctor() void CustomExecutableRunConfiguration::ctor()
@@ -72,10 +72,10 @@ void CustomExecutableRunConfiguration::ctor()
CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *parent) : CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *parent) :
LocalApplicationRunConfiguration(parent, Core::Id(CUSTOM_EXECUTABLE_ID)), LocalApplicationRunConfiguration(parent, Core::Id(CUSTOM_EXECUTABLE_ID)),
m_workingDirectory(QLatin1String(Constants::DEFAULT_WORKING_DIR)), m_workingDirectory(QLatin1String(Constants::DEFAULT_WORKING_DIR)),
m_runMode(ProjectExplorer::ApplicationLauncher::Gui),
m_dialog(0) m_dialog(0)
{ {
addExtraAspect(new LocalEnvironmentAspect(this)); addExtraAspect(new LocalEnvironmentAspect(this));
addExtraAspect(new TerminalAspect(this, QStringLiteral("ProjectExplorer.CustomExecutableRunConfiguration.UseTerminal")));
if (!parent->activeBuildConfiguration()) if (!parent->activeBuildConfiguration())
m_workingDirectory = QLatin1String(Constants::DEFAULT_WORKING_DIR_ALTERNATE); m_workingDirectory = QLatin1String(Constants::DEFAULT_WORKING_DIR_ALTERNATE);
@@ -88,7 +88,6 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *paren
m_executable(source->m_executable), m_executable(source->m_executable),
m_workingDirectory(source->m_workingDirectory), m_workingDirectory(source->m_workingDirectory),
m_cmdArguments(source->m_cmdArguments), m_cmdArguments(source->m_cmdArguments),
m_runMode(source->m_runMode),
m_dialog(0) m_dialog(0)
{ {
ctor(); ctor();
@@ -246,7 +245,7 @@ bool CustomExecutableRunConfiguration::isConfigured() const
ApplicationLauncher::Mode CustomExecutableRunConfiguration::runMode() const ApplicationLauncher::Mode CustomExecutableRunConfiguration::runMode() const
{ {
return m_runMode; return extraAspect<TerminalAspect>()->runMode();
} }
QString CustomExecutableRunConfiguration::workingDirectory() const QString CustomExecutableRunConfiguration::workingDirectory() const
@@ -287,8 +286,6 @@ QVariantMap CustomExecutableRunConfiguration::toMap() const
map.insert(QLatin1String(EXECUTABLE_KEY), m_executable); map.insert(QLatin1String(EXECUTABLE_KEY), m_executable);
map.insert(QLatin1String(ARGUMENTS_KEY), m_cmdArguments); map.insert(QLatin1String(ARGUMENTS_KEY), m_cmdArguments);
map.insert(QLatin1String(WORKING_DIRECTORY_KEY), m_workingDirectory); map.insert(QLatin1String(WORKING_DIRECTORY_KEY), m_workingDirectory);
map.insert(QLatin1String(USE_TERMINAL_KEY),
m_runMode == ProjectExplorer::ApplicationLauncher::Console);
return map; return map;
} }
@@ -297,9 +294,6 @@ bool CustomExecutableRunConfiguration::fromMap(const QVariantMap &map)
m_executable = map.value(QLatin1String(EXECUTABLE_KEY)).toString(); m_executable = map.value(QLatin1String(EXECUTABLE_KEY)).toString();
m_cmdArguments = map.value(QLatin1String(ARGUMENTS_KEY)).toString(); m_cmdArguments = map.value(QLatin1String(ARGUMENTS_KEY)).toString();
m_workingDirectory = map.value(QLatin1String(WORKING_DIRECTORY_KEY)).toString(); m_workingDirectory = map.value(QLatin1String(WORKING_DIRECTORY_KEY)).toString();
m_runMode = map.value(QLatin1String(USE_TERMINAL_KEY)).toBool()
? ProjectExplorer::ApplicationLauncher::Console
: ProjectExplorer::ApplicationLauncher::Gui;
setDefaultDisplayName(defaultDisplayName()); setDefaultDisplayName(defaultDisplayName());
return LocalApplicationRunConfiguration::fromMap(map); return LocalApplicationRunConfiguration::fromMap(map);
@@ -328,7 +322,7 @@ void CustomExecutableRunConfiguration::setBaseWorkingDirectory(const QString &wo
void CustomExecutableRunConfiguration::setRunMode(ApplicationLauncher::Mode runMode) void CustomExecutableRunConfiguration::setRunMode(ApplicationLauncher::Mode runMode)
{ {
m_runMode = runMode; extraAspect<TerminalAspect>()->setRunMode(runMode);
emit changed(); emit changed();
} }