From 4ffb6649ec587bb0124ee4dd193d8734c6771fcd Mon Sep 17 00:00:00 2001
From: Benjamin Zeller <benjamin.zeller@canonical.com>
Date: Mon, 31 Aug 2015 14:11:31 +0200
Subject: [PATCH] CMakeProjectManager: Use factories to create runconfig

At the moment RC factories are ignored when creating
runconfigurations or updating them. This patch changes
the behavior so the RCs are first created/removed and
then updated to match the build targets. This way plugins
can provide custom factories and RCs for cmake projects.

Change-Id: I4a7797e7382784e33ecf016e322eab00e20c07e0
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
---
 .../cmakeprojectmanager/cmakeproject.cpp      | 27 +++----------------
 1 file changed, 3 insertions(+), 24 deletions(-)

diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
index 3fbc00f7462..4aeeb44014f 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
@@ -646,16 +646,14 @@ void CMakeProject::updateRunConfigurations()
 // TODO Compare with updateDefaultRunConfigurations();
 void CMakeProject::updateRunConfigurations(Target *t)
 {
+    // create new and remove obsolete RCs using the factories
+    t->updateDefaultRunConfigurations();
+
     // *Update* runconfigurations:
     QMultiMap<QString, CMakeRunConfiguration*> existingRunConfigurations;
-    QList<ProjectExplorer::RunConfiguration *> toRemove;
     foreach (ProjectExplorer::RunConfiguration *rc, t->runConfigurations()) {
         if (CMakeRunConfiguration* cmakeRC = qobject_cast<CMakeRunConfiguration *>(rc))
             existingRunConfigurations.insert(cmakeRC->title(), cmakeRC);
-        QtSupport::CustomExecutableRunConfiguration *ceRC =
-                qobject_cast<QtSupport::CustomExecutableRunConfiguration *>(rc);
-        if (ceRC && !ceRC->isConfigured())
-            toRemove << rc;
     }
 
     foreach (const CMakeBuildTarget &ct, buildTargets()) {
@@ -671,27 +669,8 @@ void CMakeProject::updateRunConfigurations(Target *t)
                 rc->setBaseWorkingDirectory(ct.workingDirectory);
                 rc->setEnabled(true);
             }
-            existingRunConfigurations.remove(ct.title);
-        } else {
-            // Does not exist yet
-            Core::Id id = CMakeRunConfigurationFactory::idFromBuildTarget(ct.title);
-            CMakeRunConfiguration *rc = new CMakeRunConfiguration(t, id, ct.executable,
-                                                                  ct.workingDirectory, ct.title);
-            t->addRunConfiguration(rc);
         }
     }
-    QMultiMap<QString, CMakeRunConfiguration *>::const_iterator it =
-            existingRunConfigurations.constBegin();
-    for ( ; it != existingRunConfigurations.constEnd(); ++it) {
-        CMakeRunConfiguration *rc = it.value();
-        // The executables for those runconfigurations aren't build by the current buildconfiguration
-        // We just set a disable flag and show that in the display name
-        rc->setEnabled(false);
-        // removeRunConfiguration(rc);
-    }
-
-    foreach (ProjectExplorer::RunConfiguration *rc, toRemove)
-        t->removeRunConfiguration(rc);
 
     if (t->runConfigurations().isEmpty()) {
         // Oh no, no run configuration,
-- 
GitLab