/// <summary> /// Selects the node, optionally allowing multiple selection. /// </summary> /// <param name="allowMultiple">if set to <c>true</c>, adds this node to the current selection.</param> /// <exception cref="System.NotSupportedException"></exception> public virtual void Select(bool allowMultiple = false) { var flags = allowMultiple ? EXPANDFLAGS.EXPF_AddSelectItem : EXPANDFLAGS.EXPF_SelectItem; var hr = solutionExplorer.GetValue().ExpandItem(hierarchy as IVsUIHierarchy, itemId, flags); if (!ErrorHandler.Succeeded(hr)) { // Workaround for virtual nodes. var dte = hierarchyItem.GetServiceProvider().GetService <DTE>(); dynamic explorer = dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object; var selectionType = allowMultiple ? vsUISelectionType.vsUISelectionTypeToggle : vsUISelectionType.vsUISelectionTypeSelect; var path = Name; var current = Parent; while (current != null) { path = Path.Combine(current.Name, path); current = current.Parent; } try { var item = explorer.GetItem(path); if (item != null) { item.Select(selectionType); } } catch (Exception) { throw new NotSupportedException(Strings.SolutionExplorerNode.SelectionUnsupported(path)); } } }
//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)); }
//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)); }