From aa42a422b6735111d7080bd6215d96fe8af7c378 Mon Sep 17 00:00:00 2001
From: Jarek Kobus <jkobus@trolltech.com>
Date: Fri, 12 Nov 2010 12:07:52 +0100
Subject: [PATCH] Add "New Subproject..." context menu action in project
 explorer

Reviewed-by: dt <qtc-committer@nokia.com>
---
 .../projectexplorer/projectexplorer.cpp       | 34 +++++++++++++++++--
 src/plugins/projectexplorer/projectexplorer.h |  1 +
 .../projectexplorerconstants.h                |  1 +
 .../librarydetailscontroller.cpp              |  1 +
 .../wizards/emptyprojectwizard.cpp            |  2 +-
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 6c55f659355..02f56130a42 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -163,6 +163,7 @@ struct ProjectExplorerPluginPrivate {
     QAction *m_debugAction;
     QAction *m_addNewFileAction;
     QAction *m_addExistingFilesAction;
+    QAction *m_addNewSubprojectAction;
     QAction *m_removeFileAction;
     QAction *m_removeProjectAction;
     QAction *m_deleteFileAction;
@@ -536,7 +537,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
     cmd->setAttribute(Core::Command::CA_UpdateText);
     cmd->setDefaultText(d->m_unloadAction->text());
     mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
-    mproject->addAction(cmd, Constants::G_PROJECT_FILES);
 
     // unload session action
     d->m_clearSession = new QAction(tr("Close All Projects"), this);
@@ -715,6 +715,16 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
     msubProject->addAction(cmd, Constants::G_PROJECT_FILES);
     mfolder->addAction(cmd, Constants::G_FOLDER_FILES);
 
+    // new subproject action
+    d->m_addNewSubprojectAction = new QAction(tr("New Subproject..."), this);
+    cmd = am->registerAction(d->m_addNewSubprojectAction, ProjectExplorer::Constants::ADDNEWSUBPROJECT,
+                       globalcontext);
+    mproject->addAction(cmd, Constants::G_PROJECT_FILES);
+    msubProject->addAction(cmd, Constants::G_PROJECT_FILES);
+
+    // unload project again, in right position
+    mproject->addAction(am->command(Constants::UNLOAD), Constants::G_PROJECT_FILES);
+
     // remove file action
     d->m_removeFileAction = new QAction(tr("Remove File..."), this);
     cmd = am->registerAction(d->m_removeFileAction, ProjectExplorer::Constants::REMOVEFILE,
@@ -834,6 +844,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
     connect(d->m_clearSession, SIGNAL(triggered()), this, SLOT(clearSession()));
     connect(d->m_addNewFileAction, SIGNAL(triggered()), this, SLOT(addNewFile()));
     connect(d->m_addExistingFilesAction, SIGNAL(triggered()), this, SLOT(addExistingFiles()));
+    connect(d->m_addNewSubprojectAction, SIGNAL(triggered()), this, SLOT(addNewSubproject()));
     connect(d->m_removeProjectAction, SIGNAL(triggered()), this, SLOT(removeProject()));
     connect(d->m_openFileAction, SIGNAL(triggered()), this, SLOT(openFile()));
     connect(d->m_showInGraphicalShell, SIGNAL(triggered()), this, SLOT(showInGraphicalShell()));
@@ -2020,6 +2031,7 @@ void ProjectExplorerPlugin::updateContextMenuActions(Node *node)
 {
     d->m_addExistingFilesAction->setEnabled(false);
     d->m_addNewFileAction->setEnabled(false);
+    d->m_addNewSubprojectAction->setEnabled(false);
     d->m_removeFileAction->setEnabled(false);
     d->m_deleteFileAction->setEnabled(false);
 
@@ -2033,6 +2045,8 @@ void ProjectExplorerPlugin::updateContextMenuActions(Node *node)
 
         if (qobject_cast<FolderNode*>(d->m_currentNode)) {
             d->m_addNewFileAction->setEnabled(actions.contains(ProjectNode::AddNewFile));
+            d->m_addNewSubprojectAction->setEnabled(d->m_currentNode->nodeType() == ProjectNodeType
+                                                    && actions.contains(ProjectNode::AddSubProject));
             d->m_addExistingFilesAction->setEnabled(actions.contains(ProjectNode::AddExistingFile));
             d->m_renameFileAction->setEnabled(actions.contains(ProjectNode::Rename));
         } else if (qobject_cast<FileNode*>(d->m_currentNode)) {
@@ -2081,9 +2095,23 @@ void ProjectExplorerPlugin::addNewFile()
     QString location = directoryFor(d->m_currentNode);
 
     Core::ICore::instance()->showNewItemDialog(tr("New File", "Title of dialog"),
-                              Core::IWizard::wizardsOfKind(Core::IWizard::FileWizard)
-                              + Core::IWizard::wizardsOfKind(Core::IWizard::ClassWizard),
+                               Core::IWizard::wizardsOfKind(Core::IWizard::FileWizard)
+                               + Core::IWizard::wizardsOfKind(Core::IWizard::ClassWizard),
+                               location);
+}
+
+void ProjectExplorerPlugin::addNewSubproject()
+{
+    QTC_ASSERT(d->m_currentNode, return)
+    QString location = directoryFor(d->m_currentNode);
+
+    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::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard),
                               location);
+    }
 }
 
 void ProjectExplorerPlugin::addExistingFiles()
diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h
index 376269f98c3..f67a0936271 100644
--- a/src/plugins/projectexplorer/projectexplorer.h
+++ b/src/plugins/projectexplorer/projectexplorer.h
@@ -169,6 +169,7 @@ private slots:
 
     void addNewFile();
     void addExistingFiles();
+    void addNewSubproject();
     void removeProject();
     void openFile();
     void showInGraphicalShell();
diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h
index 448cc28c7d5..748a388d35d 100644
--- a/src/plugins/projectexplorer/projectexplorerconstants.h
+++ b/src/plugins/projectexplorer/projectexplorerconstants.h
@@ -74,6 +74,7 @@ const char * const FINDINALLPROJECTS    = "ProjectExplorer.FindInAllProjects";
 const char * const SHOWPROPERTIES       = "ProjectExplorer.ShowProperties";
 const char * const ADDNEWFILE           = "ProjectExplorer.AddNewFile";
 const char * const ADDEXISTINGFILES     = "ProjectExplorer.AddExistingFiles";
+const char * const ADDNEWSUBPROJECT     = "ProjectExplorer.AddNewSubproject";
 const char * const REMOVEPROJECT        = "ProjectExplorer.RemoveProject";
 const char * const OPENFILE             = "ProjectExplorer.OpenFile";
 const char * const SHOWINGRAPHICALSHELL = "ProjectExplorer.ShowInGraphicalShell";
diff --git a/src/plugins/qt4projectmanager/librarydetailscontroller.cpp b/src/plugins/qt4projectmanager/librarydetailscontroller.cpp
index 96d6f2206e0..8767cf6961f 100644
--- a/src/plugins/qt4projectmanager/librarydetailscontroller.cpp
+++ b/src/plugins/qt4projectmanager/librarydetailscontroller.cpp
@@ -818,6 +818,7 @@ bool PackageLibraryDetailsController::isLinkPackageGenerated() const
     const QStringList configVar = currentProject->variableValue(ConfigVar);
     if (configVar.contains(QLatin1String("link_pkgconfig")))
         return true;
+
     return false;
 }
 
diff --git a/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp
index 63cbf6fe07d..0bf6b41f0c0 100644
--- a/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp
+++ b/src/plugins/qt4projectmanager/wizards/emptyprojectwizard.cpp
@@ -70,7 +70,7 @@ Core::GeneratedFiles
     const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix());
 
     Core::GeneratedFile profile(profileName);
-    profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
+    profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute | Core::GeneratedFile::OpenEditorAttribute);
     return Core::GeneratedFiles() << profile;
 }
 
-- 
GitLab