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 #2
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);
            }