bool IsEmptySelectionContext(IVsTrackSelectionEx selCtx) { ThreadHelper.ThrowIfNotOnUIThread(); Validate.IsNotNull(selCtx, "selCtx"); IVsMonitorSelection2 monitorSelection2 = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection2; monitorSelection2.GetEmptySelectionContext(out var emptySelCtxt); return(ComUtilities.IsSameComObject(selCtx, emptySelCtxt)); }
/// <summary> /// Enumerate the window frames looking for the owner of the context /// </summary> /// <param name="selCtx"></param> /// <returns></returns> object GetContextOwner(IVsTrackSelectionEx selCtx) { ThreadHelper.ThrowIfNotOnUIThread(); if (selCtx == null) { return(null); } // No frame owns the empty selection context, just return it as its own owner. if (IsEmptySelectionContext(selCtx)) { return(selCtx); } IVsUIShell4 shell4 = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell4; Guid trackSelectionExServiceGuid = typeof(SVsTrackSelectionEx).GUID; Guid trackSelecitonExGuid = typeof(IVsTrackSelectionEx).GUID; shell4.GetWindowEnum((uint)__WindowFrameTypeFlags.WINDOWFRAMETYPE_All, out var frameEnum); foreach (IVsWindowFrame frame in ComUtilities.EnumerableFrom(frameEnum)) { if (ErrorHandler.Succeeded(frame.GetProperty((int)__VSFPROPID.VSFPROPID_SPFrame, out var frameServiceProvider)) && frameServiceProvider != null) { IntPtr pTrackSelection = IntPtr.Zero; try { if (ErrorHandler.Succeeded(((IOleServiceProvider)frameServiceProvider).QueryService(ref trackSelectionExServiceGuid, ref trackSelecitonExGuid, out pTrackSelection))) { IVsTrackSelectionEx frameCtx = Marshal.GetObjectForIUnknown(pTrackSelection) as IVsTrackSelectionEx; if (ComUtilities.IsSameComObject(selCtx, frameCtx)) { return(frame); } } } finally { if (pTrackSelection != IntPtr.Zero) { Marshal.Release(pTrackSelection); } } } } return(null); }
public int GetProjrefOfItem(IVsHierarchy pHierarchy, uint itemid, out string pbstrProjref) { foreach (var project in _projects) { if (ComUtilities.IsSameComObject(pHierarchy, project.Value.Hierarchy)) { ErrorHandler.ThrowOnFailure(project.Value.Hierarchy.GetCanonicalName(itemid, out global::System.String canonicalName)); pbstrProjref = project.Value.ProjectGuid.ToString("B") + "|" + project.Value.Filename + "|" + canonicalName; return(VSConstants.S_OK); } } pbstrProjref = null; return(VSConstants.E_FAIL); }
public void when_reopening_solution_then_vssolution_is_same() { var dte = GlobalServices.GetService <DTE>(); var solutionEmpty = GlobalServices.GetService <SVsSolution, IVsSolution>(); dte.Solution.Open(new FileInfo(Constants.SingleProjectSolution).FullName); var solution1 = GlobalServices.GetService <SVsSolution, IVsSolution>(); dte.Solution.Close(); dte.Solution.Open(new FileInfo(Constants.BlankSolution).FullName); var solution2 = GlobalServices.GetService <SVsSolution, IVsSolution>(); Assert.Same(solutionEmpty, solution1); Assert.Same(solution1, solution2); Assert.True(ComUtilities.IsSameComObject(solutionEmpty as IVsHierarchy, solution1 as IVsHierarchy)); Assert.True(ComUtilities.IsSameComObject(solution1 as IVsHierarchy, solution2 as IVsHierarchy)); }
public void when_selection_is_item_then_active_hierarchy_is_owning_project() { var library = fixture.Solution.FindProject(x => x.Text == "CsLibrary"); Assert.NotNull(library); var item = library.Nodes.OfType <IItemNode>().FirstOrDefault(); item.Select(); var active = explorer.Solution.ActiveProject; Assert.Equal(library, active); var selected = selection.GetSelection().FirstOrDefault(); var identity = item.As <IVsHierarchyItem>().HierarchyIdentity; Assert.True(ComUtilities.IsSameComObject(selected.Hierarchy, identity.Hierarchy)); Assert.Equal(selected.ItemID, identity.ItemID); }
public void when_reopening_solution_then_vssolution_is_same() { var dte = GlobalServices.GetService <DTE>(); var solutionEmpty = GlobalServices.GetService <SVsSolution, IVsSolution>(); var baseDir = Path.GetDirectoryName(GetType().Assembly.ManifestModule.FullyQualifiedName); dte.Solution.Open(Path.Combine(baseDir, Constants.SingleProjectSolution)); var solution1 = GlobalServices.GetService <SVsSolution, IVsSolution>(); dte.Solution.Close(); dte.Solution.Open(Path.Combine(baseDir, Constants.BlankSolution)); var solution2 = GlobalServices.GetService <SVsSolution, IVsSolution>(); Assert.Same(solutionEmpty, solution1); Assert.Same(solution1, solution2); Assert.True(ComUtilities.IsSameComObject(solutionEmpty as IVsHierarchy, solution1 as IVsHierarchy)); Assert.True(ComUtilities.IsSameComObject(solution1 as IVsHierarchy, solution2 as IVsHierarchy)); }