2013-07-03 69 views
1

我正在開發Visual Studio插件。 Connect.cs類的OnConnection()方法填寫視覺工作室加入選項。禁用Visual Studio插件選項

現在我想根據打開的host項目禁用加入選項。

例如,如果web project處於打開狀態,我想添加選項啓用。否則應該禁用。

其中eventconnect.cs類我可以做到這一點,怎麼樣?

回答

1

這應該做的伎倆:

_applicationObject.Events.SolutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(openedSolution); 
    _applicationObject.Events.SolutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(closedSolution); 

「內部」 REFFERENCE在MSDN:http://msdn.microsoft.com/de-de/library/EnvDTE.aspx

您可以決定項目的類型與代碼(從http://www.mztools.com/articles/2007/mz2007016.aspx):

public string GetProjectTypeGuids(EnvDTE.Project proj) 
    { 

     string projectTypeGuids = ""; 
     object service = null; 
     Microsoft.VisualStudio.Shell.Interop.IVsSolution solution = null; 
     Microsoft.VisualStudio.Shell.Interop.IVsHierarchy hierarchy = null; 
     Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject aggregatableProject = null; 
     int result = 0; 

     service = GetService(proj.DTE, typeof(Microsoft.VisualStudio.Shell.Interop.IVsSolution)); 
     solution = (Microsoft.VisualStudio.Shell.Interop.IVsSolution)service; 

     result = solution.GetProjectOfUniqueName(proj.UniqueName, hierarchy); 

     if (result == 0) 
     { 
      aggregatableProject = (Microsoft.VisualStudio.Shell.Interop.IVsAggregatableProject)hierarchy; 
      result = aggregatableProject.GetAggregateProjectTypeGuids(projectTypeGuids); 
     } 

     return projectTypeGuids; 

    } 

    public object GetService(object serviceProvider, System.Type type) 
    { 
     return GetService(serviceProvider, type.GUID); 
    } 

    public object GetService(object serviceProviderObject, System.Guid guid) 
    { 

     object service = null; 
     Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider = null; 
     IntPtr serviceIntPtr; 
     int hr = 0; 
     Guid SIDGuid; 
     Guid IIDGuid; 

     SIDGuid = guid; 
     IIDGuid = SIDGuid; 
     serviceProvider = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)serviceProviderObject; 
     hr = serviceProvider.QueryService(SIDGuid, IIDGuid, serviceIntPtr); 

     if (hr != 0) 
     { 
      System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(hr); 
     } 
     else if (!serviceIntPtr.Equals(IntPtr.Zero)) 
     { 
      service = System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(serviceIntPtr); 
      System.Runtime.InteropServices.Marshal.Release(serviceIntPtr); 
     } 

     return service; 
    } 

您可以找到已知的GUID列表here

要禁用您的選項,您可以刪除或添加有關類型(檢查GUID)的菜單項openedSolution方法

+0

Zumbe:如何禁用選項? – ChandniShah

+0

這是一個菜單條目嗎? –

+0

加入選項來當我右鍵點擊解決方案/項目 – ChandniShah

相關問題