summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorDaniel Teske <daniel.teske@theqtcompany.com>2014-11-19 17:58:33 +0100
committerDaniel Teske <daniel.teske@theqtcompany.com>2014-12-03 12:36:20 +0100
commit4943510b60acc320dff8f2c31af69cfbfa331203 (patch)
treedd879a4e751f005db97e5256b8f658a2ba243013 /src/plugins
parent042ef1aec0e04d2568c30ab19c1f89720ed8da3e (diff)
downloadqt-creator-4943510b60acc320dff8f2c31af69cfbfa331203.tar.gz
Completely rework currentNode/currentProject handling
Centralize the handling inside a new class ProjectTree. React to moving focus and remove most special handling. This properly fixes the linked task. Task-number: QTCREATORBUG-13357 Change-Id: I6b06aa32b1e4305ec8a6d432857b302585d8734b Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/android/androidqtversion.cpp4
-rw-r--r--src/plugins/beautifier/artisticstyle/artisticstyle.cpp4
-rw-r--r--src/plugins/beautifier/uncrustify/uncrustify.cpp4
-rw-r--r--src/plugins/clearcase/clearcaseplugin.cpp8
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp3
-rw-r--r--src/plugins/cpptools/cppcodestylesettings.cpp4
-rw-r--r--src/plugins/cpptools/cpptoolsplugin.cpp3
-rw-r--r--src/plugins/debugger/debuggerplugin.cpp5
-rw-r--r--src/plugins/debugger/unstartedappwatcherdialog.cpp6
-rw-r--r--src/plugins/projectexplorer/currentprojectfilter.cpp6
-rw-r--r--src/plugins/projectexplorer/currentprojectfind.cpp14
-rw-r--r--src/plugins/projectexplorer/nodesvisitor.cpp5
-rw-r--r--src/plugins/projectexplorer/nodesvisitor.h1
-rw-r--r--src/plugins/projectexplorer/projectexplorer.cpp349
-rw-r--r--src/plugins/projectexplorer/projectexplorer.h17
-rw-r--r--src/plugins/projectexplorer/projectexplorer.pro6
-rw-r--r--src/plugins/projectexplorer/projectmodels.cpp9
-rw-r--r--src/plugins/projectexplorer/projectmodels.h3
-rw-r--r--src/plugins/projectexplorer/projecttree.cpp360
-rw-r--r--src/plugins/projectexplorer/projecttree.h107
-rw-r--r--src/plugins/projectexplorer/projecttreewidget.cpp85
-rw-r--r--src/plugins/projectexplorer/projecttreewidget.h12
-rw-r--r--src/plugins/projectexplorer/session.cpp63
-rw-r--r--src/plugins/projectexplorer/session.h4
-rw-r--r--src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp6
-rw-r--r--src/plugins/qmakeprojectmanager/qmakenodes.cpp6
-rw-r--r--src/plugins/qmakeprojectmanager/qmakenodes.h1
-rw-r--r--src/plugins/qmakeprojectmanager/qmakeproject.cpp7
-rw-r--r--src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp3
-rw-r--r--src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp16
-rw-r--r--src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h2
-rw-r--r--src/plugins/qmakeprojectmanager/wizards/abstractmobileappwizard.cpp5
-rw-r--r--src/plugins/qmldesigner/components/integration/designdocument.cpp8
-rw-r--r--src/plugins/qmljseditor/qmljscompletionassist.cpp4
-rw-r--r--src/plugins/qmljstools/qmljsmodelmanager.cpp9
-rw-r--r--src/plugins/qnx/bardescriptorfilenodemanager.cpp7
-rw-r--r--src/plugins/qtsupport/qtsupportplugin.cpp4
-rw-r--r--src/plugins/resourceeditor/resourceeditorplugin.cpp22
-rw-r--r--src/plugins/tasklist/tasklistplugin.cpp4
-rw-r--r--src/plugins/valgrind/callgrindtool.cpp4
-rw-r--r--src/plugins/vcsbase/vcsbaseplugin.cpp12
-rw-r--r--src/plugins/vcsbase/vcsbasesubmiteditor.cpp4
-rw-r--r--src/plugins/vcsbase/vcsplugin.cpp8
43 files changed, 744 insertions, 470 deletions
diff --git a/src/plugins/android/androidqtversion.cpp b/src/plugins/android/androidqtversion.cpp
index cc850d673e..09e690e167 100644
--- a/src/plugins/android/androidqtversion.cpp
+++ b/src/plugins/android/androidqtversion.cpp
@@ -43,7 +43,7 @@
#include <projectexplorer/target.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/project.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <proparser/profileevaluator.h>
@@ -107,7 +107,7 @@ void AndroidQtVersion::addToEnvironment(const ProjectExplorer::Kit *k, Utils::En
env.set(QLatin1String("ANDROID_NDK_HOST"), AndroidConfigurations::currentConfig().toolchainHost());
env.set(QLatin1String("ANDROID_NDK_ROOT"), AndroidConfigurations::currentConfig().ndkLocation().toUserOutput());
- Project *project = ProjectExplorerPlugin::instance()->currentProject();
+ Project *project = ProjectTree::currentProject();
if (!project || !project->activeTarget()
|| QtSupport::QtKitInformation::qtVersion(k)->type() != QLatin1String(Constants::ANDROIDQT))
return;
diff --git a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp
index ce9ef993ff..31ff9b0311 100644
--- a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp
+++ b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp
@@ -49,7 +49,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <cppeditor/cppeditorconstants.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
@@ -108,7 +108,7 @@ void ArtisticStyle::formatFile()
if (m_settings->useOtherFiles()) {
if (const ProjectExplorer::Project *project
- = ProjectExplorer::ProjectExplorerPlugin::currentProject()) {
+ = ProjectExplorer::ProjectTree::currentProject()) {
const QStringList files = project->files(ProjectExplorer::Project::AllFiles);
for (int i = 0, total = files.size(); i < total; ++i) {
const QString &file = files.at(i);
diff --git a/src/plugins/beautifier/uncrustify/uncrustify.cpp b/src/plugins/beautifier/uncrustify/uncrustify.cpp
index 778911862f..9a092ff7d3 100644
--- a/src/plugins/beautifier/uncrustify/uncrustify.cpp
+++ b/src/plugins/beautifier/uncrustify/uncrustify.cpp
@@ -49,7 +49,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <cppeditor/cppeditorconstants.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
#include <utils/fileutils.h>
@@ -107,7 +107,7 @@ void Uncrustify::formatFile()
if (m_settings->useOtherFiles()) {
if (const ProjectExplorer::Project *project
- = ProjectExplorer::ProjectExplorerPlugin::currentProject()) {
+ = ProjectExplorer::ProjectTree::currentProject()) {
const QStringList files = project->files(ProjectExplorer::Project::AllFiles);
for (int i = 0, total = files.size(); i < total; ++i) {
const QString &file = files.at(i);
diff --git a/src/plugins/clearcase/clearcaseplugin.cpp b/src/plugins/clearcase/clearcaseplugin.cpp
index c77a3aa458..a4a9741825 100644
--- a/src/plugins/clearcase/clearcaseplugin.cpp
+++ b/src/plugins/clearcase/clearcaseplugin.cpp
@@ -54,7 +54,7 @@
#include <coreplugin/mimedatabase.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/locator/commandlocator.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
#include <projectexplorer/iprojectmanager.h>
#include <utils/algorithm.h>
@@ -453,8 +453,8 @@ bool ClearCasePlugin::initialize(const QStringList & /*arguments */, QString *er
m_settings.fromSettings(ICore::settings());
// update view name when changing active project
- connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
- this, SLOT(projectChanged(ProjectExplorer::Project*)));
+ connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged,
+ this, &ClearCasePlugin::projectChanged);
addAutoReleasedObject(new SettingsPage);
@@ -2055,7 +2055,7 @@ void ClearCasePlugin::updateIndex()
{
QTC_ASSERT(currentState().hasTopLevel(), return);
ProgressManager::cancelTasks(ClearCase::Constants::TASK_INDEX);
- Project *project = ProjectExplorerPlugin::currentProject();
+ Project *project = ProjectTree::currentProject();
if (!project)
return;
m_checkInAllAction->setEnabled(false);
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
index 3c02ca73ad..48f8ea5d7a 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
@@ -41,6 +41,7 @@
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <QDateTime>
using namespace CMakeProjectManager::Internal;
@@ -67,7 +68,7 @@ CMakeManager::CMakeManager(CMakeSettingsPage *cmakeSettingsPage)
command->setAttribute(Core::Command::CA_Hide);
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_DEPLOY);
connect(m_runCMakeAction, &QAction::triggered, [this]() {
- runCMake(ProjectExplorer::ProjectExplorerPlugin::currentProject());
+ runCMake(ProjectExplorer::ProjectTree::currentProject());
});
m_runCMakeActionContextMenu = new QAction(QIcon(), tr("Run CMake"), this);
diff --git a/src/plugins/cpptools/cppcodestylesettings.cpp b/src/plugins/cpptools/cppcodestylesettings.cpp
index 1d17776118..509dba814f 100644
--- a/src/plugins/cpptools/cppcodestylesettings.cpp
+++ b/src/plugins/cpptools/cppcodestylesettings.cpp
@@ -36,7 +36,7 @@
#include <projectexplorer/editorconfiguration.h>
#include <projectexplorer/project.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <utils/qtcassert.h>
#include <utils/settingsutils.h>
@@ -210,7 +210,7 @@ static void configureOverviewWithCodeStyleSettings(CPlusPlus::Overview &overview
CPlusPlus::Overview CppCodeStyleSettings::currentProjectCodeStyleOverview()
{
- ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
+ ProjectExplorer::Project *project = ProjectExplorer::ProjectTree::currentProject();
if (!project)
return currentGlobalCodeStyleOverview();
diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp
index 3956b5629c..0ed79950c7 100644
--- a/src/plugins/cpptools/cpptoolsplugin.cpp
+++ b/src/plugins/cpptools/cpptoolsplugin.cpp
@@ -53,6 +53,7 @@
#include <coreplugin/jsexpander.h>
#include <coreplugin/vcsmanager.h>
#include <cppeditor/cppeditorconstants.h>
+#include <projectexplorer/projecttree.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
@@ -431,7 +432,7 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader)
}
// Find files in the current project
- ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject();
+ ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectTree::currentProject();
if (currentProject) {
const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames,
currentProject);
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 4e9b867016..a387e4dd52 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -93,6 +93,7 @@
#include <projectexplorer/devicesupport/deviceprocesslist.h>
#include <projectexplorer/devicesupport/deviceprocessesdialog.h>
#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/projectexplorersettings.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
@@ -481,7 +482,7 @@ public:
bool DummyEngine::hasCapability(unsigned cap) const
{
// This can only be a first approximation of what to expect when running.
- Project *project = ProjectExplorerPlugin::currentProject();
+ Project *project = ProjectTree::currentProject();
if (!project)
return 0;
Target *target = project->activeTarget();
@@ -3437,7 +3438,7 @@ void DebuggerPlugin::extensionsInitialized()
void DebuggerPluginPrivate::testLoadProject(const QString &proFile, const TestCallBack &cb)
{
- connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::currentProjectChanged,
+ connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged,
this, &DebuggerPluginPrivate::testProjectLoaded);
m_testCallbacks.append(cb);
diff --git a/src/plugins/debugger/unstartedappwatcherdialog.cpp b/src/plugins/debugger/unstartedappwatcherdialog.cpp
index fe22bc2fc4..499b12cb0d 100644
--- a/src/plugins/debugger/unstartedappwatcherdialog.cpp
+++ b/src/plugins/debugger/unstartedappwatcherdialog.cpp
@@ -39,7 +39,7 @@
#include <projectexplorer/target.h>
#include <projectexplorer/project.h>
#include <projectexplorer/kitmanager.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/localapplicationrunconfiguration.h>
@@ -88,7 +88,7 @@ UnstartedAppWatcherDialog::UnstartedAppWatcherDialog(QWidget *parent)
m_kitChooser->populate();
m_kitChooser->setVisible(true);
- Project *project = ProjectExplorerPlugin::currentProject();
+ Project *project = ProjectTree::currentProject();
if (project && project->activeTarget() && project->activeTarget()->kit())
m_kitChooser->setCurrentKitId(project->activeTarget()->kit()->id());
else if (KitManager::defaultKit())
@@ -163,7 +163,7 @@ void UnstartedAppWatcherDialog::selectExecutable()
{
QString path;
- Project *project = ProjectExplorerPlugin::currentProject();
+ Project *project = ProjectTree::currentProject();
if (project && project->activeTarget() && project->activeTarget()->activeRunConfiguration()) {
diff --git a/src/plugins/projectexplorer/currentprojectfilter.cpp b/src/plugins/projectexplorer/currentprojectfilter.cpp
index e1c88043e2..83a78f3753 100644
--- a/src/plugins/projectexplorer/currentprojectfilter.cpp
+++ b/src/plugins/projectexplorer/currentprojectfilter.cpp
@@ -29,7 +29,7 @@
****************************************************************************/
#include "currentprojectfilter.h"
-#include "projectexplorer.h"
+#include "projecttree.h"
#include "project.h"
#include <utils/algorithm.h>
@@ -49,8 +49,8 @@ CurrentProjectFilter::CurrentProjectFilter()
setShortcutString(QString(QLatin1Char('p')));
setIncludedByDefault(false);
- connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
- this, SLOT(currentProjectChanged(ProjectExplorer::Project*)));
+ connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged,
+ this, &CurrentProjectFilter::currentProjectChanged);
}
void CurrentProjectFilter::markFilesAsOutOfDate()
diff --git a/src/plugins/projectexplorer/currentprojectfind.cpp b/src/plugins/projectexplorer/currentprojectfind.cpp
index 8c16bf62c9..235f5e7ef2 100644
--- a/src/plugins/projectexplorer/currentprojectfind.cpp
+++ b/src/plugins/projectexplorer/currentprojectfind.cpp
@@ -30,8 +30,8 @@
#include "currentprojectfind.h"
-#include "projectexplorer.h"
#include "project.h"
+#include "projecttree.h"
#include "session.h"
#include <utils/qtcassert.h>
@@ -46,8 +46,8 @@ using namespace TextEditor;
CurrentProjectFind::CurrentProjectFind()
{
- connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
- this, SLOT(handleProjectChanged()));
+ connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged,
+ this, &CurrentProjectFind::handleProjectChanged);
connect(SessionManager::instance(), SIGNAL(projectRemoved(ProjectExplorer::Project*)),
this, SLOT(handleProjectChanged()));
connect(SessionManager::instance(), SIGNAL(projectAdded(ProjectExplorer::Project*)),
@@ -66,12 +66,12 @@ QString CurrentProjectFind::displayName() const
bool CurrentProjectFind::isEnabled() const
{
- return ProjectExplorerPlugin::currentProject() != 0 && BaseFileFind::isEnabled();
+ return ProjectTree::currentProject() != 0 && BaseFileFind::isEnabled();
}
QVariant CurrentProjectFind::additionalParameters() const
{
- Project *project = ProjectExplorerPlugin::currentProject();
+ Project *project = ProjectTree::currentProject();
if (project && project->document())
return qVariantFromValue(project->projectFilePath().toString());
return QVariant();
@@ -92,8 +92,8 @@ Utils::FileIterator *CurrentProjectFind::files(const QStringList &nameFilters,
QString CurrentProjectFind::label() const
{
- QTC_ASSERT(ProjectExplorerPlugin::currentProject(), return QString());
- return tr("Project \"%1\":").arg(ProjectExplorerPlugin::currentProject()->displayName());
+ QTC_ASSERT(ProjectTree::currentProject(), return QString());
+ return tr("Project \"%1\":").arg(ProjectTree::currentProject()->displayName());
}
void CurrentProjectFind::handleProjectChanged()
diff --git a/src/plugins/projectexplorer/nodesvisitor.cpp b/src/plugins/projectexplorer/nodesvisitor.cpp
index 704ee3a46f..d4d1e84472 100644
--- a/src/plugins/projectexplorer/nodesvisitor.cpp
+++ b/src/plugins/projectexplorer/nodesvisitor.cpp
@@ -101,6 +101,11 @@ void FindNodesForFileVisitor::visitFolderNode(FolderNode *node)
}
}
+void FindNodesForFileVisitor::visitSessionNode(SessionNode *node)
+{
+ visitFolderNode(node);
+}
+
/*!
\class FindAllFilesVisitor
diff --git a/src/plugins/projectexplorer/nodesvisitor.h b/src/plugins/projectexplorer/nodesvisitor.h
index 3ac6fa1a66..ef53fc8f80 100644
--- a/src/plugins/projectexplorer/nodesvisitor.h
+++ b/src/plugins/projectexplorer/nodesvisitor.h
@@ -64,6 +64,7 @@ public:
void visitProjectNode(ProjectNode *node);
void visitFolderNode(FolderNode *node);
+ void visitSessionNode(SessionNode *node);
private:
QString m_path;
QList<Node*> m_nodes;
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 14a26c3abc..ec2f3db1ff 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -96,6 +96,7 @@
# include "wincetoolchain.h"
#endif
+#include "projecttree.h"
#include "projectwelcomepage.h"
#include <extensionsystem/pluginspec.h>
@@ -162,7 +163,6 @@
namespace {
bool debug = false;
-const char EXTERNAL_FILE_WARNING[] = "ExternalFile";
}
using namespace Core;
@@ -172,7 +172,7 @@ namespace ProjectExplorer {
static Target *activeTarget()
{
- Project *project = ProjectExplorerPlugin::currentProject();
+ Project *project = ProjectTree::currentProject();
return project ? project->activeTarget() : 0;
}
@@ -200,7 +200,6 @@ public:
QPair<bool, QString> buildSettingsEnabledForSession();
QPair<bool, QString> buildSettingsEnabled(Project *pro);
- void setCurrent(Project *project, QString filePath, Node *node);
void addToRecentProjects(const QString &fileName, const QString &displayName);
void startRunControl(RunControl *runControl, RunMode runMode);
@@ -266,10 +265,6 @@ public:
ProjectWindow *m_proWindow;
QString m_sessionToRestoreAtStartup;
- Project *m_currentProject;
- Context m_lastProjectContext;
- Node *m_currentNode;
-
QStringList m_profileMimeTypes;
AppOutputPane *m_outputPane;
@@ -291,22 +286,18 @@ public:
KitManager *m_kitManager;
ToolChainManager *m_toolChainManager;
bool m_shuttingDown;
- bool m_ignoreDocumentManagerChangedFile;
QStringList m_arguments;
QList<ProjectPanelFactory *> m_panelFactories;
QString m_renameFileError;
};
ProjectExplorerPluginPrivate::ProjectExplorerPluginPrivate() :
- m_currentProject(0),
- m_currentNode(0),
m_shouldHaveRunConfiguration(false),
m_runMode(NoRunMode),
m_projectsMode(0),
m_kitManager(0),
m_toolChainManager(0),
- m_shuttingDown(false),
- m_ignoreDocumentManagerChangedFile(false)
+ m_shuttingDown(false)
{
}
@@ -409,9 +400,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
connect(dd->m_welcomePage, SIGNAL(manageSessions()), this, SLOT(showSessionManager()));
addObject(dd->m_welcomePage);
- connect(DocumentManager::instance(), SIGNAL(currentFileChanged(QString)),
- this, SLOT(setCurrentFile(QString)));
-
QObject *sessionManager = new SessionManager(this);
connect(sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
@@ -435,13 +423,13 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
connect(sessionManager, SIGNAL(sessionLoaded(QString)),
this, SLOT(updateWelcomePage()));
- NodesWatcher *watcher = new NodesWatcher(this);
- SessionManager::sessionNode()->registerWatcher(watcher);
-
- connect(watcher, &NodesWatcher::foldersAboutToBeRemoved,
- this, &ProjectExplorerPlugin::foldersAboutToBeRemoved);
- connect(watcher, &NodesWatcher::filesAboutToBeRemoved,
- this, &ProjectExplorerPlugin::filesAboutToBeRemoved);
+ ProjectTree *tree = new ProjectTree(this);
+ connect(tree, &ProjectTree::currentProjectChanged,
+ dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
+ connect(tree, &ProjectTree::currentNodeChanged,
+ dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
+ connect(tree, &ProjectTree::currentProjectChanged,
+ dd, &ProjectExplorerPluginPrivate::updateActions);
addAutoReleasedObject(new CustomWizardMetaFactory<CustomProjectWizard>(Core::IWizardFactory::ProjectWizard));
addAutoReleasedObject(new CustomWizardMetaFactory<CustomWizard>(Core::IWizardFactory::FileWizard));
@@ -1133,7 +1121,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
tr("Current project's main file"),
[this]() -> QString {
QString projectFilePath;
- if (Project *project = ProjectExplorerPlugin::currentProject())
+ if (Project *project = ProjectTree::currentProject())
if (IDocument *doc = project->document())
projectFilePath = doc->filePath();
return projectFilePath;
@@ -1149,7 +1137,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
expander->registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
tr("The name of the current project."),
[this]() -> QString {
- Project *project = ProjectExplorerPlugin::currentProject();
+ Project *project = ProjectTree::currentProject();
return project ? project->displayName() : QString();
});
@@ -1277,7 +1265,7 @@ void ProjectExplorerPlugin::unloadProject()
if (debug)
qDebug() << "ProjectExplorerPlugin::unloadProject";
- unloadProject(dd->m_currentProject);
+ unloadProject(ProjectTree::currentProject());
}
void ProjectExplorerPlugin::unloadProject(Project *project)
@@ -1575,9 +1563,6 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
if (pro->restoreSettings()) {
connect(pro, SIGNAL(fileListChanged()), m_instance, SIGNAL(fileListChanged()));
SessionManager::addProject(pro);
- // Make sure we always have a current project / node
- if (!dd->m_currentProject && !openedPro.isEmpty())
- setCurrentNode(pro->rootProjectNode());
openedPro += pro;
} else {
appendError(errorString, tr("Failed opening project \"%1\": Settings could not be restored.")
@@ -1617,46 +1602,6 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
return openedPro;
}
-Project *ProjectExplorerPlugin::currentProject()
-{
- Project *project = dd->m_currentProject;
- if (debug) {
- if (project)
- qDebug() << "ProjectExplorerPlugin::currentProject returns " << project->displayName();
- else
- qDebug() << "ProjectExplorerPlugin::currentProject returns 0";
- }
- return project;
-}
-
-Node *ProjectExplorerPlugin::currentNode()
-{
- return dd->m_currentNode;
-}
-
-void ProjectExplorerPlugin::setCurrentFile(Project *project, const QString &filePath)
-{
- dd->setCurrent(project, filePath, 0);
-}
-
-void ProjectExplorerPlugin::setCurrentFile(const QString &filePath)
-{
- if (dd->m_ignoreDocumentManagerChangedFile)
- return;
- Project *project = SessionManager::projectForFile(filePath);
- // If the file is not in any project, stay with the current project
- // e.g. on opening a git diff buffer, git log buffer, we don't change the project
- // I'm not 100% sure this is correct
- if (!project)
- project = dd->m_currentProject;
- dd->setCurrent(project, filePath, 0);
-}
-
-void ProjectExplorerPlugin::setCurrentNode(Node *node)
-{
- dd->setCurrent(SessionManager::projectForNode(node), QString(), node);
-}
-
void ProjectExplorerPlugin::updateWelcomePage()
{
dd->m_welcomePage->reloadWelcomeScreenData();
@@ -1810,7 +1755,6 @@ void ProjectExplorerPlugin::showContextMenu(QWidget *view, const QPoint &globalP
if (node->nodeType() != SessionNodeType) {
Project *project = SessionManager::projectForNode(node);
- setCurrentNode(node);
emit m_instance->aboutToShowContextMenu(project, node);
switch (node->nodeType()) {
@@ -1959,57 +1903,6 @@ void ProjectExplorerPlugin::buildQueueFinished(bool success)
dd->m_runMode = NoRunMode;
}
-void ProjectExplorerPlugin::updateExternalFileWarning()
-{
- IDocument *document = qobject_cast<IDocument *>(sender());
- if (!document || document->filePath().isEmpty())
- return;
- InfoBar *infoBar = document->infoBar();
- Id externalFileId(EXTERNAL_FILE_WARNING);
- if (!document->isModified()) {
- infoBar->removeInfo(externalFileId);
- return;
- }
- if (!dd->m_currentProject || !infoBar->canInfoBeAdded(externalFileId))
- return;
- Utils::FileName fileName = Utils::FileName::fromString(document->filePath());
- Utils::FileName projectDir = dd->m_currentProject->projectDirectory();
- if (projectDir.isEmpty() || fileName.isChildOf(projectDir))
- return;
- // External file. Test if it under the same VCS
- QString topLevel;
- if (VcsManager::findVersionControlForDirectory(projectDir.toString(), &topLevel)
- && fileName.isChildOf(Utils::FileName::fromString(topLevel))) {
- return;
- }
- infoBar->addInfo(InfoBarEntry(externalFileId,
- tr("<b>Warning:</b> This file is outside the project directory."),
- InfoBarEntry::GlobalSuppressionEnabled));
-}
-
-void ProjectExplorerPlugin::updateContext()
-{
- dd->updateContext();
-}
-
-void ProjectExplorerPluginPrivate::updateContext()
-{
- Context oldContext;
- oldContext.add(m_lastProjectContext);
-
- Context newContext;
- if (m_currentProject) {
- newContext.add(m_currentProject->projectContext());
- newContext.add(m_currentProject->projectLanguages());
-
- m_lastProjectContext = newContext;
- } else {
- m_lastProjectContext = Context();
- }
-
- ICore::updateAdditionalContexts(oldContext, newContext);
-}
-
void ProjectExplorerPlugin::runConfigurationConfigurationFinished()
{
RunConfiguration *rc = qobject_cast<RunConfiguration *>(sender());
@@ -2074,59 +1967,6 @@ QString ProjectExplorerPlugin::directoryFor(Node *node)
return pathOrDirectoryFor(node, true);
}
-void ProjectExplorerPluginPrivate::setCurrent(Project *project, QString filePath, Node *node)
-{
- if (debug)
- qDebug() << "ProjectExplorer - setting path to " << (node ? pathFor(node) : filePath)
- << " and project to " << (project ? project->displayName() : QLatin1String("0"));
-
- if (node)
- filePath = pathFor(node);
- else
- node = ProjectTreeWidget::nodeForFile(filePath, project);
-
- bool projectChanged = false;
- if (m_currentProject != project) {
- if (m_currentProject) {
- disconnect(m_currentProject, SIGNAL(projectContextUpdated()),
- m_instance, SLOT(updateContext()));
- disconnect(m_currentProject, SIGNAL(projectLanguagesUpdated()),
- m_instance, SLOT(updateContext()));
- }
- if (project) {
- connect(project, SIGNAL(projectContextUpdated()),
- m_instance, SLOT(updateContext()));
- connect(project, SIGNAL(projectLanguagesUpdated()),
- m_instance, SLOT(updateContext()));
- }
- projectChanged = true;
- }
- m_currentProject = project;
-
- if (!node && EditorManager::currentDocument()) {
- connect(EditorManager::currentDocument(), SIGNAL(changed()),
- m_instance, SLOT(updateExternalFileWarning()), Qt::UniqueConnection);
- }
- if (projectChanged || m_currentNode != node) {
- m_currentNode = node;
- if (debug)
- qDebug() << "ProjectExplorer - currentNodeChanged(" << (node ? node->path() : QLatin1String("0")) << ", " << (project ? project->displayName() : QLatin1String("0")) << ')';
- emit m_instance->currentNodeChanged(m_currentNode, project);
- updateContextMenuActions();
- }
- if (projectChanged) {
- if (debug)
- qDebug() << "ProjectExplorer - currentProjectChanged(" << (project ? project->displayName() : QLatin1String("0")) << ')';
- emit m_instance->currentProjectChanged(project);
- updateActions();
- }
-
- m_ignoreDocumentManagerChangedFile = true;
- DocumentManager::setCurrentFile(filePath);
- updateContext();
- m_ignoreDocumentManagerChangedFile = false;
-}
-
void ProjectExplorerPlugin::updateActions()
{
dd->updateActions();
@@ -2140,13 +1980,14 @@ void ProjectExplorerPluginPrivate::updateActions()
m_newAction->setEnabled(!ICore::isNewItemDialogRunning());
Project *project = SessionManager::startupProject();
+ Project *currentProject = ProjectTree::currentProject(); // for context menu actions
QPair<bool, QString> buildActionState = buildSettingsEnabled(project);
- QPair<bool, QString> buildActionContextState = buildSettingsEnabled(m_currentProject);
+ QPair<bool, QString> buildActionContextState = buildSettingsEnabled(ProjectTree::currentProject());
QPair<bool, QString> buildSessionState = buildSettingsEnabledForSession();
QString projectName = project ? project->displayName() : QString();
- QString projectNameContextMenu = m_currentProject ? m_currentProject->displayName() : QString();
+ QString projectNameContextMenu = currentProject ? currentProject->displayName() : QString();
m_unloadAction->setParameter(projectName);
m_unloadActionContextMenu->setParameter(projectNameContextMenu);
@@ -2167,7 +2008,7 @@ void ProjectExplorerPluginPrivate::updateActions()
// Context menu actions
m_setStartupProjectAction->setParameter(projectNameContextMenu);
- bool hasDependencies = SessionManager::projectOrder(m_currentProject).size() > 1;
+ bool hasDependencies = SessionManager::projectOrder(currentProject).size() > 1;
if (hasDependencies) {
m_buildActionContextMenu->setText(tr("Build Without Dependencies"));
m_rebuildActionContextMenu->setText(tr("Rebuild Without Dependencies"));
@@ -2347,7 +2188,7 @@ void ProjectExplorerPlugin::buildProject()
void ProjectExplorerPlugin::buildProjectContextMenu()
{
- dd->queue(QList<Project *>() << dd->m_currentProject,
+ dd->queue(QList<Project *>() << ProjectTree::currentProject(),
QList<Id>() << Id(Constants::BUILDSTEPS_BUILD));
}
@@ -2371,7 +2212,7 @@ void ProjectExplorerPlugin::rebuildProject()
void ProjectExplorerPlugin::rebuildProjectContextMenu()
{
- dd->queue(QList<Project *>() << dd->m_currentProject,
+ dd->queue(QList<Project *>() << ProjectTree::currentProject(),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN) << Id(Constants::BUILDSTEPS_BUILD));
}
@@ -2393,7 +2234,7 @@ void ProjectExplorerPlugin::deployProject()
void ProjectExplorerPlugin::deployProjectContextMenu()
{
- dd->deploy(QList<Project *>() << dd->m_currentProject);
+ dd->deploy(QList<Project *>() << ProjectTree::currentProject());
}
void ProjectExplorerPlugin::deploySession()
@@ -2415,7 +2256,7 @@ void ProjectExplorerPlugin::cleanProject()
void ProjectExplorerPlugin::cleanProjectContextMenu()
{
- dd->queue(QList<Project *>() << dd->m_currentProject,
+ dd->queue(QList<Project *>() << ProjectTree::currentProject(),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN));
}
@@ -2437,9 +2278,9 @@ void ProjectExplorerPlugin::runProjectWithoutDeploy()
void ProjectExplorerPlugin::runProjectContextMenu()
{
- ProjectNode *projectNode = qobject_cast<ProjectNode*>(dd->m_currentNode);
- if (projectNode == dd->m_currentProject->rootProjectNode() || !projectNode) {
- runProject(dd->m_currentProject, NormalRunMode);
+ ProjectNode *projectNode = qobject_cast<ProjectNode*>(ProjectTree::currentNode());
+ if (projectNode == ProjectTree::currentProject()->rootProjectNode() || !projectNode) {
+ runProject(ProjectTree::currentProject(), NormalRunMode);
} else {
QAction *act = qobject_cast<QAction *>(sender());
if (!act)
@@ -2696,16 +2537,17 @@ void ProjectExplorerPluginPrivate::updateDeployActions()
bool enableDeployActions = project
&& !BuildManager::isBuilding(project)
&& hasDeploySettings(project);
- bool enableDeployActionsContextMenu = m_currentProject
- && !BuildManager::isBuilding(m_currentProject)
- && hasDeploySettings(m_currentProject);
+ Project *currentProject = ProjectTree::currentProject();
+ bool enableDeployActionsContextMenu = currentProject
+ && !BuildManager::isBuilding(currentProject)
+ && hasDeploySettings(currentProject);
if (m_projectExplorerSettings.buildBeforeDeploy) {
if (hasBuildSettings(project)
&& !buildSettingsEnabled(project).first)
enableDeployActions = false;
- if (hasBuildSettings(m_currentProject)
- && !buildSettingsEnabled(m_currentProject).first)
+ if (hasBuildSettings(currentProject)
+ && !buildSettingsEnabled(currentProject).first)
enableDeployActionsContextMenu = false;
}
@@ -2917,45 +2759,11 @@ void ProjectExplorerPlugin::invalidateProject(Project *project)
{
if (debug)
qDebug() << "ProjectExplorerPlugin::invalidateProject" << project->displayName();
- if (dd->m_currentProject == project) {
- //
- // Workaround for a bug in QItemSelectionModel
- // - currentChanged etc are not emitted if the
- // item is removed from the underlying data model
- //
- dd->setCurrent(0, QString(), 0);
- }
disconnect(project, SIGNAL(fileListChanged()), this, SIGNAL(fileListChanged()));
updateActions();
}
-void ProjectExplorerPlugin::foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode*> &list)
-{
- Node *n = ProjectExplorerPlugin::currentNode();
- while (n) {
- if (FolderNode *fn = qobject_cast<FolderNode *>(n)) {
- if (list.contains(fn)) {
- ProjectNode *pn = n->projectNode();
- // Make sure the node we are switching too isn't going to be removed also
- while (list.contains(pn))
- pn = pn->parentFolderNode()->projectNode();
- ProjectExplorerPlugin::setCurrentNode(pn);
- break;
- }
- }
- n = n->parentFolderNode();
- }
-}
-
-void ProjectExplorerPlugin::filesAboutToBeRemoved(FolderNode *, const QList<FileNode*> &list)
-{
- if (FileNode *fileNode = qobject_cast<FileNode *>(ProjectExplorerPlugin::currentNode())) {
- if (list.contains(fileNode))
- ProjectExplorerPlugin::setCurrentNode(fileNode->projectNode());
- }
-}
-
void ProjectExplorerPluginPrivate::updateContextMenuActions()
{
m_addExistingFilesAction->setEnabled(false);
@@ -2984,11 +2792,13 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions()
runMenu->menu()->clear();
runMenu->menu()->menuAction()->setVisible(false);
- if (dd->m_currentNode && dd->m_currentNode->projectNode()) {
- QList<ProjectAction> actions = dd->m_currentNode->supportedActions(dd->m_currentNode);
+ Node *currentNode = ProjectTree::currentNode();
- if (ProjectNode *pn = qobject_cast<ProjectNode *>(dd->m_currentNode)) {
- if (pn == dd->m_currentProject->rootProjectNode()) {
+ if (currentNode && currentNode->projectNode()) {
+ QList<ProjectAction> actions = currentNode->supportedActions(currentNode);
+
+ if (ProjectNode *pn = qobject_cast<ProjectNode *>(currentNode)) {
+ if (ProjectTree::currentProject() && pn == ProjectTree::currentProject()->rootProjectNode()) {
dd->m_runActionContextMenu->setVisible(true);
} else {
QList<RunConfiguration *> runConfigs = pn->runConfigurations();
@@ -3008,19 +2818,19 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions()
}
}
}
- if (qobject_cast<FolderNode*>(dd->m_currentNode)) {
+ if (qobject_cast<FolderNode*>(currentNode)) {
// Also handles ProjectNode
dd->m_addNewFileAction->setEnabled(actions.contains(AddNewFile)
&& !ICore::isNewItemDialogRunning());
- dd->m_addNewSubprojectAction->setEnabled(dd->m_currentNode->nodeType() == ProjectNodeType
+ dd->m_addNewSubprojectAction->setEnabled(currentNode->nodeType() == ProjectNodeType
&& actions.contains(AddSubProject)
&& !ICore::isNewItemDialogRunning());
- dd->m_removeProjectAction->setEnabled(dd->m_currentNode->nodeType() == ProjectNodeType
+ dd->m_removeProjectAction->setEnabled(currentNode->nodeType() == ProjectNodeType
&& actions.contains(RemoveSubProject));
dd->m_addExistingFilesAction->setEnabled(actions.contains(AddExistingFile));
dd->m_addExistingDirectoryAction->setEnabled(actions.contains(AddExistingDirectory));
dd->m_renameFileAction->setEnabled(actions.contains(Rename));
- } else if (qobject_cast<FileNode*>(dd->m_currentNode)) {
+ } else if (qobject_cast<FileNode*>(currentNode)) {
// Enable and show remove / delete in magic ways:
// If both are disabled show Remove
// If both are enabled show both (can't happen atm)
@@ -3059,13 +2869,13 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions()
void ProjectExplorerPlugin::addNewFile()
{
- QTC_ASSERT(dd->m_currentNode, return);
- QString location = directoryFor(dd->m_currentNode);
+ QTC_ASSERT(ProjectTree::currentNode(), return);
+ QString location = directoryFor(ProjectTree::currentNode());
QVariantMap map;
- map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(dd->m_currentNode));
- if (dd->m_currentProject) {
- QList<Id> profileIds = Utils::transform(dd->m_currentProject->targets(), &Target::id);
+ map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(ProjectTree::currentNode()));
+ if (ProjectTree::currentProject()) {
+ QList<Id> profileIds = Utils::transform(ProjectTree::currentProject()->targets(), &Target::id);
map.insert(QLatin1String(Constants::PROJECT_KIT_IDS), QVariant::fromValue(profileIds));
}
ICore::showNewItemDialog(tr("New File", "Title of dialog"),
@@ -3076,16 +2886,17 @@ void ProjectExplorerPlugin::addNewFile()
void ProjectExplorerPlugin::addNewSubproject()
{
- QTC_ASSERT(dd->m_currentNode, return);
- QString location = directoryFor(dd->m_currentNode);
+ QTC_ASSERT(ProjectTree::currentNode(), return);
+ Node *currentNode = ProjectTree::currentNode();
+ QString location = directoryFor(currentNode);
- if (dd->m_currentNode->nodeType() == ProjectNodeType
- && dd->m_currentNode->supportedActions(
- dd->m_currentNode).contains(AddSubProject)) {
+ if (currentNode->nodeType() == ProjectNodeType
+ && currentNode->supportedActions(
+ currentNode).contains(AddSubProject)) {
QVariantMap map;
- map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(dd->m_currentNode));
- if (dd->m_currentProject) {
- QList<Id> profileIds = Utils::transform(dd->m_currentProject->targets(), &Target::id);
+ map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(currentNode));
+ if (ProjectTree::currentProject()) {
+ QList<Id> profileIds = Utils::transform(ProjectTree::currentProject()->targets(), &Target::id);
map.insert(QLatin1String(Constants::PROJECT_KIT_IDS), QVariant::fromValue(profileIds));
}
@@ -3097,10 +2908,10 @@ void ProjectExplorerPlugin::addNewSubproject()
void ProjectExplorerPlugin::addExistingFiles()
{
- QTC_ASSERT(dd->m_currentNode, return);
+ QTC_ASSERT(ProjectTree::currentNode(), return);
QStringList fileNames = QFileDialog::getOpenFileNames(ICore::mainWindow(),
- tr("Add Existing Files"), directoryFor(dd->m_currentNode));
+ tr("Add Existing Files"), directoryFor(ProjectTree::currentNode()));
if (fileNames.isEmpty())
return;
addExistingFiles(fileNames);
@@ -3108,9 +2919,9 @@ void ProjectExplorerPlugin::addExistingFiles()
void ProjectExplorerPlugin::addExistingDirectory()
{
- QTC_ASSERT(dd->m_currentNode, return);
+ QTC_ASSERT(ProjectTree::currentNode(), return);
- SelectableFilesDialogAddDirectory dialog(directoryFor(dd->m_currentNode), QStringList(), Core::ICore::mainWindow());
+ SelectableFilesDialogAddDirectory dialog(directoryFor(ProjectTree::currentNode()), QStringList(), Core::ICore::mainWindow());
if (dialog.exec() == QDialog::Accepted)
addExistingFiles(dialog.selectedFiles());
@@ -3118,7 +2929,7 @@ void ProjectExplorerPlugin::addExistingDirectory()
void ProjectExplorerPlugin::addExistingFiles(const QStringList &filePaths)
{
- FolderNode *folderNode = qobject_cast<FolderNode *>(dd->m_currentNode);
+ FolderNode *folderNode = qobject_cast<FolderNode *>(ProjectTree::currentNode());
addExistingFiles(folderNode, filePaths);
}
@@ -3147,7 +2958,7 @@ void ProjectExplorerPlugin::addExistingFiles(FolderNode *folderNode, const QStri
void ProjectExplorerPlugin::removeProject()
{
- ProjectNode *subProjectNode = qobject_cast<ProjectNode*>(dd->m_currentNode->projectNode());
+ ProjectNode *subProjectNode = qobject_cast<ProjectNode*>(ProjectTree::currentNode()->projectNode());
ProjectNode *projectNode = qobject_cast<ProjectNode *>(subProjectNode->parentFolderNode());
if (projectNode) {
RemoveFileDialog removeFileDialog(subProjectNode->path(), ICore::mainWindow());
@@ -3159,35 +2970,36 @@ void ProjectExplorerPlugin::removeProject()
void ProjectExplorerPlugin::openFile()
{
- QTC_ASSERT(dd->m_currentNode, return);
- EditorManager::openEditor(dd->m_currentNode->path());
+ QTC_ASSERT(ProjectTree::currentNode(), return);
+ EditorManager::openEditor(ProjectTree::currentNode()->path());
}
void ProjectExplorerPlugin::searchOnFileSystem()
{
- QTC_ASSERT(dd->m_currentNode, return);
- TextEditor::FindInFiles::findOnFileSystem(pathFor(dd->m_currentNode));
+ QTC_ASSERT(ProjectTree::currentNode(), return);
+ TextEditor::FindInFiles::findOnFileSystem(pathFor(ProjectTree::currentNode()));
}
void ProjectExplorerPlugin::showInGraphicalShell()
{
- QTC_ASSERT(dd->m_currentNode, return);
- FileUtils::showInGraphicalShell(ICore::mainWindow(), pathFor(dd->m_currentNode));
+ QTC_ASSERT(ProjectTree::currentNode(), return);
+ FileUtils::showInGraphicalShell(ICore::mainWindow(), pathFor(ProjectTree::currentNode()));
}
void ProjectExplorerPlugin::openTerminalHere()
{
- QTC_ASSERT(dd->m_currentNode, return);
- FileUtils::openTerminal(directoryFor(dd->m_currentNode));
+ QTC_ASSERT(ProjectTree::currentNode(), return);
+ FileUtils::openTerminal(directoryFor(ProjectTree::currentNode()));
}
void ProjectExplorerPlugin::removeFile()
{
- QTC_ASSERT(dd->m_currentNode && dd->m_currentNode->nodeType() == FileNodeType, return);
+ Node *currentNode = ProjectTree::currentNode();
+ QTC_ASSERT(currentNode && currentNode->nodeType() == FileNodeType, return);
- FileNode *fileNode = qobject_cast<FileNode*>(dd->m_currentNode);
+ FileNode *fileNode = qobject_cast<FileNode*>(currentNode);
- QString filePath = dd->m_currentNode->path();
+ QString filePath = currentNode->path();
RemoveFileDialog removeFileDialog(filePath, ICore::mainWindow());
if (removeFileDialog.exec() == QDialog::Accepted) {
@@ -3211,11 +3023,12 @@ void ProjectExplorerPlugin::removeFile()
void ProjectExplorerPlugin::deleteFile()
{
- QTC_ASSERT(dd->m_currentNode && dd->m_currentNode->nodeType() == FileNodeType, return);
+ Node *currentNode = ProjectTree::currentNode();
+ QTC_ASSERT(currentNode && currentNode->nodeType() == FileNodeType, return);
- FileNode *fileNode = qobject_cast<FileNode*>(dd->m_currentNode);
+ FileNode *fileNode = qobject_cast<FileNode*>(currentNode);
- QString filePath = dd->m_currentNode->path();
+ QString filePath = currentNode->path();
QMessageBox::StandardButton button =
QMessageBox::question(ICore::mainWindow(),
tr("Delete File"),
@@ -3256,11 +3069,9 @@ void ProjectExplorerPlugin::renameFile()
}
}
-void ProjectExplorerPlugin::renameFile(Node *node, const QString &to)
+void ProjectExplorerPlugin::renameFile(Node *node, const QString &newFilePath)
{
QString orgFilePath = QFileInfo(node->path()).absoluteFilePath();
- QString dir = QFileInfo(orgFilePath).absolutePath();
- QString newFilePath = dir + QLatin1Char('/') + to;
if (FileUtils::renameFile(orgFilePath, newFilePath)) {
// Tell the project plugin about rename
@@ -3273,15 +3084,13 @@ void ProjectExplorerPlugin::renameFile(Node *node, const QString &to)
.arg(projectDisplayName);
QTimer::singleShot(0, m_instance, SLOT(showRenameFileError()));
- } else {
- dd->setCurrent(SessionManager::projectForFile(newFilePath), newFilePath, 0);
}
}
}
void ProjectExplorerPlugin::setStartupProject()
{
- setStartupProject(dd->m_currentProject);
+ setStartupProject(ProjectTree::currentProject());
}
void ProjectExplorerPlugin::showRenameFileError()
@@ -3291,7 +3100,7 @@ void ProjectExplorerPlugin::showRenameFileError()
void ProjectExplorerPlugin::populateOpenWithMenu()
{
- DocumentManager::populateOpenWithMenu(dd->m_openWithMenu, currentNode()->path());
+ DocumentManager::populateOpenWithMenu(dd->m_openWithMenu, ProjectTree::currentNode()->path());
}
void ProjectExplorerPlugin::updateSessionMenu()
diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h
index 5ab8e7adf1..6e5530c5ea 100644
--- a/src/plugins/projectexplorer/projectexplorer.h
+++ b/src/plugins/projectexplorer/projectexplorer.h
@@ -76,12 +76,6 @@ public:
Q_SLOT void openProjectWelcomePage(const QString &fileName);
static void unloadProject(Project *project);
- static Project *currentProject();
- static Node *currentNode();
-
- static void setCurrentFile(Project *project, const QString &file);
- static void setCurrentNode(Node *node);
-
static bool saveModifiedFiles();
static void showContextMenu(QWidget *view, const QPoint &globalPos, Node *node);
@@ -98,7 +92,7 @@ public:
static void showRunErrorMessage(const QString &errorMessage);
// internal public for FlatModel
- static void renameFile(Node *node, const QString &to);
+ static void renameFile(Node *node, const QString &newFilePath);
static QStringList projectFilePatterns();
static bool coreAboutToClose();
static QList<QPair<QString, QString> > recentProjects();
@@ -133,8 +127,6 @@ signals:
// or the file list of a specific project has changed.
void fileListChanged();
- void currentProjectChanged(ProjectExplorer::Project *project);
- void currentNodeChanged(ProjectExplorer::Node *node, ProjectExplorer::Project *project);
void aboutToExecuteProject(ProjectExplorer::Project *project, RunMode runMode);
void recentProjectsChanged();
@@ -203,12 +195,7 @@ private slots:
void updateUnloadProjectMenu();
void openTerminalHere();
- // for keeping current node / current project up to date
void invalidateProject(ProjectExplorer::Project *project);
- void foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode*> &);
- void filesAboutToBeRemoved(FolderNode *, const QList<FileNode*> &);
-
- void setCurrentFile(const QString &filePath);
void runControlFinished();
@@ -225,10 +212,8 @@ private slots:
void loadCustomWizards();
void updateWelcomePage();
- void updateExternalFileWarning();
void updateActions();
- void updateContext();
void runConfigurationConfigurationFinished();
void showRenameFileError();
diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro
index 195fa45737..6fafd53df1 100644
--- a/src/plugins/projectexplorer/projectexplorer.pro
+++ b/src/plugins/projectexplorer/projectexplorer.pro
@@ -152,7 +152,8 @@ HEADERS += projectexplorer.h \
propertiespanel.h \
panelswidget.h \
projectwelcomepage.h \
- projectpanelfactory.h
+ projectpanelfactory.h \
+ projecttree.h
SOURCES += projectexplorer.cpp \
abi.cpp \
@@ -290,7 +291,8 @@ SOURCES += projectexplorer.cpp \
propertiespanel.cpp \
panelswidget.cpp \
projectwelcomepage.cpp \
- projectpanelfactory.cpp
+ projectpanelfactory.cpp \
+ projecttree.cpp
FORMS += processstep.ui \
editorsettingspropertiespage.ui \
diff --git a/src/plugins/projectexplorer/projectmodels.cpp b/src/plugins/projectexplorer/projectmodels.cpp
index f30a71acaf..efec5bf89b 100644
--- a/src/plugins/projectexplorer/projectmodels.cpp
+++ b/src/plugins/projectexplorer/projectmodels.cpp
@@ -352,7 +352,14 @@ bool FlatModel::setData(const QModelIndex &index, const QVariant &value, int rol
if (role != Qt::EditRole)
return false;
- ProjectExplorerPlugin::renameFile(nodeForIndex(index), value.toString());
+ Node *node = nodeForIndex(index);
+
+ QString orgFilePath = QFileInfo(node->path()).absoluteFilePath();
+ QString dir = QFileInfo(orgFilePath).absolutePath();
+ QString newFilePath = dir + QLatin1Char('/') + value.toString();
+
+ ProjectExplorerPlugin::renameFile(node, newFilePath);
+ emit renamed(orgFilePath, newFilePath);
return true;
}
diff --git a/src/plugins/projectexplorer/projectmodels.h b/src/plugins/projectexplorer/projectmodels.h
index 62a4d3fe12..6b7314f6df 100644
--- a/src/plugins/projectexplorer/projectmodels.h
+++ b/src/plugins/projectexplorer/projectmodels.h
@@ -78,6 +78,9 @@ public:
bool projectFilterEnabled();
bool generatedFilesFilterEnabled();
+signals:
+ void renamed(const QString &oldName, const QString &newName);
+
public slots:
void setProjectFilterEnabled(bool filter);
void setGeneratedFilesFilterEnabled(bool filter);
diff --git a/src/plugins/projectexplorer/projecttree.cpp b/src/plugins/projectexplorer/projecttree.cpp
new file mode 100644
index 0000000000..d0ad41d144
--- /dev/null
+++ b/src/plugins/projectexplorer/projecttree.cpp
@@ -0,0 +1,360 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://www.qt.io/licensing. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** 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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "projecttree.h"
+#include "projecttreewidget.h"
+#include "session.h"
+#include "project.h"
+#include "projectnodes.h"
+
+#include <utils/algorithm.h>
+#include <coreplugin/documentmanager.h>
+#include <coreplugin/icore.h>
+#include <coreplugin/editormanager/ieditor.h>
+#include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/infobar.h>
+#include <coreplugin/vcsmanager.h>
+
+#include <QApplication>
+
+namespace {
+const char EXTERNAL_FILE_WARNING[] = "ExternalFile";
+}
+
+using namespace ProjectExplorer;
+using namespace Internal;
+
+ProjectTree *ProjectTree::s_instance = 0;
+
+ProjectTree::ProjectTree(QObject *parent)
+ : QObject(parent),
+ m_currentNode(0),
+ m_currentProject(0),
+ m_resetCurrentNodeFolder(0),
+ m_resetCurrentNodeFile(0),
+ m_resetCurrentNodeProject(0)
+{
+ s_instance = this;
+
+ connect(Core::DocumentManager::instance(), &Core::DocumentManager::currentFileChanged,
+ this, &ProjectTree::documentManagerCurrentFileChanged);
+
+ SessionManager *session = SessionManager::instance();
+ connect(session, &SessionManager::aboutToRemoveProject,
+ this, &ProjectTree::aboutToRemoveProject);
+ connect(session, &SessionManager::projectRemoved,
+ this, &ProjectTree::projectRemoved);
+
+
+ NodesWatcher *watcher = new NodesWatcher(this);
+ SessionManager::sessionNode()->registerWatcher(watcher);
+
+ connect(watcher, &NodesWatcher::foldersAboutToBeRemoved,
+ this, &ProjectTree::foldersAboutToBeRemoved);
+ connect(watcher, &NodesWatcher::foldersRemoved,
+ this, &ProjectTree::foldersRemoved);
+
+ connect(watcher, &NodesWatcher::filesAboutToBeRemoved,
+ this, &ProjectTree::filesAboutToBeRemoved);
+ connect(watcher, &NodesWatcher::filesRemoved,
+ this, &ProjectTree::filesRemoved);
+
+ connect(watcher, &NodesWatcher::foldersAdded,
+ this, &ProjectTree::nodesAdded);
+ connect(watcher, &NodesWatcher::filesAdded,
+ this, &ProjectTree::nodesAdded);
+
+ connect(qApp, &QApplication::focusChanged,
+ this, &ProjectTree::focusChanged);
+}
+
+ProjectTree *ProjectTree::instance()
+{
+ return s_instance;
+}
+
+Project *ProjectTree::currentProject()
+{
+ return s_instance->m_currentProject;
+}
+
+Node *ProjectTree::currentNode()
+{
+ return s_instance->m_currentNode;
+}
+
+void ProjectTree::registerWidget(ProjectTreeWidget *widget)
+{
+ s_instance->m_projectTreeWidgets.append(widget);
+ if (hasFocus(widget))
+ s_instance->updateFromProjectTreeWidget(widget);
+}
+
+void ProjectTree::unregisterWidget(ProjectTreeWidget *widget)
+{
+ s_instance->m_projectTreeWidgets.removeOne(widget);
+ if (hasFocus(widget))
+ s_instance->updateFromDocumentManager();
+}
+
+void ProjectTree::nodeChanged(ProjectTreeWidget *widget)
+{
+ if (hasFocus(widget))
+ s_instance->updateFromProjectTreeWidget(widget);
+}
+
+void ProjectTree::focusChanged()
+{
+ s_instance->updateFromFocus();
+}
+
+bool ProjectTree::editorHasFocus()
+{
+ Core::IEditor *editor = Core::EditorManager::currentEditor();
+ if (!editor)
+ return false;
+ QWidget *widget = editor->widget();
+ if (!widget)
+ return false;
+ widget = widget->focusWidget();
+ if (!widget)
+ return false;
+ return widget->hasFocus();
+}
+
+void ProjectTree::updateFromFocus(bool invalidCurrentNode)
+{
+ ProjectTreeWidget *focus = Utils::findOrDefault(s_instance->m_projectTreeWidgets,
+ &ProjectTree::hasFocus);
+
+ if (focus)
+ updateFromProjectTreeWidget(focus);
+ else if (editorHasFocus())
+ updateFromDocumentManager(invalidCurrentNode);
+}
+
+void ProjectTree::updateFromProjectTreeWidget(ProjectTreeWidget *widget)
+{
+ ProjectExplorer::Node *currentNode = widget->currentNode();
+ ProjectExplorer::Project *project = projectForNode(currentNode);
+
+ update(currentNode, project);
+}
+
+void ProjectTree::documentManagerCurrentFileChanged()
+{
+ if (editorHasFocus())
+ updateFromDocumentManager();
+}
+
+Project *ProjectTree::projectForNode(Node *node)
+{
+ if (!node)
+ return 0;
+
+ FolderNode *rootProjectNode = qobject_cast<FolderNode*>(node);
+ if (!rootProjectNode)
+ rootProjectNode = node->parentFolderNode();
+
+ while (rootProjectNode && rootProjectNode->parentFolderNode() != SessionManager::sessionNode())
+ rootProjectNode = rootProjectNode->parentFolderNode();
+
+ Q_ASSERT(rootProjectNode);
+
+ return Utils::findOrDefault(SessionManager::projects(), Utils::equal(&Project::rootProjectNode, rootProjectNode));
+}
+
+void ProjectTree::updateFromDocumentManager(bool invalidCurrentNode)
+{
+ const QString &fileName = Core::DocumentManager::currentFile();
+
+ ProjectExplorer::Node *currentNode = 0;
+ if (!invalidCurrentNode && m_currentNode && m_currentNode->path() == fileName)
+ currentNode = m_currentNode;
+ else
+ currentNode = ProjectTreeWidget::nodeForFile(fileName);
+
+ ProjectExplorer::Project *project = projectForNode(currentNode);
+
+ update(currentNode, project);
+ foreach (ProjectTreeWidget *widget, m_projectTreeWidgets)
+ widget->sync(currentNode);
+}
+
+void ProjectTree::update(Node *node, Project *project)
+{
+ if (project != m_currentProject) {
+ if (m_currentProject) {
+ disconnect(m_currentProject, &Project::projectContextUpdated,
+ this, &ProjectTree::updateContext);
+ disconnect(m_currentProject, &Project::projectLanguagesUpdated,
+ this, &ProjectTree::updateContext);
+ }
+
+ m_currentProject = project;
+ emit currentProjectChanged(m_currentProject);
+
+ if (m_currentProject) {
+ connect(m_currentProject, &Project::projectContextUpdated,
+ this, &ProjectTree::updateContext);
+ connect(m_currentProject, &Project::projectLanguagesUpdated,
+ this, &ProjectTree::updateContext);
+ }
+ }
+
+ if (!node && Core::EditorManager::currentDocument()) {
+ connect(Core::EditorManager::currentDocument(), &Core::IDocument::changed,
+ this, &ProjectTree::updateExternalFileWarning,
+ Qt::UniqueConnection);
+ }
+
+ if (node != m_currentNode) {
+ m_currentNode = node;
+ emit currentNodeChanged(m_currentNode, project);
+ }
+
+ updateContext();
+}
+
+void ProjectTree::updateContext()
+{
+ Core::Context oldContext;
+ oldContext.add(m_lastProjectContext);
+
+ Core::Context newContext;
+ if (m_currentProject) {
+ newContext.add(m_currentProject->projectContext());
+ newContext.add(m_currentProject->projectLanguages());
+
+ m_lastProjectContext = newContext;
+ } else {
+ m_lastProjectContext = Core::Context();
+ }
+
+ Core::ICore::updateAdditionalContexts(oldContext, newContext);
+}
+
+void ProjectTree::foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode*> &list)
+{
+ Node *n = ProjectTree::currentNode();
+ while (n) {
+ if (FolderNode *fn = qobject_cast<FolderNode *>(n)) {
+ if (list.contains(fn)) {
+ ProjectNode *pn = n->projectNode();
+ // Make sure the node we are switching too isn't going to be removed also
+ while (list.contains(pn))
+ pn = pn->parentFolderNode()->projectNode();
+ m_resetCurrentNodeFolder = true;
+ return;
+ }
+ }
+ n = n->parentFolderNode();
+ }
+}
+
+void ProjectTree::foldersRemoved()
+{
+ if (m_resetCurrentNodeFolder) {
+ updateFromFocus(true);
+ m_resetCurrentNodeFolder = false;
+ }
+}
+
+void ProjectTree::filesAboutToBeRemoved(FolderNode *, const QList<FileNode*> &list)
+{
+ if (FileNode *fileNode = qobject_cast<FileNode *>(m_currentNode))
+ if (list.contains(fileNode))
+ m_resetCurrentNodeFile = false;
+}
+
+void ProjectTree::filesRemoved()
+{
+ if (m_resetCurrentNodeFile) {
+ updateFromFocus(true);
+ m_resetCurrentNodeFile = false;
+ }
+}
+
+void ProjectTree::aboutToRemoveProject(Project *project)
+{
+ if (m_currentProject == project)
+ m_resetCurrentNodeProject = true;
+}
+
+void ProjectTree::projectRemoved()
+{
+ updateFromFocus(true);
+ m_resetCurrentNodeProject = false;
+}
+
+void ProjectTree::nodesAdded()
+{
+ if (Utils::anyOf(m_projectTreeWidgets, &ProjectTreeWidget::hasFocus))
+ return;
+
+ updateFromDocumentManager();
+}
+
+void ProjectTree::updateExternalFileWarning()
+{
+ Core::IDocument *document = qobject_cast<Core::IDocument *>(sender());
+ if (!document || document->filePath().isEmpty())
+ return;
+ Core::InfoBar *infoBar = document->infoBar();
+ Core::Id externalFileId(EXTERNAL_FILE_WARNING);
+ if (!document->isModified()) {
+ infoBar->removeInfo(externalFileId);
+ return;
+ }
+ if (!infoBar->canInfoBeAdded(externalFileId))
+ return;
+ Utils::FileName fileName = Utils::FileName::fromString(document->filePath());
+ foreach (Project *project, SessionManager::projects()) {
+ Utils::FileName projectDir = project->projectDirectory();
+ if (projectDir.isEmpty())
+ continue;
+ if (fileName.isChildOf(projectDir))
+ return;
+ // External file. Test if it under the same VCS
+ QString topLevel;
+ if (Core::VcsManager::findVersionControlForDirectory(projectDir.toString(), &topLevel)
+ && fileName.isChildOf(Utils::FileName::fromString(topLevel))) {
+ return;
+ }
+ }
+ infoBar->addInfo(Core::InfoBarEntry(externalFileId,
+ tr("<b>Warning:</b> This file is outside the project directory."),
+ Core::InfoBarEntry::GlobalSuppressionEnabled));
+}
+
+bool ProjectExplorer::ProjectTree::hasFocus(ProjectExplorer::Internal::ProjectTreeWidget *widget)
+{
+ return widget && widget->focusWidget() && widget->focusWidget()->hasFocus();
+}
diff --git a/src/plugins/projectexplorer/projecttree.h b/src/plugins/projectexplorer/projecttree.h
new file mode 100644
index 0000000000..4a4c9d8da0
--- /dev/null
+++ b/src/plugins/projectexplorer/projecttree.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://www.qt.io/licensing. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** 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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef PROJECTTREE_H
+#define PROJECTTREE_H
+
+#include "projectexplorer_export.h"
+
+#include <coreplugin/icontext.h>
+
+#include <QObject>
+
+namespace ProjectExplorer {
+class FileNode;
+class FolderNode;
+class Node;
+class Project;
+class ProjectNode;
+
+namespace Internal {
+class ProjectTreeWidget;
+}
+
+class PROJECTEXPLORER_EXPORT ProjectTree : public QObject
+{
+ Q_OBJECT
+public:
+ explicit ProjectTree(QObject *parent = 0);
+
+ static ProjectTree *instance();
+
+ static Project *currentProject();
+ static Node *currentNode();
+
+ // Integration with ProjectTreeWidget
+ static void registerWidget(ProjectExplorer::Internal::ProjectTreeWidget *widget);
+ static void unregisterWidget(ProjectExplorer::Internal::ProjectTreeWidget *widget);
+ static void nodeChanged(ProjectExplorer::Internal::ProjectTreeWidget *widget);
+ static void focusChanged();
+ static Project *projectForNode(Node *node);
+
+signals:
+ void currentProjectChanged(ProjectExplorer::Project *project);
+ void currentNodeChanged(ProjectExplorer::Node *node, ProjectExplorer::Project *project);
+
+private:
+ void updateFromProjectTreeWidget(ProjectExplorer::Internal::ProjectTreeWidget *widget);
+ void documentManagerCurrentFileChanged();
+ void updateFromDocumentManager(bool invalidCurrentNode = false);
+ void update(Node *node, Project *project);
+ void updateContext();
+
+ // slots to kepp the current node/current project from deletion
+ void foldersAboutToBeRemoved(FolderNode *, const QList<FolderNode *> &list);
+ void foldersRemoved();
+ void filesAboutToBeRemoved(FolderNode *, const QList<FileNode *> &list);
+ void filesRemoved();
+ void aboutToRemoveProject(ProjectExplorer::Project *project);
+ void projectRemoved();
+
+ void nodesAdded();
+ void updateFromFocus(bool invalidCurrentNode = false);
+
+ void updateExternalFileWarning();
+ bool editorHasFocus();
+ static bool hasFocus(Internal::ProjectTreeWidget *widget);
+
+
+ static ProjectTree *s_instance;
+ QList<ProjectExplorer::Internal::ProjectTreeWidget *> m_projectTreeWidgets;
+ Node *m_currentNode;
+ Project *m_currentProject;
+ bool m_resetCurrentNodeFolder;
+ bool m_resetCurrentNodeFile;
+ bool m_resetCurrentNodeProject;
+ Core::Context m_lastProjectContext;
+};
+}
+
+#endif // PROJECTTREE_H
diff --git a/src/plugins/projectexplorer/projecttreewidget.cpp b/src/plugins/projectexplorer/projecttreewidget.cpp
index 26173156f1..38c0dd6325 100644
--- a/src/plugins/projectexplorer/projecttreewidget.cpp
+++ b/src/plugins/projectexplorer/projecttreewidget.cpp
@@ -35,9 +35,11 @@
#include "project.h"
#include "session.h"
#include "projectmodels.h"
+#include "projecttree.h"
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
+#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
@@ -127,6 +129,7 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent)
m_view->setModel(m_model);
m_view->setItemDelegate(new ProjectTreeItemDelegate(this));
setFocusProxy(m_view);
+ m_view->installEventFilter(this);
initView();
QVBoxLayout *layout = new QVBoxLayout();
@@ -149,6 +152,8 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent)
// connections
connect(m_model, SIGNAL(modelReset()),
this, SLOT(initView()));
+ connect(m_model, &FlatModel::renamed,
+ this, &ProjectTreeWidget::renamed);
connect(m_view, SIGNAL(activated(QModelIndex)),
this, SLOT(openItem(QModelIndex)));
connect(m_view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
@@ -179,11 +184,13 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent)
setAutoSynchronization(true);
m_projectTreeWidgets << this;
+ ProjectTree::registerWidget(this);
}
ProjectTreeWidget::~ProjectTreeWidget()
{
m_projectTreeWidgets.removeOne(this);
+ ProjectTree::unregisterWidget(this);
}
// returns how many nodes need to be expanded to make node visible
@@ -208,21 +215,32 @@ int ProjectTreeWidget::expandedCount(Node *node)
return count;
}
-void ProjectTreeWidget::rowsInserted(const QModelIndex &parent, int, int)
+void ProjectTreeWidget::rowsInserted(const QModelIndex &parent, int start, int end)
{
const QString &path = m_model->nodeForIndex(parent)->path();
if (m_toExpand.contains(path)) {
m_view->expand(parent);
m_toExpand.remove(path);
}
+ int i = start;
+ while (i <= end) {
+ QModelIndex idx = m_model->index(i, 0, parent);
+ Node *n = m_model->nodeForIndex(idx);
+ if (n && n->path() == m_delayedRename) {
+ m_view->setCurrentIndex(idx);
+ m_delayedRename.clear();
+ break;
+ }
+ ++i;
+ }
}
-Node *ProjectTreeWidget::nodeForFile(const QString &fileName, Project *project)
+Node *ProjectTreeWidget::nodeForFile(const QString &fileName)
{
Node *bestNode = 0;
int bestNodeExpandCount = INT_MAX;
- foreach (Node *node, SessionManager::nodesForFile(fileName, project)) {
+ foreach (Node *node, SessionManager::nodesForFile(fileName)) {
if (!bestNode) {
bestNode = node;
bestNodeExpandCount = ProjectTreeWidget::expandedCount(node->parentFolderNode());
@@ -304,7 +322,7 @@ bool ProjectTreeWidget::autoSynchronization() const
return m_autoSync;
}
-void ProjectTreeWidget::setAutoSynchronization(bool sync, bool syncNow)
+void ProjectTreeWidget::setAutoSynchronization(bool sync)
{
m_toggleSync->setChecked(sync);
if (sync == m_autoSync)
@@ -314,14 +332,12 @@ void ProjectTreeWidget::setAutoSynchronization(bool sync, bool syncNow)
if (debug)
qDebug() << (m_autoSync ? "Enabling auto synchronization" : "Disabling auto synchronization");
+
if (m_autoSync) {
- connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::currentNodeChanged,
- this, &ProjectTreeWidget::setCurrentItem);
- if (syncNow)
- setCurrentItem(ProjectExplorerPlugin::currentNode(), ProjectExplorerPlugin::currentProject());
- } else {
- disconnect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::currentNodeChanged,
- this, &ProjectTreeWidget::setCurrentItem);
+ // sync from document manager
+ const QString &fileName = Core::DocumentManager::currentFile();
+ if (!currentNode() || currentNode()->path() != fileName)
+ setCurrentItem(ProjectTreeWidget::nodeForFile(fileName));
}
}
@@ -332,19 +348,27 @@ void ProjectTreeWidget::collapseAll()
void ProjectTreeWidget::editCurrentItem()
{
+ m_delayedRename.clear();
if (m_view->selectionModel()->currentIndex().isValid())
m_view->edit(m_view->selectionModel()->currentIndex());
}
-void ProjectTreeWidget::setCurrentItem(Node *node, Project *project)
-{
- if (debug)
- qDebug() << "ProjectTreeWidget::setCurrentItem(" << (project ? project->displayName() : QLatin1String("0"))
- << ", " << (node ? node->path() : QLatin1String("0")) << ")";
- if (!project)
- return;
+void ProjectTreeWidget::renamed(const QString &oldPath, const QString &newPath)
+{
+ Q_UNUSED(oldPath);
+ if (!currentNode() || currentNode()->path() != newPath) {
+ // try to find the node
+ Node *node = nodeForFile(newPath);
+ if (node)
+ m_view->setCurrentIndex(m_model->indexForNode(node));
+ else
+ m_delayedRename = newPath;
+ }
+}
+void ProjectTreeWidget::setCurrentItem(Node *node)
+{
const QModelIndex mainIndex = m_model->indexForNode(node);
if (mainIndex.isValid()) {
@@ -353,8 +377,6 @@ void ProjectTreeWidget::setCurrentItem(Node *node, Project *project)
m_view->scrollTo(mainIndex);
}
} else {
- if (debug)
- qDebug() << "clear selection";
m_view->clearSelection();
}
@@ -362,12 +384,19 @@ void ProjectTreeWidget::setCurrentItem(Node *node, Project *project)
void ProjectTreeWidget::handleCurrentItemChange(const QModelIndex &current)
{
- Node *node = m_model->nodeForIndex(current);
- // node might be 0. that's okay
- bool autoSync = autoSynchronization();
- setAutoSynchronization(false);
- ProjectExplorerPlugin::setCurrentNode(node);
- setAutoSynchronization(autoSync, false);
+ Q_UNUSED(current);
+ ProjectTree::nodeChanged(this);
+}
+
+Node *ProjectTreeWidget::currentNode()
+{
+ return m_model->nodeForIndex(m_view->currentIndex());
+}
+
+void ProjectTreeWidget::sync(Node *node)
+{
+ if (m_autoSync)
+ setCurrentItem(node);
}
void ProjectTreeWidget::showContextMenu(const QPoint &pos)
@@ -413,7 +442,7 @@ void ProjectTreeWidget::initView()
for (int i = 0; i < m_model->rowCount(sessionIndex); ++i)
m_view->expand(m_model->index(i, 0, sessionIndex));
- setCurrentItem(ProjectExplorerPlugin::currentNode(), ProjectExplorerPlugin::currentProject());
+ setCurrentItem(ProjectTree::currentNode());
}
void ProjectTreeWidget::openItem(const QModelIndex &mainIndex)
@@ -496,5 +525,5 @@ void ProjectTreeWidgetFactory::restoreSettings(int position, QWidget *widget)
const QString baseKey = QLatin1String("ProjectTreeWidget.") + QString::number(position);
ptw->setProjectFilter(settings->value(baseKey + QLatin1String(".ProjectFilter"), false).toBool());
ptw->setGeneratedFilesFilter(settings->value(baseKey + QLatin1String(".GeneratedFilter"), true).toBool());
- ptw->setAutoSynchronization(settings->value(baseKey + QLatin1String(".SyncWithEditor"), true).toBool());
+ ptw->setAutoSynchronization(settings->value(baseKey + QLatin1String(".SyncWithEditor")).toBool());
}
diff --git a/src/plugins/projectexplorer/projecttreewidget.h b/src/plugins/projectexplorer/projecttreewidget.h
index ca7a859235..6f1cbef1bb 100644
--- a/src/plugins/projectexplorer/projecttreewidget.h
+++ b/src/plugins/projectexplorer/projecttreewidget.h
@@ -58,12 +58,14 @@ public:
~ProjectTreeWidget();
bool autoSynchronization() const;
- void setAutoSynchronization(bool sync, bool syncNow = true);
+ void setAutoSynchronization(bool sync);
bool projectFilter();
bool generatedFilesFilter();
QToolButton *toggleSync();
+ Node *currentNode();
+ void sync(ProjectExplorer::Node *node);
- static Node *nodeForFile(const QString &fileName, Project *project);
+ static Node *nodeForFile(const QString &fileName);
public slots:
void toggleAutoSynchronization();
@@ -71,7 +73,6 @@ public slots:
void collapseAll();
private slots:
- void setCurrentItem(ProjectExplorer::Node *node, ProjectExplorer::Project *project);
void setProjectFilter(bool filter);
void setGeneratedFilesFilter(bool filter);
@@ -87,10 +88,12 @@ private slots:
void disableAutoExpand();
private:
+ void setCurrentItem(ProjectExplorer::Node *node);
void recursiveLoadExpandData(const QModelIndex &index, QSet<QString> &data);
void recursiveSaveExpandData(const QModelIndex &index, QStringList *data);
static int expandedCount(Node *node);
- void rowsInserted(const QModelIndex &parent, int, int);
+ void rowsInserted(const QModelIndex &parent, int start, int end);
+ void renamed(const QString &oldPath, const QString &newPath);
QSet<QString> m_toExpand;
QTreeView *m_view;
@@ -103,6 +106,7 @@ private:
QString m_modelId;
bool m_autoSync;
bool m_autoExpand;
+ QString m_delayedRename;
static QList<ProjectTreeWidget *> m_projectTreeWidgets;
friend class ProjectTreeWidgetFactory;
diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp
index 03f12e319b..9d2fa0acb9 100644
--- a/src/plugins/projectexplorer/session.cpp
+++ b/src/plugins/projectexplorer/session.cpp
@@ -536,6 +536,26 @@ QList<Project *> SessionManager::projectOrder(Project *project)
return result;
}
+QList<Node *> SessionManager::nodesForFile(const QString &fileName)
+{
+ FindNodesForFileVisitor findNodes(fileName);
+ sessionNode()->accept(&findNodes);
+ return findNodes.nodes();
+}
+
+// node for file returns a randomly selected node if there are multiple
+// prefer to use nodesForFile and figure out which node you want
+Node *SessionManager::nodeForFile(const QString &fileName)
+{
+ Node *node = 0;
+ foreach (Node *n, nodesForFile(fileName)) {
+ // prefer file nodes
+ if (!node || (node->nodeType() != FileNodeType && n->nodeType() == FileNodeType))
+ node = n;
+ }
+ return node;
+}
+
Project *SessionManager::projectForNode(Node *node)
{
if (!node)
@@ -553,47 +573,14 @@ Project *SessionManager::projectForNode(Node *node)
return Utils::findOrDefault(d->m_projects, Utils::equal(&Project::rootProjectNode, rootProjectNode));
}
-QList<Node *> SessionManager::nodesForFile(const QString &fileName, Project *project)
-{
- if (!project)
- project = projectForFile(fileName);
-
- if (project) {
- FindNodesForFileVisitor findNodes(fileName);
- project->rootProjectNode()->accept(&findNodes);
- return findNodes.nodes();
- }
-
- return QList<Node *>();
-}
-
-// node for file returns a randomly selected node if there are multiple
-// prefer to use nodesForFile and figure out which node you want
-Node *SessionManager::nodeForFile(const QString &fileName, Project *project)
-{
- Node *node = 0;
- foreach (Node *n, nodesForFile(fileName, project)) {
- // prefer file nodes
- if (!node || (node->nodeType() != FileNodeType && n->nodeType() == FileNodeType))
- node = n;
- }
- return node;
-}
-
Project *SessionManager::projectForFile(const QString &fileName)
{
if (debug)
qDebug() << "SessionManager::projectForFile(" << fileName << ")";
const QList<Project *> &projectList = projects();
-
- // Check current project first
- Project *currentProject = ProjectExplorerPlugin::currentProject();
- if (currentProject && d->projectContainsFile(currentProject, fileName))
- return currentProject;
-
foreach (Project *p, projectList)
- if (p != currentProject && d->projectContainsFile(p, fileName))
+ if (d->projectContainsFile(p, fileName))
return p;
return 0;
@@ -1023,15 +1010,7 @@ void SessionManager::projectDisplayNameChanged()
{
Project *pro = qobject_cast<Project*>(m_instance->sender());
if (pro) {
- Node *currentNode = 0;
- if (ProjectExplorerPlugin::currentProject() == pro)
- currentNode = ProjectExplorerPlugin::currentNode();
-
d->m_sessionNode->projectDisplayNameChanged(pro->rootProjectNode());
-
- if (currentNode)
- ProjectExplorerPlugin::setCurrentNode(currentNode);
-
emit m_instance->projectDisplayNameChanged(pro);
}
}
diff --git a/src/plugins/projectexplorer/session.h b/src/plugins/projectexplorer/session.h
index 2670614d20..e5c5f0d42f 100644
--- a/src/plugins/projectexplorer/session.h
+++ b/src/plugins/projectexplorer/session.h
@@ -117,8 +117,8 @@ public:
static SessionNode *sessionNode();
static Project *projectForNode(Node *node);
- static QList<Node *> nodesForFile(const QString &fileName, Project *project = 0);
- static Node *nodeForFile(const QString &fileName, Project *project = 0);
+ static QList<Node *> nodesForFile(const QString &fileName);
+ static Node *nodeForFile(const QString &fileName);
static Project *projectForFile(const QString &fileName);
static QStringList projectsForSessionName(const QString &session);
diff --git a/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp b/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp
index 0b84f35fdb..003e558f80 100644
--- a/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp
+++ b/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp
@@ -53,6 +53,7 @@
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
@@ -184,9 +185,8 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
connect(m_buildSubproject, SIGNAL(triggered()), this, SLOT(buildSubproject()));
// Connect
- connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
- SIGNAL(currentNodeChanged(ProjectExplorer::Node*,ProjectExplorer::Project*)),
- this, SLOT(nodeSelectionChanged(ProjectExplorer::Node*,ProjectExplorer::Project*)));
+ connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
+ this, &QbsProjectManagerPlugin::nodeSelectionChanged);
connect(BuildManager::instance(), SIGNAL(buildStateChanged(ProjectExplorer::Project*)),
this, SLOT(buildStateChanged(ProjectExplorer::Project*)));
diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.cpp b/src/plugins/qmakeprojectmanager/qmakenodes.cpp
index bf199406ce..4f486c45b9 100644
--- a/src/plugins/qmakeprojectmanager/qmakenodes.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakenodes.cpp
@@ -772,10 +772,6 @@ void QmakePriFileNode::update(const Internal::PriFileEvalResult &result)
}
contents.updateSubFolders(this);
- if (!m_setCurrentNodeDelayed.isEmpty()) {
- ProjectExplorer::ProjectExplorerPlugin::setCurrentFile(m_project, m_setCurrentNodeDelayed);
- m_setCurrentNodeDelayed.clear();
- }
}
void QmakePriFileNode::watchFolders(const QSet<QString> &folders)
@@ -1107,8 +1103,6 @@ bool QmakePriFileNode::renameFile(const QString &filePath, const QString &newFil
if (newFilePath.isEmpty())
return false;
- m_setCurrentNodeDelayed = newFilePath;
-
bool changeProFileOptional = deploysFolder(QFileInfo(filePath).absolutePath());
const Core::MimeType mt = Core::MimeDatabase::findByFile(newFilePath);
QStringList dummy;
diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.h b/src/plugins/qmakeprojectmanager/qmakenodes.h
index 7cf4ba8cb5..8b7d9a33b2 100644
--- a/src/plugins/qmakeprojectmanager/qmakenodes.h
+++ b/src/plugins/qmakeprojectmanager/qmakenodes.h
@@ -240,7 +240,6 @@ private:
QSet<Utils::FileName> m_recursiveEnumerateFiles;
QSet<QString> m_watchedFolders;
bool m_includedInExactParse;
- QString m_setCurrentNodeDelayed;
// managed by QmakeProFileNode
friend class QmakeProjectManager::QmakeProFileNode;
diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp
index a0b030b7f8..77efbcb1bd 100644
--- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp
@@ -42,7 +42,6 @@
#include "wizards/qtquickapp.h"
#include <utils/algorithm.h>
-#include <coreplugin/documentmanager.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
@@ -55,7 +54,6 @@
#include <projectexplorer/headerpath.h>
#include <projectexplorer/target.h>
#include <projectexplorer/projectexplorer.h>
-#include <projectexplorer/session.h>
#include <proparser/qmakevfs.h>
#include <qtsupport/profilereader.h>
#include <qtsupport/qtkitinformation.h>
@@ -842,11 +840,6 @@ void QmakeProject::decrementPendingEvaluateFutures()
updateBoilerPlateCodeFiles(&qtQuickApp, path);
}
}
-
- ProjectExplorer::Node *node = ProjectExplorer::SessionManager::nodeForFile(Core::DocumentManager::currentFile());
- if (node)
- ProjectExplorerPlugin::setCurrentNode(node);
-
m_checkForTemplateUpdate = false;
}
diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp
index e668d27814..c12f9da501 100644
--- a/src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanager.cpp
@@ -42,6 +42,7 @@
#include <coreplugin/icore.h>
#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
@@ -139,7 +140,7 @@ void QmakeManager::addLibrary()
void QmakeManager::addLibraryContextMenu()
{
- Node *node = ProjectExplorerPlugin::currentNode();
+ Node *node = ProjectTree::currentNode();
if (qobject_cast<QmakeProFileNode *>(node))
addLibrary(node->path());
}
diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp
index 0d682cdccf..fa464df46a 100644
--- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp
@@ -53,7 +53,7 @@
#include <coreplugin/icore.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/session.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/target.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/coreconstants.h>
@@ -100,8 +100,6 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":qmakeprojectmanager/QmakeProjectManager.mimetypes.xml"), errorMessage))
return false;
- m_projectExplorer = ProjectExplorerPlugin::instance();
-
//create and register objects
m_qmakeProjectManager = new QmakeManager;
addObject(m_qmakeProjectManager);
@@ -235,8 +233,8 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
this, SLOT(buildStateChanged(ProjectExplorer::Project*)));
connect(SessionManager::instance(), SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
this, SLOT(startupProjectChanged()));
- connect(m_projectExplorer, SIGNAL(currentNodeChanged(ProjectExplorer::Node*,ProjectExplorer::Project*)),
- this, SLOT(updateContextActions(ProjectExplorer::Node*,ProjectExplorer::Project*)));
+ connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
+ this, &QmakeProjectManagerPlugin::updateContextActions);
Core::ActionContainer *contextMenu = Core::ActionManager::createMenu(QmakeProjectManager::Constants::M_CONTEXT);
@@ -307,9 +305,9 @@ void QmakeProjectManagerPlugin::activeTargetChanged()
void QmakeProjectManagerPlugin::updateRunQMakeAction()
{
bool enable = true;
- if (BuildManager::isBuilding(m_projectExplorer->currentProject()))
+ if (BuildManager::isBuilding(ProjectTree::currentProject()))
enable = false;
- QmakeProject *pro = qobject_cast<QmakeProject *>(m_projectExplorer->currentProject());
+ QmakeProject *pro = qobject_cast<QmakeProject *>(ProjectTree::currentProject());
if (!pro
|| !pro->activeTarget()
|| !pro->activeTarget()->activeBuildConfiguration())
@@ -380,10 +378,10 @@ void QmakeProjectManagerPlugin::updateContextActions(ProjectExplorer::Node *node
void QmakeProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
{
- ProjectExplorer::Project *currentProject = m_projectExplorer->currentProject();
+ ProjectExplorer::Project *currentProject = ProjectTree::currentProject();
if (pro == currentProject) {
updateRunQMakeAction();
- updateContextActions(ProjectExplorerPlugin::currentNode(), pro);
+ updateContextActions(ProjectTree::currentNode(), pro);
updateBuildFileAction();
}
}
diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h
index 249cfc1fc2..02c8eb8613 100644
--- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h
+++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h
@@ -41,7 +41,6 @@ QT_END_NAMESPACE
namespace ProjectExplorer {
class Node;
class Project;
-class ProjectExplorerPlugin;
class KitInformation;
class Target;
}
@@ -79,7 +78,6 @@ private slots:
#endif
private:
- ProjectExplorer::ProjectExplorerPlugin *m_projectExplorer;
QmakeManager *m_qmakeProjectManager;
QmakeProject *m_previousStartupProject;
ProjectExplorer::Target *m_previousTarget;
diff --git a/src/plugins/qmakeprojectmanager/wizards/abstractmobileappwizard.cpp b/src/plugins/qmakeprojectmanager/wizards/abstractmobileappwizard.cpp
index dbd1524aa4..866b0cdafb 100644
--- a/src/plugins/qmakeprojectmanager/wizards/abstractmobileappwizard.cpp
+++ b/src/plugins/qmakeprojectmanager/wizards/abstractmobileappwizard.cpp
@@ -131,11 +131,8 @@ bool AbstractMobileAppWizard::postGenerateFiles(const QWizard *w,
}
if (success) {
const QString fileToOpen = fileToOpenPostGeneration();
- if (!fileToOpen.isEmpty()) {
+ if (!fileToOpen.isEmpty())
EditorManager::openEditor(fileToOpen);
- Project *project = SessionManager::projectForFile(fileToOpen);
- ProjectExplorerPlugin::setCurrentFile(project, fileToOpen);
- }
}
return success;
}
diff --git a/src/plugins/qmldesigner/components/integration/designdocument.cpp b/src/plugins/qmldesigner/components/integration/designdocument.cpp
index 80b5928235..b32c5db707 100644
--- a/src/plugins/qmldesigner/components/integration/designdocument.cpp
+++ b/src/plugins/qmldesigner/components/integration/designdocument.cpp
@@ -41,7 +41,7 @@
#include <viewmanager.h>
#include <nodeinstanceview.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <projectexplorer/session.h>
@@ -639,8 +639,7 @@ static bool isFileInProject(DesignDocument *designDocument, ProjectExplorer::Pro
static inline ProjectExplorer::Kit *getActiveKit(DesignDocument *designDocument)
{
- ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
- ProjectExplorer::Project *currentProject = projectExplorer->currentProject();
+ ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectTree::currentProject();
if (!currentProject)
currentProject = ProjectExplorer::SessionManager::projectForFile(designDocument->fileName());
@@ -651,7 +650,8 @@ static inline ProjectExplorer::Kit *getActiveKit(DesignDocument *designDocument)
if (!isFileInProject(designDocument, currentProject))
return 0;
- designDocument->connect(projectExplorer, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)), designDocument, SLOT(updateActiveQtVersion()), Qt::UniqueConnection);
+ QObject::connect(ProjectExplorer::ProjectTree::instance(), &ProjectExplorer::ProjectTree::currentProjectChanged,
+ designDocument, &DesignDocument::updateActiveQtVersion, Qt::UniqueConnection);
designDocument->connect(currentProject, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)), designDocument, SLOT(updateActiveQtVersion()), Qt::UniqueConnection);
diff --git a/src/plugins/qmljseditor/qmljscompletionassist.cpp b/src/plugins/qmljseditor/qmljscompletionassist.cpp
index d4ebebcd56..349921e846 100644
--- a/src/plugins/qmljseditor/qmljscompletionassist.cpp
+++ b/src/plugins/qmljseditor/qmljscompletionassist.cpp
@@ -54,7 +54,7 @@
#include <qmljs/qmljscompletioncontextfinder.h>
#include <qmljs/qmljsbundle.h>
#include <qmljs/qmljsscopebuilder.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <QFile>
#include <QFileInfo>
@@ -652,7 +652,7 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const AssistInterface *
// currently path-in-stringliteral is the only completion available in imports
if (contextFinder.isInImport()) {
QmlJS::ModelManagerInterface::ProjectInfo pInfo = QmlJS::ModelManagerInterface::instance()
- ->projectInfo(ProjectExplorer::ProjectExplorerPlugin::currentProject());
+ ->projectInfo(ProjectExplorer::ProjectTree::currentProject());
QmlBundle platform = pInfo.extendedBundle.bundleForLanguage(document->language());
if (!platform.supportedImports().isEmpty()) {
QTextCursor tc(qmlInterface->textDocument());
diff --git a/src/plugins/qmljstools/qmljsmodelmanager.cpp b/src/plugins/qmljstools/qmljsmodelmanager.cpp
index 3135a78134..ac4ab52c41 100644
--- a/src/plugins/qmljstools/qmljsmodelmanager.cpp
+++ b/src/plugins/qmljstools/qmljsmodelmanager.cpp
@@ -40,7 +40,8 @@
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/project.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projectexplorerconstants.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <qmljs/qmljsbind.h>
@@ -224,8 +225,8 @@ void ModelManager::delayedInitialization()
connect(ProjectExplorer::SessionManager::instance(), SIGNAL(projectRemoved(ProjectExplorer::Project*)),
this, SLOT(removeProjectInfo(ProjectExplorer::Project*)));
- connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
- SLOT(updateDefaultProjectInfo()));
+ connect(ProjectExplorer::ProjectTree::instance(), &ProjectExplorer::ProjectTree::currentProjectChanged,
+ this, &ModelManager::updateDefaultProjectInfo);
QmlJS::ViewerContext qbsVContext;
qbsVContext.language = Dialect::QmlQbs;
@@ -264,7 +265,7 @@ ModelManagerInterface::WorkingCopy ModelManager::workingCopyInternal() const
void ModelManager::updateDefaultProjectInfo()
{
// needs to be performed in the ui therad
- ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject();
+ ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectTree::currentProject();
ProjectInfo newDefaultProjectInfo = projectInfo(currentProject,
defaultProjectInfoForProject(currentProject));
setDefaultProject(projectInfo(currentProject,newDefaultProjectInfo), currentProject);
diff --git a/src/plugins/qnx/bardescriptorfilenodemanager.cpp b/src/plugins/qnx/bardescriptorfilenodemanager.cpp
index 5d3f815ef6..008241f236 100644
--- a/src/plugins/qnx/bardescriptorfilenodemanager.cpp
+++ b/src/plugins/qnx/bardescriptorfilenodemanager.cpp
@@ -46,7 +46,7 @@
#include <projectexplorer/buildstep.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/project.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/target.h>
#include <projectexplorer/buildconfiguration.h>
#include <qmakeprojectmanager/qmakenodes.h>
@@ -65,9 +65,8 @@ const char SKIP_BAR_DESCRIPTOR_CREATION_KEY[] = "Qnx.BlackBerry.BarDescriptorFil
BarDescriptorFileNodeManager::BarDescriptorFileNodeManager(QObject *parent)
: QObject(parent)
{
- connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
- SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
- this, SLOT(setCurrentProject(ProjectExplorer::Project*)));
+ connect(ProjectExplorer::ProjectTree::instance(), &ProjectExplorer::ProjectTree::currentProjectChanged,
+ this, &BarDescriptorFileNodeManager::setCurrentProject);
}
void BarDescriptorFileNodeManager::setCurrentProject(ProjectExplorer::Project *project)
diff --git a/src/plugins/qtsupport/qtsupportplugin.cpp b/src/plugins/qtsupport/qtsupportplugin.cpp
index f344c7045a..abcfa24bd2 100644
--- a/src/plugins/qtsupport/qtsupportplugin.cpp
+++ b/src/plugins/qtsupport/qtsupportplugin.cpp
@@ -49,7 +49,7 @@
#include <coreplugin/jsexpander.h>
#include <projectexplorer/project.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/target.h>
#include <utils/macroexpander.h>
@@ -102,7 +102,7 @@ bool QtSupportPlugin::initialize(const QStringList &arguments, QString *errorMes
static QString qmakeProperty(const char *propertyName)
{
- ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
+ ProjectExplorer::Project *project = ProjectExplorer::ProjectTree::currentProject();
if (!project || !project->activeTarget())
return QString();
diff --git a/src/plugins/resourceeditor/resourceeditorplugin.cpp b/src/plugins/resourceeditor/resourceeditorplugin.cpp
index 86fd1c8d71..764450dec3 100644
--- a/src/plugins/resourceeditor/resourceeditorplugin.cpp
+++ b/src/plugins/resourceeditor/resourceeditorplugin.cpp
@@ -44,6 +44,7 @@
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectnodes.h>
#include <extensionsystem/pluginmanager.h>
@@ -202,9 +203,8 @@ bool ResourceEditorPlugin::initialize(const QStringList &arguments, QString *err
m_renameResourceFile->setEnabled(false);
m_removeResourceFile->setEnabled(false);
- connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(currentNodeChanged(ProjectExplorer::Node*,ProjectExplorer::Project*)),
- this, SLOT(updateContextActions(ProjectExplorer::Node*,ProjectExplorer::Project*)));
-
+ connect(ProjectExplorer::ProjectTree::instance(), &ProjectTree::currentNodeChanged,
+ this, &ResourceEditorPlugin::updateContextActions);
return true;
}
@@ -236,13 +236,13 @@ void ResourceEditorPlugin::addPrefixContextMenu()
QString prefix = dialog.prefix();
if (prefix.isEmpty())
return;
- ResourceTopLevelNode *topLevel = static_cast<ResourceTopLevelNode *>(ProjectExplorer::ProjectExplorerPlugin::currentNode());
+ ResourceTopLevelNode *topLevel = static_cast<ResourceTopLevelNode *>(ProjectTree::currentNode());
topLevel->addPrefix(prefix, dialog.lang());
}
void ResourceEditorPlugin::removePrefixContextMenu()
{
- ResourceFolderNode *rfn = static_cast<ResourceFolderNode *>(ProjectExplorer::ProjectExplorerPlugin::instance()->currentNode());
+ ResourceFolderNode *rfn = static_cast<ResourceFolderNode *>(ProjectTree::currentNode());
if (QMessageBox::question(Core::ICore::mainWindow(),
tr("Remove Prefix"),
tr("Remove prefix %1 and all its files?").arg(rfn->displayName()))
@@ -259,7 +259,7 @@ void ResourceEditorPlugin::renameFileContextMenu()
void ResourceEditorPlugin::removeFileContextMenu()
{
- ResourceFolderNode *rfn = static_cast<ResourceFolderNode *>(ProjectExplorer::ProjectExplorerPlugin::instance()->currentNode());
+ ResourceFolderNode *rfn = static_cast<ResourceFolderNode *>(ProjectTree::currentNode());
QString path = rfn->path();
ProjectExplorer::FolderNode *parent = rfn->parentFolderNode();
if (!parent->removeFiles(QStringList() << path))
@@ -270,33 +270,33 @@ void ResourceEditorPlugin::removeFileContextMenu()
void ResourceEditorPlugin::openEditorContextMenu()
{
- ResourceTopLevelNode *topLevel = static_cast<ResourceTopLevelNode *>(ProjectExplorer::ProjectExplorerPlugin::instance()->currentNode());
+ ResourceTopLevelNode *topLevel = static_cast<ResourceTopLevelNode *>(ProjectTree::currentNode());
QString path = topLevel->path();
Core::EditorManager::openEditor(path);
}
void ResourceEditorPlugin::openTextEditorContextMenu()
{
- ResourceTopLevelNode *topLevel = static_cast<ResourceTopLevelNode *>(ProjectExplorerPlugin::currentNode());
+ ResourceTopLevelNode *topLevel = static_cast<ResourceTopLevelNode *>(ProjectTree::currentNode());
QString path = topLevel->path();
Core::EditorManager::openEditor(path, Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
}
void ResourceEditorPlugin::copyPathContextMenu()
{
- ResourceFileNode *node = static_cast<ResourceFileNode *>(ProjectExplorerPlugin::currentNode());
+ ResourceFileNode *node = static_cast<ResourceFileNode *>(ProjectTree::currentNode());
QApplication::clipboard()->setText(QLatin1String(resourcePrefix) + node->qrcPath());
}
void ResourceEditorPlugin::copyUrlContextMenu()
{
- ResourceFileNode *node = static_cast<ResourceFileNode *>(ProjectExplorerPlugin::currentNode());
+ ResourceFileNode *node = static_cast<ResourceFileNode *>(ProjectTree::currentNode());
QApplication::clipboard()->setText(QLatin1String(urlPrefix) + node->qrcPath());
}
void ResourceEditorPlugin::renamePrefixContextMenu()
{
- ResourceFolderNode *node = static_cast<ResourceFolderNode *>(ProjectExplorerPlugin::currentNode());
+ ResourceFolderNode *node = static_cast<ResourceFolderNode *>(ProjectTree::currentNode());
PrefixLangDialog dialog(tr("Rename Prefix"), node->prefix(), node->lang(), Core::ICore::mainWindow());
if (dialog.exec() != QDialog::Accepted)
diff --git a/src/plugins/tasklist/tasklistplugin.cpp b/src/plugins/tasklist/tasklistplugin.cpp
index e4bc0e6459..3b28f9e8d4 100644
--- a/src/plugins/tasklist/tasklistplugin.cpp
+++ b/src/plugins/tasklist/tasklistplugin.cpp
@@ -38,7 +38,7 @@
#include <coreplugin/idocumentfactory.h>
#include <coreplugin/documentmanager.h>
#include <coreplugin/mimedatabase.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
#include <projectexplorer/task.h>
@@ -209,7 +209,7 @@ bool TaskListPlugin::initialize(const QStringList &arguments, QString *errorMess
m_fileFactory = new IDocumentFactory;
m_fileFactory->addMimeType(QLatin1String("text/x-tasklist"));
m_fileFactory->setOpener([this](const QString &fileName) -> IDocument * {
- ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
+ ProjectExplorer::Project *project = ProjectExplorer::ProjectTree::currentProject();
return this->openTasks(project ? project->projectDirectory().toString() : QString(), fileName);
});
diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp
index be13feb7e9..9af5548a5e 100644
--- a/src/plugins/valgrind/callgrindtool.cpp
+++ b/src/plugins/valgrind/callgrindtool.cpp
@@ -65,7 +65,7 @@
#include <utils/styledbar.h>
#include <projectexplorer/project.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <QFile>
#include <QFileInfo>
@@ -399,7 +399,7 @@ void CallgrindToolPrivate::updateCostFormat()
void CallgrindToolPrivate::handleFilterProjectCosts()
{
- ProjectExplorer::Project *pro = ProjectExplorer::ProjectExplorerPlugin::currentProject();
+ ProjectExplorer::Project *pro = ProjectExplorer::ProjectTree::currentProject();
QTC_ASSERT(pro, return);
if (m_filterProjectCosts->isChecked()) {
diff --git a/src/plugins/vcsbase/vcsbaseplugin.cpp b/src/plugins/vcsbase/vcsbaseplugin.cpp
index 55a05f66a8..ae0a708d54 100644
--- a/src/plugins/vcsbase/vcsbaseplugin.cpp
+++ b/src/plugins/vcsbase/vcsbaseplugin.cpp
@@ -42,7 +42,7 @@
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/vcsmanager.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
#include <utils/qtcassert.h>
@@ -217,9 +217,9 @@ StateListener::StateListener(QObject *parent) :
connect(Core::VcsManager::instance(), SIGNAL(repositoryChanged(QString)),
this, SLOT(slotStateChanged()));
- connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
- SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
- this, SLOT(slotStateChanged()));
+ connect(ProjectExplorer::ProjectTree::instance(),
+ &ProjectExplorer::ProjectTree::currentProjectChanged,
+ this, &StateListener::slotStateChanged);
Core::EditorManager::setWindowTitleVcsTopicHandler(&StateListener::windowTitleVcsTopic);
}
@@ -308,7 +308,7 @@ void StateListener::slotStateChanged()
}
// Check for project, find the control
Core::IVersionControl *projectControl = 0;
- if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject()) {
+ if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectTree::currentProject()) {
state.currentProjectPath = currentProject->projectDirectory().toString();
state.currentProjectName = currentProject->displayName();
projectControl = Core::VcsManager::findVersionControlForDirectory(state.currentProjectPath,
@@ -677,7 +677,7 @@ void VcsBasePlugin::createRepository()
QTC_ASSERT(d->m_versionControl->supportsOperation(Core::IVersionControl::CreateRepositoryOperation), return);
// Find current starting directory
QString directory;
- if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject())
+ if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectTree::currentProject())
directory = QFileInfo(currentProject->document()->filePath()).absolutePath();
// Prompt for a directory that is not under version control yet
QWidget *mw = Core::ICore::mainWindow();
diff --git a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp
index f2a3c138e4..31b0d0389b 100644
--- a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp
+++ b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp
@@ -51,7 +51,7 @@
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
#include <QDebug>
@@ -739,7 +739,7 @@ QStringList VcsBaseSubmitEditor::currentProjectFiles(bool nativeSeparators, QStr
if (name)
name->clear();
- if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject()) {
+ if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectTree::currentProject()) {
QStringList files = currentProject->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
if (name)
*name = currentProject->displayName();
diff --git a/src/plugins/vcsbase/vcsplugin.cpp b/src/plugins/vcsbase/vcsplugin.cpp
index c1b42cfe61..13f226d43a 100644
--- a/src/plugins/vcsbase/vcsplugin.cpp
+++ b/src/plugins/vcsbase/vcsplugin.cpp
@@ -42,7 +42,7 @@
#include <coreplugin/vcsmanager.h>
#include <projectexplorer/project.h>
-#include <projectexplorer/projectexplorer.h>
+#include <projectexplorer/projecttree.h>
#include <utils/macroexpander.h>
@@ -94,7 +94,7 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
tr("Name of the version control system in use by the current project."),
[]() -> QString {
IVersionControl *vc = 0;
- if (Project *project = ProjectExplorerPlugin::currentProject())
+ if (Project *project = ProjectTree::currentProject())
vc = VcsManager::findVersionControlForDirectory(project->projectDirectory().toString());
return vc ? vc->displayName() : QString();
});
@@ -104,7 +104,7 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
[]() -> QString {
IVersionControl *vc = 0;
QString topLevel;
- if (Project *project = ProjectExplorerPlugin::currentProject())
+ if (Project *project = ProjectTree::currentProject())
vc = VcsManager::findVersionControlForDirectory(project->projectDirectory().toString(), &topLevel);
return vc ? vc->vcsTopic(topLevel) : QString();
});
@@ -112,7 +112,7 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
expander->registerVariable(Constants::VAR_VCS_TOPLEVELPATH,
tr("The top level path to the repository the current project is in."),
[]() -> QString {
- if (Project *project = ProjectExplorerPlugin::currentProject())
+ if (Project *project = ProjectTree::currentProject())
return VcsManager::findTopLevelForDirectory(project->projectDirectory().toString());
return QString();
});