// ========================================================================================= // Methods // ========================================================================================= /// <summary> /// Hides all of the tabs in the Add Reference dialog except for the browse tab, which will search for wixlibs. /// </summary> /// <param name="project">The project that will contain the reference.</param> /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns> internal static int AddProjectReference(WixProjectNode project) { CCITracing.TraceCall(); Guid showOnlyThisTabGuid = Guid.Empty; Guid startOnThisTabGuid = VSConstants.GUID_BrowseFilePage; string helpTopic = "VS.AddReference"; string machineName = String.Empty; string browseFilters = WixProjectReferenceNode.AddReferenceDialogFilter; string browseLocation = WixProjectReferenceNode.GetAddReferenceDialogInitialDirectory(project.WixPackage); // initialize the structure that we have to pass into the dialog call VSCOMPONENTSELECTORTABINIT[] tabInitializers = new VSCOMPONENTSELECTORTABINIT[2]; // tab 1 is the Project References tab: passing VSHPROPID_ShowProjInSolutionPage will tell the Add Reference // dialog to call into our GetProperty to determine if we should show ourself in the dialog tabInitializers[0].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); tabInitializers[0].guidTab = VSConstants.GUID_SolutionPage; tabInitializers[0].varTabInitInfo = (int)__VSHPROPID.VSHPROPID_ShowProjInSolutionPage; // tab 2 is the Browse tab tabInitializers[1].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); tabInitializers[1].guidTab = VSConstants.GUID_BrowseFilePage; tabInitializers[1].varTabInitInfo = 0; // initialize the flags to control the dialog __VSCOMPSELFLAGS flags = __VSCOMPSELFLAGS.VSCOMSEL_HideCOMClassicTab | __VSCOMPSELFLAGS.VSCOMSEL_HideCOMPlusTab | __VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName | __VSCOMPSELFLAGS.VSCOMSEL_MultiSelectMode; // get the dialog service from the environment IVsComponentSelectorDlg dialog = WixHelperMethods.GetService <IVsComponentSelectorDlg, SVsComponentSelectorDlg>(project.Site); try { // show the dialog ErrorHandler.ThrowOnFailure(dialog.ComponentSelectorDlg( (uint)flags, (IVsComponentUser)project, WixProjectReferenceNode.AddReferenceDialogTitle, helpTopic, ref showOnlyThisTabGuid, ref startOnThisTabGuid, machineName, (uint)tabInitializers.Length, tabInitializers, browseFilters, ref browseLocation)); } catch (COMException e) { CCITracing.Trace(e); return(e.ErrorCode); } return(VSConstants.S_OK); }
/// <summary> /// This overrides the base class method to show the VS 2005 style Add reference dialog. The ProjectNode implementation /// shows the VS 2003 style Add Reference dialog. /// </summary> /// <returns>S_OK if succeeded. Failure other wise</returns> public override int AddProjectReference() { IVsComponentSelectorDlg2 componentDialog; Guid guidEmpty = Guid.Empty; VSCOMPONENTSELECTORTABINIT[] tabInit = new VSCOMPONENTSELECTORTABINIT[1]; string strBrowseLocations = Path.GetDirectoryName(BaseURI.Uri.LocalPath); //Add the Project page tabInit[0].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); // Tell the Add Reference dialog to call hierarchies GetProperty with the following // propID to enable filtering out ourself from the Project to Project reference tabInit[0].varTabInitInfo = (int)__VSHPROPID.VSHPROPID_ShowProjInSolutionPage; tabInit[0].guidTab = VSConstants.GUID_SolutionPage; uint pX = 0, pY = 0; componentDialog = GetService(typeof(SVsComponentSelectorDlg)) as IVsComponentSelectorDlg2; try { // call the container to open the add reference dialog. if (componentDialog != null) { // Let the project know not to show itself in the Add Project Reference Dialog page ShowProjectInSolutionPage = false; // call the container to open the add reference dialog. ErrorHandler.ThrowOnFailure(componentDialog.ComponentSelectorDlg2( (System.UInt32)(__VSCOMPSELFLAGS.VSCOMSEL_MultiSelectMode | __VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName), (IVsComponentUser)this, 0, null, DynamicProjectSR.GetString(Microsoft.VisualStudio.Project.SR.AddReferenceDialogTitle), // Title "VS.AddReference", // Help topic ref pX, ref pY, (uint)tabInit.Length, tabInit, ref guidEmpty, "*.dll", ref strBrowseLocations)); } } catch (COMException e) { Trace.WriteLine("Exception : " + e.Message); return(e.ErrorCode); } finally { // Let the project know it can show itself in the Add Project Reference Dialog page ShowProjectInSolutionPage = true; } return(VSConstants.S_OK); }
/// <summary> /// Affichage de la fenetre de sélection /// </summary> /// <param name="max">Nbre maximun d'assembly à sélectionner</param> /// <returns></returns> public bool ShowDialog(int max) { this._max = max; _selectedAssemblies = new List <Assembly>(); IVsComponentSelectorDlg componentDialog; Guid guidEmpty = Guid.Empty; VSCOMPONENTSELECTORTABINIT[] tabInit = new VSCOMPONENTSELECTORTABINIT[0]; string strBrowseLocations = ""; // Path.GetDirectoryName(this.BaseURI.Uri.LocalPath); //tabInit[0].dwSize = (uint)Marshal.SizeOf(tabInit[0]); //// Tell the Add Reference dialog to call hierarchies GetProperty with the following //// propID to enablefiltering out ourself from the Project to Project reference //tabInit[0].varTabInitInfo = (int)__VSHPROPID.VSHPROPID_ShowProjInSolutionPage; //tabInit[0].guidTab = VSConstants.GUID_SolutionPage; componentDialog = _serviceProvider.GetService(typeof(IVsComponentSelectorDlg)) as IVsComponentSelectorDlg; try { // call the container to open the add reference dialog. if (componentDialog != null) { // call the container to open the add reference dialog. UInt32 flag = max == 1 ? (UInt32)__VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName : (UInt32)(__VSCOMPSELFLAGS.VSCOMSEL_MultiSelectMode | __VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName); ErrorHandler.ThrowOnFailure( componentDialog.ComponentSelectorDlg( flag, (IVsComponentUser)this, "Add reference", // Title "VS.AddReference", // Help topic ref guidEmpty, ref guidEmpty, String.Empty, // Machine Name (uint)tabInit.Length, tabInit, "*.dll", ref strBrowseLocations) ); } componentDialog = null; return(_selectedAssemblies.Count > 0); } catch (COMException) { return(false); } }
// ========================================================================================= // Methods // ========================================================================================= /// <summary> /// Hides all of the tabs in the Add Reference dialog except for the browse tab, which will search for wixlibs. /// </summary> /// <param name="project">The project that will contain the reference.</param> /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns> internal static int AddProjectReference(WixProjectNode project) { CCITracing.TraceCall(); Guid showOnlyThisTabGuid = Guid.Empty; Guid startOnThisTabGuid = VSConstants.GUID_BrowseFilePage; string helpTopic = "VS.AddReference"; string machineName = String.Empty; string browseFilters = WixProjectReferenceNode.AddReferenceDialogFilter; string browseLocation = WixProjectReferenceNode.GetAddReferenceDialogInitialDirectory(project.WixPackage); // initialize the structure that we have to pass into the dialog call VSCOMPONENTSELECTORTABINIT[] tabInitializers = new VSCOMPONENTSELECTORTABINIT[2]; // tab 1 is the Project References tab: passing VSHPROPID_ShowProjInSolutionPage will tell the Add Reference // dialog to call into our GetProperty to determine if we should show ourself in the dialog tabInitializers[0].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); tabInitializers[0].guidTab = VSConstants.GUID_SolutionPage; tabInitializers[0].varTabInitInfo = (int)__VSHPROPID.VSHPROPID_ShowProjInSolutionPage; // tab 2 is the Browse tab tabInitializers[1].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); tabInitializers[1].guidTab = VSConstants.GUID_BrowseFilePage; tabInitializers[1].varTabInitInfo = 0; // initialize the flags to control the dialog __VSCOMPSELFLAGS flags = __VSCOMPSELFLAGS.VSCOMSEL_HideCOMClassicTab | __VSCOMPSELFLAGS.VSCOMSEL_HideCOMPlusTab | __VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName | __VSCOMPSELFLAGS.VSCOMSEL_MultiSelectMode; // get the dialog service from the environment IVsComponentSelectorDlg dialog = WixHelperMethods.GetService<IVsComponentSelectorDlg, SVsComponentSelectorDlg>(project.Site); try { // show the dialog ErrorHandler.ThrowOnFailure(dialog.ComponentSelectorDlg( (uint)flags, (IVsComponentUser)project, WixProjectReferenceNode.AddReferenceDialogTitle, helpTopic, ref showOnlyThisTabGuid, ref startOnThisTabGuid, machineName, (uint)tabInitializers.Length, tabInitializers, browseFilters, ref browseLocation)); } catch (COMException e) { CCITracing.Trace(e); return e.ErrorCode; } return VSConstants.S_OK; }
/// <summary> /// Shows the Visual Studio standard "Add Reference" dialog. The dialog calls into /// IVsComponentUser.AddComponent, which is implemented in this class. /// </summary> public virtual void ShowAddReferenceDialog() { Guid emptyGuid = Guid.Empty; Guid showOnlyThisTabGuid = Guid.Empty; Guid startOnThisTabGuid = Guid.Empty; string helpTopic = String.Empty; string machineName = String.Empty; string browseFilters = this.AddReferenceDialogFilter; string browseLocation = this.AddReferenceDialogInitialDirectory; // Initialize the structure that we have to pass into the dialog call. uint tabInitializesArrayLength = 0; VSCOMPONENTSELECTORTABINIT[] tabInitializers = new VSCOMPONENTSELECTORTABINIT[1]; tabInitializers[0].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); tabInitializers[0].guidTab = Guid.Empty; tabInitializers[0].varTabInitInfo = 0; // Initialize the flags to control the dialog. // TODO: Support project references. __VSCOMPSELFLAGS flags = __VSCOMPSELFLAGS.VSCOMSEL_HideCOMClassicTab | __VSCOMPSELFLAGS.VSCOMSEL_HideCOMPlusTab | __VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName | __VSCOMPSELFLAGS.VSCOMSEL_MultiSelectMode; // Get the dialog service from the environment. IVsComponentSelectorDlg dialog = (IVsComponentSelectorDlg)this.GetService(typeof(SVsComponentSelectorDlg)); // Show the dialog. int hr = dialog.ComponentSelectorDlg( (uint)flags, (IVsComponentUser)this, this.AddReferenceDialogTitle, helpTopic, ref showOnlyThisTabGuid, ref startOnThisTabGuid, machineName, tabInitializesArrayLength, tabInitializers, browseFilters, ref browseLocation); if (NativeMethods.Failed(hr)) { Tracer.WriteLineWarning(classType, "ShowAddReferenceDialog", "The Add Reference dialog failed to show. Hr=0x{0:x}", hr); return; } }
/// <summary> /// Override this method if you want to modify the behavior of the Add Reference dialog /// By example you could change which pages are visible and which is visible by default. /// </summary> /// <returns></returns> public virtual int AddProjectReference() { CCITracing.TraceCall(); IVsComponentSelectorDlg componentDialog; Guid guidEmpty = Guid.Empty; VSCOMPONENTSELECTORTABINIT[] tabInit = new VSCOMPONENTSELECTORTABINIT[2]; string strBrowseLocations = Path.GetDirectoryName(this.BaseURI.Uri.LocalPath); tabInit[0].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); // Tell the Add Reference dialog to call hierarchies GetProperty with the following // propID to enablefiltering out ourself from the Project to Project reference tabInit[0].varTabInitInfo = (int)__VSHPROPID.VSHPROPID_ShowProjInSolutionPage; tabInit[0].guidTab = VSConstants.GUID_SolutionPage; // Add the Browse for file page tabInit[1].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); tabInit[1].guidTab = VSConstants.GUID_BrowseFilePage; tabInit[1].varTabInitInfo = 0; componentDialog = this.GetService(typeof(IVsComponentSelectorDlg)) as IVsComponentSelectorDlg; try { // call the container to open the add reference dialog. if(componentDialog != null) { // Let the project know not to show itself in the Add Project Reference Dialog page this.ShowProjectInSolutionPage = false; // call the container to open the add reference dialog. string browseFilters = "Component files (*.dll)" + "\0*.dll\0"; ErrorHandler.ThrowOnFailure(componentDialog.ComponentSelectorDlg( (System.UInt32)(__VSCOMPSELFLAGS.VSCOMSEL_MultiSelectMode | __VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName), (IVsComponentUser)this, SR.GetString(SR.AddReferenceDialogTitle, CultureInfo.CurrentUICulture), // Title "VS.AddReference", // Help topic ref guidEmpty, ref guidEmpty, String.Empty, // Machine Name (uint)tabInit.Length, tabInit, browseFilters, ref strBrowseLocations)); } } catch(COMException e) { Trace.WriteLine("Exception : " + e.Message); return e.ErrorCode; } finally { // Let the project know it can show itself in the Add Project Reference Dialog page this.ShowProjectInSolutionPage = true; } return VSConstants.S_OK; }
/// <summary> /// This overrides the base class method to show the VS 2005 style Add reference dialog. The ProjectNode implementation /// shows the VS 2003 style Add Reference dialog. /// </summary> /// <returns>S_OK if succeeded. Failure other wise</returns> public override int AddProjectReference() { IVsComponentSelectorDlg2 componentDialog; Guid guidEmpty = Guid.Empty; VSCOMPONENTSELECTORTABINIT[] tabInit = new VSCOMPONENTSELECTORTABINIT[5]; string strBrowseLocations = Path.GetDirectoryName(this.BaseURI.Uri.LocalPath); //Add the .NET page tabInit[0].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); tabInit[0].varTabInitInfo = 0; tabInit[0].guidTab = VSConstants.GUID_COMPlusPage; //Add the COM page tabInit[1].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); tabInit[1].varTabInitInfo = 0; tabInit[1].guidTab = VSConstants.GUID_COMClassicPage; //Add the Project page tabInit[2].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); // Tell the Add Reference dialog to call hierarchies GetProperty with the following // propID to enablefiltering out ourself from the Project to Project reference tabInit[2].varTabInitInfo = (int)__VSHPROPID.VSHPROPID_ShowProjInSolutionPage; tabInit[2].guidTab = VSConstants.GUID_SolutionPage; // Add the Browse page tabInit[3].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); tabInit[3].guidTab = VSConstants.GUID_BrowseFilePage; tabInit[3].varTabInitInfo = 0; //// Add the Recent page tabInit[4].dwSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT)); tabInit[4].guidTab = GUID_MruPage; tabInit[4].varTabInitInfo = 0; uint pX = 0, pY = 0; componentDialog = this.GetService(typeof(SVsComponentSelectorDlg)) as IVsComponentSelectorDlg2; try { // call the container to open the add reference dialog. if (componentDialog != null) { // Let the project know not to show itself in the Add Project Reference Dialog page this.ShowProjectInSolutionPage = false; // call the container to open the add reference dialog. ErrorHandler.ThrowOnFailure(componentDialog.ComponentSelectorDlg2( (System.UInt32)(__VSCOMPSELFLAGS.VSCOMSEL_MultiSelectMode | __VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName), (IVsComponentUser)this, 0, null, Microsoft.VisualStudio.Project.SR.GetString(Microsoft.VisualStudio.Project.SR.AddReferenceDialogTitle), // Title "VS.AddReference", // Help topic ref pX, ref pY, (uint)tabInit.Length, tabInit, ref guidEmpty, "*.dll", ref strBrowseLocations)); } } catch (COMException e) { Trace.WriteLine("Exception : " + e.Message); return e.ErrorCode; } finally { // Let the project know it can show itself in the Add Project Reference Dialog page this.ShowProjectInSolutionPage = true; } return VSConstants.S_OK; }
/// <include file='doc\Hierarchy.uex' path='docs/doc[@for="HierarchyNode.AddProjectReference"]/*' /> /// <summary> /// Get's called to add a project reference. Uses the IVsComponentSelectorDialog to do so. /// that one calls back on IVsComponentUser.AddComponent to tell us about changes to the store /// </summary> /// <returns>0 to indicate we handled the command</returns> public virtual int AddProjectReference(){ IVsComponentSelectorDlg componentDialog; Guid guidEmpty = Guid.Empty; VSCOMPONENTSELECTORTABINIT[] tabInit = new VSCOMPONENTSELECTORTABINIT[1]; string strBrowseLocations = Path.GetDirectoryName(new Uri(this.projectMgr.projFile.BaseURI).LocalPath); tabInit[0].dwSize = 48; tabInit[0].guidTab = guidEmpty; tabInit[0].varTabInitInfo = 0; componentDialog = this.GetService(typeof(IVsComponentSelectorDlg)) as IVsComponentSelectorDlg; try{ // call the container to open the add reference dialog. componentDialog.ComponentSelectorDlg((System.UInt32)(__VSCOMPSELFLAGS.VSCOMSEL_MultiSelectMode | __VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName), (IVsComponentUser)this, "Add Reference", "", ref guidEmpty, ref guidEmpty, "", 0, tabInit, "*.dll", ref strBrowseLocations); } catch{ } unchecked{ return (int)0; } }
private int ExecCommandAddReference( uint itemid, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut ) { int hr = Utility.COM_HResults.S_OK; VSCOMPONENTSELECTORTABINIT[] tabinit = new VSCOMPONENTSELECTORTABINIT[] { CreateComponentSelectorTab(ComponentSelectorGuids80.COMPlusPage, this.ActiveCfg.PlatformInfo.AssemblyFoldersList), CreateComponentSelectorTab(ComponentSelectorGuids80.SolutionPage,(int)__VSHPROPID.VSHPROPID_ShowProjInSolutionPage), CreateComponentSelectorTab(ComponentSelectorGuids80.MRUPage, null), CreateComponentSelectorTab(ComponentSelectorGuids80.BrowseFilesPage, null), }; IVsComponentSelectorDlg2 compSelDlg = ( IVsComponentSelectorDlg2 )ServiceProvider.GlobalProvider.GetService( typeof( IVsComponentSelectorDlg ) ); if(m_addReferenceState == null) { m_addReferenceState = new AddReferenceState(); GetCanonicalName( VSConstants.VSITEMID_ROOT, out m_addReferenceState.startBrowse); m_addReferenceState.lastActiveTab = new Guid( ComponentSelectorGuids80.COMPlusPage ); } m_addReferenceState.fDialogActive = true; hr = compSelDlg.ComponentSelectorDlg2( (uint)__VSCOMPSELFLAGS2.VSCOMSEL2_MultiSelectMode, this, 0, null, "Add Reference" /*get VS localized string?*/, "VS.AddReference", ref m_addReferenceState.xDlgSize, ref m_addReferenceState.yDlgSize, (uint)tabinit.Length, tabinit, ref m_addReferenceState.lastActiveTab, "Component Files (*.exe *.dll)\0*.exe;*.dll\0", ref m_addReferenceState.startBrowse ); m_addReferenceState.fDialogActive = false; return hr; }
private VSCOMPONENTSELECTORTABINIT CreateComponentSelectorTab( string guid, object initInfo ) { VSCOMPONENTSELECTORTABINIT tab = new VSCOMPONENTSELECTORTABINIT(); tab.dwSize = (uint)Marshal.SizeOf( tab ); tab.guidTab = new Guid( guid ); tab.varTabInitInfo = initInfo; return tab; }