Example #1
0
        public static IEnumerable <IVsWindowFrame> GetToolWindows(this IVsUIShell shell)
        {
            Contract.Requires <ArgumentNullException>(shell != null, "shell");
            Contract.Ensures(Contract.Result <IEnumerable <IVsWindowFrame> >() != null);

            IEnumWindowFrames frames;

            ErrorHandler.ThrowOnFailure(shell.GetToolWindowEnum(out frames));

            IVsWindowFrame[] array = new IVsWindowFrame[1];
            while (true)
            {
                uint count;
                int  hr = frames.Next((uint)array.Length, array, out count);
                ErrorHandler.ThrowOnFailure(hr);
                if (hr == VSConstants.S_FALSE || count == 0)
                {
                    break;
                }

                for (uint i = 0; i < count; i++)
                {
                    yield return(array[i]);
                }
            }
        }
Example #2
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);
        }
Example #4
0
        public static IEnumerable <IVsWindowFrame> GetToolWindows([NotNull] this IVsUIShell shell)
        {
            Requires.NotNull(shell, nameof(shell));

            IEnumWindowFrames frames;

            ErrorHandler.ThrowOnFailure(shell.GetToolWindowEnum(out frames));

            IVsWindowFrame[] array = new IVsWindowFrame[1];
            while (true)
            {
                uint count;
                int  hr = frames.Next((uint)array.Length, array, out count);
                ErrorHandler.ThrowOnFailure(hr);
                if (hr == VSConstants.S_FALSE || count == 0)
                {
                    break;
                }

                for (uint i = 0; i < count; i++)
                {
                    yield return(array[i]);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Retrieves captions and positions of all active tool windows
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<ToolWindowData> GetToolWindowData(IVsUIShell shell) {
            var data = new List<ToolWindowData>();
            try {
                IEnumWindowFrames e;
                shell.GetToolWindowEnum(out e);

                IVsWindowFrame[] frame = new IVsWindowFrame[1];
                uint fetched = 0;
                while (VSConstants.S_OK == e.Next(1, frame, out fetched) && fetched > 0) {
                    object objCaption;
                    frame[0].GetProperty((int)__VSFPROPID.VSFPROPID_Caption, out objCaption);

                    VSSETFRAMEPOS[] pos = new VSSETFRAMEPOS[1];
                    Guid relative;
                    int x, y, cx, cy;
                    frame[0].GetFramePos(pos, out relative, out x, out y, out cx, out cy);

                    var d = new ToolWindowData() {
                        Caption = objCaption as string,
                        X = x,
                        Y = y,
                        Width = cx,
                        Height = cy
                    };

                    data.Add(d);
                }
            } catch (Exception) { }

            return data;
        }
Example #6
0
        /// <summary>
        /// Retrieves captions and positions of all active tool windows
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <ToolWindowData> GetToolWindowData(IVsUIShell shell)
        {
            var data = new List <ToolWindowData>();

            try {
                IEnumWindowFrames e;
                shell.GetToolWindowEnum(out e);

                IVsWindowFrame[] frame   = new IVsWindowFrame[1];
                uint             fetched = 0;
                while (VSConstants.S_OK == e.Next(1, frame, out fetched) && fetched > 0)
                {
                    object objCaption;
                    frame[0].GetProperty((int)__VSFPROPID.VSFPROPID_Caption, out objCaption);

                    VSSETFRAMEPOS[] pos = new VSSETFRAMEPOS[1];
                    Guid            relative;
                    int             x, y, cx, cy;
                    frame[0].GetFramePos(pos, out relative, out x, out y, out cx, out cy);

                    var d = new ToolWindowData()
                    {
                        Caption = objCaption as string,
                        X       = x,
                        Y       = y,
                        Width   = cx,
                        Height  = cy
                    };

                    data.Add(d);
                }
            } catch (Exception) { }

            return(data);
        }
        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;
        }
Example #8
0
        /// <summary>
        /// returns an enumerable to both tool and document IVsWindowFrames
        /// </summary>
        /// <param name="package"></param>
        /// <returns></returns>
        public static List <IVsFrameView> GetIVsWindowFramesEnumerator(AsyncPackage package)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsUIShell          uiShell       = UtilityMethods.GetIVsUIShell(package);
            List <IVsFrameView> genericFrames = new List <IVsFrameView>();


            IEnumWindowFrames toolFramesEnum;

            ErrorHandler.ThrowOnFailure(uiShell.GetToolWindowEnum(out toolFramesEnum));
            genericFrames = ExtractFrames(toolFramesEnum).ToList();

            IEnumWindowFrames documentFramesEnum;

            ErrorHandler.ThrowOnFailure(uiShell.GetDocumentWindowEnum(out documentFramesEnum));
            genericFrames.AddRange(ExtractFrames(documentFramesEnum).ToList());

            return(genericFrames);
        }
        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;
        }