From faad3fcef47fce1eea746f51aaf2ae0d072209cb Mon Sep 17 00:00:00 2001
From: Jarek Kobus <jkobus@trolltech.com>
Date: Wed, 24 Nov 2010 15:18:50 +0100
Subject: [PATCH] Fixes:    Add new subdirs project wizard

Task:     QTCREATORBUG-1297
RevBy:    dt <qtc-committer@nokia.com>
---
 .../projectexplorer/projectexplorer.cpp       |  2 +-
 .../qt4projectmanager/qt4projectmanager.pro   |  4 +
 .../qt4projectmanagerplugin.cpp               | 19 ++--
 .../qt4projectmanagerplugin.h                 |  6 --
 .../wizards/subdirsprojectwizard.cpp          | 95 +++++++++++++++++++
 .../wizards/subdirsprojectwizard.h            | 58 +++++++++++
 .../wizards/subdirsprojectwizarddialog.cpp    | 64 +++++++++++++
 .../wizards/subdirsprojectwizarddialog.h      | 55 +++++++++++
 .../wizards/targetsetuppage.cpp               |  2 +
 9 files changed, 285 insertions(+), 20 deletions(-)
 create mode 100644 src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.cpp
 create mode 100644 src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.h
 create mode 100644 src/plugins/qt4projectmanager/wizards/subdirsprojectwizarddialog.cpp
 create mode 100644 src/plugins/qt4projectmanager/wizards/subdirsprojectwizarddialog.h

diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 8e70440bd9e..e9e0a77e436 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -2106,7 +2106,7 @@ void ProjectExplorerPlugin::addNewSubproject()
     if (d->m_currentNode->nodeType() == ProjectNodeType
             && d->m_currentNode->projectNode()->supportedActions(
                 d->m_currentNode->projectNode()).contains(ProjectNode::AddSubProject)) {
-        Core::ICore::instance()->showNewItemDialog(tr("New Project", "Title of dialog"),
+        Core::ICore::instance()->showNewItemDialog(tr("New Subproject", "Title of dialog"),
                               Core::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard),
                               location);
     }
diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.pro b/src/plugins/qt4projectmanager/qt4projectmanager.pro
index d0a823d5a97..564d471da78 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.pro
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.pro
@@ -41,6 +41,8 @@ HEADERS += qt4deployconfiguration.h \
     wizards/abstractmobileapp.h \
     wizards/qmlstandaloneapp.h \
     wizards/abstractmobileappwizard.h \
+    wizards/subdirsprojectwizard.h \
+    wizards/subdirsprojectwizarddialog.h \
     qt4projectmanagerconstants.h \
     makestep.h \
     qmakestep.h \
@@ -103,6 +105,8 @@ SOURCES += qt4projectmanagerplugin.cpp \
     wizards/abstractmobileapp.cpp \
     wizards/qmlstandaloneapp.cpp \
     wizards/abstractmobileappwizard.cpp \
+    wizards/subdirsprojectwizard.cpp \
+    wizards/subdirsprojectwizarddialog.cpp \
     makestep.cpp \
     qmakestep.cpp \
     qt4runconfiguration.cpp \
diff --git a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
index fd670e6a464..e740616953e 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
+++ b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
@@ -38,6 +38,7 @@
 #include "wizards/librarywizard.h"
 #include "wizards/testwizard.h"
 #include "wizards/emptyprojectwizard.h"
+#include "wizards/subdirsprojectwizard.h"
 #include "wizards/qmlstandaloneappwizard.h"
 #include "customwidgetwizard/customwidgetwizard.h"
 #include "profileeditorfactory.h"
@@ -132,20 +133,12 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
     addObject(m_proFileEditorFactory);
 
     addAutoReleasedObject(new EmptyProjectWizard);
-
-    GuiAppWizard *guiWizard = new GuiAppWizard;
-    addAutoReleasedObject(guiWizard);
-
-    ConsoleAppWizard *consoleWizard = new ConsoleAppWizard;
-    addAutoReleasedObject(consoleWizard);
-
-    MobileAppWizard *mobileWizard = new MobileAppWizard;
-    addAutoReleasedObject(mobileWizard);
-
+    addAutoReleasedObject(new SubdirsProjectWizard);
+    addAutoReleasedObject(new GuiAppWizard);
+    addAutoReleasedObject(new ConsoleAppWizard);
+    addAutoReleasedObject(new MobileAppWizard);
     addAutoReleasedObject(new QmlStandaloneAppWizard());
