From 66bea14fef08fbae841995e0b1e288fb66cc4678 Mon Sep 17 00:00:00 2001
From: dt <qtc-committer@nokia.com>
Date: Tue, 5 May 2009 18:21:40 +0200
Subject: [PATCH] Add options to: Save All before Build and Build before Run

So now you can choose not to automatically build before running.
And you can chose to automatically save all files before building.
The options are global and the default is the same as before.
---
 src/plugins/projectexplorer/project.cpp       |   6 +-
 .../projectexplorer/projectexplorer.cpp       | 111 ++++++++++++------
 src/plugins/projectexplorer/projectexplorer.h |  11 ++
 .../projectexplorer/projectexplorer.pro       |  11 +-
 .../projectexplorerconstants.h                |   5 +
 5 files changed, 98 insertions(+), 46 deletions(-)

diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp
index 459f8114acf..cc18fbcfd36 100644
--- a/src/plugins/projectexplorer/project.cpp
+++ b/src/plugins/projectexplorer/project.cpp
@@ -506,17 +506,17 @@ void Project::setDisplayNameFor(const QString &buildConfiguration, const QString
     emit buildConfigurationDisplayNameChanged(buildConfiguration);
 }
 
-QByteArray Project::predefinedMacros(const QString &fileName) const
+QByteArray Project::predefinedMacros(const QString &) const
 {
     return QByteArray();
 }
 
-QStringList Project::includePaths(const QString &fileName) const
+QStringList Project::includePaths(const QString &) const
 {
     return QStringList();
 }
 
-QStringList Project::frameworkPaths(const QString &fileName) const
+QStringList Project::frameworkPaths(const QString &) const
 {
     return QStringList();
 }
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index ebb6a1000a7..4dbf49d7561 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -56,6 +56,7 @@
 #include "session.h"
 #include "sessiondialog.h"
 #include "buildparserfactory.h"
+#include "projectexplorersettingspage.h"
 
 #include <coreplugin/basemode.h>
 #include <coreplugin/coreconstants.h>
@@ -233,6 +234,9 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
     addAutoReleasedObject(new GccParserFactory);
     addAutoReleasedObject(new MsvcParserFactory);
 
+    // Settings page
+    addAutoReleasedObject(new ProjectExplorerSettingsPage);
+
     // context menus
     Core::ActionContainer *msessionContextMenu =
         am->createMenu(Constants::M_SESSIONCONTEXT);
@@ -619,7 +623,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
     }
     // < -- Creator 1.0 compatibility code
 
-    // TODO restore recentProjects
     if (QSettings *s = core->settings()) {
         const QStringList fileNames = s->value("ProjectExplorer/RecentProjects/FileNames").toStringList();
         const QStringList displayNames = s->value("ProjectExplorer/RecentProjects/DisplayNames").toStringList();
@@ -631,7 +634,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
         }
     }
 
-
+    if (QSettings *s = core->settings()) {
+        m_projectExplorerSettings.buildBeforeRun = s->value("ProjectExplorer/Settings/BuildBeforeRun", true).toBool();
+        m_projectExplorerSettings.saveBeforeBuild = s->value("ProjectExplorer/Settings/SaveBeforeBuild", false).toBool();
+    }
 
     connect(m_sessionManagerAction, SIGNAL(triggered()), this, SLOT(showSessionManager()));
     connect(m_newAction, SIGNAL(triggered()), this, SLOT(newProject()));
@@ -856,6 +862,9 @@ void ProjectExplorerPlugin::savePersistentSettings()
 
         s->setValue("ProjectExplorer/RecentProjects/FileNames", fileNames);
         s->setValue("ProjectExplorer/RecentProjects/DisplayNames", displayNames);
+
+        s->setValue("ProjectExplorer/Settings/BuildBeforeRun", m_projectExplorerSettings.buildBeforeRun);
+        s->setValue("ProjectExplorer/Settings/SaveBeforeBuild", m_projectExplorerSettings.saveBeforeBuild);
     }
 }
 
@@ -1110,6 +1119,36 @@ void ProjectExplorerPlugin::buildStateChanged(Project * pro)
     updateActions();
 }
 
