Example #1
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                Debug.Assert(disposing, "Finalizing a tool window without disposing.");
                if (disposing)
                {
                    if (!m_disposed)
                    {
                        VsShell.IVsWindowFrame frame = this.Frame;
                        if (frame != null)
                        {
                            ErrorHandler.ThrowOnFailure(frame.CloseFrame((uint)VsShell.__FRAMECLOSE.FRAMECLOSE_NoSave));
                        }

                        if (m_control != null)
                        {
                            m_control.Dispose();
                            m_control = null;
                        }

                        m_disposed = true;
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Example #2
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);
                    //////
                }
            }
        }
Example #3
0
        public List <string> GetDirtyFiles(Predicate <string> shouldHandle)
        {
            ArgumentValidation.CheckForNullReference(shouldHandle, "shouldHandle");

            var dirtyFiles = new List <string>();
            var rdt        = Instance.GetRunningDocumentTable();

            if (rdt != null)
            {
                // Get the UI Shell
                var uiShell = _uiShell;

                // Go through the open documents and find it
                VsShell.IEnumWindowFrames windowFramesEnum;
                ErrorHandler.ThrowOnFailure(uiShell.GetDocumentWindowEnum(out windowFramesEnum));
                var  windowFrames = new VsShell.IVsWindowFrame[1];
                uint fetched;
                while (windowFramesEnum.Next(1, windowFrames, out fetched) == VSConstants.S_OK &&
                       fetched == 1)
                {
                    var    windowFrame = windowFrames[0];
                    object data;
                    ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)VsShell.__VSFPROPID.VSFPROPID_DocData, out data));

                    var fileFormat = data as VsShell.IPersistFileFormat;
                    if (fileFormat != null)
                    {
                        string candidateFilename;
                        uint   formatIndex;
                        int    dirty;

                        // The binary editor returns notimpl for IsDirty so just continue if
                        // the interface returns E_NOTIMPL
                        var hr = fileFormat.IsDirty(out dirty);
                        if (hr == VSConstants.E_NOTIMPL)
                        {
                            continue;
                        }

                        ErrorHandler.ThrowOnFailure(hr);
                        if (dirty == 1)
                        {
                            NativeMethods.ThrowOnFailure(fileFormat.GetCurFile(out candidateFilename, out formatIndex));
                            if (string.IsNullOrEmpty(candidateFilename) == false
                                &&
                                shouldHandle(candidateFilename))
                            {
                                dirtyFiles.Add(candidateFilename);
                            }
                        }
                    }
                }
            }

            return(dirtyFiles);
        }
Example #4
0
        /// <summary>
        ///     Returns the window frame for our document window
        /// </summary>
        /// <returns>
        ///     The IWindowFrame for our open document.
        /// </returns>
        public VsShell.IVsWindowFrame GetWindowFrame(string fullFileName)
        {
            if (string.IsNullOrEmpty(fullFileName))
            {
                return(null);
            }

            VsShell.IVsWindowFrame foundFrame = null;

            var rdt = Instance.GetRunningDocumentTable();

            if (rdt != null)
            {
                // Get the UI Shell
                var uiShell = _uiShell;

                // Go through the open documents and find it
                VsShell.IEnumWindowFrames windowFramesEnum;
                ErrorHandler.ThrowOnFailure(uiShell.GetDocumentWindowEnum(out windowFramesEnum));
                var  windowFrames = new VsShell.IVsWindowFrame[1];
                uint fetched;
                var  thisFilename = fullFileName;

                while (windowFramesEnum.Next(1, windowFrames, out fetched) == VSConstants.S_OK &&
                       fetched == 1)
                {
                    var    windowFrame = windowFrames[0];
                    object data;
                    ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)VsShell.__VSFPROPID.VSFPROPID_DocData, out data));

                    var fileFormat = data as VsShell.IPersistFileFormat;
                    if (fileFormat != null)
                    {
                        string candidateFilename;
                        uint   formatIndex;

                        NativeMethods.ThrowOnFailure(fileFormat.GetCurFile(out candidateFilename, out formatIndex));
                        if (string.IsNullOrEmpty(candidateFilename) == false
                            &&
                            (string.Compare(candidateFilename, thisFilename, true, CultureInfo.CurrentCulture) == 0 ||
                             FileUtils.IsSamePath(candidateFilename, thisFilename)))
                        {
                            // Found it
                            foundFrame = windowFrame;
                            break;
                        }
                    }
                }
            }
            return(foundFrame);
        }
        /// <summary>
        /// Search for packages using the searchText.
        /// </summary>
        /// <param name="windowFrame">A window frame that hosts the PackageManagerControl.</param>
        /// <param name="searchText">Search text.</param>
        // private void Search(System.Windows.Window windowFrame, string searchText)
        private void Search(vsShellInterop.IVsWindowFrame windowFrame, string searchText)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (string.IsNullOrWhiteSpace(searchText))
            {
                return;
            }

            var packageManagerControl = VsUtility.GetPackageManagerControl(windowFrame);

            if (packageManagerControl != null)
            {
                packageManagerControl.Search(searchText);
            }
        }
        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;
            }
        }
