OSDN Git Service

Merge remote branch 'origin/2.0'
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / projectexplorer.cpp
index fb4d557..b4a419e 100644 (file)
@@ -33,6 +33,9 @@
 #include "projectexplorersettings.h"
 #include "target.h"
 #include "targetsettingspanel.h"
+#include "copytaskhandler.h"
+#include "showineditortaskhandler.h"
+#include "vcsannotatetaskhandler.h"
 #include "applicationrunconfiguration.h"
 #include "allprojectsfilter.h"
 #include "allprojectsfind.h"
@@ -77,7 +80,6 @@
 #include <coreplugin/mainwindow.h>
 #include <coreplugin/mimedatabase.h>
 #include <coreplugin/modemanager.h>
-#include <coreplugin/uniqueidmanager.h>
 #include <coreplugin/actionmanager/actionmanager.h>
 #include <coreplugin/actionmanager/actioncontainer.h>
 #include <coreplugin/actionmanager/command.h>
@@ -261,11 +263,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
 
     d->m_proWindow = new ProjectWindow;
 
-    QList<int> globalcontext;
-    globalcontext.append(Core::Constants::C_GLOBAL_ID);
-
-    QList<int> pecontext;
-    pecontext << core->uniqueIDManager()->uniqueIdentifier(Constants::C_PROJECTEXPLORER);
+    Core::Context globalcontext(Core::Constants::C_GLOBAL);
+    Core::Context pecontext(Constants::C_PROJECTEXPLORER);
 
     d->m_projectsMode = new Core::BaseMode;
     d->m_projectsMode->setDisplayName(tr("Projects"));
@@ -273,12 +272,16 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
     d->m_projectsMode->setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Project.png")));
     d->m_projectsMode->setPriority(Constants::P_MODE_SESSION);
     d->m_projectsMode->setWidget(d->m_proWindow);
-    d->m_projectsMode->setContext(QList<int>() << pecontext);
+    d->m_projectsMode->setContext(pecontext);
     d->m_projectsMode->setEnabled(session()->startupProject());
     d->m_projectsMode->setContextHelpId(QLatin1String("Managing Projects"));
     addAutoReleasedObject(d->m_projectsMode);
     d->m_proWindow->layout()->addWidget(new Core::FindToolBarPlaceHolder(d->m_proWindow));
 
+    addAutoReleasedObject(new CopyTaskHandler);
+    addAutoReleasedObject(new ShowInEditorTaskHandler);
+    addAutoReleasedObject(new VcsAnnotateTaskHandler);
+
     d->m_buildManager = new BuildManager(this);
     connect(d->m_buildManager, SIGNAL(buildStateChanged(ProjectExplorer::Project *)),
             this, SLOT(buildStateChanged(ProjectExplorer::Project *)));
@@ -687,13 +690,15 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
                        globalcontext);
     mfilec->addAction(cmd, Constants::G_FILE_OTHER);
 
-    // renamefile action (TODO: Not supported yet)
+    // renamefile action
     d->m_renameFileAction = new QAction(tr("Rename"), this);
     cmd = am->registerAction(d->m_renameFileAction, ProjectExplorer::Constants::RENAMEFILE,
                        globalcontext);
     mfilec->addAction(cmd, Constants::G_FILE_OTHER);
-    d->m_renameFileAction->setEnabled(false);
-    d->m_renameFileAction->setVisible(false);
+    // Not yet used by anyone, so hide for now
+//    mfolder->addAction(cmd, Constants::G_FOLDER_FILES);
+//    msubProject->addAction(cmd, Constants::G_FOLDER_FILES);
+//    mproject->addAction(cmd, Constants::G_FOLDER_FILES);
 
     // target selector
     d->m_projectSelectorAction = new QAction(this);
@@ -970,7 +975,7 @@ void ProjectExplorerPlugin::savePersistentSettings()
 
     QSettings *s = Core::ICore::instance()->settings();
     if (s) {
-        s->setValue("ProjectExplorer/StartupSession", d->m_session->file()->fileName());
+        s->setValue("ProjectExplorer/StartupSession", d->m_session->currentSession());
         s->remove("ProjectExplorer/RecentProjects/Files");
 
         QStringList fileNames;
@@ -1218,7 +1223,7 @@ void ProjectExplorerPlugin::showContextMenu(const QPoint &globalPos, Node *node)
         contextMenu = d->m_sessionContextMenu;
     }
 
-    updateContextMenuActions(node);
+    updateContextMenuActions(d->m_currentNode);
     if (contextMenu && contextMenu->actions().count() > 0) {
         contextMenu->popup(globalPos);
     }