+void ProjectExplorerPlugin::executeRunConfiguration(QSharedPointer<RunConfiguration> runConfiguration, const QString &runMode)
+{
+    IRunConfigurationRunner *runner = findRunner(runConfiguration, runMode);
+    if (runner) {
+        emit aboutToExecuteProject(runConfiguration->project());
+
+        RunControl *control = runner->run(runConfiguration, runMode);
+        m_outputPane->createNewOutputWindow(control);
+        if (runMode == ProjectExplorer::Constants::RUNMODE)
+            m_outputPane->popup(false);
+        m_outputPane->showTabFor(control);
+
+        connect(control, SIGNAL(addToOutputWindow(RunControl *, const QString &)),
+                this, SLOT(addToApplicationOutputWindow(RunControl *, const QString &)));
+        connect(control, SIGNAL(addToOutputWindowInline(RunControl *, const QString &)),
+                this, SLOT(addToApplicationOutputWindowInline(RunControl *, const QString &)));
+        connect(control, SIGNAL(error(RunControl *, const QString &)),
+                this, SLOT(addErrorToApplicationOutputWindow(RunControl *, const QString &)));
+        connect(control, SIGNAL(finished()),
+                this, SLOT(runControlFinished()));
+
+        if (runMode == ProjectExplorer::Constants::DEBUGMODE)
+            m_debuggingRunControl = control;
+
+        control->start();
+        updateRunAction();
+    }
+
+}
+
 void ProjectExplorerPlugin::buildQueueFinished(bool success)
 {
     if (debug)
@@ -1118,38 +1157,13 @@ void ProjectExplorerPlugin::buildQueueFinished(bool success)
     updateActions();
 
     if (success && m_delayedRunConfiguration) {
-        IRunConfigurationRunner *runner = findRunner(m_delayedRunConfiguration, m_runMode);
-        if (runner) {
-            emit aboutToExecuteProject(m_delayedRunConfiguration->project());
-
-            RunControl *control = runner->run(m_delayedRunConfiguration, m_runMode);
-            m_outputPane->createNewOutputWindow(control);
-            if (m_runMode == ProjectExplorer::Constants::RUNMODE)
-                m_outputPane->popup(false);
-            m_outputPane->showTabFor(control);
-
-            connect(control, SIGNAL(addToOutputWindow(RunControl *, const QString &)),
-                    this, SLOT(addToApplicationOutputWindow(RunControl *, const QString &)));
-            connect(control, SIGNAL(addToOutputWindowInline(RunControl *, const QString &)),
-                    this, SLOT(addToApplicationOutputWindowInline(RunControl *, const QString &)));
-            connect(control, SIGNAL(error(RunControl *, const QString &)),
-                    this, SLOT(addErrorToApplicationOutputWindow(RunControl *, const QString &)));
-            connect(control, SIGNAL(finished()),
-                    this, SLOT(runControlFinished()));
-
-            if (m_runMode == ProjectExplorer::Constants::DEBUGMODE)
-                m_debuggingRunControl = control;
-
-            control->start();
-            updateRunAction();
-        }
+        executeRunConfiguration(m_delayedRunConfiguration, m_runMode);
+        m_delayedRunConfiguration = QSharedPointer<RunConfiguration>(0);
+        m_runMode = QString::null;
     } else {
         if (m_buildManager->tasksAvailable())
             m_buildManager->showTaskWindow();
     }
-
-    m_delayedRunConfiguration = QSharedPointer<RunConfiguration>(0);
-    m_runMode = QString::null;
 }
 
 void ProjectExplorerPlugin::updateTaskActions()
@@ -1306,10 +1320,14 @@ bool ProjectExplorerPlugin::saveModifiedFiles(const QList<Project *> & projects)
     }
 
     if (!filesToSave.isEmpty()) {
-        bool cancelled;
-        Core::ICore::instance()->fileManager()->saveModifiedFiles(filesToSave, &cancelled);
-        if (cancelled) {
-            return false;
+        if (m_projectExplorerSettings.saveBeforeBuild) {
+            Core::ICore::instance()->fileManager()->saveModifiedFilesSilently(filesToSave);
+        } else {
+            bool cancelled = false;
+            Core::ICore::instance()->fileManager()->saveModifiedFiles(filesToSave, &cancelled);
+            if (cancelled) {
+                return false;
+            }
         }
     }
     return true;
@@ -1408,12 +1426,16 @@ void ProjectExplorerPlugin::runProjectImpl(Project *pro)
     if (!pro)
         return;
 
-    if (saveModifiedFiles(QList<Project *>() << pro)) {
-        m_runMode = ProjectExplorer::Constants::RUNMODE;
+    if (m_projectExplorerSettings.buildBeforeRun) {
+        if (saveModifiedFiles(QList<Project *>() << pro)) {
+            m_runMode = ProjectExplorer::Constants::RUNMODE;
+            m_delayedRunConfiguration = pro->activeRunConfiguration();
 
-        m_delayedRunConfiguration = pro->activeRunConfiguration();
-        //NBS TODO make the build project step take into account project dependencies
-        m_buildManager->buildProject(pro, pro->activeBuildConfiguration());
+            //NBS TODO make the build project step take into account project dependencies
+            m_buildManager->buildProject(pro, pro->activeBuildConfiguration());
+        }
+    } else {
+        executeRunConfiguration(pro->activeRunConfiguration(), ProjectExplorer::Constants::RUNMODE);
     }
 }
 
@@ -1905,4 +1927,15 @@ void ProjectExplorerPlugin::setSession(QAction *action)
         m_session->loadSession(session);
 }
 