Example #7
0
            public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
            {
                if (pguidCmdGroup == GuidList.guidPythonProfilingCmdSet)
                {
                    switch (nCmdID)
                    {
                    case PkgCmdIDList.cmdidOpenReport:
                        _node.OpenProfile(_itemid);
                        return(VSConstants.S_OK);

                    case PkgCmdIDList.cmdidPerfCtxSetAsCurrent:
                        _node._parent.SetActiveSession(_node);
                        return(VSConstants.S_OK);

                    case PkgCmdIDList.cmdidPerfCtxStartProfiling:
                        _node.StartProfiling();
                        return(VSConstants.S_OK);

                    case PkgCmdIDList.cmdidReportsCompareReports:
                        CompareReportsWindow compare;
                        if (_node.IsReportItem(_itemid))
                        {
                            var report = _node.GetReport(_itemid);
                            compare = new CompareReportsWindow(report.Filename);
                        }
                        else
                        {
                            compare = new CompareReportsWindow();
                        }

                        var cmpRes = compare.ShowDialog();
                        if (cmpRes != null && cmpRes.Value)
                        {
                            IVsUIShellOpenDocument sod = PythonProfilingPackage.GetGlobalService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
                            Debug.Assert(sod != null);
                            Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame frame = null;
                            Guid guid     = new Guid("{9C710F59-984F-4B83-B781-B6356C363B96}"); // performance diff guid
                            Guid guidNull = Guid.Empty;

                            sod.OpenSpecificEditor(
                                (uint)(_VSRDTFLAGS.RDT_CantSave | _VSRDTFLAGS.RDT_DontAddToMRU | _VSRDTFLAGS.RDT_NonCreatable | _VSRDTFLAGS.RDT_NoLock),
                                compare.ComparisonUrl,
                                ref guid,
                                null,
                                ref guidNull,
                                "Performance Comparison",
                                _node,
                                _itemid,
                                IntPtr.Zero,
                                null,
                                out frame
                                );

                            if (frame != null)
                            {
                                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(frame.Show());
                            }
                        }
                        return(VSConstants.S_OK);

                    case PkgCmdIDList.cmdidReportsAddReport:
                        var open = new OpenFileDialog();
                        open.Filter          = PythonProfilingPackage.PerformanceFileFilter;
                        open.CheckFileExists = true;
                        var res = open.ShowDialog();
                        if (res != null && res.Value)
                        {
                            _node.AddProfile(open.FileName);
                        }

                        return(VSConstants.S_OK);
                    }
                }
                else if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
                {
                    switch ((VSConstants.VSStd97CmdID)nCmdID)
                    {
                    case VSConstants.VSStd97CmdID.PropSheetOrProperties:
                        _node.OpenTargetProperties();
                        return(VSConstants.S_OK);
                    }
                }
                return((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED);
            }
Example #8
0
        /// <summary>
        ///     Returns the window frame for our document window
        /// </summary>
        /// <returns>
        ///     The IWindowFrame for our open document.
        /// </returns>
        public VsShell.IVsWindowFrame GetWindowFrame(string fullFileName)
        {
            if (string.IsNullOrEmpty(fullFileName))
            {
                return null;
            }

            VsShell.IVsWindowFrame foundFrame = null;

            var rdt = Instance.GetRunningDocumentTable();
            if (rdt != null)
            {
                // Get the UI Shell
                var uiShell = _uiShell;

                // Go through the open documents and find it
                VsShell.IEnumWindowFrames windowFramesEnum;
                ErrorHandler.ThrowOnFailure(uiShell.GetDocumentWindowEnum(out windowFramesEnum));
                var windowFrames = new VsShell.IVsWindowFrame[1];
                uint fetched;
                var thisFilename = fullFileName;

                while (windowFramesEnum.Next(1, windowFrames, out fetched) == VSConstants.S_OK
                       && fetched == 1)
                {
                    var windowFrame = windowFrames[0];
                    object data;
                    ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)VsShell.__VSFPROPID.VSFPROPID_DocData, out data));

                    var fileFormat = data as VsShell.IPersistFileFormat;
                    if (fileFormat != null)
                    {
                        string candidateFilename;
                        uint formatIndex;

                        NativeMethods.ThrowOnFailure(fileFormat.GetCurFile(out candidateFilename, out formatIndex));
                        if (string.IsNullOrEmpty(candidateFilename) == false
                            &&
                            (string.Compare(candidateFilename, thisFilename, true, CultureInfo.CurrentCulture) == 0 ||
                             FileUtils.IsSamePath(candidateFilename, thisFilename)))
                        {
                            // Found it
                            foundFrame = windowFrame;
                            break;
                        }
                    }
                }
            }
            return foundFrame;
        }
