internal static IEnumerable <uint> EnumerateProjectItems(this IVsProject project) { var enumHierarchyItemsFactory = Package.GetGlobalService(typeof(SVsEnumHierarchyItemsFactory)) as IVsEnumHierarchyItemsFactory; var hierarchy = (IVsHierarchy)project; if (enumHierarchyItemsFactory != null && project != null) { IEnumHierarchyItems enumHierarchyItems; if (ErrorHandler.Succeeded( enumHierarchyItemsFactory.EnumHierarchyItems( hierarchy, (uint)(__VSEHI.VSEHI_Leaf | __VSEHI.VSEHI_Nest | __VSEHI.VSEHI_OmitHier), (uint)VSConstants.VSITEMID_ROOT, out enumHierarchyItems))) { if (enumHierarchyItems != null) { VSITEMSELECTION[] rgelt = new VSITEMSELECTION[1]; uint fetched; while (VSConstants.S_OK == enumHierarchyItems.Next(1, rgelt, out fetched) && fetched == 1) { yield return(rgelt[0].itemid); } } } } }
private IEnumerable <string> GetSelectedFileFullPaths() { IVsMultiItemSelect multiItemSelect; uint itemId; IntPtr hierarchyPtr; IntPtr selectionContainerPtr; var currentSelectionResult = (GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection). GetCurrentSelection(out hierarchyPtr, out itemId, out multiItemSelect, out selectionContainerPtr); if (ErrorHandler.Failed(currentSelectionResult) || hierarchyPtr == IntPtr.Zero || itemId == VSConstants.VSITEMID_NIL || itemId == VSConstants.VSITEMID_ROOT) { return(Enumerable.Empty <string>()); } if (multiItemSelect == null) { return(new[] { GetSelectedFileFullPath(itemId, Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy) }); } uint selectedItemCount; int pfSingleHirearchy; multiItemSelect.GetSelectionInfo(out selectedItemCount, out pfSingleHirearchy); var selectedItems = new VSITEMSELECTION[selectedItemCount]; multiItemSelect.GetSelectedItems(0, selectedItemCount, selectedItems); return(selectedItems.Select(_ => GetSelectedFileFullPath(_.itemid, _.pHier))); }
internal static VSITEMSELECTION GetParent(this VSITEMSELECTION vsItemSelection) { object parent; ErrorHandler.ThrowOnFailure( vsItemSelection.pHier.GetProperty( vsItemSelection.itemid, (int)__VSHPROPID.VSHPROPID_Parent, out parent ) ); var res = new VSITEMSELECTION(); var i = parent as int?; if (i.HasValue) { res.itemid = (uint)i.GetValueOrDefault(); } else { var ip = parent as IntPtr?; res.itemid = (uint)ip.GetValueOrDefault().ToInt32(); } res.pHier = vsItemSelection.pHier; return(res); }
public async Task <IVsHierarchy> GetCurrentSelectionAsync(CancellationToken cancellationToken) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsMonitorSelection monitorSelection = (IVsMonitorSelection)Package.GetGlobalService(typeof(SVsShellMonitorSelection)); List <IVsHierarchy> list = new List <IVsHierarchy>(); int hr = monitorSelection.GetCurrentSelection( out IntPtr hierarchyPtr, out uint itemID, out IVsMultiItemSelect multiSelect, out IntPtr containerPtr); if (IntPtr.Zero != containerPtr) { Marshal.Release(containerPtr); containerPtr = IntPtr.Zero; } if (itemID == (uint)VSConstants.VSITEMID.Selection) { hr = multiSelect.GetSelectionInfo(out uint itemCount, out int fSingleHierarchy); VSITEMSELECTION[] items = new VSITEMSELECTION[itemCount]; hr = multiSelect.GetSelectedItems(0, itemCount, items); foreach (VSITEMSELECTION item in items) { list.Add(item.pHier); } } else { if (hierarchyPtr != IntPtr.Zero) { IVsHierarchy hierarchy = (IVsHierarchy)Marshal.GetUniqueObjectForIUnknown(hierarchyPtr); list.Add(hierarchy); } } return(list.FirstOrDefault()); }
public VSITEMEX(VSITEMSELECTION vsSelect, string _canonicalName = null, IVsSolution _vsSolution = null) : this(vsSelect.pHier, vsSelect.itemid, _canonicalName, _vsSolution) { /* * pHier = vsSelect.pHier; * itemid = vsSelect.itemid; */ }
public static ICollection <VSITEMSELECTION> GetSelectedProjectItems([NotNull] this IVsMonitorSelection monitorSelection) { Contract.Requires(monitorSelection != null); Contract.Ensures(Contract.Result <ICollection <VSITEMSELECTION> >() != null); var hierarchyPtr = IntPtr.Zero; var selectionContainerPtr = IntPtr.Zero; try { IVsMultiItemSelect multiItemSelect; uint itemId; var hr = monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemId, out multiItemSelect, out selectionContainerPtr); if (ErrorHandler.Failed(hr)) { return(new VSITEMSELECTION[0]); } if ((itemId == VSConstants.VSITEMID_SELECTION) && (multiItemSelect != null)) { uint cItems; int info; multiItemSelect.GetSelectionInfo(out cItems, out info); var items = new VSITEMSELECTION[cItems]; multiItemSelect.GetSelectedItems(0, cItems, items); return(items); } if ((hierarchyPtr == IntPtr.Zero) || (itemId == VSConstants.VSITEMID_ROOT)) { return(new VSITEMSELECTION[0]); } return(new[] { new VSITEMSELECTION { pHier = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy, itemid = itemId } }); } finally { if (selectionContainerPtr != IntPtr.Zero) { Marshal.Release(selectionContainerPtr); } if (hierarchyPtr != IntPtr.Zero) { Marshal.Release(hierarchyPtr); } } }
static public IList <IVsProject> GetProjectsOfCurrentSelections() { List <IVsProject> results = new List <IVsProject>(); int hr = VSConstants.S_OK; var selectionMonitor = _serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; if (selectionMonitor == null) { Debug.Fail("Failed to get SVsShellMonitorSelection service."); return(results); } IntPtr hierarchyPtr = IntPtr.Zero; uint itemID = 0; IVsMultiItemSelect multiSelect = null; IntPtr containerPtr = IntPtr.Zero; hr = selectionMonitor.GetCurrentSelection(out hierarchyPtr, out itemID, out multiSelect, out containerPtr); if (IntPtr.Zero != containerPtr) { Marshal.Release(containerPtr); containerPtr = IntPtr.Zero; } Debug.Assert(hr == VSConstants.S_OK, "GetCurrentSelection failed."); if (itemID == (uint)VSConstants.VSITEMID.Selection) { uint itemCount = 0; int fSingleHierarchy = 0; hr = multiSelect.GetSelectionInfo(out itemCount, out fSingleHierarchy); System.Diagnostics.Debug.Assert(hr == VSConstants.S_OK, "GetSelectionInfo failed."); VSITEMSELECTION[] items = new VSITEMSELECTION[itemCount]; hr = multiSelect.GetSelectedItems(0, itemCount, items); System.Diagnostics.Debug.Assert(hr == VSConstants.S_OK, "GetSelectedItems failed."); foreach (VSITEMSELECTION item in items) { IVsProject project = GetProjectOfItem(item.pHier, item.itemid); if (!results.Contains(project)) { results.Add(project); } } } else { // case where no visible project is open (single file) if (hierarchyPtr != System.IntPtr.Zero) { IVsHierarchy hierarchy = (IVsHierarchy)Marshal.GetUniqueObjectForIUnknown(hierarchyPtr); results.Add(GetProjectOfItem(hierarchy, itemID)); } } return(results); }
internal static async Task AddHierarchiesFromSelectionAsync(IntPtr hierPtr, uint itemId, IVsMultiItemSelect?multiSelect, List <IVsHierarchyItem> hierarchies) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (itemId == VSConstants.VSITEMID_SELECTION && multiSelect is not null) { multiSelect.GetSelectionInfo(out uint itemCount, out int _); VSITEMSELECTION[] items = new VSITEMSELECTION[itemCount]; multiSelect.GetSelectedItems(0, itemCount, items); hierarchies.Capacity = (int)itemCount; foreach (VSITEMSELECTION item in items) { IVsHierarchyItem?hierItem = await item.pHier.ToHierarchyItemAsync(item.itemid); if (hierItem != null) { hierarchies.Add(hierItem); } else { IVsHierarchy solution = (IVsHierarchy)await VS.Services.GetSolutionAsync(); IVsHierarchyItem?sol = await solution.ToHierarchyItemAsync(VSConstants.VSITEMID_ROOT); if (sol != null) { hierarchies.Add(sol); } } } } else if (itemId == VSConstants.VSITEMID_NIL) { // Empty Solution Explorer or nothing selected, so don't add anything. } else if (hierPtr != IntPtr.Zero) { IVsHierarchy hierarchy = (IVsHierarchy)Marshal.GetUniqueObjectForIUnknown(hierPtr); IVsHierarchyItem?hierItem = await hierarchy.ToHierarchyItemAsync(itemId); if (hierItem != null) { hierarchies.Add(hierItem); } } else if (await VS.Services.GetSolutionAsync() is IVsHierarchy solution) { IVsHierarchyItem?sol = await solution.ToHierarchyItemAsync(VSConstants.VSITEMID_ROOT); if (sol != null) { hierarchies.Add(sol); } } }
private static bool ItemOrChildrenStatusMatches(VSITEMSELECTION item, HgFileStatus pattern) { if (ItemStatusMatches(item, pattern)) { return(true); } return(AnyChildItemStatusMatches(item, pattern)); }
public static EnvDTE.Project GetActiveProject(this IVsMonitorSelection vsMonitorSelection) { ThreadHelper.ThrowIfNotOnUIThread(); IntPtr ppHier = IntPtr.Zero; uint pitemid; IVsMultiItemSelect ppMIS; IntPtr ppSC = IntPtr.Zero; try { IVsHierarchy hierarchy = null; vsMonitorSelection.GetCurrentSelection(out ppHier, out pitemid, out ppMIS, out ppSC); if (ppHier == IntPtr.Zero) { return(null); } // multiple items are selected. if (pitemid == (uint)VSConstants.VSITEMID.Selection) { VSITEMSELECTION[] vsItemSelections = ppMIS.GetSelectedItemsInSingleHierachy(); if (vsItemSelections != null && vsItemSelections.Length > 0) { VSITEMSELECTION sel = vsItemSelections[0]; hierarchy = sel.pHier; } } else { hierarchy = Marshal.GetTypedObjectForIUnknown(ppHier, typeof(IVsHierarchy)) as IVsHierarchy; } if (hierarchy != null) { object project; if (hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out project) >= 0) { return(project as EnvDTE.Project); } } return(null); } finally { if (ppHier != IntPtr.Zero) { Marshal.Release(ppHier); } if (ppSC != IntPtr.Zero) { Marshal.Release(ppSC); } } }
public IList <IVsHierarchy> GetSelectedProjects() { ThreadHelper.ThrowIfNotOnUIThread(); List <IVsHierarchy> rslt = null; IVsMonitorSelection vsMonitorSelection = GetVsMonitorSelection(); if (vsMonitorSelection != null) { bool success = PackageHelper.Success(vsMonitorSelection.GetCurrentSelection(out IntPtr hierarchyPtr, out uint itemId, out IVsMultiItemSelect multiSelect, out IntPtr containerPtr)); if (IntPtr.Zero != containerPtr) { Marshal.Release(containerPtr); } if (success) { rslt = new List <IVsHierarchy>(); if (itemId == (uint)VSConstants.VSITEMID.Selection && multiSelect != null) { success = PackageHelper.Success(multiSelect.GetSelectionInfo(out uint itemCount, out int fSingleHierarchy)); if (success) { VSITEMSELECTION[] items = new VSITEMSELECTION[itemCount]; success = PackageHelper.Success(multiSelect.GetSelectedItems(0, itemCount, items)); if (success) { foreach (VSITEMSELECTION item in items) { if (item.pHier == null || rslt.Contains(item.pHier)) { continue; } rslt.Add(item.pHier); } } } } else if (hierarchyPtr != IntPtr.Zero) { object uniqueObjectForIUnknown = Marshal.GetUniqueObjectForIUnknown(hierarchyPtr); if (uniqueObjectForIUnknown != null && uniqueObjectForIUnknown is IVsHierarchy) { IVsHierarchy hierarchy = (IVsHierarchy)uniqueObjectForIUnknown; rslt.Add(hierarchy); } } } } return(rslt); }
public static SortCommandState GetCommandState(IVsMonitorSelection monitorSelection) { IntPtr hierarchyPointer, selectionContainerPointer; IVsMultiItemSelect multiItemSelect; uint itemId; monitorSelection.GetCurrentSelection(out hierarchyPointer, out itemId, out multiItemSelect, out selectionContainerPointer); var selectedHierarchy = Marshal.GetTypedObjectForIUnknown(hierarchyPointer, typeof(IVsHierarchy)) as IVsHierarchy; Marshal.Release(hierarchyPointer); object selectedObject; selectedHierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out selectedObject); var projectItems = new List <ProjectItem>(); var activeDocumentProjectItem = selectedObject as ProjectItem; // Context menu invoked on the active document or on an item in Solution Explorer if (activeDocumentProjectItem != null) { projectItems.Add(activeDocumentProjectItem); } // Context menu was invoked on multiple selected items in Solution Explorer else if (multiItemSelect != null) { uint itemCount; int isSingleHierarchy; multiItemSelect.GetSelectionInfo(out itemCount, out isSingleHierarchy); var selectedItems = new VSITEMSELECTION[itemCount]; multiItemSelect.GetSelectedItems(0, itemCount, selectedItems); foreach (var item in selectedItems) { selectedHierarchy.GetProperty(item.itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out selectedObject); var projectItem = selectedObject as ProjectItem; if (projectItem != null) { projectItems.Add(projectItem); } } } return(new SortCommandState { IsVisible = (projectItems.Count > 0) && projectItems.TrueForAll(DocumentHelper.IsResXProjectItem), IsEnabled = (projectItems.Count > 0) && projectItems.TrueForAll(item => item.Document?.ReadOnly != true), SelectedFiles = projectItems.Select(item => item.FileNames[0]).ToArray() }); }
static public IList<IVsProject> GetProjectsOfCurrentSelections() { List<IVsProject> results = new List<IVsProject>(); int hr = VSConstants.S_OK; var selectionMonitor = _serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; if (selectionMonitor == null) { Debug.Fail("Failed to get SVsShellMonitorSelection service."); return results; } IntPtr hierarchyPtr = IntPtr.Zero; uint itemID = 0; IVsMultiItemSelect multiSelect = null; IntPtr containerPtr = IntPtr.Zero; hr = selectionMonitor.GetCurrentSelection(out hierarchyPtr, out itemID, out multiSelect, out containerPtr); if (IntPtr.Zero != containerPtr) { Marshal.Release(containerPtr); containerPtr = IntPtr.Zero; } Debug.Assert(hr == VSConstants.S_OK, "GetCurrentSelection failed."); if (itemID == (uint)VSConstants.VSITEMID.Selection) { uint itemCount = 0; int fSingleHierarchy = 0; hr = multiSelect.GetSelectionInfo(out itemCount, out fSingleHierarchy); Debug.Assert(hr == VSConstants.S_OK, "GetSelectionInfo failed."); VSITEMSELECTION[] items = new VSITEMSELECTION[itemCount]; hr = multiSelect.GetSelectedItems(0, itemCount, items); Debug.Assert(hr == VSConstants.S_OK, "GetSelectedItems failed."); foreach (VSITEMSELECTION item in items) { IVsProject project = GetProjectOfItem(item.pHier, item.itemid); if (!results.Contains(project)) { results.Add(project); } } } else { // case where no visible project is open (single file) if (hierarchyPtr != IntPtr.Zero) { IVsHierarchy hierarchy = (IVsHierarchy)Marshal.GetUniqueObjectForIUnknown(hierarchyPtr); results.Add(GetProjectOfItem(hierarchy, itemID)); } } return results; }
internal static VSITEMSELECTION GetParentFolder(this VSITEMSELECTION vsItemSelection) { var parent = vsItemSelection.GetParent(); while (!parent.IsFolder()) { parent = parent.GetParent(); } return(parent); }
private static List <string> GetSelectedFilesInsideFolderView() { var hierarchyPtr = IntPtr.Zero; var containerPtr = IntPtr.Zero; try { if (Package.MonitorSelection != null && Package.MonitorSelection.GetCurrentSelection(out hierarchyPtr, out var itemid, out var multiSelect, out containerPtr) == VSConstants.S_OK) { var files = new List <string>(); if (itemid != VSConstants.VSITEMID_SELECTION) { if (itemid != VSConstants.VSCOOKIE_NIL && hierarchyPtr != IntPtr.Zero && Marshal.GetObjectForIUnknown(hierarchyPtr) is IVsHierarchy hierarchy && TryGetFile(hierarchy, itemid, out var file)) { files.Add(file); } } else if (multiSelect != null) { if (multiSelect.GetSelectionInfo(out var numberOfSelectedItems, out _) == VSConstants.S_OK && numberOfSelectedItems == 2) { var vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems]; if (multiSelect.GetSelectedItems(0, numberOfSelectedItems, vsItemSelections) == VSConstants.S_OK) { foreach (var selection in vsItemSelections) { if (TryGetFile(selection.pHier, selection.itemid, out var file)) { files.Add(file); } } } } } return(files); } return(null); } finally { if (hierarchyPtr != IntPtr.Zero) { Marshal.Release(hierarchyPtr); } if (containerPtr != IntPtr.Zero) { Marshal.Release(containerPtr); } } }
public SourceImage(VSITEMSELECTION item) { this.item = item; this.features = new ObservableCollection<OutputFeature>(); InitSourcePathAndScale(); InitSourceImage(); OutputHelpers.PopulateFeatures(this); this.PostInitialize(); }
private static AddAzureServiceDialog CreateAddServiceDialog(VSITEMSELECTION item) { switch (GetProjectKind(item)) { case ProjectKind.Bottle: return(new AddAzureServiceDialog("views", true)); default: return(new AddAzureServiceDialog(null, false)); } }
private static string GetItemFileName(VSITEMSELECTION item) { var project = item.pHier as IVsProject; if (project == null) { return(SolutionFileName); } return(GetItemFileName(project, item.itemid)); }
private static bool AnyChildItemStatusMatches(VSITEMSELECTION item, HgFileStatus pattern) { var project = item.pHier as IVsProject; if (project == null) { return(false); } return(GetProjectItemIds(item.pHier, item.itemid). Any(x => ItemStatusMatches(x, project, pattern))); }
private static VSITEMSELECTION[] GetSelectedItems(IVsMultiItemSelect multiSelect) { var selectedItemsCount = GetSelectedItemsCount(multiSelect); var selectedItems = new VSITEMSELECTION[selectedItemsCount]; if (selectedItemsCount > 0) { ErrorHandler.ThrowOnFailure(multiSelect.GetSelectedItems(0, selectedItemsCount, selectedItems)); } return(selectedItems); }
public Project[] GetSelectedProjects() { IntPtr hierarchyPointer, selectionContainerPointer; IVsMultiItemSelect multiItemSelect; uint projectItemId; MonitorSelectionService.GetCurrentSelection(out hierarchyPointer, out projectItemId, out multiItemSelect, out selectionContainerPointer); if (projectItemId == (uint)VSConstants.VSITEMID.Selection) { // Multiple projects are selected uint numberOfSelectedItems; int isSingleHieracrchy; multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHieracrchy); var selectedItems = new VSITEMSELECTION[numberOfSelectedItems]; multiItemSelect.GetSelectedItems(0, numberOfSelectedItems, selectedItems); var result = new Project[numberOfSelectedItems]; for (int i = 0; i < numberOfSelectedItems; i++) { object selectedObject = null; ErrorHandler.ThrowOnFailure(selectedItems[i].pHier.GetProperty(selectedItems[i].itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out selectedObject)); result[i] = selectedObject as Project; } return result; } else { // Only one project is selected object selectedObject = null; IVsHierarchy selectedHierarchy = null; try { selectedHierarchy = Marshal.GetTypedObjectForIUnknown(hierarchyPointer, typeof(IVsHierarchy)) as IVsHierarchy; } catch (Exception) { return null; } if (selectedHierarchy != null) { ErrorHandler.ThrowOnFailure(selectedHierarchy.GetProperty(projectItemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out selectedObject)); } Project selectedProject = selectedObject as Project; return new Project[] { selectedProject }; } }
public IEnumerable <HierarchyItemPair> GetSelection() { return(jtf.Run(async() => { // The VS selection operations must be performed on the UI thread. await jtf.SwitchToMainThreadAsync(); var selHier = IntPtr.Zero; var selContainer = IntPtr.Zero; try { // Get the current project hierarchy, project item, and selection container for the current selection // If the selection spans multiple hierarchies, hierarchyPtr is Zero ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out selHier, out var selId, out var selMulti, out selContainer)); // There may be no selection at all. if (selMulti == null && selHier == IntPtr.Zero) { return Enumerable.Empty <HierarchyItemPair>(); } // This is a single item selection. if (selMulti == null) { return new[] { new HierarchyItemPair( (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(selHier, typeof(IVsHierarchy)), selId) }; } // This is a multiple item selection. ErrorHandler.ThrowOnFailure(selMulti.GetSelectionInfo(out var selCount, out var singleHier)); var selection = new VSITEMSELECTION[selCount]; ErrorHandler.ThrowOnFailure(selMulti.GetSelectedItems(0, selCount, selection)); return selection.Where(sel => sel.pHier != null) .Select(sel => new HierarchyItemPair(sel.pHier, sel.itemid)) .ToArray(); } finally { if (selHier != IntPtr.Zero) { Marshal.Release(selHier); } if (selContainer != IntPtr.Zero) { Marshal.Release(selContainer); } } })); }
public static ICollection <VSITEMSELECTION> GetSelectedProjectItems(this IVsMonitorSelection monitorSelection) { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); var hierarchyPtr = IntPtr.Zero; var selectionContainerPtr = IntPtr.Zero; try { var hr = monitorSelection.GetCurrentSelection(out hierarchyPtr, out var itemId, out var multiItemSelect, out selectionContainerPtr); if (ErrorHandler.Failed(hr)) { return(Array.Empty <VSITEMSELECTION>()); } if ((itemId == VSConstants.VSITEMID_SELECTION) && (multiItemSelect != null)) { multiItemSelect.GetSelectionInfo(out var cItems, out _); var items = new VSITEMSELECTION[cItems]; multiItemSelect.GetSelectedItems(0, cItems, items); return(items); } if ((hierarchyPtr == IntPtr.Zero) || (itemId == VSConstants.VSITEMID_ROOT)) { return(Array.Empty <VSITEMSELECTION>()); } return(new[] { new VSITEMSELECTION { pHier = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy, itemid = itemId } }); } finally { if (selectionContainerPtr != IntPtr.Zero) { Marshal.Release(selectionContainerPtr); } if (hierarchyPtr != IntPtr.Zero) { Marshal.Release(hierarchyPtr); } } }
private static VSITEMSELECTION GetSelectedItem(IntPtr hierarchyPtr, uint itemId) { var item = new VSITEMSELECTION { itemid = itemId }; if (hierarchyPtr != IntPtr.Zero) { var hierarchy = (IVsHierarchy)Marshal.GetObjectForIUnknown(hierarchyPtr); item.pHier = hierarchy; } return(item); }
internal static EnvDTE.ProjectItem GetExtensionObject(VSITEMSELECTION selection) { object project; ErrorHandler.ThrowOnFailure( selection.pHier.GetProperty( selection.itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out project ) ); return(project as EnvDTE.ProjectItem); }
// ------------------------------------------------------------------- /// <summary> /// Gets an array of hierarchy items that represent the currently /// selected items in the Solution Explorer. /// </summary> /// <param name="provider"> /// The DTE object to use as a service provider. /// </param> /// <returns> /// An array of HierarchyItem objects that are currently selected. /// </returns> public static HierarchyItem[] GetCurrentSelection( IServiceProvider provider) { IVsMonitorSelection vsms = (IVsMonitorSelection) provider.GetService(typeof(SVsShellMonitorSelection)); IntPtr hierPtr; uint itemID; IVsMultiItemSelect multiSel; IntPtr selCont; vsms.GetCurrentSelection(out hierPtr, out itemID, out multiSel, out selCont); if (hierPtr != IntPtr.Zero) { // Single selection IVsHierarchy hier = IntPtrToInterface <IVsHierarchy>(hierPtr); return(new HierarchyItem[] { new HierarchyItem(hier, itemID) }); } else if (itemID == VSConstants.VSITEMID_SELECTION) { // Multiple selection uint count; int isSingle; multiSel.GetSelectionInfo(out count, out isSingle); VSITEMSELECTION[] selection = new VSITEMSELECTION[count]; multiSel.GetSelectedItems(0, count, selection); HierarchyItem[] hierItems = new HierarchyItem[count]; int i = 0; foreach (VSITEMSELECTION selectedItem in selection) { hierItems[i++] = new HierarchyItem(selectedItem.pHier, selectedItem.itemid); } return(hierItems); } else { return(new HierarchyItem[] { }); } }
private bool IsLoneProjectWithoutSolution(VSITEMSELECTION selectedItem) { bool flag = false; if ((int)selectedItem.itemid == -2 && selectedItem.pHier != null) { IVsHierarchy service = (IVsSolution)this.ServiceProvider.GetService(typeof(SVsSolution)) as IVsHierarchy; object pvar; if (service != null && this.GetNumberOfProjectUnderTheSolution() == 1 && (selectedItem.pHier.GetProperty(selectedItem.itemid, -2032, out pvar) == 0 && object.ReferenceEquals(pvar, (object)service))) { flag = this.IsSolutionNodeHidden(); } } return(flag); }
private static void AddToNewFile(VSITEMSELECTION item, AddAzureServiceDialog dlg) { var code = dlg.GenerateServiceCode(); var tempFile = Path.GetTempFileName(); File.WriteAllText(tempFile, code); var projectItem = GetProjectItems(item).AddFromTemplate( tempFile, dlg.ServiceName.Text + ".py" ); var window = projectItem.Open(); window.Activate(); }
private void Collapse() { IVsUIHierarchyWindow explorerToolWindow = this.GetSolutionExplorerToolWindow(); if (explorerToolWindow == null) { return; } VSITEMSELECTION[] selectedNodes = this.GetSelectedNodes(explorerToolWindow); bool flag1 = this.ContainsSolutionNode(selectedNodes); bool flag2 = false; VSITEMSELECTION loneProjectWithoutSolution = new VSITEMSELECTION() { itemid = 4294967294, pHier = (IVsHierarchy)null }; if (!flag1) { flag2 = this.ContainsLoneProjectWithoutSolution(selectedNodes, out loneProjectWithoutSolution); } if (flag1) { IVsHierarchy service = (IVsSolution)this.ServiceProvider.GetService(typeof(SVsSolution)) as IVsHierarchy; if (service == null) { return; } this.CollapseHierarchyItems(explorerToolWindow, service, 4294967294U, true); } else if (flag2) { if (loneProjectWithoutSolution.pHier == null || (int)loneProjectWithoutSolution.itemid == -1) { return; } this.CollapseHierarchyItems(explorerToolWindow, loneProjectWithoutSolution.pHier, loneProjectWithoutSolution.itemid, true); } else { foreach (VSITEMSELECTION vsitemselection in selectedNodes) { this.CollapseHierarchyItems(explorerToolWindow, vsitemselection.pHier, vsitemselection.itemid, false); } } }
public IEnumerable <string> GetFullFilePath(IServiceProvider serviceProvider) { var selectionMonitor = serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; if (selectionMonitor == null) { Debug.Fail("Failed to get SVsShellMonitorSelection service."); return(Enumerable.Empty <string>()); } int hr = selectionMonitor.GetCurrentSelection(out IntPtr hierarchyPtr, out uint itemid, out IVsMultiItemSelect multiSelect, out IntPtr containerPtr); if (hierarchyPtr == IntPtr.Zero) { return(Enumerable.Empty <string>()); } if (IntPtr.Zero != containerPtr) { Marshal.Release(containerPtr); containerPtr = IntPtr.Zero; } Debug.Assert(hr == VSConstants.S_OK, "GetCurrentSelection failed."); if (itemid == (uint)VSConstants.VSITEMID.Selection) { multiSelect.GetSelectionInfo(out uint count, out int somethingElse); if (count > 0) { VSITEMSELECTION[] selectedItems = new VSITEMSELECTION[count]; var sel = multiSelect.GetSelectedItems((uint)__VSGSIFLAGS.GSI_fOmitHierPtrs, count, selectedItems); //multiple selection return(selectedItems.Select(info => GetItemPath(hierarchyPtr, info.itemid))); } else { return(Enumerable.Empty <string>()); } } else { return(new string[] { GetItemPath(hierarchyPtr, itemid) }); } }
internal static bool IsNonMemberItem(this VSITEMSELECTION item) { object obj; try { ErrorHandler.ThrowOnFailure( item.pHier.GetProperty( item.itemid, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out obj ) ); } catch (System.Runtime.InteropServices.COMException) { return(false); } return((obj as bool?) ?? false); }
internal static Guid GetItemType(this VSITEMSELECTION vsItemSelection) { Guid typeGuid; try { ErrorHandler.ThrowOnFailure( vsItemSelection.pHier.GetGuidProperty( vsItemSelection.itemid, (int)__VSHPROPID.VSHPROPID_TypeGuid, out typeGuid ) ); } catch (System.Runtime.InteropServices.COMException) { return(Guid.Empty); } return(typeGuid); }
public IEnumerable <IVsHierarchyItem> GetSelection() { return(jtf.Run(async() => { await jtf.SwitchToMainThreadAsync(); var selHier = IntPtr.Zero; try { ErrorHandler.ThrowOnFailure(hierarchyWindow.GetCurrentSelection(out selHier, out var selId, out var selMulti)); // There may be no selection at all. if (selMulti == null && selHier == IntPtr.Zero) { return Enumerable.Empty <IVsHierarchyItem>(); } // This is a single item selection. if (selMulti == null) { return new[] { hierarchyManager.GetHierarchyItem( (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(selHier, typeof(IVsHierarchy)), selId) }; } // This is a multiple item selection. ErrorHandler.ThrowOnFailure(selMulti.GetSelectionInfo(out var selCount, out var singleHier)); var selection = new VSITEMSELECTION[selCount]; ErrorHandler.ThrowOnFailure(selMulti.GetSelectedItems(0, selCount, selection)); return selection.Where(sel => sel.pHier != null) .Select(sel => hierarchyManager.GetHierarchyItem(sel.pHier, sel.itemid)) .ToArray(); } finally { if (selHier != IntPtr.Zero) { Marshal.Release(selHier); } } })); }
public IEnumerable<IVsHierarchyItem> GetSelection () { return asyncManager.Run (async () => { await asyncManager.SwitchToMainThread (); var selHier = IntPtr.Zero; uint selId; IVsMultiItemSelect selMulti; try { ErrorHandler.ThrowOnFailure (hierarchyWindow.GetCurrentSelection (out selHier, out selId, out selMulti)); // There may be no selection at all. if (selMulti == null && selHier == IntPtr.Zero) return Enumerable.Empty<IVsHierarchyItem> (); // This is a single item selection. if (selMulti == null) { return new[] { hierarchyManager.GetHierarchyItem ( (IVsHierarchy)Marshal.GetTypedObjectForIUnknown (selHier, typeof (IVsHierarchy)), selId) }; } // This is a multiple item selection. uint selCount; int singleHier; ErrorHandler.ThrowOnFailure (selMulti.GetSelectionInfo (out selCount, out singleHier)); var selection = new VSITEMSELECTION[selCount]; ErrorHandler.ThrowOnFailure (selMulti.GetSelectedItems (0, selCount, selection)); return selection.Where (sel => sel.pHier != null) .Select (sel => hierarchyManager.GetHierarchyItem (sel.pHier, sel.itemid)) .ToArray (); } finally { if (selHier != IntPtr.Zero) Marshal.Release (selHier); } }); }
private IEnumerable<string> GetSelectedFileFullPaths() { IVsMultiItemSelect multiItemSelect; uint itemId; IntPtr hierarchyPtr; IntPtr selectionContainerPtr; var currentSelectionResult = (GetGlobalService(typeof (SVsShellMonitorSelection)) as IVsMonitorSelection). GetCurrentSelection(out hierarchyPtr, out itemId, out multiItemSelect, out selectionContainerPtr); if (ErrorHandler.Failed(currentSelectionResult) || hierarchyPtr == IntPtr.Zero || itemId == VSConstants.VSITEMID_NIL || itemId == VSConstants.VSITEMID_ROOT) { return Enumerable.Empty<string>(); } if (multiItemSelect == null) { return new[] { GetSelectedFileFullPath(itemId, Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy) }; } uint selectedItemCount; int pfSingleHirearchy; multiItemSelect.GetSelectionInfo(out selectedItemCount, out pfSingleHirearchy); var selectedItems = new VSITEMSELECTION[selectedItemCount]; multiItemSelect.GetSelectedItems(0, selectedItemCount, selectedItems); return selectedItems.Select(_ => GetSelectedFileFullPath(_.itemid, _.pHier)); }
/// <summary> /// Gets all of the currently selected items. /// </summary> /// <returns></returns> private IEnumerable<VSITEMSELECTION> GetSelectedItems() { IVsMonitorSelection monitorSelection = _package.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection; IntPtr hierarchyPtr = IntPtr.Zero; IntPtr selectionContainer = IntPtr.Zero; try { uint selectionItemId; IVsMultiItemSelect multiItemSelect = null; ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out selectionItemId, out multiItemSelect, out selectionContainer)); if (selectionItemId != VSConstants.VSITEMID_NIL && hierarchyPtr != IntPtr.Zero) { IVsHierarchy hierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy; if (selectionItemId != VSConstants.VSITEMID_SELECTION) { // This is a single selection. Compare hirarchy with our hierarchy and get node from itemid if (Utilities.IsSameComObject(this, hierarchy)) { yield return new VSITEMSELECTION() { itemid = selectionItemId, pHier = hierarchy }; } } else if (multiItemSelect != null) { // This is a multiple item selection. // Get number of items selected and also determine if the items are located in more than one hierarchy uint numberOfSelectedItems; int isSingleHierarchyInt; ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt)); bool isSingleHierarchy = (isSingleHierarchyInt != 0); // Now loop all selected items and add to the list only those that are selected within this hierarchy if (!isSingleHierarchy || (isSingleHierarchy && Utilities.IsSameComObject(this, hierarchy))) { Debug.Assert(numberOfSelectedItems > 0, "Bad number of selected itemd"); VSITEMSELECTION[] vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems]; uint flags = (isSingleHierarchy) ? (uint)__VSGSIFLAGS.GSI_fOmitHierPtrs : 0; ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(flags, numberOfSelectedItems, vsItemSelections)); foreach (VSITEMSELECTION vsItemSelection in vsItemSelections) { yield return new VSITEMSELECTION() { itemid = vsItemSelection.itemid, pHier = hierarchy }; } } } } } finally { if (hierarchyPtr != IntPtr.Zero) { Marshal.Release(hierarchyPtr); } if (selectionContainer != IntPtr.Zero) { Marshal.Release(selectionContainer); } } }
private static AddAzureServiceDialog CreateAddServiceDialog(VSITEMSELECTION item) { switch (GetProjectKind(item)) { case ProjectKind.Bottle: return new AddAzureServiceDialog("views", true); default: return new AddAzureServiceDialog(null, false); } }
public static IEnumerable<Tuple<IVsHierarchy, uint>> GetSelection(this IVsMonitorSelection monitorSelection, IUIThread uiThread, IVsHierarchy solution) { var hierarchyPtr = IntPtr.Zero; var selectionContainer = IntPtr.Zero; return uiThread.Invoke(() => { try { // Get the current project hierarchy, project item, and selection container for the current selection // If the selection spans multiple hierarchies, hierarchyPtr is Zero uint itemid; IVsMultiItemSelect multiItemSelect = null; ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainer)); if (itemid == VSConstants.VSITEMID_NIL) return Enumerable.Empty<Tuple<IVsHierarchy, uint>>(); if (itemid == VSConstants.VSITEMID_ROOT) { if (hierarchyPtr == IntPtr.Zero) return new[] { Tuple.Create(solution, VSConstants.VSITEMID_ROOT) }; else return new[] { Tuple.Create( (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy)), VSConstants.VSITEMID_ROOT) }; } if (itemid != VSConstants.VSITEMID_SELECTION) return new[] { Tuple.Create( (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy)), itemid) }; // This is a multiple item selection. uint numberOfSelectedItems; int isSingleHierarchyInt; ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt)); var isSingleHierarchy = (isSingleHierarchyInt != 0); var vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems]; var flags = (isSingleHierarchy) ? (uint)__VSGSIFLAGS.GSI_fOmitHierPtrs : 0; ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(flags, numberOfSelectedItems, vsItemSelections)); return vsItemSelections.Where(sel => sel.pHier != null) // NOTE: we can return lazy results here, since // the GetSelectedItems has already returned in the UI thread // the array of results. We're just delaying the creation of the tuples // in case they aren't all needed. .Select(sel => Tuple.Create(sel.pHier, sel.itemid)); } finally { if (hierarchyPtr != IntPtr.Zero) { Marshal.Release(hierarchyPtr); } if (selectionContainer != IntPtr.Zero) { Marshal.Release(selectionContainer); } } }); }
public void TestSccMenuCommands() { int result = 0; Guid badGuid = new Guid(); Guid guidCmdGroup = GuidList.guidSccProviderCmdSet; OLECMD[] cmdAddToScc = new OLECMD[1]; cmdAddToScc[0].cmdID = CommandId.icmdAddToSourceControl; OLECMD[] cmdCheckin = new OLECMD[1]; cmdCheckin[0].cmdID = CommandId.icmdCheckin; OLECMD[] cmdCheckout = new OLECMD[1]; cmdCheckout[0].cmdID = CommandId.icmdCheckout; OLECMD[] cmdUseSccOffline = new OLECMD[1]; cmdUseSccOffline[0].cmdID = CommandId.icmdUseSccOffline; OLECMD[] cmdViewToolWindow = new OLECMD[1]; cmdViewToolWindow[0].cmdID = CommandId.icmdViewToolWindow; OLECMD[] cmdToolWindowToolbarCommand = new OLECMD[1]; cmdToolWindowToolbarCommand[0].cmdID = CommandId.icmdToolWindowToolbarCommand; OLECMD[] cmdUnsupported = new OLECMD[1]; cmdUnsupported[0].cmdID = 0; // Initialize the provider, etc SccProviderService target = GetSccProviderServiceInstance; // Mock a service implementing IVsMonitorSelection BaseMock monitorSelection = MockIVsMonitorSelectionFactory.GetMonSel(); serviceProvider.AddService(typeof(IVsMonitorSelection), monitorSelection, true); // Commands that don't belong to our package should not be supported result = _sccProvider.QueryStatus(ref badGuid, 1, cmdAddToScc, IntPtr.Zero); Assert.AreEqual((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED, result); // The command should be invisible when there is no solution VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdAddToScc); // Activate the provider and test the result target.SetActive(); Assert.AreEqual(true, target.Active, "Microsoft.Samples.VisualStudio.SourceControlIntegration.SccProvider.SccProviderService.Active was not reported correctly."); // The commands should be invisible when there is no solution VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdUseSccOffline); // Commands that don't belong to our package should not be supported result = _sccProvider.QueryStatus(ref guidCmdGroup, 1, cmdUnsupported, IntPtr.Zero); Assert.AreEqual((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED, result); // Deactivate the provider and test the result target.SetInactive(); Assert.AreEqual(false, target.Active, "Microsoft.Samples.VisualStudio.SourceControlIntegration.SccProvider.SccProviderService.Active was not reported correctly."); // Create a solution solution.SolutionFile = Path.GetTempFileName(); MockIVsProject project = new MockIVsProject(Path.GetTempFileName()); project.AddItem(Path.GetTempFileName()); solution.AddProject(project); // The commands should be invisible when the provider is not active VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdUseSccOffline); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdViewToolWindow); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdToolWindowToolbarCommand); // Activate the provider and test the result target.SetActive(); Assert.AreEqual(true, target.Active, "Microsoft.Samples.VisualStudio.SourceControlIntegration.SccProvider.SccProviderService.Active was not reported correctly."); // The command should be visible but disabled now, except the toolwindow ones VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdViewToolWindow); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdToolWindowToolbarCommand); // Set selection to solution node VSITEMSELECTION selSolutionRoot; selSolutionRoot.pHier = _solution as IVsHierarchy; selSolutionRoot.itemid = VSConstants.VSITEMID_ROOT; monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot }; // The add command should be available, rest should be disabled VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Still solution hierarchy, but other way selSolutionRoot.pHier = null; selSolutionRoot.itemid = VSConstants.VSITEMID_ROOT; monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot }; // The add command should be available, rest should be disabled VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Set selection to project node VSITEMSELECTION selProjectRoot; selProjectRoot.pHier = project as IVsHierarchy; selProjectRoot.itemid = VSConstants.VSITEMID_ROOT; monitorSelection["Selection"] = new VSITEMSELECTION[] { selProjectRoot }; // The add command should be available, rest should be disabled VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Set selection to project item VSITEMSELECTION selProjectItem; selProjectItem.pHier = project as IVsHierarchy; selProjectItem.itemid = 0; monitorSelection["Selection"] = new VSITEMSELECTION[] { selProjectItem }; // The add command should be available, rest should be disabled VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Set selection to project and item node and add project to scc monitorSelection["Selection"] = new VSITEMSELECTION[] { selProjectRoot, selProjectItem }; VerifyCommandExecution(cmdAddToScc); // The add command and checkin should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdUseSccOffline); // Checkout the project VerifyCommandExecution(cmdCheckout); // The add command and checkout should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdUseSccOffline); // Select the solution monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot }; // The checkout and offline should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Checkin the project VerifyCommandExecution(cmdCheckin); // The add command and checkout should be enabled, rest should be disabled VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Add the solution to scc VerifyCommandExecution(cmdAddToScc); // The add command and checkin should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdUseSccOffline); // Select the solution and project monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot, selProjectRoot }; // Take the project and solution offline VerifyCommandExecution(cmdUseSccOffline); // The offline command should be latched VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_LATCHED, cmdUseSccOffline); // Select the solution only monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot}; // Take the solution online VerifyCommandExecution(cmdUseSccOffline); // The offline command should be normal again VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdUseSccOffline); // Select the solution and project monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot, selProjectRoot }; // The offline command should be disabled for mixed selection VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Add a new item to the project project.AddItem(Path.GetTempFileName()); // Select the new item selProjectItem.pHier = project as IVsHierarchy; selProjectItem.itemid = 1; monitorSelection["Selection"] = new VSITEMSELECTION[] { selProjectItem }; // The add command and checkout should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_LATCHED, cmdUseSccOffline); // Checkin the new file (this should do an add) VerifyCommandExecution(cmdCheckin); // The add command and checkout should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_LATCHED, cmdUseSccOffline); }
private void UpdateNode(VSITEMSELECTION vsItemSel) { try { var sccProject2 = vsItemSel.pHier as IVsSccProject2; var rgpszFullPaths = new string[1]; vsItemSel.pHier.GetCanonicalName(vsItemSel.itemid, out rgpszFullPaths[0]); var rgsiGlyphs = new VsStateIcon[1]; var rgdwSccStatus = new uint[1]; this.GetSccGlyph(1, rgpszFullPaths, rgsiGlyphs, rgdwSccStatus); var rguiAffectedNodes = new uint[] { vsItemSel.itemid }; sccProject2.SccGlyphChanged(1, rguiAffectedNodes, rgsiGlyphs, rgdwSccStatus); } catch (Exception e) { e.ToString(); } }
private static bool IsCommandDisabledForFile(VSITEMSELECTION? item) { if (item.Value.IsFile() && String.Equals(Path.GetExtension(item.Value.GetCanonicalName()), ".py", StringComparison.OrdinalIgnoreCase)) { return false; } return true; }
private static ProjectKind GetProjectKind(VSITEMSELECTION? item) { if (item == null) { throw new InvalidOperationException(); } string projectTypeGuids; ErrorHandler.ThrowOnFailure( ((IVsAggregatableProject)item.Value.pHier).GetAggregateProjectTypeGuids(out projectTypeGuids) ); var guidStrs = projectTypeGuids.Split(';'); foreach (var guidStr in guidStrs) { Guid projectGuid; if (Guid.TryParse(guidStr, out projectGuid)) { if (projectGuid == GuidList.FlaskGuid) { return ProjectKind.Flask; } else if (projectGuid == GuidList.BottleGuid) { return ProjectKind.Bottle; } else if (projectGuid == GuidList.DjangoGuid) { return ProjectKind.Django; } else if (projectGuid == GuidList.WorkerRoleGuid) { return ProjectKind.Worker; } } } return ProjectKind.None; }
private void ValidateReferences() { // can happen when project is unloaded and reloaded or in venus (aspx) case if (_filePathOpt == null || _binOutputPathOpt == null || _objOutputPathOpt == null) { return; } object property = null; if (ErrorHandler.Failed(_hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out property))) { return; } var dteProject = property as EnvDTE.Project; if (dteProject == null) { return; } var vsproject = dteProject.Object as VSProject; if (vsproject == null) { return; } var noReferenceOutputAssemblies = new List<string>(); var factory = this.ServiceProvider.GetService(typeof(SVsEnumHierarchyItemsFactory)) as IVsEnumHierarchyItemsFactory; IEnumHierarchyItems items; if (ErrorHandler.Failed(factory.EnumHierarchyItems(_hierarchy, (uint)__VSEHI.VSEHI_Leaf, (uint)VSConstants.VSITEMID.Root, out items))) { return; } uint fetched; VSITEMSELECTION[] item = new VSITEMSELECTION[1]; while (ErrorHandler.Succeeded(items.Next(1, item, out fetched)) && fetched == 1) { // ignore ReferenceOutputAssembly=false references since those will not be added to us in design time. var storage = _hierarchy as IVsBuildPropertyStorage; string value; storage.GetItemAttribute(item[0].itemid, "ReferenceOutputAssembly", out value); object caption; _hierarchy.GetProperty(item[0].itemid, (int)__VSHPROPID.VSHPROPID_Caption, out caption); if (string.Equals(value, "false", StringComparison.OrdinalIgnoreCase) || string.Equals(value, "off", StringComparison.OrdinalIgnoreCase) || string.Equals(value, "0", StringComparison.OrdinalIgnoreCase)) { noReferenceOutputAssemblies.Add((string)caption); } } var delta = vsproject.References.Count - noReferenceOutputAssemblies.Count - (_projectReferences.Count + _metadataReferences.Count); if (delta == 0) { return; } // okay, two has different set of dlls referenced. check special Microsoft.VisualBasic case. if (delta != 1) { //// Contract.Requires(false, "different set of references!!!"); return; } var set = new HashSet<string>(vsproject.References.OfType<Reference>().Select(r => PathUtilities.IsAbsolute(r.Name) ? Path.GetFileNameWithoutExtension(r.Name) : r.Name), StringComparer.OrdinalIgnoreCase); set.ExceptWith(noReferenceOutputAssemblies); set.ExceptWith(_projectReferences.Select(r => ProjectTracker.GetProject(r.ProjectId).DisplayName)); set.ExceptWith(_metadataReferences.Select(m => Path.GetFileNameWithoutExtension(m.FilePath))); //// Contract.Requires(set.Count == 1); var reference = set.First(); if (!string.Equals(reference, "Microsoft.VisualBasic", StringComparison.OrdinalIgnoreCase)) { //// Contract.Requires(false, "unknown new reference " + reference); return; } #if DEBUG // when we are missing microsoft.visualbasic reference, make sure we have embedded vb core option on. Contract.Requires(Debug_VBEmbeddedCoreOptionOn); #endif }
internal static VSITEMSELECTION GetParent(this VSITEMSELECTION vsItemSelection) { object parent; ErrorHandler.ThrowOnFailure( vsItemSelection.pHier.GetProperty( vsItemSelection.itemid, (int)__VSHPROPID.VSHPROPID_Parent, out parent ) ); var res = new VSITEMSELECTION(); var i = parent as int?; if (i.HasValue) { res.itemid = (uint)i.GetValueOrDefault(); } else { var ip = parent as IntPtr?; res.itemid = (uint)ip.GetValueOrDefault().ToInt32(); } res.pHier = vsItemSelection.pHier; return res; }
private static bool IsCommandDisabledForFolder(VSITEMSELECTION? item) { if (item.Value.IsFolder()) { return false; } return true; }
int IVsSimpleObjectList2.GetMultipleSourceItems(uint index, uint grfGSI, uint cItems, VSITEMSELECTION[] rgItemSel) { return VSConstants.E_NOTIMPL; }
DataObject PackageSelectionDataObject(bool cutHighlightItems){ CleanupSelectionDataObject(false, false, false); IVsUIHierarchyWindow w = this.projectMgr.GetIVsUIHierarchyWindow(VsConstants.Guid_SolutionExplorer); IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution; IVsMonitorSelection ms = this.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection; IntPtr psel; IVsMultiItemSelect itemSelect; IntPtr psc; uint vsitemid; StringBuilder sb = new StringBuilder(); ms.GetCurrentSelection(out psel, out vsitemid, out itemSelect, out psc); IVsHierarchy sel = (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(psel, typeof(IVsHierarchy)); ISelectionContainer sc = (ISelectionContainer)Marshal.GetTypedObjectForIUnknown(psc, typeof(ISelectionContainer)); const uint GSI_fOmitHierPtrs = 0x00000001; if ((sel != (IVsHierarchy)this) || (vsitemid == VsConstants.VSITEMID_ROOT) || (vsitemid == VsConstants.VSITEMID_NIL)) throw new InvalidOperationException(); if ((vsitemid == VsConstants.VSITEMID_SELECTION) && (itemSelect != null)){ int singleHierarchy; uint pcItems; itemSelect.GetSelectionInfo(out pcItems, out singleHierarchy); if (singleHierarchy != 0) // "!BOOL" == "!= 0" ? throw new InvalidOperationException(); this.itemsDragged = new ArrayList(); VSITEMSELECTION[] items = new VSITEMSELECTION[pcItems]; itemSelect.GetSelectedItems(GSI_fOmitHierPtrs, pcItems, items); for (uint i = 0; i < pcItems; i++){ if (items[i].itemid == VsConstants.VSITEMID_ROOT){ this.itemsDragged.Clear();// abort break; } this.itemsDragged.Add(items[i].pHier); string projref; solution.GetProjrefOfItem((IVsHierarchy)this, items[i].itemid, out projref); if ((projref == null) || (projref.Length == 0)){ this.itemsDragged.Clear(); // abort break; } sb.Append(projref); sb.Append('\0'); // separated by nulls. } } else if (vsitemid != VsConstants.VSITEMID_ROOT){ this.itemsDragged = new ArrayList(); this.itemsDragged.Add(this.projectMgr.NodeFromItemId(vsitemid)); string projref; solution.GetProjrefOfItem((IVsHierarchy)this, vsitemid, out projref); sb.Append(projref); } if (sb.ToString() == "" || this.itemsDragged.Count == 0) return null; sb.Append('\0'); // double null at end. _DROPFILES df = new _DROPFILES(); int dwSize = Marshal.SizeOf(df); Int16 wideChar = 0; int dwChar = Marshal.SizeOf(wideChar); IntPtr ptr = Marshal.AllocHGlobal(dwSize + ((sb.Length + 1) * dwChar)); df.pFiles = dwSize; df.fWide = 1; IntPtr data = DataObject.GlobalLock(ptr); Marshal.StructureToPtr(df, data, false); IntPtr strData = new IntPtr((long)data + dwSize); DataObject.CopyStringToHGlobal(sb.ToString(), strData); DataObject.GlobalUnLock(data); DataObject dobj = new DataObject(); FORMATETC fmt = DragDropHelper.CreateFormatEtc(); dobj.SetData(fmt, ptr); if (cutHighlightItems){ bool first = true; foreach (HierarchyNode node in this.itemsDragged){ w.ExpandItem((IVsUIHierarchy)this.projectMgr, node.hierarchyId, first ? EXPANDFLAGS.EXPF_CutHighlightItem : EXPANDFLAGS.EXPF_AddCutHighlightItem); first = false; } } return dobj; }
internal static Guid GetItemType(VSITEMSELECTION vsItemSelection) { Guid typeGuid; try { ErrorHandler.ThrowOnFailure( vsItemSelection.pHier.GetGuidProperty( vsItemSelection.itemid, (int)__VSHPROPID.VSHPROPID_TypeGuid, out typeGuid ) ); } catch (System.Runtime.InteropServices.COMException) { return Guid.Empty; } return typeGuid; }
/// <summary> /// Gets the list of selected HierarchyNode objects /// </summary> /// <returns>A list of HierarchyNode objects</returns> protected internal virtual IList<HierarchyNode> GetSelectedNodes() { // Retrieve shell interface in order to get current selection IVsMonitorSelection monitorSelection = this.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection; if (monitorSelection == null) { throw new InvalidOperationException(); } List<HierarchyNode> selectedNodes = new List<HierarchyNode>(); IntPtr hierarchyPtr = IntPtr.Zero; IntPtr selectionContainer = IntPtr.Zero; try { // Get the current project hierarchy, project item, and selection container for the current selection // If the selection spans multiple hierachies, hierarchyPtr is Zero uint itemid; IVsMultiItemSelect multiItemSelect = null; ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainer)); // We only care if there are one ore more nodes selected in the tree if (itemid != VSConstants.VSITEMID_NIL && hierarchyPtr != IntPtr.Zero) { IVsHierarchy hierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy; if (itemid != VSConstants.VSITEMID_SELECTION) { // This is a single selection. Compare hirarchy with our hierarchy and get node from itemid if (Utilities.IsSameComObject(this, hierarchy)) { HierarchyNode node = this.NodeFromItemId(itemid); if (node != null) { selectedNodes.Add(node); } } else { NestedProjectNode node = this.GetNestedProjectForHierarchy(hierarchy); if (node != null) { selectedNodes.Add(node); } } } else if (multiItemSelect != null) { // This is a multiple item selection. //Get number of items selected and also determine if the items are located in more than one hierarchy uint numberOfSelectedItems; int isSingleHierarchyInt; ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt)); bool isSingleHierarchy = (isSingleHierarchyInt != 0); // Now loop all selected items and add to the list only those that are selected within this hierarchy if (!isSingleHierarchy || (isSingleHierarchy && Utilities.IsSameComObject(this, hierarchy))) { Debug.Assert(numberOfSelectedItems > 0, "Bad number of selected itemd"); VSITEMSELECTION[] vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems]; uint flags = (isSingleHierarchy) ? (uint)__VSGSIFLAGS.GSI_fOmitHierPtrs : 0; ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(flags, numberOfSelectedItems, vsItemSelections)); foreach (VSITEMSELECTION vsItemSelection in vsItemSelections) { if (isSingleHierarchy || Utilities.IsSameComObject(this, vsItemSelection.pHier)) { HierarchyNode node = this.NodeFromItemId(vsItemSelection.itemid); if (node != null) { selectedNodes.Add(node); } } } } } } } finally { if (hierarchyPtr != IntPtr.Zero) { Marshal.Release(hierarchyPtr); } if (selectionContainer != IntPtr.Zero) { Marshal.Release(selectionContainer); } } return selectedNodes; }
/// <summary> /// Gets the list of directly selected VSITEMSELECTION objects /// </summary> /// <returns>A list of VSITEMSELECTION objects</returns> private IList<VSITEMSELECTION> GetSelectedNodes() { // Retrieve shell interface in order to get current selection IVsMonitorSelection monitorSelection = _sccProvider.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection; Debug.Assert(monitorSelection != null, "Could not get the IVsMonitorSelection object from the services exposed by this project"); if (monitorSelection == null) { throw new InvalidOperationException(); } List<VSITEMSELECTION> selectedNodes = new List<VSITEMSELECTION>(); IntPtr hierarchyPtr = IntPtr.Zero; IntPtr selectionContainer = IntPtr.Zero; try { // Get the current project hierarchy, project item, and selection container for the current selection // If the selection spans multiple hierachies, hierarchyPtr is Zero uint itemid; IVsMultiItemSelect multiItemSelect = null; ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainer)); if (itemid != VSConstants.VSITEMID_SELECTION) { // We only care if there are nodes selected in the tree if (itemid != VSConstants.VSITEMID_NIL) { if (hierarchyPtr == IntPtr.Zero) { // Solution is selected VSITEMSELECTION vsItemSelection; vsItemSelection.pHier = null; vsItemSelection.itemid = itemid; selectedNodes.Add(vsItemSelection); } else { IVsHierarchy hierarchy = (IVsHierarchy)Marshal.GetObjectForIUnknown(hierarchyPtr); // Single item selection VSITEMSELECTION vsItemSelection; vsItemSelection.pHier = hierarchy; vsItemSelection.itemid = itemid; selectedNodes.Add(vsItemSelection); } } } else { if (multiItemSelect != null) { // This is a multiple item selection. //Get number of items selected and also determine if the items are located in more than one hierarchy uint numberOfSelectedItems; int isSingleHierarchyInt; ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt)); bool isSingleHierarchy = (isSingleHierarchyInt != 0); // Now loop all selected items and add them to the list Debug.Assert(numberOfSelectedItems > 0, "Bad number of selected itemd"); if (numberOfSelectedItems > 0) { VSITEMSELECTION[] vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems]; ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(0, numberOfSelectedItems, vsItemSelections)); foreach (VSITEMSELECTION vsItemSelection in vsItemSelections) { selectedNodes.Add(vsItemSelection); } } } } } finally { if (hierarchyPtr != IntPtr.Zero) { Marshal.Release(hierarchyPtr); } if (selectionContainer != IntPtr.Zero) { Marshal.Release(selectionContainer); } } return selectedNodes; }
/// <summary> /// Enumerate all hierarchy project items recursively traversing nested hierarchies. /// </summary> private List<VSITEMSELECTION> GetAllItems(Func<VSITEMSELECTION, bool> where) { //Get the solution service so we can traverse each project hierarchy contained within. IVsSolution solution = (IVsSolution)this.Package.GetService<SVsSolution>(); var items = new List<VSITEMSELECTION>(); if (null != solution) { IVsHierarchy solutionHierarchy = solution as IVsHierarchy; if (null != solutionHierarchy) { Action<IVsHierarchy, uint, int> action = delegate(IVsHierarchy hier, uint itemid, int recursion) { var item = new VSITEMSELECTION(); item.pHier = hier; item.itemid = itemid; if(where == null || where(item)) items.Add(item); }; this.EnumHierarchyItems(solutionHierarchy, VSConstants.VSITEMID_ROOT, 0, true, false, action); } } return items; }
internal static EnvDTE.ProjectItem GetExtensionObject(VSITEMSELECTION selection) { object project; ErrorHandler.ThrowOnFailure( selection.pHier.GetProperty( selection.itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out project ) ); return (project as EnvDTE.ProjectItem); }
/// <summary> /// Returns the ItemID corresponding to source files for the given list item if more than one. /// </summary> /// <param name="index"></param> /// <param name="grfGSI"></param> /// <param name="cItems"></param> /// <param name="rgItemSel"></param> /// <returns></returns> public int GetMultipleSourceItems(uint index, uint grfGSI, uint cItems, VSITEMSELECTION[] rgItemSel) { throw new NotImplementedException(); }
internal static EnvDTE.ProjectItems GetProjectItems(VSITEMSELECTION selection) { object project; ErrorHandler.ThrowOnFailure( selection.pHier.GetProperty( selection.itemid, (int)__VSHPROPID.VSHPROPID_ExtObject, out project ) ); if (project is EnvDTE.ProjectItem) { return ((EnvDTE.ProjectItem)project).ProjectItems; } return ((EnvDTE.Project)project).ProjectItems; }
public static VSITEMSELECTION GetSelectedSourceImage(this IVsMonitorSelection monitorSelection) { VSITEMSELECTION sel = new VSITEMSELECTION(); if (monitorSelection != null) { IntPtr hierarchyPtr = IntPtr.Zero; IntPtr selectionContainerPtr = IntPtr.Zero; try { IVsMultiItemSelect multiSelect; if (monitorSelection.GetCurrentSelection(out hierarchyPtr, out sel.itemid, out multiSelect, out selectionContainerPtr) >= 0) { sel.pHier = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy; if (sel.pHier != null && multiSelect != null) { uint items; int singleHierarchy; if (multiSelect.GetSelectionInfo(out items, out singleHierarchy) >= 0 && items != 1) { // Must have only one item selected sel.pHier = null; } } } } finally { if (hierarchyPtr != IntPtr.Zero) { Marshal.Release(hierarchyPtr); hierarchyPtr = IntPtr.Zero; } if (selectionContainerPtr != IntPtr.Zero) { Marshal.Release(selectionContainerPtr); selectionContainerPtr = IntPtr.Zero; } } } bool isImage = false; if (sel.pHier != null) { object nameObj; if (sel.pHier.GetProperty(sel.itemid, (int)__VSHPROPID.VSHPROPID_Name, out nameObj) >= 0) { isImage = ImageHelpers.IsSourceImageFile(nameObj as string); } } if (!isImage) { sel = new VSITEMSELECTION(); } return sel; }
public int GetSelectedItems(uint grfGSI, uint cItems, VSITEMSELECTION[] rgItemSel) { var flags = (__VSGSIFLAGS)grfGSI; for (int i = 0; i < cItems && i < _items.Length; i++) { rgItemSel[i].itemid = _items[i].ItemId; if (!flags.HasFlag(__VSGSIFLAGS.GSI_fOmitHierPtrs)) { rgItemSel[i].pHier = _items[i].Hierarchy; } } return VSConstants.S_OK; }
private void RefreshSourceControlGlyphs(VSITEMSELECTION node) { var project = node.pHier as IVsSccProject2; if (project != null) { // Refresh all the glyphs in the project; the project will call back GetSccGlyphs() // with the files for each node that will need new glyph project.SccGlyphChanged(0, null, null, null); } else if (node.itemid == VSConstants.VSITEMID_ROOT) { // Note: The solution's hierarchy does not implement IVsSccProject2, IVsSccProject interfaces // It may be a pain to treat the solution as special case everywhere; a possible workaround is // to implement a solution-wrapper class, that will implement IVsSccProject2, IVsSccProject and // IVsHierarhcy interfaces, and that could be used in provider's code wherever a solution is needed. // This approach could unify the treatment of solution and projects in the provider's code. // Until then, solution is treated as special case var sccService = _serviceProvider.GetService<SourceControlProvider>(); string directory, fileName, userFile; ErrorHandler.ThrowOnFailure(_vsSolution.GetSolutionInfo(out directory, out fileName, out userFile)); var rgpszFullPaths = new[] {fileName}; var rgsiGlyphs = new VsStateIcon[1]; sccService.GetSccGlyph(1, rgpszFullPaths, rgsiGlyphs, new uint[1]); // Set the solution's glyph directly in the hierarchy ((IVsHierarchy)_vsSolution).SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_StateIconIndex, rgsiGlyphs[0]); } }
/// <summary> /// Builds a list of nodes currently selected in the solution explorer /// </summary> /// <returns></returns> public List<ItemNode> GetSelectedNodes() { var selected_nodes = new List<ItemNode>(); IntPtr hierarchyPtr = IntPtr.Zero; IntPtr selectionContainer = IntPtr.Zero; try { // Get the current project hierarchy, project item, and selection container for the current selection // If the selection spans multiple hierachies, hierarchyPtr is Zero uint itemid; IVsMultiItemSelect multiItemSelect = null; ErrorHandler.ThrowOnFailure(GlobalServices.SelectionMonitor.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainer)); // We only care if there are one ore more nodes selected in the tree if (itemid != VSConstants.VSITEMID_NIL && hierarchyPtr != IntPtr.Zero) { IVsHierarchy hierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy; if (itemid != VSConstants.VSITEMID_SELECTION) { // This is a single selection. Compare hirarchy with our hierarchy and get node from itemid ItemNode node; if (GlobalServices.IsSameComObject(Project, hierarchy) && itemMap.TryGetValue(itemid, out node)) { selected_nodes.Add(node); } } else if (multiItemSelect != null) { // This is a multiple item selection. //Get number of items selected and also determine if the items are located in more than one hierarchy uint numberOfSelectedItems; int isSingleHierarchyInt; ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt)); bool isSingleHierarchy = (isSingleHierarchyInt != 0); // Now loop all selected items and add to the list only those that are selected within this hierarchy if (!isSingleHierarchy || (isSingleHierarchy && GlobalServices.IsSameComObject(Project, hierarchy))) { Debug.Assert(numberOfSelectedItems > 0, "Bad number of selected items"); VSITEMSELECTION[] vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems]; uint flags = (isSingleHierarchy) ? (uint)__VSGSIFLAGS.GSI_fOmitHierPtrs : 0; ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(flags, numberOfSelectedItems, vsItemSelections)); foreach (VSITEMSELECTION vsItemSelection in vsItemSelections) { if (isSingleHierarchy || GlobalServices.IsSameComObject(Project, vsItemSelection.pHier)) { ItemNode node; if (itemMap.TryGetValue(vsItemSelection.itemid, out node)) { selected_nodes.Add(node); } } } } } } } finally { if (hierarchyPtr != IntPtr.Zero) { Marshal.Release(hierarchyPtr); } if (selectionContainer != IntPtr.Zero) { Marshal.Release(selectionContainer); } } return selected_nodes; }
internal static string Name(VSITEMSELECTION item) { return GetItemName(item.pHier, item.itemid); }