Exemple #1
0
        private bool IsImmediateWindow(IVsUIShell shellService, IVsTextView textView)
        {
            IEnumWindowFrames windowEnum = null;
            IVsTextLines      buffer     = null;

            Marshal.ThrowExceptionForHR(shellService.GetToolWindowEnum(out windowEnum));
            Marshal.ThrowExceptionForHR(textView.GetBuffer(out buffer));

            IVsWindowFrame[] frame = new IVsWindowFrame[1];
            uint             value;

            var immediateWindowGuid = Guid.Parse(ToolWindowGuids80.ImmediateWindow);

            while (windowEnum.Next(1, frame, out value) == VSConstants.S_OK)
            {
                Guid toolWindowGuid;
                Marshal.ThrowExceptionForHR(frame[0].GetGuidProperty((int)__VSFPROPID.VSFPROPID_GuidPersistenceSlot, out toolWindowGuid));
                if (toolWindowGuid == immediateWindowGuid)
                {
                    IntPtr frameTextView;
                    Marshal.ThrowExceptionForHR(frame[0].QueryViewInterface(typeof(IVsTextView).GUID, out frameTextView));
                    try
                    {
                        var immediateWindowTextView = Marshal.GetObjectForIUnknown(frameTextView) as IVsTextView;
                        return(textView == immediateWindowTextView);
                    }
                    finally
                    {
                        Marshal.Release(frameTextView);
                    }
                }
            }

            return(false);
        }
        internal static bool ContainsImmediateWindow(this IEnumerable <IVsTextView> vsTextViews, IVsUIShell shellService, IVsEditorAdaptersFactoryService _editorAdaptersFactoryService)
        {
            IEnumWindowFrames windowEnum = null;

            Marshal.ThrowExceptionForHR(shellService.GetToolWindowEnum(out windowEnum));

            IVsWindowFrame[] frame = new IVsWindowFrame[1];
            uint             value;

            var immediateWindowGuid = Guid.Parse(ToolWindowGuids80.ImmediateWindow);

            while (windowEnum.Next(1, frame, out value) == VSConstants.S_OK)
            {
                Guid toolWindowGuid;
                Marshal.ThrowExceptionForHR(frame[0].GetGuidProperty((int)__VSFPROPID.VSFPROPID_GuidPersistenceSlot, out toolWindowGuid));
                if (toolWindowGuid == immediateWindowGuid)
                {
                    IntPtr frameTextView;
                    Marshal.ThrowExceptionForHR(frame[0].QueryViewInterface(typeof(IVsTextView).GUID, out frameTextView));
                    try
                    {
                        var immediateWindowTextView    = Marshal.GetObjectForIUnknown(frameTextView) as IVsTextView;
                        var immediateWindowWpfTextView = _editorAdaptersFactoryService.GetWpfTextView(immediateWindowTextView);
                        return(vsTextViews.Any(vsTextView => _editorAdaptersFactoryService.GetWpfTextView(vsTextView) == immediateWindowWpfTextView));
                    }
                    finally
                    {
                        Marshal.Release(frameTextView);
                    }
                }
            }

            return(false);
        }
        public static Result <List <IVsWindowFrame> > GetContents(this IEnumWindowFrames enumFrames)
        {
            var list  = new List <IVsWindowFrame>();
            var array = new IVsWindowFrame[16];

            while (true)
            {
                uint num;
                var  hr = enumFrames.Next((uint)array.Length, array, out num);
                if (ErrorHandler.Failed(hr))
                {
                    return(Result.CreateError(hr));
                }

                if (0 == num)
                {
                    return(list);
                }

                for (var i = 0; i < num; i++)
                {
                    list.Add(array[i]);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// yield tool or document windows to an iterator
        /// </summary>
        /// <param name="frames">this set of tool or document windows</param>
        /// <returns></returns>
        private static IEnumerable <IVsFrameView> ExtractFrames(IEnumWindowFrames frames)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var frame = new IVsWindowFrame[1];
            int ok    = VSConstants.S_OK;

            while (ok == VSConstants.S_OK)
            {
                uint fetched;
                ok = frames.Next(1, frame, out fetched);
                ErrorHandler.ThrowOnFailure(ok);
                if (fetched == 1)
                {
                    yield return(new IVsFrameView(frame[0]));
                }
            }
        }