Пример #1
0
        public static Result <List <IVsWindowFrame> > GetDocumentWindowFrames(this IVsUIShell4 vsShell, __WindowFrameTypeFlags flags)
        {
            IEnumWindowFrames enumFrames;
            var hr = vsShell.GetWindowEnum((uint)flags, out enumFrames);

            return(ErrorHandler.Failed(hr) ? Result.CreateError(hr) : enumFrames.GetContents());
        }
Пример #2
0
        public static IEnumerable <IVsWindowFrame> EnumerateWindows(this IVsUIShell4 shell, __WindowFrameTypeFlags flags, Guid?windowGuid = null)
        {
            IEnumWindowFrames enumerator;

            ErrorHandler.ThrowOnFailure(shell.GetWindowEnum((uint)flags, out enumerator));

            var  frames  = new IVsWindowFrame[1];
            uint fetched = 0;

            while (VSConstants.S_OK == enumerator.Next(1, frames, out fetched) && fetched > 0)
            {
                var frame = frames[0];

                bool include = true;
                if (windowGuid.HasValue)
                {
                    Guid persist;
                    ErrorHandler.ThrowOnFailure(frame.GetGuidProperty((int)__VSFPROPID.VSFPROPID_GuidPersistenceSlot, out persist));
                    include = persist == windowGuid;
                }

                if (include)
                {
                    yield return(frame);
                }
            }
        }
Пример #3
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);
        }
Пример #4
0
        private IVsInfoBarHost GetInfoBarHost(string fileType)
        {
            IVsUIShell4       uiShell = _serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell4;
            IEnumWindowFrames windowEnumerator;

            uint flags = unchecked (((uint)(__WindowFrameTypeFlags.WINDOWFRAMETYPE_Document)));

            ErrorHandler.ThrowOnFailure(uiShell.GetWindowEnum(flags, out windowEnumerator));

            IVsWindowFrame[] frame   = new IVsWindowFrame[1];
            uint             fetched = 0;
            int hr = VSConstants.S_OK;

            // Note that we get S_FALSE when there is no more item, so only loop while we are getting S_OK
            while (hr == VSConstants.S_OK)
            {
                // For each tool window, add it to the list
                hr = windowEnumerator.Next(1, frame, out fetched);
                ErrorHandler.ThrowOnFailure(hr);
                if (fetched == 1)
                {
                    if (frame[0].IsVisible() == VSConstants.S_OK)
                    {
                        // We successfully retrieved a window frame, update our lists
                        object obj;
                        object caption;
                        frame[0].GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out obj);
                        frame[0].GetProperty((int)__VSFPROPID.VSFPROPID_Caption, out caption);

                        if (obj != null && caption != null && caption.ToString().Contains(fileType))
                        {
                            return((IVsInfoBarHost)obj);
                        }
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Update the content of the list by asking VS
        /// </summary>
        /// <returns></returns>
        public void RefreshList()
        {
            framesList      = new List <IVsWindowFrame>();
            toolWindowNames = new List <string>();

            // Get the UI Shell service
            IVsUIShell4 uiShell = (IVsUIShell4)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsUIShell));
            // Get the tool windows enumerator
            IEnumWindowFrames windowEnumerator;

            uint flags = unchecked (((uint)__WindowFrameTypeFlags.WINDOWFRAMETYPE_Tool | (uint)__WindowFrameTypeFlags.WINDOWFRAMETYPE_Uninitialized));

            ErrorHandler.ThrowOnFailure(uiShell.GetWindowEnum(flags, out windowEnumerator));

            IVsWindowFrame[] frame   = new IVsWindowFrame[1];
            uint             fetched = 0;
            int hr = VsConstants.S_OK;

            // Note that we get S_FALSE when there is no more item, so only loop while we are getting S_OK
            while (hr == VsConstants.S_OK)
            {
                // For each tool window, add it to the list
                hr = windowEnumerator.Next(1, frame, out fetched);
                ErrorHandler.ThrowOnFailure(hr);
                if (fetched == 1)
                {
                    if (frame[0].IsVisible() == VsConstants.S_OK)
                    {
                        // We successfully retrieved a window frame, update our lists
                        string caption = (string)GetProperty(frame[0], (int)__VSFPROPID.VSFPROPID_Caption);
                        toolWindowNames.Add(caption);
                        framesList.Add(frame[0]);
                    }
                }
            }
        }