예제 #1
0
static EnvDTE::ProjectItemPtr FindItem(EnvDTE::ProjectPtr pProject, _bstr_t ItemName, EnvDTE::ProjectItemPtr pPrevElem)
{
	EnvDTE::ProjectItemsPtr pItems = NULL;
	if (pPrevElem == NULL)
	{
		pProject->get_ProjectItems(&pItems);
	}
	else
	{
		pPrevElem->get_ProjectItems(&pItems);
	}
	if (pItems == NULL)
		return EnvDTE::ProjectItemPtr(NULL);
	long Count;
	pItems->get_Count(&Count);
	if (Count == 0)
		return EnvDTE::ProjectItemPtr(NULL);
	for (long i = 1; i <= Count; i++)
	{
		EnvDTE::ProjectItemPtr pItem;
		pItems->Item(_variant_t(i), &pItem);
		_bstr_t IName;
		pItem->get_Name(IName.GetAddress());

		if (!_wcsicmp(IName, ItemName))
		{
			return pItem;
		}

		EnvDTE::ProjectItemPtr pItem2 = FindItem(pProject, ItemName, pItem);
		if (pItem2 != NULL)
			return pItem2;
	}
	return EnvDTE::ProjectItemPtr(NULL);
}
예제 #2
0
HRESULT vsnet_addin::GetActiveProject(EnvDTE::ProjectPtr& pProj)
{
	EnvDTE::DocumentPtr pCurDoc;
	m_pDTE->get_ActiveDocument(&pCurDoc);
	if (pCurDoc != NULL)
	{
		EnvDTE::ProjectItemPtr pProjItem;
		pCurDoc->get_ProjectItem(&pProjItem);
		if (pProjItem == NULL)
		{
			return S_FALSE;
		}
		return pProjItem->get_ContainingProject(&pProj);
	}
	else
	{
		_variant_t vt, vt2;

		if (FAILED(m_pDTE->get_ActiveSolutionProjects(&vt)))
		{
			return S_FALSE;
		}

		if (vt.vt != (VT_ARRAY | VT_VARIANT))
		{
			return S_FALSE;
		}
		SAFEARRAY* pArray = vt.parray;
		if (pArray->cDims != 1 && !(pArray->fFeatures & FADF_DISPATCH ))
		{
			return S_FALSE;
		}

		if (pArray[0].rgsabound[0].cElements > 0)
		{
			vt2 = ((_variant_t*)pArray[0].pvData)[0];
			pProj = vt2.pdispVal;
			if (pProj == NULL)
			{
				return S_FALSE;
			}
		}
		else
			return S_FALSE;
	}

	return S_OK;
}
예제 #3
0
static EnvDTE::ProjectItemPtr EnumItem(EnvDTE::ProjectPtr & pProject, CSimpleArray<CString> & ar, EnvDTE::ProjectItemPtr pPrevElem)
{
	EnvDTE::ProjectItemsPtr pItems = NULL;
	if (pPrevElem == NULL)
	{
		pProject->get_ProjectItems(&pItems);
	}
	else
	{
		pPrevElem->get_ProjectItems(&pItems);
	}
	if (pItems == NULL)
		return EnvDTE::ProjectItemPtr(NULL);
	long Count;
	pItems->get_Count(&Count);
	if (Count == 0)
		return EnvDTE::ProjectItemPtr(NULL);
	for (short i = 1; i <= Count; i++)
	{
		EnvDTE::ProjectItemPtr pItem;
		pItems->Item(_variant_t(i), &pItem);
		_bstr_t IName;
		//pItem->get_Name(IName.GetAddress());
		pItem->get_FileNames(i,IName.GetAddress());
		/*
		if (!_wcsicmp(IName, ItemName))
		{
			return pItem;
		}
		*/
		CString Name = (LPCTSTR)IName;
		ar.Add(Name);
		EnvDTE::ProjectItemPtr pItem2 = EnumItem(pProject, ar,pItem);
		if (pItem2 != NULL)
			return pItem2;
	}
	return EnvDTE::ProjectItemPtr(NULL);
}
예제 #4
0
HRESULT vsnet_addin::GetSelectedProject(EnvDTE::ProjectPtr& pProj)
{
	EnvDTE::SelectedItemsPtr pSelItems;
	if (m_pDTE->get_SelectedItems(&pSelItems) == S_OK)
	{
		ATLASSERT(pSelItems != NULL);
		long Count;
		pSelItems->get_Count(&Count);
		if (Count)
		{
			EnvDTE::SelectedItemPtr pSelItem;
			pSelItems->Item(_variant_t(1), &pSelItem);
			ATLASSERT(pSelItem != NULL);
			EnvDTE::ProjectItemPtr pProjItem;
			pSelItem->get_ProjectItem(&pProjItem);
			if (pProjItem != NULL)
			{
				return pProjItem->get_ContainingProject(&pProj);
			}
		}
	}
	return E_FAIL;
}
예제 #5
0
bool CDDXManager::CheckCString(VSClass* pClass)
{
	EnvDTE::ProjectPtr pProject;
	EnvDTE::ProjectItemPtr pProjectItem;
	EnvDTE::GlobalsPtr pProjGlobals;

	pClass->pElement->get_ProjectItem(&pProjectItem);
	pProjectItem->get_ContainingProject(&pProject);

	pProject->get_Globals(&pProjGlobals);
	if (pProjGlobals != NULL)
	{
		VARIANT_BOOL bExist;
		pProjGlobals->get_VariableExists(_bstr_t(L"CTypeCString.Ask"), &bExist);
		if (bExist == VARIANT_TRUE)
			return true;
	}
	if (FindInclude(pClass, L"<atlstr.h>", true) != NULL ||
		FindInclude(pClass, L"<atlmisc.h>", true) != NULL)
	{
		return true;
	}

	CSmartAtlArray<InsertionPoint*>& CurInsPoints = m_pModifications->InsertPoints;
	for (size_t i = 0; i < CurInsPoints.GetCount(); i++)
	{
		if (CurInsPoints[i]->Type == INSERT_POINT_INCLUDE)
		{
			InsertInclude* pInsInclude = (InsertInclude*)CurInsPoints[i];
			if (pInsInclude->pElement->Name == _T("<atlstr.h>") ||
				pInsInclude->pElement->Name == _T("<atlmisc.h>"))
			{
				return true;
			}
		}
	}

	ATLASSERT(m_pGlobalModifications);
	for (size_t i = 0; i < m_pGlobalModifications->GetCount(); i++)
	{
		CSmartAtlArray<InsertionPoint*>& InsPoints = (*m_pGlobalModifications)[i].InsertPoints;
		for (size_t j = 0; j < InsPoints.GetCount(); j++)
		{
			if (InsPoints[j]->Type == INSERT_POINT_INCLUDE)
			{
				InsertInclude* pInsInclude = (InsertInclude*)InsPoints[j];
				if (pInsInclude->pProjectFile != NULL)
				{
					if (pInsInclude->pElement->Name == _T("<atlstr.h>") ||
						pInsInclude->pElement->Name == _T("<atlmisc.h>"))
					{
						return true;
					}
				}
			}
		}
	}

	//показать диалог в котором можно будет выбрать CString используемый
	CTypeCStringDlg dlg;
	EnvDTE::ProjectItemPtr pStdAfxFile = FindItem(pProject, _bstr_t(L"stdafx.h"), EnvDTE::ProjectItemPtr(NULL));
	if (pStdAfxFile != NULL)
	{
		dlg.m_bStdAfx = true;
	}
	else
	{
		dlg.m_bStdAfx = false;
	}
	if (dlg.DoModal() == IDOK)
	{
		if (dlg.m_Type == STYPE_ANOTHER)
			return true;
		if (dlg.m_Type == STYPE_WTL)
		{
			InsertWtlCString(pProject, CurInsPoints, dlg.m_Place);
			return true;
		}
		if (dlg.m_Type == STYPE_ATL)
		{
			InsertAtlCString(pProject, CurInsPoints);
		}

		if (dlg.m_bAskAgain)
		{
			pProjGlobals->put_VariablePersists(_bstr_t(L"CTypeCString.Ask"), VARIANT_TRUE);
		}
	}
	return true;
}