Example #9
0
        public List<string> GetDirtyFiles(Predicate<string> shouldHandle)
        {
            ArgumentValidation.CheckForNullReference(shouldHandle, "shouldHandle");

            var dirtyFiles = new List<string>();
            var rdt = Instance.GetRunningDocumentTable();
            if (rdt != null)
            {
                // Get the UI Shell
                var uiShell = _uiShell;

                // Go through the open documents and find it
                VsShell.IEnumWindowFrames windowFramesEnum;
                ErrorHandler.ThrowOnFailure(uiShell.GetDocumentWindowEnum(out windowFramesEnum));
                var windowFrames = new VsShell.IVsWindowFrame[1];
                uint fetched;
                while (windowFramesEnum.Next(1, windowFrames, out fetched) == VSConstants.S_OK
                       && fetched == 1)
                {
                    var windowFrame = windowFrames[0];
                    object data;
                    ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)VsShell.__VSFPROPID.VSFPROPID_DocData, out data));

                    var fileFormat = data as VsShell.IPersistFileFormat;
                    if (fileFormat != null)
                    {
                        string candidateFilename;
                        uint formatIndex;
                        int dirty;

                        // The binary editor returns notimpl for IsDirty so just continue if
                        // the interface returns E_NOTIMPL
                        var hr = fileFormat.IsDirty(out dirty);
                        if (hr == VSConstants.E_NOTIMPL)
                        {
                            continue;
                        }

                        ErrorHandler.ThrowOnFailure(hr);
                        if (dirty == 1)
                        {
                            NativeMethods.ThrowOnFailure(fileFormat.GetCurFile(out candidateFilename, out formatIndex));
                            if (string.IsNullOrEmpty(candidateFilename) == false
                                &&
                                shouldHandle(candidateFilename))
                            {
                                dirtyFiles.Add(candidateFilename);
                            }
                        }
                    }
                }
            }

            return dirtyFiles;
        }