Commit d7551d0c authored by Daniel Teske's avatar Daniel Teske
Browse files

CustomExecutableRunConfigurationWidget: Make different use cases explicit



Change-Id: I435ce0fe59d9e5d937e5ed3ed06ddbf4a54f967d
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 5a06e6f9
......@@ -47,7 +47,7 @@
namespace QtSupport {
namespace Internal {
CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomExecutableRunConfiguration *rc)
CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomExecutableRunConfiguration *rc, ApplyMode mode)
: m_ignoreChange(false), m_runConfiguration(rc)
{
QFormLayout *layout = new QFormLayout;
......@@ -86,14 +86,25 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE
changed();
connect(m_executableChooser, SIGNAL(changed(QString)),
this, SLOT(executableEdited()));
connect(m_commandLineArgumentsLineEdit, SIGNAL(textEdited(QString)),
this, SLOT(argumentsEdited(QString)));
connect(m_workingDirectory, SIGNAL(changed(QString)),
this, SLOT(workingDirectoryEdited()));
connect(m_useTerminalCheck, SIGNAL(toggled(bool)),
this, SLOT(termToggled(bool)));
if (mode == InstantApply) {
connect(m_executableChooser, SIGNAL(changed(QString)),
this, SLOT(executableEdited()));
connect(m_commandLineArgumentsLineEdit, SIGNAL(textEdited(QString)),
this, SLOT(argumentsEdited(QString)));
connect(m_workingDirectory, SIGNAL(changed(QString)),
this, SLOT(workingDirectoryEdited()));
connect(m_useTerminalCheck, SIGNAL(toggled(bool)),
this, SLOT(termToggled(bool)));
} else {
connect(m_executableChooser, SIGNAL(changed(QString)),
this, SIGNAL(validChanged()));
connect(m_commandLineArgumentsLineEdit, SIGNAL(textEdited(QString)),
this, SIGNAL(validChanged()));
connect(m_workingDirectory, SIGNAL(changed(QString)),
this, SIGNAL(validChanged()));
connect(m_useTerminalCheck, SIGNAL(toggled(bool)),
this, SIGNAL(validChanged()));
}
ProjectExplorer::EnvironmentAspect *aspect = rc->extraAspect<ProjectExplorer::EnvironmentAspect>();
if (aspect) {
......@@ -101,7 +112,11 @@ CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomE
environmentWasChanged();
}
connect(m_runConfiguration, SIGNAL(changed()), this, SLOT(changed()));
// If we are in mode InstantApply, we keep us in sync with the rc
// otherwise we ignore changes to the rc and override them on apply,
// or keep them on cancel
if (mode == InstantApply)
connect(m_runConfiguration, SIGNAL(changed()), this, SLOT(changed()));
}
void CustomExecutableConfigurationWidget::environmentWasChanged()
......@@ -153,5 +168,21 @@ void CustomExecutableConfigurationWidget::changed()
== ProjectExplorer::ApplicationLauncher::Console);
}
void CustomExecutableConfigurationWidget::apply()
{
m_ignoreChange = true;
m_runConfiguration->setExecutable(m_executableChooser->rawPath());
m_runConfiguration->setCommandLineArguments(m_commandLineArgumentsLineEdit->text());
m_runConfiguration->setBaseWorkingDirectory(m_workingDirectory->rawPath());
m_runConfiguration->setRunMode(m_useTerminalCheck->isChecked() ? ProjectExplorer::ApplicationLauncher::Console
: ProjectExplorer::ApplicationLauncher::Gui);
m_ignoreChange = false;
}
bool CustomExecutableConfigurationWidget::isValid() const
{
return !m_executableChooser->rawPath().isEmpty();
}
} // namespace Internal
} // namespace QtSupport
......@@ -55,7 +55,13 @@ class CustomExecutableConfigurationWidget : public QWidget
Q_OBJECT
public:
CustomExecutableConfigurationWidget(CustomExecutableRunConfiguration *rc);
enum ApplyMode { InstantApply, DelayedApply};
CustomExecutableConfigurationWidget(CustomExecutableRunConfiguration *rc, ApplyMode mode);
void apply(); // only used for DelayedApply
bool isValid() const;
signals:
void validChanged();
private slots:
void changed();
......
......@@ -104,10 +104,12 @@ class CustomExecutableDialog : public QDialog
public:
explicit CustomExecutableDialog(CustomExecutableRunConfiguration *rc, QWidget *parent = 0);
void accept();
private slots:
void changed()
{
setOkButtonEnabled(m_runConfiguration->isConfigured());
setOkButtonEnabled(m_widget->isValid());
}
private:
......@@ -117,6 +119,7 @@ private:
}
QDialogButtonBox *m_dialogButtonBox;
CustomExecutableConfigurationWidget *m_widget;
CustomExecutableRunConfiguration *m_runConfiguration;
};
......@@ -125,15 +128,15 @@ CustomExecutableDialog::CustomExecutableDialog(CustomExecutableRunConfiguration
, m_dialogButtonBox(new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel))
, m_runConfiguration(rc)
{
connect(rc, SIGNAL(changed()), this, SLOT(changed()));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
QVBoxLayout *layout = new QVBoxLayout(this);
QLabel *label = new QLabel(tr("Could not find the executable, please specify one."));
label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
layout->addWidget(label);
QWidget *configWidget = rc->createConfigurationWidget();
configWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
layout->addWidget(configWidget);
m_widget = new CustomExecutableConfigurationWidget(rc, CustomExecutableConfigurationWidget::DelayedApply);
m_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
connect(m_widget, SIGNAL(validChanged()), this, SLOT(changed()));
layout->addWidget(m_widget);
setOkButtonEnabled(false);
connect(m_dialogButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(m_dialogButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
......@@ -141,6 +144,12 @@ CustomExecutableDialog::CustomExecutableDialog(CustomExecutableRunConfiguration
layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
}
void CustomExecutableDialog::accept()
{
m_widget->apply();
QDialog::accept();
}
bool CustomExecutableRunConfiguration::ensureConfigured(QString *errorMessage)
{
if (isConfigured())
......@@ -301,7 +310,7 @@ void CustomExecutableRunConfiguration::setRunMode(ApplicationLauncher::Mode runM
QWidget *CustomExecutableRunConfiguration::createConfigurationWidget()
{
return new CustomExecutableConfigurationWidget(this);
return new CustomExecutableConfigurationWidget(this, CustomExecutableConfigurationWidget::InstantApply);
}
Abi CustomExecutableRunConfiguration::abi() const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment