コード例 #1
0
        /// <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);
        }
        private IVsHierarchy FindSharedProject()
        {
            var              sln   = (IVsSolution)this.GetService(typeof(SVsSolution));
            Guid             empty = Guid.Empty;
            IEnumHierarchies enumHiers;

            ErrorHandler.ThrowOnFailure(sln.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref empty, out enumHiers));

            foreach (IVsHierarchy hier in ComUtilities.EnumerableFrom(enumHiers))
            {
                if (PackageUtilities.IsCapabilityMatch(hier, "SharedAssetsProject"))
                {
                    return(hier);
                }
            }

            return(null);
        }
コード例 #3
0
        public WindowFramesCollection(bool showDocumentWindowFrames, bool showToolWindowFrames)
        {
            Shell.ThreadHelper.ThrowIfNotOnUIThread();
            if (Package.GetGlobalService(typeof(SVsUIShell)) is IVsUIShell uiShell)
            {
                if (showDocumentWindowFrames)
                {
                    int hr = uiShell.GetDocumentWindowEnum(out IEnumWindowFrames enumWindowFrames);
                    if (ErrorHandler.Succeeded(hr))
                    {
                        _vsWindowFrames = ComUtilities.EnumerableFrom(enumWindowFrames);
                    }
                }

                if (showToolWindowFrames)
                {
                    int hr = uiShell.GetToolWindowEnum(out IEnumWindowFrames enumWindowFrames);
                    if (ErrorHandler.Succeeded(hr))
                    {
                        _vsWindowFrames = _vsWindowFrames.Union(ComUtilities.EnumerableFrom(enumWindowFrames));
                    }
                }
            }
        }