|
#include "StdAfx.h"
#include "SolutionExplorer.h"
SolutionExplorer::SolutionExplorer()
{
}
SolutionExplorer::~SolutionExplorer()
{
}
void SolutionExplorer::VisitSolution(EnvDTE::_Solution* pSolution)
{
CComPtr<EnvDTE::Projects> pProjects;
if (FAILED(pSolution->get_Projects(&pProjects)) || !pProjects) return;
long nProjects = 0;
if (FAILED(pProjects->get_Count(&nProjects))) return;
for (long i = 1; i <= nProjects; ++i)
{
CComPtr<EnvDTE::Project> pProject;
if (FAILED(pProjects->Item(CComVariant(i), &pProject)) || !pProject) continue;
CComBSTR name;
pProject->get_Name(&name);
PathStackItem item(m_CurrentPath, CString(name));
VisitProject(pProject);
}
// TODO: Check for files at solution level (not sure how!)
}
void SolutionExplorer::VisitProject(EnvDTE::Project* pProject)
{
CComPtr<EnvDTE::ProjectItems> pProjectItems;
if (SUCCEEDED(pProject->get_ProjectItems(&pProjectItems)) && pProjectItems)
VisitProjectItems(pProjectItems);
}
void SolutionExplorer::VisitProjectItems(EnvDTE::ProjectItems* pProjectItems)
{
long items = 0;
if (FAILED(pProjectItems->get_Count(&items))) return;
for (long i = 1; i <= items; ++i)
{
CComPtr<EnvDTE::ProjectItem> pProjectItem;
pProjectItems->Item(CComVariant(i), &pProjectItem);
if (pProjectItem)
VisitProjectItem(pProjectItem);
}
}
void SolutionExplorer::VisitProjectItem(EnvDTE::ProjectItem* pProjectItem)
{
CComBSTR name;
pProjectItem->get_Name(&name);
CComPtr<EnvDTE::ProjectItems> pProjectItems;
if (SUCCEEDED(pProjectItem->get_ProjectItems(&pProjectItems)) && pProjectItems)
{
PathStackItem item(m_CurrentPath, CString(name));
VisitProjectItems(pProjectItems);
}
if (GetIgnoreProjectItemFiles(pProjectItem))
return;
short files = 0;
pProjectItem->get_FileCount(&files);
for (short j = 0; j < files; ++j)
{
CComBSTR filename;
if (FAILED(pProjectItem->get_FileNames(j, &filename))) continue;
VisitProjectItemFile(CString(name), CString(filename));
}
}
void SolutionExplorer::VisitProjectItemFile(CString strName, CString strFileName)
{
}
CString SolutionExplorer::GetCurrentPath() const
{
CString s;
for (PathStack::const_iterator i = m_CurrentPath.begin(); i != m_CurrentPath.end(); ++i)
{
if (i != m_CurrentPath.begin())
s += _T("\\");
s += *i;
}
return s;
}
bool SolutionExplorer::GetIgnoreProjectItemFiles(EnvDTE::ProjectItem* pProjectItem)
{
// If the ProjectItem is a folder, we ignore its FileNames property as it
// appears to be just the folder name repeated once for each file in the folder
// (the files in the folder still get added as they are returned through the
// ProjectItems property.
CComBSTR kind;
pProjectItem->get_Kind(&kind);
if (kind == _T("{6BB5F8F0-4483-11D3-8BCF-00C04F8EC28C}"))
return true; // VC++ folder
if (kind == _T("{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}"))
return true; // C# or VB folder
return false;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.