From 61df428d14c7bb785b50f26a90517aecb701a9eb Mon Sep 17 00:00:00 2001 From: Alexander Drozdov Date: Sat, 5 Mar 2016 14:42:35 +1000 Subject: [PATCH] Read directory tree to form project list This option can be make configurable. Check ability to add new item to the project settings. --- cmakeproject.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/cmakeproject.cpp b/cmakeproject.cpp index 69672780..d0ba570c 100644 --- a/cmakeproject.cpp +++ b/cmakeproject.cpp @@ -133,6 +133,10 @@ static ProjectExplorer::FileNode* fileToFileNode(const Utils::FileName &fileName return node; } +bool sortNodesByPath(Node *a, Node *b) +{ + return a->filePath() < b->filePath(); +} /*! \class CMakeProject @@ -333,6 +337,48 @@ bool CMakeProject::extractCXXFlagsFromNinja(const CMakeBuildTarget &buildTarget, return !cache.isEmpty(); } +namespace { + +bool isValidDir(const QFileInfo &fileInfo) +{ + const QString fileName = fileInfo.fileName(); + const QString suffix = fileInfo.suffix(); + + if (fileName.startsWith(QLatin1Char('.'))) + return false; + + else if (fileName == QLatin1String("CVS")) + return false; + + // ### user include/exclude + + return true; +} + +void getFileList(const QDir &dir, const QString &projectRoot, + QList &files) +{ + const QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | + QDir::Dirs | + QDir::NoDotAndDotDot | + QDir::NoSymLinks); + + foreach (const QFileInfo &fileInfo, fileInfoList) { + QString filePath = fileInfo.absoluteFilePath(); + + if (fileInfo.isDir() && isValidDir(fileInfo)) { + // Recursive call for subdirectory + getFileList(QDir(fileInfo.absoluteFilePath()), projectRoot, files); + } else { + // Skip settings file + if (!filePath.endsWith(QLatin1String("CMakeLists.txt.user"))) + files.append(fileToFileNode(FileName::fromString(filePath))); + } + } +} + +} // ::anonymous + void CMakeProject::parseCMakeOutput() { QTC_ASSERT(m_buildDirManager, return); @@ -342,7 +388,29 @@ void CMakeProject::parseCMakeOutput() rootProjectNode()->setDisplayName(m_buildDirManager->projectName()); - buildTree(static_cast(rootProjectNode()), m_buildDirManager->files()); + auto cmakefiles = m_buildDirManager->files(); + QList treefiles; + + // Take file list from file system instead cbp project file + const QDir dir(projectDirectory().toString()); + + // Step 1: get files + getFileList(dir, projectDirectory().toString(), treefiles); + + // Step 2: sort lists. It duplicate actions in buildTree() + Utils::sort(cmakefiles, sortNodesByPath); + Utils::sort(treefiles, sortNodesByPath); + + // Step 3: get only added files + QList added; + QList deleted; + ProjectExplorer::compareSortedLists(cmakefiles, treefiles, deleted, added, sortNodesByPath); + qDeleteAll(ProjectExplorer::subtractSortedList(treefiles, added, sortNodesByPath)); + + // Step 4: now add new files to the cmakefiles. Note: using cmakefiles as a base is a good idea! + cmakefiles.append(added); + + buildTree(static_cast(rootProjectNode()), cmakefiles); m_buildDirManager->clearFiles(); // Some of the FileNodes in files() were deleted! updateApplicationAndDeploymentTargets(); @@ -556,11 +624,6 @@ void CMakeProject::gatherFileNodes(ProjectExplorer::FolderNode *parent, QListfilePath() < b->filePath(); -} - void CMakeProject::buildTree(CMakeProjectNode *rootNode, QList newList) { // Gather old list