Пример #1
0
        public static Microsoft.VisualStudio.Text.Editor.IWpfTextView GetActiveTextView(System.IServiceProvider serviceProvider)
        {
            var monitorSelection = (Microsoft.VisualStudio.Shell.Interop.IVsMonitorSelection)serviceProvider.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsShellMonitorSelection));

            if (monitorSelection == null)
            {
                return(null);
            }
            object curDocument;

            if (Microsoft.VisualStudio.ErrorHandler.Failed(monitorSelection.GetCurrentElementValue((uint)Microsoft.VisualStudio.VSConstants.VSSELELEMID.SEID_DocumentFrame, out curDocument)))
            {
                return(null);
            }

            Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame frame = curDocument as Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame;
            if (frame == null)
            {
                return(null);
            }

            object docView = null;

            if (Microsoft.VisualStudio.ErrorHandler.Failed(frame.GetProperty((int)Microsoft.VisualStudio.Shell.Interop.__VSFPROPID.VSFPROPID_DocView, out docView)))
            {
                return(null);
            }

            if (docView is Microsoft.VisualStudio.TextManager.Interop.IVsCodeWindow)
            {
                Microsoft.VisualStudio.TextManager.Interop.IVsTextView textView;
                if (Microsoft.VisualStudio.ErrorHandler.Failed(((Microsoft.VisualStudio.TextManager.Interop.IVsCodeWindow)docView).GetPrimaryView(out textView)))
                {
                    return(null);
                }

                var model          = (Microsoft.VisualStudio.ComponentModelHost.IComponentModel)serviceProvider.GetService(typeof(Microsoft.VisualStudio.ComponentModelHost.SComponentModel));
                var adapterFactory = model.GetService <Microsoft.VisualStudio.Editor.IVsEditorAdaptersFactoryService>();
                var wpfTextView    = adapterFactory.GetWpfTextView(textView);
                return(wpfTextView);
            }
            return(null);
        }
