bool Supports (IVsHierarchyItem item, out IVsHierarchyItem actualItem) { actualItem = item; if (!item.HierarchyIdentity.IsRoot) return false; // We need the hierarchy fully loaded if it's not yet. if (!item.GetProperty<bool> (__VSPROPID4.VSPROPID_IsSolutionFullyLoaded)) { Guid guid; if (ErrorHandler.Succeeded (item.GetActualHierarchy ().GetGuidProperty ((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out guid)) && // For the solution root item itself, the GUID will be empty. guid != Guid.Empty) { if (ErrorHandler.Succeeded (((IVsSolution4)solution.Value).EnsureProjectIsLoaded (ref guid, (uint)__VSBSLFLAGS.VSBSLFLAGS_None))) actualItem = hierarchyManager.GetHierarchyItem (item.GetActualHierarchy (), item.GetActualItemId ()); } } if (!(actualItem.GetActualHierarchy () is IVsProject)) return false; // Finally, solution folders look like projects, but they are not. // We need to filter them out too. var extenderObject = actualItem.GetExtenderObject(); var dteProject = extenderObject as EnvDTE.Project; if (extenderObject != null && extenderObject.GetType ().FullName == "Microsoft.VisualStudio.Project.Automation.OAProject") return false; if (extenderObject != null && dteProject != null && (dteProject.Object is EnvDTE80.SolutionFolder)) return false; return true; }
bool Supports(IVsHierarchyItem item, out IVsHierarchyItem actualItem) { actualItem = item; if (!item.HierarchyIdentity.IsRoot) { return(false); } // We need the hierarchy fully loaded if it's not yet. if (!item.GetProperty <bool>(__VSPROPID4.VSPROPID_IsSolutionFullyLoaded)) { // EnsureProjectIsLoaded MUST be executed in the UI/Main thread // Otherwise (if the Supports method is being invoked from a worker thread) duplicate keys might be generated actualItem = asyncManager.Run(async() => { await asyncManager.SwitchToMainThreadAsync(); Guid guid; if (ErrorHandler.Succeeded(item.GetActualHierarchy().GetGuidProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out guid)) && // For the solution root item itself, the GUID will be empty. guid != Guid.Empty) { if (ErrorHandler.Succeeded(((IVsSolution4)solution.GetValue()).EnsureProjectIsLoaded(ref guid, (uint)__VSBSLFLAGS.VSBSLFLAGS_None))) { return(hierarchyManager.GetHierarchyItem(item.GetActualHierarchy(), item.GetActualItemId())); } } return(item); }); } var hierarchy = actualItem.GetActualHierarchy(); if (!(actualItem.GetActualHierarchy() is IVsProject) && !(hierarchy is FlavoredProjectBase)) { return(false); } // Finally, solution folders look like projects, but they are not. // We need to filter them out too. var extenderObject = actualItem.GetExtenderObject(); var dteProject = extenderObject as EnvDTE.Project; if (extenderObject != null && extenderObject.GetType().FullName == "Microsoft.VisualStudio.Project.Automation.OAProject") { return(false); } if (extenderObject != null && dteProject != null && (dteProject.Object is EnvDTE80.SolutionFolder)) { return(false); } return(true); }
static bool WritePropertyIfDefined(IVsHierarchyItem item, ITestOutputHelper output, int propertyId, Type enumType) { if (Enum.IsDefined(enumType, propertyId)) { output.WriteLine(PropertyValue, Enum.GetName(enumType, propertyId), item.GetProperty(propertyId)); return(true); } return(false); }
public static void Dump(this IVsHierarchyItem item, ITestOutputHelper output, params int[] additionalProperties) { using (var indented = new IndentedTestOutputHeper(output)) { indented.WriteLine(PropertyValue, "Name", item.GetProperty <string>(VsHierarchyPropID.Name)); indented.WriteLine(PropertyValue, "Text", item.Text); foreach (var propertyId in additionalProperties) { if (!WritePropertyIfDefined(item, indented, propertyId, typeof(__VSPROPID))) { if (!WritePropertyIfDefined(item, indented, propertyId, typeof(__VSPROPID2))) { if (!WritePropertyIfDefined(item, indented, propertyId, typeof(__VSPROPID3))) { if (!WritePropertyIfDefined(item, indented, propertyId, typeof(__VSPROPID4))) { if (!WritePropertyIfDefined(item, indented, propertyId, typeof(__VSPROPID5))) { if (!WritePropertyIfDefined(item, indented, propertyId, typeof(VsHierarchyPropID))) { indented.WriteLine(PropertyValue, propertyId, item.GetProperty(propertyId)); } } } } } } } string fullPath; if (ErrorHandler.Succeeded(item.GetActualHierarchy().GetCanonicalName(item.GetActualItemId(), out fullPath)) && File.Exists(fullPath)) { indented.WriteLine(PropertyValue, "FullPath", fullPath); } if (item.Children.Any()) { indented.WriteLine("Children = "); using (var childIndent = new IndentedTestOutputHeper(indented, begin: "[", end: "]")) { foreach (var child in item.Children) { child.Dump(childIndent, additionalProperties); } } } } }
//Lazy<string> name; //Lazy<string> caption; internal VsSolutionItemNode (IVsHierarchyItem item) { if (item.HierarchyIdentity.IsNestedItem) { VsHierarchy = item.HierarchyIdentity.NestedHierarchy; ItemId = item.HierarchyIdentity.NestedItemID; } else { VsHierarchy = item.HierarchyIdentity.Hierarchy; ItemId = item.HierarchyIdentity.ItemID; } extensibilityObject = new Lazy<object>(() => item.GetProperty((int)__VSHPROPID.VSHPROPID_ExtObject)); serviceProvider = new Lazy<IServiceProvider> (() => item.GetServiceProvider ()); //name = new Lazy<string> (() => item.GetProperty<string> ((int)__VSHPROPID.VSHPROPID_Name)); //caption = new Lazy<string> (() => item.GetProperty<string> ((int)__VSHPROPID.VSHPROPID_Caption)); parent = new Lazy<VsSolutionItemNode> (() => item.Parent == null ? null : new VsSolutionItemNode (item.Parent)); }
bool Supports(IVsHierarchyItem item, out IVsHierarchyItem actualItem) { actualItem = item; if (!item.HierarchyIdentity.IsRoot) { return(false); } // We need the hierarchy fully loaded if it's not yet. if (!item.GetProperty <bool>(__VSPROPID4.VSPROPID_IsSolutionFullyLoaded)) { Guid guid; if (ErrorHandler.Succeeded(item.GetActualHierarchy().GetGuidProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out guid)) && // For the solution root item itself, the GUID will be empty. guid != Guid.Empty) { if (ErrorHandler.Succeeded(((IVsSolution4)solution.Value).EnsureProjectIsLoaded(ref guid, (uint)__VSBSLFLAGS.VSBSLFLAGS_None))) { actualItem = hierarchyManager.GetHierarchyItem(item.GetActualHierarchy(), item.GetActualItemId()); } } } if (!(actualItem.GetActualHierarchy() is IVsProject)) { return(false); } // Finally, solution folders look like projects, but they are not. // We need to filter them out too. var extenderObject = actualItem.GetExtenderObject(); var dteProject = extenderObject as EnvDTE.Project; if (extenderObject != null && extenderObject.GetType().FullName == "Microsoft.VisualStudio.Project.Automation.OAProject") { return(false); } if (extenderObject != null && dteProject != null && (dteProject.Object is EnvDTE80.SolutionFolder)) { return(false); } return(true); }
//Lazy<string> name; //Lazy<string> caption; internal VsSolutionItemNode(IVsHierarchyItem item) { if (item.HierarchyIdentity.IsNestedItem) { VsHierarchy = item.HierarchyIdentity.NestedHierarchy; ItemId = item.HierarchyIdentity.NestedItemID; } else { VsHierarchy = item.HierarchyIdentity.Hierarchy; ItemId = item.HierarchyIdentity.ItemID; } extensibilityObject = new Lazy <object>(() => item.GetProperty((int)__VSHPROPID.VSHPROPID_ExtObject)); serviceProvider = new Lazy <IServiceProvider> (() => item.GetServiceProvider()); //name = new Lazy<string> (() => item.GetProperty<string> ((int)__VSHPROPID.VSHPROPID_Name)); //caption = new Lazy<string> (() => item.GetProperty<string> ((int)__VSHPROPID.VSHPROPID_Caption)); parent = new Lazy <VsSolutionItemNode> (() => item.Parent == null ? null : new VsSolutionItemNode(item.Parent)); }
/// <summary> /// Initializes a new instance of the <see cref="SolutionExplorerNode"/> class. /// </summary> /// <param name="nodeKind">Kind of the node.</param> /// <param name="hierarchyItem">The underlying hierarchy represented by this node.</param> /// <param name="nodeFactory">The factory for child nodes.</param> /// <param name="adapter">The adapter service that implements the smart cast <see cref="ISolutionExplorerNode.As{T}"/>.</param> protected SolutionExplorerNode( SolutionNodeKind nodeKind, IVsHierarchyItem hierarchyItem, ISolutionExplorerNodeFactory nodeFactory, IAdapterService adapter, JoinableLazy <IVsUIHierarchyWindow> solutionExplorer) { Guard.NotNull(nameof(hierarchyItem), hierarchyItem); Guard.NotNull(nameof(nodeFactory), nodeFactory); Guard.NotNull(nameof(adapter), adapter); Guard.NotNull(nameof(solutionExplorer), solutionExplorer); this.hierarchyItem = hierarchyItem; this.nodeFactory = nodeFactory; this.adapter = adapter; this.solutionExplorer = solutionExplorer; Kind = nodeKind; parent = hierarchyItem.Parent == null ? new Lazy <ISolutionExplorerNode>(() => null) : new Lazy <ISolutionExplorerNode>(() => nodeFactory.CreateNode(hierarchyItem.Parent)); name = new Lazy <string>(() => hierarchyItem.GetProperty(VsHierarchyPropID.Name, "")); Func <bool> getHiddenProperty = () => this.hierarchyItem.GetProperty(VsHierarchyPropID.IsHiddenItem, false); isHidden = hierarchyItem.Parent != null ? new Lazy <bool>(() => getHiddenProperty() || parent.Value.IsHidden) : new Lazy <bool>(() => getHiddenProperty()); solutionNode = new JoinableLazy <ISolutionNode>(async() => await ServiceLocator.Global.GetExport <ISolutionExplorer>().Solution); if (hierarchyItem.HierarchyIdentity.IsNestedItem) { hierarchy = hierarchyItem.HierarchyIdentity.NestedHierarchy; itemId = hierarchyItem.HierarchyIdentity.NestedItemID; } else { hierarchy = hierarchyItem.HierarchyIdentity.Hierarchy; itemId = hierarchyItem.HierarchyIdentity.ItemID; } }
/// <summary> /// Retrieves the value of a property for the current hierarchy item. /// </summary> protected T GetProperty <T>(int propId, T defaultValue = default(T)) => hierarchyItem.GetProperty(propId, defaultValue);
public static T GetProperty <T>(this IVsHierarchyItem item, VsHierarchyPropID propId, T defaultValue = default(T)) { return(item.GetProperty <T> ((int)propId, defaultValue)); }
/// <summary> /// Gets the DTE extensibility object for the given hierarchy item. /// </summary> public static object GetExtenderObject(this IVsHierarchyItem item) { return(item.GetProperty((int)__VSHPROPID.VSHPROPID_ExtObject)); }