diff --git a/src/plugins/qtsupport/customexecutableconfigurationwidget.cpp b/src/plugins/qtsupport/customexecutableconfigurationwidget.cpp index 7202a7b650f8d106c033c08a81e2d336acb2e3e2..be0a4c5e2ab1757622a2b76c45512de74d37d73e 100644 --- a/src/plugins/qtsupport/customexecutableconfigurationwidget.cpp +++ b/src/plugins/qtsupport/customexecutableconfigurationwidget.cpp @@ -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 diff --git a/src/plugins/qtsupport/customexecutableconfigurationwidget.h b/src/plugins/qtsupport/customexecutableconfigurationwidget.h index b0990a1e8b409fa56bfaeaf6b87dfba906952dc3..568a13852d4e6acbdef9e06bbbeadc39bff238f6 100644 --- a/src/plugins/qtsupport/customexecutableconfigurationwidget.h +++ b/src/plugins/qtsupport/customexecutableconfigurationwidget.h @@ -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(); diff --git a/src/plugins/qtsupport/customexecutablerunconfiguration.cpp b/src/plugins/qtsupport/customexecutablerunconfiguration.cpp index f6f63034ce7665b92261711923fa476bdbac274e..da6652ad6977453bca2224628a27991336318822 100644 --- a/src/plugins/qtsupport/customexecutablerunconfiguration.cpp +++ b/src/plugins/qtsupport/customexecutablerunconfiguration.cpp @@ -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