diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Helpers/IVsHierarchyItem.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Helpers/IVsHierarchyItem.cs new file mode 100644 index 0000000..1ffa78f --- /dev/null +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Helpers/IVsHierarchyItem.cs @@ -0,0 +1,43 @@ +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; + +namespace Community.VisualStudio.Toolkit.Shared.Helpers +{ + /// + /// Extensions for the interface. + /// + public static class VsHierarchyExtensions + { + /// + /// Returns the for the + /// + /// + /// + public static IVsHierarchy GetHierarchy(this IVsHierarchyItemIdentity item) => + item.IsNestedItem ? item.NestedHierarchy : item.Hierarchy; + + /// + /// Returns the 'ItemId' for the + /// + /// + /// + public static uint GetItemId(this IVsHierarchyItemIdentity item) => + item.IsNestedItem ? item.NestedItemID : item.ItemID; + + /// + /// Returns the for the + /// + /// + /// + public static IVsHierarchy GetHierarchy(this IVsHierarchyItem item) => + item.HierarchyIdentity.GetHierarchy(); + + /// + /// Returns the 'ItemId' for the + /// + /// + /// + public static uint GetItemId(this IVsHierarchyItem item) => + item.HierarchyIdentity.GetItemId(); + } +} diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs index 6431d07..29878f5 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs @@ -3,7 +3,7 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; -using System.Windows.Automation.Peers; +using Community.VisualStudio.Toolkit.Shared.Helpers; using Microsoft.Internal.VisualStudio.PlatformUI; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell; @@ -23,6 +23,7 @@ public class SolutionItem private IVsHierarchy _hierarchy = default!; // Initialized to non-null via the `Update()` method. private string? _fullPath; private uint _itemId; + private Lazy _isNonVisibleItem = default!; // Initialized to non-null via the `Update()` method. /// /// Creates a new instance of the solution item. @@ -38,9 +39,18 @@ internal void Update(IVsHierarchyItem item) { ThreadHelper.ThrowIfNotOnUIThread(); _item = item; - _hierarchy = item.HierarchyIdentity.IsNestedItem ? item.HierarchyIdentity.NestedHierarchy : item.HierarchyIdentity.Hierarchy; - _itemId = item.HierarchyIdentity.IsNestedItem ? item.HierarchyIdentity.NestedItemID : item.HierarchyIdentity.ItemID; + _hierarchy = item.GetHierarchy(); + _itemId = item.GetItemId(); _fullPath = GetFullPath(); + _isNonVisibleItem = new Lazy(() => + { + if (HierarchyUtilities.TryGetHierarchyProperty(_hierarchy, _itemId, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out bool isNonMemberItem) + && isNonMemberItem) + { + return isNonMemberItem; + } + return false; + }); } /// @@ -73,6 +83,11 @@ internal void Update(IVsHierarchyItem item) /// public IEnumerable Children => _children ??= _item.Children.Select(t => FromHierarchyItem(t)); + /// + /// Returns whether the item is normally visible in soltuion explorer + /// + public bool IsNonVisibleItem => _isNonVisibleItem.Value; + /// /// Gets information from the underlying data types. /// @@ -128,7 +143,7 @@ public void GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out IVsHier { throw new ArgumentNullException(nameof(hierarchy)); } - + ThreadHelper.ThrowIfNotOnUIThread(); IVsHierarchyItem item = hierarchy.ToHierarchyItem(itemId); diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems b/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems index 968b78f..5807193 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems @@ -10,6 +10,7 @@ +