コード例 #1
0
        private bool IsDocumentOpen(string fullPath, Guid logicalView, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame)
        {
            TestServices.ThrowIfNotOnMainThread();

            var uiShellOpenDocument  = (IVsUIShellOpenDocument)ServiceProvider.GetService(typeof(SVsUIShellOpenDocument));
            var runningDocumentTable = (IVsRunningDocumentTable)ServiceProvider.GetService(typeof(SVsRunningDocumentTable));

            var docData = IntPtr.Zero;

            try
            {
                var itemidOpen = new uint[1];
                ErrorHandler.ThrowOnFailure(runningDocumentTable.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, fullPath, out var hier, out itemidOpen[0], out docData, out var cookie));

                var flags = logicalView == Guid.Empty ? (uint)__VSIDOFLAGS.IDO_IgnoreLogicalView : 0;
                ErrorHandler.ThrowOnFailure(uiShellOpenDocument.IsDocumentOpen((IVsUIHierarchy)hier, itemidOpen[0], fullPath, logicalView, flags, out hierarchy, itemidOpen, out windowFrame, out var open));
                if (windowFrame is object)
                {
                    itemID = itemidOpen[0];
                    return(open == 1);
                }
            }
            finally
            {
                if (docData != IntPtr.Zero)
                {
                    Marshal.Release(docData);
                }
            }

            itemID = (uint)VSConstants.VSITEMID.Nil;
            return(false);
        }
コード例 #2
0
            public SolutionEvents(TestServices testServices, IVsSolution solution)
            {
                testServices.ThrowIfNotOnMainThread();

                _joinableTaskFactory = testServices.JoinableTaskFactory;
                _solution            = solution;
                ErrorHandler.ThrowOnFailure(solution.AdviseSolutionEvents(this, out _cookie));
            }
コード例 #3
0
        private string GetAbsolutePathForProjectRelativeFilePath(string projectName, string relativeFilePath)
        {
            TestServices.ThrowIfNotOnMainThread();

            var dte         = (EnvDTE.DTE)ServiceProvider.GetService(typeof(EnvDTE.DTE));
            var project     = dte.Solution.Projects.Cast <EnvDTE.Project>().First(x => x.Name == projectName);
            var projectPath = Path.GetDirectoryName(project.FullName);

            return(Path.Combine(projectPath, relativeFilePath));
        }
コード例 #4
0
        private IVsTextView GetTextView(IVsWindowFrame windowFrame)
        {
            TestServices.ThrowIfNotOnMainThread();

            ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out var docView));
            var textView = docView as IVsTextView;

            if (textView is null)
            {
                if (docView is IVsCodeWindow codeWindow)
                {
                    ErrorHandler.ThrowOnFailure(codeWindow.GetPrimaryView(out textView));
                }
            }

            return(textView);
        }
コード例 #5
0
        private void SetForegroundWindow(IntPtr window)
        {
            TestServices.ThrowIfNotOnMainThread();

            var activeWindow = NativeMethods.GetLastActivePopup(window);

            activeWindow = NativeMethods.IsWindowVisible(activeWindow) ? activeWindow : window;
            NativeMethods.SwitchToThisWindow(activeWindow, true);

            if (!NativeMethods.SetForegroundWindow(activeWindow))
            {
                if (!NativeMethods.AllocConsole())
                {
                    Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                }

                try
                {
                    var consoleWindow = NativeMethods.GetConsoleWindow();
                    if (consoleWindow == IntPtr.Zero)
                    {
                        throw new InvalidOperationException("Failed to obtain the console window.");
                    }

                    if (!NativeMethods.SetWindowPos(consoleWindow, IntPtr.Zero, 0, 0, 0, 0, NativeMethods.SWP_NOZORDER))
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }
                }
                finally
                {
                    if (!NativeMethods.FreeConsole())
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }
                }

                if (!NativeMethods.SetForegroundWindow(activeWindow))
                {
                    throw new InvalidOperationException("Failed to set the foreground window.");
                }
            }
        }