From af6e06dfb2391875d404f63980766aa10ef4fdb9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint <Friedemann.Kleint@nokia.com> Date: Tue, 20 Dec 2011 17:03:10 +0100 Subject: [PATCH] Do not start LocalRunConfiguration when the executable is empty. When accidentally pressing 'Debug' on a library project, the dialog asking for the executable pops up and debugging still starts although cancel is pressed. Add dialog title, set flags, and check its return values. Change-Id: I8518b8af70b12a7059f9ee0e20a9d0b325db1e98 Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com> --- src/plugins/debugger/debuggerrunner.cpp | 6 +++++- .../customexecutablerunconfiguration.cpp | 21 ++++++++++++------- .../localapplicationruncontrol.cpp | 6 +++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/plugins/debugger/debuggerrunner.cpp b/src/plugins/debugger/debuggerrunner.cpp index aae13465670..db59fd1b150 100644 --- a/src/plugins/debugger/debuggerrunner.cpp +++ b/src/plugins/debugger/debuggerrunner.cpp @@ -717,7 +717,6 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration); QTC_ASSERT(rc, return sp); - sp.startMode = StartInternal; sp.environment = rc->environment(); sp.workingDirectory = rc->workingDirectory(); @@ -727,6 +726,9 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu #endif sp.executable = rc->executable(); + if (sp.executable.isEmpty()) + return sp; + sp.startMode = StartInternal; sp.processArgs = rc->commandLineArguments(); sp.toolChainAbi = rc->abi(); if (!sp.toolChainAbi.isValid()) { @@ -784,6 +786,8 @@ RunControl *DebuggerRunControlFactory::create { QTC_ASSERT(mode == Constants::DEBUGMODE || mode == Constants::DEBUGMODE2, return 0); DebuggerStartParameters sp = localStartParameters(runConfiguration); + if (sp.startMode == NoStartMode) + return 0; if (mode == Constants::DEBUGMODE2) sp.breakOnMain = true; return create(sp, runConfiguration); diff --git a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp index 8cb89f70d75..8dc30c72d8a 100644 --- a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp +++ b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp @@ -128,9 +128,12 @@ QString CustomExecutableRunConfiguration::executable() const if (exec.isEmpty() || !QFileInfo(exec).exists()) { // Oh the executable doesn't exists, ask the user. - QWidget *confWidget = const_cast<CustomExecutableRunConfiguration *>(this)->createConfigurationWidget(); + CustomExecutableRunConfiguration *that = const_cast<CustomExecutableRunConfiguration *>(this); + QWidget *confWidget = that->createConfigurationWidget(); confWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); QDialog dialog(Core::ICore::instance()->mainWindow()); + dialog.setWindowTitle(displayName()); + dialog.setWindowFlags(dialog.windowFlags() & ~Qt::WindowContextHelpButtonHint); dialog.setLayout(new QVBoxLayout()); QLabel *label = new QLabel(tr("Could not find the executable, please specify one.")); label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); @@ -146,14 +149,18 @@ QString CustomExecutableRunConfiguration::executable() const QString oldWorkingDirectory = m_workingDirectory; QString oldCmdArguments = m_cmdArguments; - if (dialog.exec()) { + if (dialog.exec() == QDialog::Accepted) { return executable(); } else { - CustomExecutableRunConfiguration *that = const_cast<CustomExecutableRunConfiguration *>(this); - that->m_executable = oldExecutable; - that->m_workingDirectory = oldWorkingDirectory; - that->m_cmdArguments = oldCmdArguments; - emit that->changed(); + // Restore values changed by the configuration widget. + if (that->m_executable != oldExecutable + || that->m_workingDirectory != oldWorkingDirectory + || that->m_cmdArguments != oldCmdArguments) { + that->m_executable = oldExecutable; + that->m_workingDirectory = oldWorkingDirectory; + that->m_cmdArguments = oldCmdArguments; + emit that->changed(); + } return QString(); } } diff --git a/src/plugins/projectexplorer/localapplicationruncontrol.cpp b/src/plugins/projectexplorer/localapplicationruncontrol.cpp index 85c90cdbd35..2ab3cfbd0fa 100644 --- a/src/plugins/projectexplorer/localapplicationruncontrol.cpp +++ b/src/plugins/projectexplorer/localapplicationruncontrol.cpp @@ -67,7 +67,11 @@ QString LocalApplicationRunControlFactory::displayName() const RunControl *LocalApplicationRunControlFactory::create(ProjectExplorer::RunConfiguration *runConfiguration, const QString &mode) { QTC_ASSERT(canRun(runConfiguration, mode), return 0); - return new LocalApplicationRunControl(qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration), mode); + LocalApplicationRunConfiguration *localRunConfiguration = qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration); + // Force the dialog about executables at this point and fail if there is none + if (localRunConfiguration->executable().isEmpty()) + return 0; + return new LocalApplicationRunControl(localRunConfiguration, mode); } RunConfigWidget *LocalApplicationRunControlFactory::createConfigurationWidget(RunConfiguration *runConfiguration) -- GitLab