-
-    LibraryWizard *libWizard = new LibraryWizard;
-    addAutoReleasedObject(libWizard);
+    addAutoReleasedObject(new LibraryWizard);
     addAutoReleasedObject(new TestWizard);
     addAutoReleasedObject(new CustomWidgetWizard);
 
diff --git a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h
index a74a978ae3c..c6f9f992c6d 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h
+++ b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h
@@ -50,12 +50,6 @@ class QtVersionManager;
 namespace Internal {
 
 class ProFileEditorFactory;
-class ConsoleAppWizard;
-class GuiAppWizard;
-class EmptyProjectWizard;
-class QMakeStepFactory;
-class MakeStepFactory;
-class EmbeddedPropertiesPage;
 class GettingStartedWelcomePage;
 
 class Qt4ProjectManagerPlugin : public ExtensionSystem::IPlugin
diff --git a/src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.cpp b/src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.cpp
new file mode 100644
index 00000000000..f9f0f76971d
--- /dev/null
+++ b/src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.cpp
@@ -0,0 +1,95 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "subdirsprojectwizard.h"
+
+#include "subdirsprojectwizarddialog.h"
+
+#include <projectexplorer/projectexplorerconstants.h>
+#include <coreplugin/icore.h>
+
+#include <QtGui/QIcon>
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+SubdirsProjectWizard::SubdirsProjectWizard()
+  : QtWizard(QLatin1String("U.Qt4Subdirs"),
+             QLatin1String(ProjectExplorer::Constants::PROJECT_WIZARD_CATEGORY),
+             QLatin1String(ProjectExplorer::Constants::PROJECT_WIZARD_TR_SCOPE),
+             QLatin1String(ProjectExplorer::Constants::PROJECT_WIZARD_TR_CATEGORY),
+             tr("Subdirs Project"),
+             tr("Creates a qmake-based subdirs project. This allows you to group "
+                "your projects in a tree structure."),
+             QIcon(QLatin1String(":/wizards/images/gui.png")))
+{
+}
+
+QWizard *SubdirsProjectWizard::createWizardDialog(QWidget *parent,
+                                              const QString &defaultPath,
+                                              const WizardPageList &extensionPages) const
+{
+    SubdirsProjectWizardDialog *dialog = new SubdirsProjectWizardDialog(displayName(), icon(), extensionPages, parent);
+    dialog->setPath(defaultPath);
+    dialog->setProjectName(SubdirsProjectWizardDialog::uniqueProjectName(defaultPath));
+    const QString buttonText = dialog->wizardStyle() == QWizard::MacStyle
+            ? tr("Done && Add Subproject") : tr("Finish && Add Subproject");
+    dialog->setButtonText(QWizard::FinishButton, buttonText);
+    return dialog;
+}
+
+Core::GeneratedFiles SubdirsProjectWizard::generateFiles(const QWizard *w,
+                                                         QString * /*errorMessage*/) const
+{
+    const SubdirsProjectWizardDialog *wizard = qobject_cast< const SubdirsProjectWizardDialog *>(w);
+    const QtProjectParameters params = wizard->parameters();
+    const QString projectPath = params.projectPath();
+    const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix());
+
+    Core::GeneratedFile profile(profileName);
+    profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute | Core::GeneratedFile::OpenEditorAttribute);
+    profile.setContents(QLatin1String("TEMPLATE = subdirs\n"));
+    return Core::GeneratedFiles() << profile;
+}
+
+bool SubdirsProjectWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &files, QString *errorMessage)
+{
+    const SubdirsProjectWizardDialog *wizard = qobject_cast< const SubdirsProjectWizardDialog *>(w);
+    if (QtWizard::qt4ProjectPostGenerateFiles(wizard, files, errorMessage)) {
+        Core::ICore::instance()->showNewItemDialog(tr("New Subproject", "Title of dialog"),
+                              Core::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard),
+                              wizard->parameters().projectPath());
+    } else {
+        return false;
+    }
+    return true;
+}
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
diff --git a/src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.h b/src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.h
new file mode 100644
index 00000000000..74c3fda4dfd
--- /dev/null
+++ b/src/plugins/qt4projectmanager/wizards/subdirsprojectwizard.h
@@ -0,0 +1,58 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef SUBDIRSPROJECTWIZARD_H
+#define SUBDIRSPROJECTWIZARD_H
+
+#include "qtwizard.h"
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+class SubdirsProjectWizard : public QtWizard
+{
+    Q_OBJECT
+
+public:
+    SubdirsProjectWizard();
+
+protected:
+    virtual QWizard *createWizardDialog(QWidget *parent,
+                                        const QString &defaultPath,
+                                        const WizardPageList &extensionPages) const;
+
+    virtual Core::GeneratedFiles generateFiles(const QWizard *w,
+                                               QString *errorMessage) const;
+    virtual bool postGenerateFiles(const QWizard *, const Core::GeneratedFiles &l, QString *errorMessage);
+};
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
+
+#endif // SUBDIRSPROJECTWIZARD_H
diff --git a/src/plugins/qt4projectmanager/wizards/subdirsprojectwizarddialog.cpp b/src/plugins/qt4projectmanager/wizards/subdirsprojectwizarddialog.cpp
new file mode 100644
index 00000000000..d11350cf110
--- /dev/null
+++ b/src/plugins/qt4projectmanager/wizards/subdirsprojectwizarddialog.cpp
@@ -0,0 +1,64 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "subdirsprojectwizarddialog.h"
+#include "qtprojectparameters.h"
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+SubdirsProjectWizardDialog::SubdirsProjectWizardDialog(const QString &templateName,
+                                               const QIcon &icon,
+                                               const QList<QWizardPage*> &extensionPages,
+                                               QWidget *parent) :
+    BaseQt4ProjectWizardDialog(parent)
+{
+    setWindowIcon(icon);
+    setWindowTitle(templateName);
+
+    setIntroDescription(tr("This wizard generates Qt4 subdirs project. "
+                           "Add subprojects to it later on by using the other wizards."));
+
+    addTargetSetupPage();
+
+    foreach (QWizardPage *p, extensionPages)
+        Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
+}
+
+QtProjectParameters SubdirsProjectWizardDialog::parameters() const
+{
+    QtProjectParameters rc;
+    rc.type = QtProjectParameters::EmptyProject;
+    rc.fileName = projectName();
+    rc.path = path();
+    return rc;
+}
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
diff --git a/src/plugins/qt4projectmanager/wizards/subdirsprojectwizarddialog.h b/src/plugins/qt4projectmanager/wizards/subdirsprojectwizarddialog.h
new file mode 100644
index 00000000000..d5a51e01b94
--- /dev/null
+++ b/src/plugins/qt4projectmanager/wizards/subdirsprojectwizarddialog.h
@@ -0,0 +1,55 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef SUBDIRSPROJECTWIZARDDIALOG_H
+#define SUBDIRSPROJECTWIZARDDIALOG_H
+
+#include "qtwizard.h"
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+struct QtProjectParameters;
+
+class SubdirsProjectWizardDialog : public BaseQt4ProjectWizardDialog
+{
+    Q_OBJECT
+public:
+    explicit SubdirsProjectWizardDialog(const QString &templateName,
+                                    const QIcon &icon,
+                                    const QList<QWizardPage*> &extensionPages,
+                                    QWidget *parent = 0);
+
+    QtProjectParameters parameters() const;
+};
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
+
+#endif // SUBDIRSPROJECTWIZARDDIALOG_H
diff --git a/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp b/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp
index 601472054e5..979c7f88a8e 100644
--- a/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp
+++ b/src/plugins/qt4projectmanager/wizards/targetsetuppage.cpp
@@ -84,6 +84,8 @@ TargetSetupPage::TargetSetupPage(QWidget *parent) :
             this, SLOT(handleDoubleClicks(QTreeWidgetItem*,int)));
     connect(m_ui->versionTree, SIGNAL(customContextMenuRequested(QPoint)),
             this, SLOT(contextMenuRequested(QPoint)));
+
+    setTitle(tr("Qt Versions"));
 }
 
 void TargetSetupPage::initializePage()
-- 
GitLab