@@ -1308,16 +1313,16 @@ void ProjectExplorerPlugin::setCurrent(Project *project, QString filePath, Node
 
     bool projectChanged = false;
     if (d->m_currentProject != project) {
-        QList<int> oldContext;
-        QList<int> newContext;
+        Core::Context oldContext;
+        Core::Context newContext;
 
         if (d->m_currentProject) {
-            oldContext.append(d->m_currentProject->projectManager()->projectContext());
-            oldContext.append(d->m_currentProject->projectManager()->projectLanguage());
+            oldContext.add(d->m_currentProject->projectManager()->projectContext());
+            oldContext.add(d->m_currentProject->projectManager()->projectLanguage());
         }
         if (project) {
-            newContext.append(project->projectManager()->projectContext());
-            newContext.append(project->projectManager()->projectLanguage());
+            newContext.add(project->projectManager()->projectContext());
+            newContext.add(project->projectManager()->projectLanguage());
         }
 
         core->updateAdditionalContexts(oldContext, newContext);
@@ -1628,8 +1633,8 @@ void ProjectExplorerPlugin::runProjectContextMenu()
 bool ProjectExplorerPlugin::hasBuildSettings(Project *pro)
 {
     const QList<Project *> & projects = d->m_session->projectOrder(pro);
-    foreach(Project *pro, projects)
-        if (pro->activeTarget()->activeBuildConfiguration())
+    foreach(Project *project, projects)
+        if (project->activeTarget()->activeBuildConfiguration())
             return true;
     return false;
 }
@@ -1650,9 +1655,9 @@ void ProjectExplorerPlugin::runProjectImpl(Project *pro, QString mode)
 
             const QList<Project *> & projects = d->m_session->projectOrder(pro);
             QList<BuildConfiguration *> configurations;
-            foreach(Project *pro, projects)
-                if (pro->activeTarget()->activeBuildConfiguration())
-                    configurations << pro->activeTarget()->activeBuildConfiguration();
+            foreach(Project *project, projects)
+                if (project->activeTarget()->activeBuildConfiguration())
+                    configurations << project->activeTarget()->activeBuildConfiguration();
             d->m_buildManager->buildProjects(configurations);
 
             updateRunActions();
@@ -1897,14 +1902,18 @@ void ProjectExplorerPlugin::updateContextMenuActions(Node *node)
     d->m_removeFileAction->setEnabled(false);
 
     if (node->projectNode()) {
-        QList<ProjectNode::ProjectAction> supportedActions = node->projectNode()->supportedActions();
-        if (qobject_cast<FolderNode*>(node)) {
-            const bool addFilesEnabled = supportedActions.contains(ProjectNode::AddFile);
+        QList<ProjectNode::ProjectAction> actions =
+                d->m_currentNode->projectNode()->supportedActions(node);
+
+        if (qobject_cast<FolderNode*>(d->m_currentNode)) {
+            bool addFilesEnabled = actions.contains(ProjectNode::AddFile);
             d->m_addExistingFilesAction->setEnabled(addFilesEnabled);
             d->m_addNewFileAction->setEnabled(addFilesEnabled);
-        } else if (qobject_cast<FileNode*>(node)) {
-            const bool removeFileEnabled = supportedActions.contains(ProjectNode::RemoveFile);
+            d->m_renameFileAction->setEnabled(actions.contains(ProjectNode::Rename));
+        } else if (qobject_cast<FileNode*>(d->m_currentNode)) {
+            bool removeFileEnabled = actions.contains(ProjectNode::RemoveFile);
             d->m_removeFileAction->setEnabled(removeFileEnabled);
+            d->m_renameFileAction->setEnabled(actions.contains(ProjectNode::Rename));
         }
     }
 }
@@ -2003,8 +2012,7 @@ void ProjectExplorerPlugin::removeFile()
     FileNode *fileNode = qobject_cast<FileNode*>(d->m_currentNode);
     Core::ICore *core = Core::ICore::instance();
 
-    const QString filePath = d->m_currentNode->path();
-    const QString fileDir = QFileInfo(filePath).dir().absolutePath();
+    QString filePath = d->m_currentNode->path();
     RemoveFileDialog removeFileDialog(filePath, core->mainWindow());
 
     if (removeFileDialog.exec() == QDialog::Accepted) {
@@ -2050,6 +2058,31 @@ void ProjectExplorerPlugin::renameFile()
     }
 }
 
+void ProjectExplorerPlugin::renameFile(Node *node, const QString &to)
+{
+    FileNode *fileNode = qobject_cast<FileNode *>(node);
+    if (!fileNode)
+        return;
+    QString orgFilePath = node->path();
+    QString dir = QFileInfo(orgFilePath).absolutePath();
+    QString newFilePath = dir + "/" + to;
+    Core::ICore *core = Core::ICore::instance();
+    Core::IVersionControl *vc = core->vcsManager()->findVersionControlForDirectory(dir);
+    bool result = false;
+    if (vc && vc->supportsOperation(Core::IVersionControl::MoveOperation))
+        result = vc->vcsMove(orgFilePath, newFilePath);
+    if (!result) // The moving via vcs failed or the vcs does not support moving, fall back
+        result = QFile::rename(orgFilePath, newFilePath);
+    if (result) {
+        // yeah we moved, tell the filemanager about it
+        Core::ICore::instance()->fileManager()->renamedFile(orgFilePath, newFilePath);
+        // Tell the project plugin about it
+        ProjectNode *projectNode = fileNode->projectNode();
+        projectNode->renameFile(fileNode->fileType(), orgFilePath, newFilePath);
+        // TODO emit a signal?
+    }
+}
+
 void ProjectExplorerPlugin::populateOpenWithMenu(QMenu *menu, const QString &fileName)
 {
     typedef QList<Core::IEditorFactory*> EditorFactoryList;