diff options
Diffstat (limited to 'src/plugins/projectexplorer/projectexplorer.cpp')
-rw-r--r-- | src/plugins/projectexplorer/projectexplorer.cpp | 510 |
1 files changed, 143 insertions, 367 deletions
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 91afb6820b..89dcd44dd3 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -36,6 +36,9 @@ #include "deployablefile.h" #include "deployconfiguration.h" #include "gcctoolchainfactories.h" +#ifdef WITH_JOURNALD +#include "journaldwatcher.h" +#endif #include "jsonwizard/jsonwizardfactory.h" #include "jsonwizard/jsonwizardgeneratorfactory.h" #include "jsonwizard/jsonwizardpagefactory_p.h" @@ -96,6 +99,7 @@ # include "wincetoolchain.h" #endif +#include "projecttree.h" #include "projectwelcomepage.h" #include <extensionsystem/pluginspec.h> @@ -162,7 +166,6 @@ namespace { bool debug = false; -const char EXTERNAL_FILE_WARNING[] = "ExternalFile"; } using namespace Core; @@ -172,7 +175,7 @@ namespace ProjectExplorer { static Target *activeTarget() { - Project *project = ProjectExplorerPlugin::currentProject(); + Project *project = ProjectTree::currentProject(); return project ? project->activeTarget() : 0; } @@ -194,13 +197,12 @@ public: ProjectExplorerPluginPrivate(); void deploy(QList<Project *>); - int queue(QList<Project *>, QList<Core::Id> stepIds); + int queue(QList<Project *>, QList<Id> stepIds); void updateContextMenuActions(); void executeRunConfiguration(RunConfiguration *, RunMode mode); 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); @@ -209,12 +211,7 @@ public: void updateDeployActions(); void updateRunWithoutDeployMenu(); - QMenu *m_sessionContextMenu; QMenu *m_sessionMenu; - QMenu *m_projectMenu; - QMenu *m_subProjectMenu; - QMenu *m_folderMenu; - QMenu *m_fileMenu; QMenu *m_openWithMenu; QMultiMap<int, QObject*> m_actionMap; @@ -266,10 +263,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 +284,24 @@ public: KitManager *m_kitManager; ToolChainManager *m_toolChainManager; bool m_shuttingDown; - bool m_ignoreDocumentManagerChangedFile; QStringList m_arguments; QList<ProjectPanelFactory *> m_panelFactories; QString m_renameFileError; +#ifdef WITH_JOURNALD + JournaldWatcher *m_journalWatcher; +#endif }; 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) +#ifdef WITH_JOURNALD + , m_journalWatcher(0) +#endif { } @@ -345,6 +340,9 @@ ProjectExplorerPlugin::~ProjectExplorerPlugin() // Force sequence of deletion: delete dd->m_kitManager; // remove all the profile information delete dd->m_toolChainManager; +#ifdef WITH_JOURNALD + delete dd->m_journalWatcher; +#endif ProjectPanelFactory::destroyFactories(); delete dd; } @@ -368,6 +366,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er addAutoReleasedObject(new DeviceManager); +#ifdef WITH_JOURNALD + dd->m_journalWatcher = new JournaldWatcher; +#endif + // Add ToolChainFactories: #ifdef Q_OS_WIN addAutoReleasedObject(new WinDebugInterface); @@ -389,7 +391,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er dd->m_kitManager = new KitManager; // register before ToolChainManager dd->m_toolChainManager = new ToolChainManager; - Core::IWizardFactory::registerFeatureProvider(new KitFeatureProvider); + IWizardFactory::registerFeatureProvider(new KitFeatureProvider); // Register KitInformation: KitManager::registerKitInformation(new DeviceTypeKitInformation); @@ -409,9 +411,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,17 +434,17 @@ 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)); - addAutoReleasedObject(new CustomWizardMetaFactory<CustomWizard>(Core::IWizardFactory::ClassWizard)); + addAutoReleasedObject(new CustomWizardMetaFactory<CustomProjectWizard>(IWizardFactory::ProjectWizard)); + addAutoReleasedObject(new CustomWizardMetaFactory<CustomWizard>(IWizardFactory::FileWizard)); + addAutoReleasedObject(new CustomWizardMetaFactory<CustomWizard>(IWizardFactory::ClassWizard)); // For JsonWizard: JsonWizardFactory::registerPageFactory(new FieldPageFactory); @@ -562,12 +561,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er ActionContainer *mfileContextMenu = ActionManager::createMenu(Constants::M_FILECONTEXT); - dd->m_sessionContextMenu = msessionContextMenu->menu(); - dd->m_projectMenu = mprojectContextMenu->menu(); - dd->m_subProjectMenu = msubProjectContextMenu->menu(); - dd->m_folderMenu = mfolderContextMenu->menu(); - dd->m_fileMenu = mfileContextMenu->menu(); - ActionContainer *mfile = ActionManager::actionContainer(Core::Constants::M_FILE); ActionContainer *menubar = @@ -913,7 +906,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er // add existing directory action dd->m_addExistingDirectoryAction = new QAction(tr("Add Existing Directory..."), this); - cmd = Core::ActionManager::registerAction(dd->m_addExistingDirectoryAction, + cmd = ActionManager::registerAction(dd->m_addExistingDirectoryAction, Constants::ADDEXISTINGDIRECTORY, projecTreeContext); mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_FILES); @@ -1020,7 +1013,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er addAutoReleasedObject(new ProjectTreeWidgetFactory); addAutoReleasedObject(new FolderNavigationWidgetFactory); - addAutoReleasedObject(new DeployConfigurationFactory); + addAutoReleasedObject(new DefaultDeployConfigurationFactory); QSettings *s = ICore::settings(); const QStringList fileNames = @@ -1104,6 +1097,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er connect(dd->m_deleteFileAction, SIGNAL(triggered()), this, SLOT(deleteFile())); connect(dd->m_renameFileAction, SIGNAL(triggered()), this, SLOT(renameFile())); connect(dd->m_setStartupProjectAction, SIGNAL(triggered()), this, SLOT(setStartupProject())); + connect(dd->m_projectTreeCollapseAllAction, &QAction::triggered, + ProjectTree::instance(), &ProjectTree::collapseAll); connect(this, SIGNAL(updateRunActions()), this, SLOT(slotUpdateRunActions())); connect(this, &ProjectExplorerPlugin::settingsChanged, @@ -1132,11 +1127,11 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er expander->registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX, tr("Current project's main file"), [this]() -> QString { - QString projectFilePath; - if (Project *project = ProjectExplorerPlugin::currentProject()) + Utils::FileName projectFilePath; + if (Project *project = ProjectTree::currentProject()) if (IDocument *doc = project->document()) projectFilePath = doc->filePath(); - return projectFilePath; + return projectFilePath.toString(); }); expander->registerVariable(Constants::VAR_CURRENTPROJECT_BUILDPATH, @@ -1149,7 +1144,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(); }); @@ -1161,7 +1156,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er }); expander->registerVariable(Constants::VAR_CURRENTKIT_FILESYSTEMNAME, - tr("The name of the currently active kit in a filesystem friendly version."), + tr("The name of the currently active kit in a filesystem-friendly version."), []() -> QString { Kit *kit = currentKit(); return kit ? kit->fileSystemFriendlyName() : QString(); @@ -1254,12 +1249,12 @@ void ProjectExplorerPlugin::loadAction() // for your special convenience, we preselect a pro file if it is // the current file if (const IDocument *document = EditorManager::currentDocument()) { - const QString fn = document->filePath(); + const QString fn = document->filePath().toString(); const bool isProject = dd->m_profileMimeTypes.contains(document->mimeType()); dir = isProject ? fn : QFileInfo(fn).absolutePath(); } - QString filename = QFileDialog::getOpenFileName(Core::ICore::dialogParent(), + QString filename = QFileDialog::getOpenFileName(ICore::dialogParent(), tr("Load Project"), dir, dd->m_projectFilterString); if (filename.isEmpty()) @@ -1277,7 +1272,7 @@ void ProjectExplorerPlugin::unloadProjectContextMenu() if (debug) qDebug() << "ProjectExplorerPlugin::unloadProjectContextMenu"; - if (Project *p = currentProject()) + if (Project *p = ProjectTree::currentProject()) unloadProject(p); } @@ -1316,7 +1311,7 @@ void ProjectExplorerPlugin::unloadProject(Project *project) if (!DocumentManager::saveModifiedDocumentSilently(document)) return; - dd->addToRecentProjects(document->filePath(), project->displayName()); + dd->addToRecentProjects(document->filePath().toString(), project->displayName()); SessionManager::removeProject(project); m_instance->updateActions(); @@ -1342,7 +1337,7 @@ void ProjectExplorerPlugin::extensionsInitialized() QList<IProjectManager*> projectManagers = ExtensionSystem::PluginManager::getObjects<IProjectManager>(); - QList<Core::MimeGlobPattern> allGlobPatterns; + QList<MimeGlobPattern> allGlobPatterns; const QString filterSeparator = QLatin1String(";;"); QStringList filterStrings; @@ -1352,7 +1347,7 @@ void ProjectExplorerPlugin::extensionsInitialized() QString errorMessage; ProjectExplorerPlugin::openProject(fileName, &errorMessage); if (!errorMessage.isEmpty()) - QMessageBox::critical(Core::ICore::mainWindow(), + QMessageBox::critical(ICore::mainWindow(), tr("Failed to open project"), errorMessage); return 0; }); @@ -1404,6 +1399,7 @@ ExtensionSystem::IPlugin::ShutdownFlag ProjectExplorerPlugin::aboutToShutdown() { disconnect(ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*,Core::IMode*)), this, SLOT(currentModeChanged(Core::IMode*,Core::IMode*))); + ProjectTree::aboutToShutDown(); dd->m_proWindow->aboutToShutdown(); // disconnect from session SessionManager::closeAllProjects(); dd->m_projectsMode = 0; @@ -1587,9 +1583,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.") @@ -1629,46 +1622,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(); @@ -1723,6 +1676,11 @@ QStringList ProjectExplorerPlugin::projectFileGlobs() return result; } +void ProjectExplorerPlugin::updateContextMenuActions() +{ + dd->updateContextMenuActions(); +} + /*! This function is connected to the ICore::coreOpened signal. If there was no session explicitly loaded, it creates an empty new @@ -1812,50 +1770,6 @@ void ProjectExplorerPlugin::loadSession(const QString &session) SessionManager::loadSession(session); } - -void ProjectExplorerPlugin::showContextMenu(QWidget *view, const QPoint &globalPos, Node *node) -{ - QMenu *contextMenu = 0; - - if (!node) - node = SessionManager::sessionNode(); - - if (node->nodeType() != SessionNodeType) { - Project *project = SessionManager::projectForNode(node); - setCurrentNode(node); - - emit m_instance->aboutToShowContextMenu(project, node); - switch (node->nodeType()) { - case ProjectNodeType: - if (node->parentFolderNode() == SessionManager::sessionNode()) - contextMenu = dd->m_projectMenu; - else - contextMenu = dd->m_subProjectMenu; - break; - case VirtualFolderNodeType: - case FolderNodeType: - contextMenu = dd->m_folderMenu; - break; - case FileNodeType: - m_instance->populateOpenWithMenu(); - contextMenu = dd->m_fileMenu; - break; - default: - qWarning("ProjectExplorerPlugin::showContextMenu - Missing handler for node type"); - } - } else { // session item - emit m_instance->aboutToShowContextMenu(0, node); - - contextMenu = dd->m_sessionContextMenu; - } - - dd->updateContextMenuActions(); - dd->m_projectTreeCollapseAllAction->disconnect(SIGNAL(triggered())); - connect(dd->m_projectTreeCollapseAllAction, SIGNAL(triggered()), view, SLOT(collapseAll())); - if (contextMenu && contextMenu->actions().count() > 0) - contextMenu->popup(globalPos); -} - void ProjectExplorerPlugin::buildStateChanged(Project * pro) { if (debug) { @@ -1971,57 +1885,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()); @@ -2041,7 +1904,7 @@ static QString pathOrDirectoryFor(Node *node, bool dir) { QString path = node->path(); QString location; - FolderNode *folder = qobject_cast<FolderNode *>(node); + FolderNode *folder = dynamic_cast<FolderNode *>(node); if (node->nodeType() == VirtualFolderNodeType && folder) { // Virtual Folder case // If there are files directly below or no subfolders, take the folder path @@ -2086,59 +1949,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(); @@ -2152,13 +1962,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(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); @@ -2179,7 +1990,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")); @@ -2359,7 +2170,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)); } @@ -2383,7 +2194,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)); } @@ -2405,7 +2216,7 @@ void ProjectExplorerPlugin::deployProject() void ProjectExplorerPlugin::deployProjectContextMenu() { - dd->deploy(QList<Project *>() << dd->m_currentProject); + dd->deploy(QList<Project *>() << ProjectTree::currentProject()); } void ProjectExplorerPlugin::deploySession() @@ -2427,7 +2238,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)); } @@ -2449,9 +2260,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 = dynamic_cast<ProjectNode*>(ProjectTree::currentNode()); + if (projectNode == ProjectTree::currentProject()->rootProjectNode() || !projectNode) { + runProject(ProjectTree::currentProject(), NormalRunMode); } else { QAction *act = qobject_cast<QAction *>(sender()); if (!act) @@ -2708,16 +2519,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; } @@ -2929,45 +2741,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); @@ -2996,17 +2774,19 @@ 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()) { - dd->m_runActionContextMenu->setVisible(true); + if (currentNode && currentNode->projectNode()) { + QList<ProjectAction> actions = currentNode->supportedActions(currentNode); + + if (ProjectNode *pn = dynamic_cast<ProjectNode *>(currentNode)) { + if (ProjectTree::currentProject() && pn == ProjectTree::currentProject()->rootProjectNode()) { + m_runActionContextMenu->setVisible(true); } else { QList<RunConfiguration *> runConfigs = pn->runConfigurations(); if (runConfigs.count() == 1) { - dd->m_runActionContextMenu->setVisible(true); - dd->m_runActionContextMenu->setData(QVariant::fromValue(runConfigs.first())); + m_runActionContextMenu->setVisible(true); + m_runActionContextMenu->setData(QVariant::fromValue(runConfigs.first())); } else if (runConfigs.count() > 1) { runMenu->menu()->menuAction()->setVisible(true); foreach (RunConfiguration *rc, runConfigs) { @@ -3020,64 +2800,66 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions() } } } - if (qobject_cast<FolderNode*>(dd->m_currentNode)) { + if (dynamic_cast<FolderNode*>(currentNode)) { // Also handles ProjectNode - dd->m_addNewFileAction->setEnabled(actions.contains(AddNewFile) + m_addNewFileAction->setEnabled(actions.contains(AddNewFile) && !ICore::isNewItemDialogRunning()); - dd->m_addNewSubprojectAction->setEnabled(dd->m_currentNode->nodeType() == ProjectNodeType + m_addNewSubprojectAction->setEnabled(currentNode->nodeType() == ProjectNodeType && actions.contains(AddSubProject) && !ICore::isNewItemDialogRunning()); - dd->m_removeProjectAction->setEnabled(dd->m_currentNode->nodeType() == ProjectNodeType + 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)) { + m_addExistingFilesAction->setEnabled(actions.contains(AddExistingFile)); + m_addExistingDirectoryAction->setEnabled(actions.contains(AddExistingDirectory)); + m_renameFileAction->setEnabled(actions.contains(Rename)); + } else if (dynamic_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) // If only removeFile is enabled only show it // If only deleteFile is enable only show it bool enableRemove = actions.contains(RemoveFile); - dd->m_removeFileAction->setEnabled(enableRemove); + m_removeFileAction->setEnabled(enableRemove); bool enableDelete = actions.contains(EraseFile); - dd->m_deleteFileAction->setEnabled(enableDelete); - dd->m_deleteFileAction->setVisible(enableDelete); + m_deleteFileAction->setEnabled(enableDelete); + m_deleteFileAction->setVisible(enableDelete); + + m_removeFileAction->setVisible(!enableDelete || enableRemove); + m_renameFileAction->setEnabled(actions.contains(Rename)); - dd->m_removeFileAction->setVisible(!enableDelete || enableRemove); - dd->m_renameFileAction->setEnabled(actions.contains(Rename)); + DocumentManager::populateOpenWithMenu(m_openWithMenu, ProjectTree::currentNode()->path()); } if (actions.contains(HidePathActions)) { - dd->m_openTerminalHere->setVisible(false); - dd->m_showInGraphicalShell->setVisible(false); - dd->m_searchOnFileSystem->setVisible(false); + m_openTerminalHere->setVisible(false); + m_showInGraphicalShell->setVisible(false); + m_searchOnFileSystem->setVisible(false); } if (actions.contains(HideFileActions)) { - dd->m_deleteFileAction->setVisible(false); - dd->m_removeFileAction->setVisible(false); + m_deleteFileAction->setVisible(false); + m_removeFileAction->setVisible(false); } if (actions.contains(HideFolderActions)) { - dd->m_addNewFileAction->setVisible(false); - dd->m_addNewSubprojectAction->setVisible(false); - dd->m_removeProjectAction->setVisible(false); - dd->m_addExistingFilesAction->setVisible(false); - dd->m_addExistingDirectoryAction->setVisible(false); + m_addNewFileAction->setVisible(false); + m_addNewSubprojectAction->setVisible(false); + m_removeProjectAction->setVisible(false); + m_addExistingFilesAction->setVisible(false); + m_addExistingDirectoryAction->setVisible(false); } } } 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"), @@ -3088,16 +2870,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)); } @@ -3109,10 +2892,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); @@ -3120,9 +2903,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(), ICore::mainWindow()); if (dialog.exec() == QDialog::Accepted) addExistingFiles(dialog.selectedFiles()); @@ -3130,7 +2913,7 @@ void ProjectExplorerPlugin::addExistingDirectory() void ProjectExplorerPlugin::addExistingFiles(const QStringList &filePaths) { - FolderNode *folderNode = qobject_cast<FolderNode *>(dd->m_currentNode); + FolderNode *folderNode = dynamic_cast<FolderNode *>(ProjectTree::currentNode()); addExistingFiles(folderNode, filePaths); } @@ -3159,8 +2942,8 @@ void ProjectExplorerPlugin::addExistingFiles(FolderNode *folderNode, const QStri void ProjectExplorerPlugin::removeProject() { - ProjectNode *subProjectNode = qobject_cast<ProjectNode*>(dd->m_currentNode->projectNode()); - ProjectNode *projectNode = qobject_cast<ProjectNode *>(subProjectNode->parentFolderNode()); + ProjectNode *subProjectNode = dynamic_cast<ProjectNode*>(ProjectTree::currentNode()->projectNode()); + ProjectNode *projectNode = dynamic_cast<ProjectNode *>(subProjectNode->parentFolderNode()); if (projectNode) { RemoveFileDialog removeFileDialog(subProjectNode->path(), ICore::mainWindow()); removeFileDialog.setDeleteFileVisible(false); @@ -3171,35 +2954,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 = dynamic_cast<FileNode*>(currentNode); - QString filePath = dd->m_currentNode->path(); + QString filePath = currentNode->path(); RemoveFileDialog removeFileDialog(filePath, ICore::mainWindow()); if (removeFileDialog.exec() == QDialog::Accepted) { @@ -3223,11 +3007,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 = dynamic_cast<FileNode*>(currentNode); - QString filePath = dd->m_currentNode->path(); + QString filePath = currentNode->path(); QMessageBox::StandardButton button = QMessageBox::question(ICore::mainWindow(), tr("Delete File"), @@ -3268,11 +3053,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 @@ -3285,15 +3068,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() @@ -3301,11 +3082,6 @@ void ProjectExplorerPlugin::showRenameFileError() QMessageBox::warning(ICore::mainWindow(), tr("Project Editing Failed"), dd->m_renameFileError); } -void ProjectExplorerPlugin::populateOpenWithMenu() -{ - DocumentManager::populateOpenWithMenu(dd->m_openWithMenu, currentNode()->path()); -} - void ProjectExplorerPlugin::updateSessionMenu() { dd->m_sessionMenu->clear(); |