+
+void ProjectExplorerPlugin::setProjectExplorerSettings(const Internal::ProjectExplorerSettings &pes)
+{
+    m_projectExplorerSettings = pes;
+}
+
+Internal::ProjectExplorerSettings ProjectExplorerPlugin::projectExplorerSettings() const
+{
+    return m_projectExplorerSettings;
+}
+
 Q_EXPORT_PLUGIN(ProjectExplorerPlugin)
diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h
index 987cb323fb6..6beca9504f9 100644
--- a/src/plugins/projectexplorer/projectexplorer.h
+++ b/src/plugins/projectexplorer/projectexplorer.h
@@ -71,6 +71,12 @@ class OutputPane;
 class ProjectWindow;
 class ProjectFileFactory;
 
+struct ProjectExplorerSettings
+{
+    bool buildBeforeRun;
+    bool saveBeforeBuild;
+};
+
 } // namespace Internal
 
 class PROJECTEXPLORER_EXPORT ProjectExplorerPlugin
@@ -109,6 +115,9 @@ public:
     void extensionsInitialized();
     void shutdown();
 
+    void setProjectExplorerSettings(const Internal::ProjectExplorerSettings &pes);
+    Internal::ProjectExplorerSettings projectExplorerSettings() const;
+
 signals:
     void aboutToShowContextMenu(ProjectExplorer::Project *project,
                                 ProjectExplorer::Node *node);
@@ -186,6 +195,7 @@ private slots:
 
 private:
     void runProjectImpl(Project *pro);
+    void executeRunConfiguration(QSharedPointer<RunConfiguration>, const QString &mode);
     void setCurrent(Project *project, QString filePath, Node *node);
 
     QStringList allFilesWithDependencies(Project *pro);
@@ -259,6 +269,7 @@ private:
     RunControl *m_debuggingRunControl;
     QString m_runMode;
     QString m_projectFilterString;
+    Internal::ProjectExplorerSettings m_projectExplorerSettings;
 };
 
 namespace Internal {
diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro
index e6a04cf83d9..170a54387ea 100644
--- a/src/plugins/projectexplorer/projectexplorer.pro
+++ b/src/plugins/projectexplorer/projectexplorer.pro
@@ -59,8 +59,9 @@ HEADERS += projectexplorer.h \
     gccparser.h \
     msvcparser.h \
     filewatcher.h \
-    debugginghelper.h\
-    abstractmakestep.h
+    debugginghelper.h \
+    abstractmakestep.h \
+    projectexplorersettingspage.h
 SOURCES += projectexplorer.cpp \
     projectwindow.cpp \
     buildmanager.cpp \
@@ -109,7 +110,8 @@ SOURCES += projectexplorer.cpp \
     msvcparser.cpp \
     filewatcher.cpp \
     debugginghelper.cpp \
-    abstractmakestep.cpp
+    abstractmakestep.cpp \
+    projectexplorersettingspage.cpp
 FORMS += dependenciespanel.ui \
     buildsettingspropertiespage.ui \
     processstep.ui \
@@ -118,7 +120,8 @@ FORMS += dependenciespanel.ui \
     sessiondialog.ui \
     projectwizardpage.ui \
     buildstepspage.ui \
-    removefiledialog.ui
+    removefiledialog.ui \
+    projectexplorersettingspage.ui
 win32 { 
     SOURCES += applicationlauncher_win.cpp \
         winguiprocess.cpp
diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h
index 10c56b8deaa..351f333a27e 100644
--- a/src/plugins/projectexplorer/projectexplorerconstants.h
+++ b/src/plugins/projectexplorer/projectexplorerconstants.h
@@ -176,6 +176,11 @@ const char * const RESOURCE_MIMETYPE = "application/vnd.nokia.xml.qt.resource";
 // build parsers
 const char * const BUILD_PARSER_MSVC    = "BuildParser.MSVC";
 const char * const BUILD_PARSER_GCC     = "BuildParser.Gcc";
+
+// settings page
+const char * const PROJECTEXPLORER_CATEGORY            = "ProjectExplorer";
+const char * const PROJECTEXPLORER_PAGE                = "ProjectExplorer.ProjectExplorer";
+
 } // namespace Constants
 } // namespace ProjectExplorer
 
-- 
GitLab