/// <summary> /// Adds the component. /// </summary> /// <param name="dwAddCompOperation">The dw add comp operation.</param> /// <param name="cComponents">The c components.</param> /// <param name="rgpcsdComponents">The RGPCSD components.</param> /// <param name="hwndPickerDlg">The HWND picker DLG.</param> /// <param name="pResult">The p result.</param> /// <returns></returns> int IVsComponentUser.AddComponent(VSADDCOMPOPERATION dwAddCompOperation, uint cComponents, IntPtr[] rgpcsdComponents, IntPtr hwndPickerDlg, VSADDCOMPRESULT[] pResult) { VSADDCOMPRESULT result = VSADDCOMPRESULT.ADDCOMPRESULT_Success; int returnValue = VSConstants.S_OK; try { for (int cCount = 0; cCount < cComponents; cCount++) { VSCOMPONENTSELECTORDATA selectorData = new VSCOMPONENTSELECTORDATA(); IntPtr ptr = rgpcsdComponents[cCount]; selectorData = (VSCOMPONENTSELECTORDATA)Marshal.PtrToStructure(ptr, typeof(VSCOMPONENTSELECTORDATA)); _selectedAssemblies.Add(Assembly.LoadFile(selectorData.bstrFile)); if (_max > 0 && cCount == _max) { break; } } } catch (BadImageFormatException) { // Trace.WriteLine("Exception : " + e.Message); result = VSADDCOMPRESULT.ADDCOMPRESULT_Failure; //string message = e.Message; //string title = string.Empty; //OLEMSGICON icon = OLEMSGICON.OLEMSGICON_CRITICAL; //OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK; //OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST; //VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton); } pResult[0] = result; return(returnValue); }
/// <summary> /// Add Components to the Project. /// Used by the environment to add components specified by the user in the Component Selector dialog /// to the specified project /// </summary> /// <param name="dwAddCompOperation">The component operation to be performed.</param> /// <param name="cComponents">Number of components to be added</param> /// <param name="rgpcsdComponents">array of component selector data</param> /// <param name="hwndDialog">Handle to the component picker dialog</param> /// <param name="pResult">Result to be returned to the caller</param> public virtual int AddComponent(VSADDCOMPOPERATION dwAddCompOperation, uint cComponents, System.IntPtr[] rgpcsdComponents, System.IntPtr hwndDialog, VSADDCOMPRESULT[] pResult) { if (rgpcsdComponents == null || pResult == null) { return VSConstants.E_FAIL; } //initalize the out parameter pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Success; IReferenceContainer references = GetReferenceContainer(); if (null == references) { // This project does not support references or the reference container was not created. // In both cases this operation is not supported. return VSConstants.E_NOTIMPL; } for (int cCount = 0; cCount < cComponents; cCount++) { VSCOMPONENTSELECTORDATA selectorData = new VSCOMPONENTSELECTORDATA(); IntPtr ptr = rgpcsdComponents[cCount]; selectorData = (VSCOMPONENTSELECTORDATA)Marshal.PtrToStructure(ptr, typeof(VSCOMPONENTSELECTORDATA)); if (null == references.AddReferenceFromSelectorData(selectorData)) { //Skip further proccessing since a reference has to be added pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Failure; return VSConstants.S_OK; } } return VSConstants.S_OK; }
public override int AddComponent(VSADDCOMPOPERATION dwAddCompOperation, uint cComponents, IntPtr[] rgpcsdComponents, IntPtr hwndDialog, VSADDCOMPRESULT[] pResult) { return VSConstants.E_NOTIMPL; }
//========================================================================================== // IVsComponentUser Members //========================================================================================== /// <summary> /// This is called in response to the Visual Studio "Add Reference" dialog and where we add /// all of the references that the user specified. /// </summary> /// <param name="dwAddCompOperation">Specifies the type of add component operation.</param> /// <param name="cComponents">The count of the components to add.</param> /// <param name="rgpcsdComponents">An array of <see cref="VSCOMPONENTSELECTORDATA"/> objects to add.</param> /// <param name="hwndPickerDlg">The HWND of the "Add Reference" dialog.</param> /// <param name="pResult">Specifies the result of the operation.</param> /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns> /// <remarks> /// The contents of <paramref name="pResult"/> determine whether the dialog closes. If the /// component add succeeds or is cancelled by the user, the dialog is closed. If the /// component add operation fails, the dialog remains open. /// </remarks> int IVsComponentUser.AddComponent(VSADDCOMPOPERATION dwAddCompOperation, uint cComponents, IntPtr[] rgpcsdComponents, IntPtr hwndPickerDlg, VSADDCOMPRESULT[] pResult) { StringCollection referenceFiles = new StringCollection(); bool sawProjectTypes = false; // Instead of adding each reference in this loop, we'll just gather the files that we // should add and detect if we have any project references. We do this so we can show // the dialog saying the project references aren't supported yet before we actually do // the work of adding any references. for (int i = 0; i < cComponents; i++) { IntPtr pSelectorData = rgpcsdComponents[i]; VSCOMPONENTSELECTORDATA selectorData = (VSCOMPONENTSELECTORDATA)Marshal.PtrToStructure(pSelectorData, typeof(VSCOMPONENTSELECTORDATA)); switch (selectorData.type) { case VSCOMPONENTTYPE.VSCOMPONENTTYPE_File: referenceFiles.Add(selectorData.bstrFile); break; case VSCOMPONENTTYPE.VSCOMPONENTTYPE_Project: sawProjectTypes = true; break; default: Tracer.WriteLineWarning(classType, "IVsComponentUser.AddComponent", "We should not be getting {0} for the component type since we don't show those tabs in the Add Reference dialog.", selectorData.type); break; } } // If we saw some project types, then kindly tell the user that we don't support it yet. if (sawProjectTypes) { Context.ShowMessageBox("Sorry, project references are not yet supported in Votive. If you want to add the code, by all means! :)", OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_INFO); pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Failure; } else { try { // Loop through the reference files, adding each one. foreach (string referenceFile in referenceFiles) { this.AddReference(referenceFile, true); } } catch { // We catch here because we're calling a virtual function that could be outside // of our assembly (3rd party). } pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Success; } return NativeMethods.S_OK; }
/// <include file='doc\Hierarchy.uex' path='docs/doc[@for="HierarchyNode.AddComponent"]/*' /> /// <summary> /// Add Component of the IVsComponentUser interface /// it serves as a callback from IVsComponentSelector dialog /// to notify us when a component was added as a reference to the project /// - needs to update the persistence data here. /// </summary> public virtual int AddComponent(VSADDCOMPOPERATION dwAddCompOperation, uint cComponents, System.IntPtr[] rgpcsdComponents, System.IntPtr hwndDialog, VSADDCOMPRESULT[] pResult){ try{ for (int cCount = 0; cCount < cComponents; cCount++){ VSCOMPONENTSELECTORDATA selectorData = new VSCOMPONENTSELECTORDATA(); IntPtr ptr = rgpcsdComponents[cCount]; selectorData = (VSCOMPONENTSELECTORDATA)Marshal.PtrToStructure(ptr, typeof(VSCOMPONENTSELECTORDATA)); this.projectMgr.AddReference(selectorData); } }catch{} pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Success; return 0; }
/// <summary> /// This is overridden to handle file references correctly when added to the project /// </summary> /// <inheritdoc /> public override int AddComponent(VSADDCOMPOPERATION dwAddCompOperation, uint cComponents, IntPtr[] rgpcsdComponents, IntPtr hwndDialog, VSADDCOMPRESULT[] pResult) { if(rgpcsdComponents == null || pResult == null) return VSConstants.E_FAIL; // Initialize the out parameter pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Success; IReferenceContainer references = GetReferenceContainer(); if(null == references) { // This project does not support references or the reference container was not created. // In both cases this operation is not supported. return VSConstants.E_NOTIMPL; } for(int cCount = 0; cCount < cComponents; cCount++) { VSCOMPONENTSELECTORDATA selectorData = new VSCOMPONENTSELECTORDATA(); IntPtr ptr = rgpcsdComponents[cCount]; selectorData = (VSCOMPONENTSELECTORDATA)Marshal.PtrToStructure(ptr, typeof(VSCOMPONENTSELECTORDATA)); var node = references.AddReferenceFromSelectorData(selectorData); if(node == null) { // Skip further processing since a reference has to be added pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Failure; return VSConstants.S_OK; } // If it's a file, get rid of the Name and AssemblyName metadata and add the HintPath metadata. // If not, when the project is opened the next time, the reference will appear as missing // if it isn't in the GAC. if(node != null && selectorData.type == VSCOMPONENTTYPE.VSCOMPONENTTYPE_File) { string hintPath = selectorData.bstrFile; if(Path.IsPathRooted(hintPath)) hintPath = PackageUtilities.GetPathDistance(this.ProjectMgr.BaseURI.Uri, new Uri(hintPath)); node.ItemNode.SetMetadata(ProjectFileConstants.Name, null); node.ItemNode.SetMetadata(ProjectFileConstants.AssemblyName, null); node.ItemNode.SetMetadata(ProjectFileConstants.HintPath, hintPath); } } return VSConstants.S_OK; }
/// <summary> /// Add Component of the IVsComponentUser interface /// it serves as a callback from IVsComponentSelector dialog /// to notify us when a component was added as a reference to the project /// - needs to update the persistence data here. /// </summary> public virtual void AddComponent(VSADDCOMPOPERATION dwAddCompOperation, uint cComponents, System.IntPtr[] rgpcsdComponents, System.IntPtr hwndDialog, VSADDCOMPRESULT[] pResult) { CCITracing.TraceCall(); try { for (int cCount=0; cCount < cComponents; cCount++) { VSCOMPONENTSELECTORDATA selectorData= new VSCOMPONENTSELECTORDATA(); IntPtr ptr = rgpcsdComponents[cCount]; selectorData = (VSCOMPONENTSELECTORDATA) Marshal.PtrToStructure(ptr, typeof(VSCOMPONENTSELECTORDATA)); CCITracing.TraceData(selectorData.bstrFile); this.projectMgr.AddReference(selectorData); } } catch (System.Exception e) { CCITracing.Trace(e); } pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Success; }
/// <summary> /// Add Component of the IVsComponentUser interface /// it serves as a callback from IVsComponentSelector dialog /// to notify us when a component was added as a reference to the project /// - needs to update the persistence data here. /// </summary> public virtual int AddComponent(VSADDCOMPOPERATION dwAddCompOperation, uint cComponents, System.IntPtr[] rgpcsdComponents, System.IntPtr hwndDialog, VSADDCOMPRESULT[] pResult) { VSADDCOMPRESULT result = VSADDCOMPRESULT.ADDCOMPRESULT_Success; int returnValue = VSConstants.S_OK; IReferenceContainer references = GetReferenceContainer(); if (null == references) { // This project does not support references or the reference container was not created. // In both cases this operation is not supported. return VSConstants.E_NOTIMPL; } try { for (int cCount = 0; cCount < cComponents; cCount++) { VSCOMPONENTSELECTORDATA selectorData = new VSCOMPONENTSELECTORDATA(); IntPtr ptr = rgpcsdComponents[cCount]; selectorData = (VSCOMPONENTSELECTORDATA)Marshal.PtrToStructure(ptr, typeof(VSCOMPONENTSELECTORDATA)); Debug.Assert(selectorData.bstrFile != null, "Could not retrieve selectordata from the add reference dialog box"); references.AddReferenceFromSelectorData(selectorData); } } catch (BadImageFormatException e) { Trace.WriteLine("Exception : " + e.Message); result = VSADDCOMPRESULT.ADDCOMPRESULT_Failure; string message = e.Message; string title = string.Empty; OLEMSGICON icon = OLEMSGICON.OLEMSGICON_CRITICAL; OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK; OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST; VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton); } pResult[0] = result; return returnValue; }
int IVsComponentUser.AddComponent( VSADDCOMPOPERATION dwAddCompOperation, uint cComponents, IntPtr[] rgpcsdComponents, IntPtr hwndPickerDlg, VSADDCOMPRESULT[] pResult ) { int hr = Utility.COM_HResults.S_OK; pResult[0] = VSADDCOMPRESULT.ADDCOMPRESULT_Success; //Do some validation checking here. Make sure the component is TinyCLR compatible. VSLangProj.References references = this.VSLangProj_References; VSLangProj.Reference reference = null; for(int iComponent = 0; iComponent < cComponents; iComponent++) { VSCOMPONENTSELECTORDATA compData = (VSCOMPONENTSELECTORDATA)Marshal.PtrToStructure( rgpcsdComponents[iComponent], typeof( VSCOMPONENTSELECTORDATA ) ); switch(compData.type) { case VSCOMPONENTTYPE.VSCOMPONENTTYPE_ComPlus: string fileName = Path.GetFileName(compData.bstrFile); reference = references.Add(fileName); break; case VSCOMPONENTTYPE.VSCOMPONENTTYPE_File: case VSCOMPONENTTYPE.VSCOMPONENTTYPE_Path: reference = references.Add( compData.bstrFile ); break; case VSCOMPONENTTYPE.VSCOMPONENTTYPE_Project: string strNull = null; IVsSolution solution = this.IVsSolution; IVsHierarchy hier; hr = solution.GetProjectOfProjref( compData.bstrProjRef, out hier, out strNull, null ); if(Utility.COM_HResults.FAILED( hr )) break; EnvDTE.Project proj = this.GetProjectFromHierarchy( hier ); reference = references.AddProject( proj ); break; default: hr = Utility.COM_HResults.E_FAIL; break; } if(Utility.COM_HResults.FAILED( hr )) break; } return hr; }