From 41a91ff9d2fa60d6f186d3cf7bff94715b6bac57 Mon Sep 17 00:00:00 2001
From: Tobias Hunger <tobias.hunger@nokia.com>
Date: Tue, 30 Mar 2010 19:14:26 +0200
Subject: [PATCH] Remove customexecutable RCs again if they are unused

---
 .../customexecutablerunconfiguration.cpp             |  4 ++++
 .../customexecutablerunconfiguration.h               |  4 ++++
 src/plugins/qt4projectmanager/qt4project.cpp         | 12 ++++++++++++
 3 files changed, 20 insertions(+)

diff --git a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp
index 491ff4f085e..e087914cf30 100644
--- a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp
+++ b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp
@@ -371,6 +371,10 @@ QString CustomExecutableRunConfiguration::executable() const
     return exec;
 }
 
+bool CustomExecutableRunConfiguration::isConfigured() const
+{
+    return !m_executable.isEmpty();
+}
 
 LocalApplicationRunConfiguration::RunMode CustomExecutableRunConfiguration::runMode() const
 {
diff --git a/src/plugins/projectexplorer/customexecutablerunconfiguration.h b/src/plugins/projectexplorer/customexecutablerunconfiguration.h
index 9e056a981bb..c591a1e9ea8 100644
--- a/src/plugins/projectexplorer/customexecutablerunconfiguration.h
+++ b/src/plugins/projectexplorer/customexecutablerunconfiguration.h
@@ -76,6 +76,10 @@ public:
      */
     QString executable() const;
 
+    /** Returns whether this runconfiguration ever was configured with a executable
+     */
+    bool isConfigured() const;
+
     /**
      * Returns only what is stored in the internal variable, not what we might
      * get after extending it with a path or asking the user. This value is
diff --git a/src/plugins/qt4projectmanager/qt4project.cpp b/src/plugins/qt4projectmanager/qt4project.cpp
index 8c46d2c8980..2399e015333 100644
--- a/src/plugins/qt4projectmanager/qt4project.cpp
+++ b/src/plugins/qt4projectmanager/qt4project.cpp
@@ -999,6 +999,18 @@ void Qt4Project::checkForNewApplicationProjects()
             if (!found) {
                 qt4Target->addRunConfigurationForPath(qt4proFile->path());
             }
+
+            // Remove unused CustomExecutableRCs:
+            if (target->runConfigurations().count() > 1) {
+                QList<RunConfiguration*> toRemove;
+                foreach (RunConfiguration * rc, target->runConfigurations()) {
+                    CustomExecutableRunConfiguration *cerc = qobject_cast<CustomExecutableRunConfiguration *>(rc);
+                    if (cerc && !cerc->isConfigured())
+                        toRemove.append(rc);
+                }
+                foreach (RunConfiguration *rc, toRemove)
+                    target->removeRunConfiguration(rc);
+            }
         }
     }
 }
-- 
GitLab