Esempio n. 1
0
        public void centerLine(int nNum)
        {
            ///VSAnything 窗口是否为autoHIde
            bool bIsAutoHide = false;

            ToolWindowPane window = VSAnythingPackage.Inst.FindToolWindow(typeof(FastFindToolWindowPane), 0, true);

            if (window != null && window.Frame != null)
            {
                Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame frame = (Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame)window.Frame;
                if (frame != null && frame.IsVisible() == 0) // 0 is visible !!!
                {
                    object currentFrameMode;

                    frame.GetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, out currentFrameMode);
                    if ((VsFrameMode)currentFrameMode == VsFrameMode.AutoHide)
                    {
                        bIsAutoHide = true;
                    }
                }

                IVsTextView textViewCurrent;
                var         txtMngr = (IVsTextManager)VSAnythingPackage.Inst.GetService(typeof(SVsTextManager));
                txtMngr.GetActiveView(1, null, out textViewCurrent);

                /// 如果VSAnything窗口不是autoHide,简单地把改行滚动到Editor中间即可
                /// 但是在autoHide情况下,即使滚动到Editor中间,也可能被挡住。得计算出Editor的可视区域,将line滚到中间
                if (!bIsAutoHide)
                {
                    textViewCurrent.CenterLines(nNum, 1);
                }
                else
                {
                    int nMin;       // 当前页滚动条最小值
                    int nMax;       // 当前页滚动条最大值
                    int nPerPage;   // 当前页的高度等于多少滚动值
                    int nCurPos;    // 当前滚动条所在位置,能展示的区域为 [nCurPos,nCurPos + nPerPage],即一页的内容

                    var scrollInfo = textViewCurrent.GetScrollInfo(1, out nMin, out nMax, out nPerPage, out nCurPos);

                    /// 获取VSAnything窗口大小,还需要加上toolbar高度
                    VSSETFRAMEPOS[] vars = new VSSETFRAMEPOS[20];
                    Guid            guid;
                    int             xToLeft, yToTop, width, height;

                    frame.GetFramePos(vars, out guid, out xToLeft, out yToTop, out width, out height);

                    /// todo ~~~
                    TextDocument text_doc = this.m_DTE.ActiveDocument.Object("") as TextDocument;
                    if (text_doc != null)
                    {
                    }
                    ////// todo ~~~
                    textViewCurrent.CenterLines(nNum, 1);
                    //////
                }
            }
        }
        private void WindowActivated(Window GotFocus, Window LostFocus)
        {
            if (GotFocus.Caption == VSAnythingPackage.m_ProductName)
            {
                //this.m_FastFindWindowCmd.SelectText(false);
            }
            string doc_name = null;

            if (GotFocus != null && GotFocus.Document != null)
            {
                doc_name = Utils.NormalisePathAndLowerCase(GotFocus.Document.FullName);
            }
            VSAnythingPackage.ActivateDocEvent active_doc_event = this.GetActivateDocEvent(doc_name);
            if (active_doc_event != null && Utils.NormalisePathAndLowerCase(this.m_DTE.GetActiveDocumentFilename()) == active_doc_event.m_Filename && active_doc_event.m_SetLine)
            {
                if (active_doc_event.m_Line != -1)
                {
                    this.m_DTE.SetActiveDocumentLine(active_doc_event.m_Line);
                    /// 通过ListBox打开文档后,把焦点拿回来,否则在非autoHide 情况下,界面不会关掉,很烦
                    ToolWindowPane window = VSAnythingPackage.Inst.FindToolWindow(typeof(FastFindToolWindowPane), 0, true);
                    if (window != null && window.Frame != null)
                    {
                        Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame frame = (Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame)window.Frame;
                        if (frame != null && frame.IsVisible() == 0) // 0 is visible !!!
                        {
                            frame.Show();
                        }
                    }
                }
                active_doc_event.m_SetLine = false;
            }
            if (this.m_ForceActivateDocEvent != null && doc_name != this.m_ForceActivateDocEvent.m_Filename)
            {
                if (Environment.TickCount - this.m_ForceActivateDocEvent.m_RequestTime < 200 && this.m_ForceActivateDocCount > 0)
                {
                    this.m_ForceActivateDocCount--;
                    this.m_ForceActivateDocEvent.m_SetLine = true;
                    this.m_DTE.OpenFile(this.m_ForceActivateDocEvent.m_Filename);
                    return;
                }
                this.m_ForceActivateDocEvent = null;
            }
        }