Reputation: 249
I am developing Visual studio plugin . I am populating visual studio add in option in OnConnection()
method of Connect.cs
class.
Now I want to disable the add in option, based on the opened host
project.
For example, I want add in option enable if web project
is open. otherwise it should be disabled.
In which event
of connect.cs
class I can achieve this and how ?
Upvotes: 1
Views: 160
Reputation: 8079
This should do the trick:
_applicationObject.Events.SolutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(openedSolution);
_applicationObject.Events.SolutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(closedSolution);
"Internal" refference in the MSDN: http://msdn.microsoft.com/de-de/library/EnvDTE.aspx
You can determine the type of the project with this code (from 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;
}
You find a list of known GUIDs here
To disable your option you would remove or add the menuentry regarding on the Type (check for GUID) in the openedSolution
method
Upvotes: 1