Пример #2
0
        public override int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            ProjectInfo projectInfo = ProjectInfo.FindProject(GetFullPathForDocument());

            if (projectInfo != null)
            {
                projectInfo.IsDocumentOpening = true;
            }

            try
            {
                return(base.OpenWithSpecific(editorFlags, ref editorType, physicalView, ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
            }
            finally
            {
                if (projectInfo != null)
                {
                    projectInfo.IsDocumentOpening = false;
                }
            }
        }
Пример #3
0
 public override int Open(ref Guid logicalView, IntPtr docDataExisting, out Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
 {
     return(base.Open(ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
 }
Пример #4
0
        public override int Open(bool newFile, bool openWith, ref Guid logicalView, IntPtr docDataExisting, out Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            //TODO: It's not best way to find project. NemerleFileDocumentManager must contain reference to ProjectInfo.
            ProjectInfo projectInfo = ProjectInfo.FindProject(GetFullPathForDocument());

            if (projectInfo != null)
            {
                projectInfo.IsDocumentOpening = true;
            }

            try
            {
                return(base.Open(newFile, openWith, ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
            }
            finally
            {
                if (projectInfo != null)
                {
                    projectInfo.IsDocumentOpening = false;
                }
            }
        }
        private void ShowDiff(string oldFile, string newFile, bool bIgnoreCase, bool bIgnoreEOL, bool bIgnoreWhiteSpace, string sOldFileName, string sNewFileName)
        {
            string sCustomDiffViewer = CustomDiffViewer;

            if (!string.IsNullOrEmpty(sCustomDiffViewer))
            {
                try
                {
                    int iOldFile = sCustomDiffViewer.IndexOf('?');
                    int iNewFile = sCustomDiffViewer.LastIndexOf('?');
                    sCustomDiffViewer = sCustomDiffViewer.Substring(0, iOldFile) + '"' + oldFile + '"' + sCustomDiffViewer.Substring(iOldFile + 1, iNewFile - iOldFile - 1) + '"' + newFile + '"' + sCustomDiffViewer.Substring(iNewFile + 1);
                    Microsoft.VisualBasic.Interaction.Shell(sCustomDiffViewer, Microsoft.VisualBasic.AppWinStyle.MaximizedFocus, true, -1);
                    return;
                }
                catch (Exception ex)
                {
                    throw new Exception("There was a problem using the custom diff viewer: " + sCustomDiffViewer, ex);
                }
            }


            //try the VS2012 built-in diff viewer
            string sVS2012Error = string.Empty;

            if (this.ApplicationObject.Version.CompareTo("11.") == 1 || this.ApplicationObject.Version.CompareTo("12.") == 1)
            {
                try
                {
                    System.Reflection.Assembly vsAssembly = System.Reflection.Assembly.Load(VS2012_SHELL_INTEROP_ASSEMBLY_FULL_NAME);

                    UIHierarchy     solExplorer = this.ApplicationObject.ToolWindows.SolutionExplorer;
                    UIHierarchyItem hierItem    = (UIHierarchyItem)((System.Array)solExplorer.SelectedItems).GetValue(0);
                    ProjectItem     projItem    = (ProjectItem)hierItem.Object;
                    string          sTabName    = projItem.Name + " (BIDS Helper Smart Diff)";

                    System.IServiceProvider provider = package.ServiceProvider; //works in all project types even C# projects
                    //if (projItem.ContainingProject is System.IServiceProvider)
                    //{
                    //    provider = (System.IServiceProvider)projItem.ContainingProject;
                    //}
                    //else
                    //{
                    //    provider = TabularHelpers.GetTabularServiceProviderFromBimFile(hierItem, false);
                    //}

                    Type   t = vsAssembly.GetType("Microsoft.VisualStudio.Shell.Interop.IVsDifferenceService");
                    object oVsDifferenceService = provider.GetService(vsAssembly.GetType("Microsoft.VisualStudio.Shell.Interop.SVsDifferenceService"));
                    Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame frame = (Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame)t.InvokeMember("OpenComparisonWindow2", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, oVsDifferenceService, new object[] { oldFile, newFile, sTabName, "BIDS Helper Smart Diff", sOldFileName, sNewFileName, "", "", (uint)0 });

                    return;
                }
                catch (Exception exVS2012)
                {
                    sVS2012Error = exVS2012.Message;
                }
            }

            int    fFlags = 0;
            string sFlags = "";

            if (bIgnoreCase)
            {
                fFlags |= 1;
                sFlags += " -ic";
            }
            if (bIgnoreEOL)
            {
                fFlags |= 4;
                sFlags += " -ie";
            }
            if (bIgnoreWhiteSpace)
            {
                fFlags |= 2;
                sFlags += " -iw";
            }

            try
            {
                MSDiff_ShowDiffUI(IntPtr.Zero, oldFile, newFile, fFlags, sOldFileName, sNewFileName);
                MSDiff_Cleanup();
            }
            catch (Exception exMSDiff)
            {
                //couldn't use MSDiff (which gets intalled with TFS2010 and below)
                //try VSS EXE
                try
                {
                    string sVSSDir = VSSInstallDir;
                    if (string.IsNullOrEmpty(sVSSDir))
                    {
                        throw new Exception("");
                    }
                    else
                    {
                        Microsoft.VisualBasic.Interaction.Shell("\"" + sVSSDir + "ssexp.exe\" /diff" + sFlags + " \"" + oldFile + "\" \"" + newFile + "\"", Microsoft.VisualBasic.AppWinStyle.MaximizedFocus, true, -1);
                    }
                }
                catch (Exception exVSS)
                {
                    if (!string.IsNullOrEmpty(sVS2012Error))
                    {
                        sVS2012Error = "\r\n\r\nCould not use the built-in Visual Studio diff viewer:\r\n" + sVS2012Error;
                    }
                    throw new Exception("Could not start Microsoft Visual SourceSafe 2005 to view diff. " + exVSS.Message + "\r\n\r\nCould not utilize Microsoft Team Foundation Server to view diff. " + exMSDiff.Message + sVS2012Error);
                }
            }
        }
Пример #6
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: {
                        CompareReportsView compareView;
                        if (_node.IsReportItem(_itemid))
                        {
                            var report = _node.GetReport(_itemid);
                            compareView = new CompareReportsView(report.Filename);
                        }
                        else
                        {
                            compareView = new CompareReportsView();
                        }

                        var dialog = new CompareReportsWindow(compareView);
                        var res    = dialog.ShowModal() ?? false;
                        if (res && compareView.IsValid)
                        {
                            IVsUIShellOpenDocument sod = _node._serviceProvider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
                            if (sod == null)
                            {
                                return(VSConstants.E_FAIL);
                            }
                            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),
                                compareView.GetComparisonUri(),
                                ref guid,
                                null,
                                ref guidNull,
                                Strings.PerformanceComparisonTitle,
                                _node,
                                _itemid,
                                IntPtr.Zero,
                                null,
                                out frame
                                );

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

                    case PkgCmdIDList.cmdidReportsAddReport: {
                        var dialog = new OpenFileDialog();
                        dialog.Filter          = PythonProfilingPackage.PerformanceFileFilter;
                        dialog.CheckFileExists = true;
                        var res = dialog.ShowDialog() ?? false;
                        if (res)
                        {
                            _node.AddProfile(dialog.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);
            }