コード例 #1
0
        public bool GetAlreadyOpenedDocument(string path, out IVsWindowFrame windowFrame)
        {
            Validate.IsNotNull(path, nameof(path));

            IVsUIHierarchy hierarchy;
            uint           itemId;

            // DevDiv 248655:  Calling OpenFile on a previewed document will promote it.
            // Do not promote unnecessarily.  Simply activate the window if it exists.
            if (!VsShellUtilities.IsDocumentOpen(this.singletons.ServiceProvider, path, VSConstants.LOGVIEWID.Code_guid, out hierarchy, out itemId, out windowFrame) || windowFrame == null)
            {
                return(false);
            }

            return(ErrorHandler.Succeeded(windowFrame.Show()));
        }
コード例 #2
0
ファイル: EtoPreviewPane.cs プロジェクト: yaram/Eto
        void ViewCode()
        {
            // Open the referenced document using the standard text editor.
            var codeFile = preview.GetCodeFile(FileName);

            IVsWindowFrame frame;
            IVsUIHierarchy hierarchy;
            uint           itemid;

            if (!VsShellUtilities.IsDocumentOpen(this, codeFile, VSConstants.LOGVIEWID.Primary_guid, out hierarchy, out itemid, out frame) &&
                !VsShellUtilities.IsDocumentOpen(this, codeFile, VSConstants.LOGVIEWID.TextView_guid, out hierarchy, out itemid, out frame))
            {
                VsShellUtilities.OpenDocumentWithSpecificEditor(this, codeFile, VSConstants.VsEditorFactoryGuid.TextEditor_guid, VSConstants.LOGVIEWID.Primary_guid, out hierarchy, out itemid, out frame);
            }
            ErrorHandler.ThrowOnFailure(frame.Show());
        }
コード例 #3
0
        internal static IVsTextView OpenStupidFile(string full_file_name)
        {
            var dte2             = (EnvDTE80.DTE2)Package.GetGlobalService(typeof(SDTE));
            IServiceProvider isp = (IServiceProvider)dte2;
            ServiceProvider  sp  = new ServiceProvider(isp);
            IVsUIHierarchy   ivsuih;
            uint             item_id;
            IVsWindowFrame   ivswf;

            if (!VsShellUtilities.IsDocumentOpen(sp, full_file_name, Guid.Empty,
                                                 out ivsuih, out item_id, out ivswf))
            {
                VsShellUtilities.OpenDocument(sp, full_file_name);
            }
            return(GetIVsTextView(full_file_name));
        }
コード例 #4
0
ファイル: EditorWindow.cs プロジェクト: shijiong/ntvsiot
        internal static IWpfTextView GetTextView(string filePath)
        {
            IVsUIHierarchy uiHierarchy;
            uint           itemID;
            IVsWindowFrame windowFrame;

            if (VsShellUtilities.IsDocumentOpen(VSTestContext.ServiceProvider, filePath, Guid.Empty, out uiHierarchy, out itemID, out windowFrame))
            {
                var             textView    = VsShellUtilities.GetTextView(windowFrame);
                IComponentModel compModel   = (IComponentModel)VSTestContext.ServiceProvider.GetService(typeof(SComponentModel));
                var             adapterFact = compModel.GetService <IVsEditorAdaptersFactoryService>();
                return(adapterFact.GetWpfTextView(textView));
            }

            return(null);
        }
コード例 #5
0
        /// <summary>
        /// Closes a nested project and releases the nested hierrachy pointer.
        /// </summary>
        internal void CloseNestedProjectNode()
        {
            if (this.isDisposed || this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                return;
            }

            uint itemid = VSConstants.VSITEMID_NIL;

            ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                this.DisconnectPropertyNotifySink();

                IVsUIHierarchy hier;

                IVsWindowFrame windowFrame;
                VsShellUtilities.IsDocumentOpen(this.ProjectMgr.Site, this.projectPath, Guid.Empty, out hier, out itemid, out windowFrame);


                if (itemid == VSConstants.VSITEMID_NIL)
                {
                    this.UnlockRDTEntry();
                }

                IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;
                if (solution == null)
                {
                    throw new InvalidOperationException();
                }

                ErrorHandler.ThrowOnFailure(solution.RemoveVirtualProject(this.nestedHierarchy, 0));
            }
            finally
            {
                this.StopObservingNestedProjectFile();

                // if we haven't already release the RDT cookie, do so now.
                if (itemid == VSConstants.VSITEMID_NIL)
                {
                    this.UnlockRDTEntry();
                }

                this.Dispose(true);
            }
        }
コード例 #6
0
ファイル: TestPackage.cs プロジェクト: papergirl/VSTest
        private void DocumentEvents_DocumentOpened(Document document)
        {
            //check if the item opened is a text document
            TextDocument txtDoc = document.Object("") as TextDocument;

            if (txtDoc == null)
            {
                return;
            }
            //is the text document a member of one of our projects with tests?
            if (!_projectsWithTests.ContainsKey(document.ProjectItem.ContainingProject.Name))
            {
                return;
            }
            ConfiguredProject project = _projectsWithTests[document.ProjectItem.ContainingProject.Name];

            if (project == null)
            {
                return;
            }
            IVsUIHierarchy uiHierarchy;
            uint           itemID;
            IVsTextLines   lines;
            IVsWindowFrame windowFrame;
            var            serviceProvider = project.BelongsTo.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
            var            x = new ServiceProvider(serviceProvider);
            IVsTextView    view;

            //IVsTextManager2 txtManager2 = (IVsTextManager2) GetService(typeof (SVsTextManager));
            //txtManager2.GetActiveView2(0,null,(uint)_VIEWFRAMETYPE.vftAny,out view);

            if (VsShellUtilities.IsDocumentOpen(x, document.FullName, Guid.Empty,
                                                out uiHierarchy, out itemID, out windowFrame))
            {
                view = VsShellUtilities.GetTextView(windowFrame);
                view.GetBuffer(out lines);
            }
            else
            {
                throw new Exception("COM happened");
            }
            if (!_referencesToMarkers.ContainsKey(document.FullName))
            {
                _referencesToMarkers.Add(document.FullName, lines);
            }
            MarkTests(project, lines);
        }
コード例 #7
0
        /// <summary>
        /// Called when navigating to an error task.
        /// </summary>
        private void OnTaskNavigate(Object sender, EventArgs e)
        {
            var task = (ErrorTask)sender;

            var fullPath    = task.Document;
            var logicalView = new Guid(LogicalViewID.TextView);

            var hierarchy   = default(IVsUIHierarchy);
            var itemID      = default(uint);
            var windowFrame = default(IVsWindowFrame);

            var isClosed = !VsShellUtilities.IsDocumentOpen(serviceProvider,
                                                            fullPath, logicalView, out hierarchy, out itemID, out windowFrame);

            if (isClosed)
            {
                try
                {
                    VsShellUtilities.OpenDocument(serviceProvider,
                                                  fullPath, logicalView, out hierarchy, out itemID, out windowFrame);
                }
                catch { return; }
            }

            ThreadHelper.ThrowIfNotOnUIThread();
            ErrorHandler.ThrowOnFailure(windowFrame.Show());

            var vsTextView = VsShellUtilities.GetTextView(windowFrame);

            var vsTextBuffer = default(IVsTextLines);

            ErrorHandler.ThrowOnFailure(vsTextView.GetBuffer(out vsTextBuffer));

            var startLine = task.Line;
            var startCol  = task.Column;

            var endLine = task.Line;
            var endCol  = task.Column;

            var vsTextManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            if (vsTextManager != null)
            {
                vsTextManager.NavigateToLineAndColumn(vsTextBuffer, ref logicalView, startLine, startCol, endLine, endCol);
            }
        }
コード例 #8
0
        /// <summary>
        /// To the i vs text view.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="dte2">The dte2.</param>
        /// <returns></returns>
        public static IVsTextView ToIVsTextView(this Document document, DTE2 dte2)
        {
            ArgumentGuard.ArgumentNotNull(document, "document");
            ArgumentGuard.ArgumentNotNull(dte2, "dte2");

            IVsUIHierarchy uiHierarchy;
            uint           itemId;
            IVsWindowFrame windowFrame;

            if (VsShellUtilities.IsDocumentOpen(new ServiceProvider(dte2 as VSIServiceProvider),
                                                document.FullName, Guid.Empty, out uiHierarchy, out itemId, out windowFrame))
            {
                return(VsShellUtilities.GetTextView(windowFrame));
            }

            return(null);
        }
コード例 #9
0
        public static IWpfTextView GetWpfTextViewFromFilePath(string filePath, IServiceProvider serviceProvider, IVsEditorAdaptersFactoryService editorAdaptersFactoryService)
        {
            if (VsShellUtilities.IsDocumentOpen(serviceProvider, filePath, Guid.Empty,
                                                out var _, out var _, out var windowFrame))
            {
                // Get the IVsTextView from the windowFrame.
                IVsTextView textView = VsShellUtilities.GetTextView(windowFrame);
                if (!IsInitialized(textView))
                {
                    return(null);
                }

                return(editorAdaptersFactoryService.GetWpfTextView(textView));
            }

            return(null);
        }
コード例 #10
0
        /// <summary>
        /// Returns an IVsTextView for the given file path if the file is opened in Visual Studio.
        /// </summary>
        /// <param name="filePath">Full Path of the file you are looking for.</param>
        /// <returns>The IVsTextView for this file if it is open. Returns null otherwise.</returns>
        private static IVsTextView GetIVsTextView(string filePath)
        {
            var            sp = ShellUtils.Default.GetGloblalServiceProvider();
            IVsUIHierarchy uiHierarchy;
            uint           itemID;
            IVsWindowFrame windowFrame;

            if (VsShellUtilities.IsDocumentOpen(
                    sp, filePath, Guid.Empty,
                    out uiHierarchy, out itemID, out windowFrame))
            {
                // Get the IVsTextView from the windowFrame.
                return(VsShellUtilities.GetTextView(windowFrame));
            }

            return(null);
        }
コード例 #11
0
        /// <summary>
        /// Attempts to get the text view associated with the specified document.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <returns>The associated text view, otherwise null.</returns>
        private IVsTextView GetTextView(Document document)
        {
            if (_serviceProvider == null || document == null)
            {
                return(null);
            }

            IVsUIHierarchy hierarchy;
            uint           itemID;
            IVsWindowFrame windowFrame;

            if (VsShellUtilities.IsDocumentOpen(_serviceProvider, document.FullName, Guid.Empty, out hierarchy, out itemID, out windowFrame))
            {
                return(VsShellUtilities.GetTextView(windowFrame));
            }

            return(null);
        }
コード例 #12
0
        /// <summary>
        /// Returns an IVsTextView for the given file path, if the given file is open in Visual Studio.
        /// </summary>
        /// <param name="filePath">Full Path of the file you are looking for.</param>
        /// <returns>The IVsTextView for this file, if it is open, null otherwise.</returns>
        /// <remarks>Based on http://stackoverflow.com/questions/2413530/find-an-ivstextview-or-iwpftextview-for-a-given-projectitem-in-vs-2010-rc-exten</remarks>
        public static IVsTextView GetIVsTextView(string filePath)
        {
            var sp = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)EditorExtensionsPackage.DTE;

            using (var serviceProvider = new ServiceProvider(sp))
            {
                uint           itemId;
                IVsUIHierarchy uiHierarchy;
                IVsWindowFrame windowFrame;

                if (VsShellUtilities.IsDocumentOpen(serviceProvider, filePath, Guid.Empty, out uiHierarchy, out itemId, out windowFrame))
                {
                    // Get the IVsTextView from the windowFrame.
                    return(VsShellUtilities.GetTextView(windowFrame));
                }
            }
            return(null);
        }
コード例 #13
0
ファイル: Vsix.cs プロジェクト: shaneharper/clang-power-tools
        public static IVsTextView GetVsTextViewFrompPath(string filePath)
        {
            var dte2            = (EnvDTE80.DTE2)Package.GetGlobalService(typeof(SDTE));
            var sp              = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte2;
            var serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(sp);

            IVsUIHierarchy uiHierarchy;
            uint           itemID;
            IVsWindowFrame windowFrame;

            if (VsShellUtilities.IsDocumentOpen(serviceProvider, filePath, Guid.Empty,
                                                out uiHierarchy, out itemID, out windowFrame))
            {
                // Get the IVsTextView from the windowFrame.
                return(VsShellUtilities.GetTextView(windowFrame));
            }
            return(null);
        }
コード例 #14
0
ファイル: VsHierarchy.cs プロジェクト: emptywalls/vs-chromium
        public int OpenItem(uint itemid, ref Guid rguidLogicalView, IntPtr punkDocDataExisting, out IVsWindowFrame ppWindowFrame)
        {
            _logger.LogHierarchy("OpenItem({0})", (int)itemid);
            ppWindowFrame = null;

            NodeViewModel node;
            uint          flags   = 536936448U;
            int           hresult = 0;

            if (!_nodes.FindNode(itemid, out node))
            {
                return(VSConstants.E_FAIL);
            }

            if (string.IsNullOrEmpty(node.FullPath))
            {
                return(VSConstants.E_NOTIMPL);
            }
            IVsUIHierarchy hierarchy;
            uint           itemid1;

            if (!VsShellUtilities.IsDocumentOpen(_serviceProvider, node.FullPath, rguidLogicalView, out hierarchy, out itemid1, out ppWindowFrame))
            {
                IVsHierarchy hierOpen;
                int          isDocInProj;
                IsDocumentInAnotherProject(node.FullPath, out hierOpen, out itemid1, out isDocInProj);
                if (hierOpen == null)
                {
                    hresult = OpenItemViaMiscellaneousProject(flags, node.FullPath, ref rguidLogicalView, out ppWindowFrame);
                }
                else
                {
                    var vsProject3 = hierOpen as IVsProject3;
                    hresult = vsProject3 == null
            ? OpenItemViaMiscellaneousProject(flags, node.FullPath, ref rguidLogicalView, out ppWindowFrame)
            : vsProject3.OpenItem(itemid1, ref rguidLogicalView, punkDocDataExisting, out ppWindowFrame);
                }
            }
            if (ppWindowFrame != null)
            {
                hresult = ppWindowFrame.Show();
            }
            return(hresult);
        }
コード例 #15
0
        internal bool IsDocumentOpen(IServiceProvider sp)
        {
            if (sp != null)
            {
                var uri = Uri;
                if (uri != null)
                {
                    IVsUIHierarchy hier;
                    uint           itemId;
                    IVsWindowFrame frame;
                    if (VsShellUtilities.IsDocumentOpen(sp, uri.LocalPath, Guid.Empty, out hier, out itemId, out frame))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #16
0
        public static IVsTextBuffer GetWindowVisualBuffer(Window window, IServiceProvider serviceProvider)
        {
            if (window == null || window.Document == null || !window.Kind.Equals("Document", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var fullPath = Path.Combine(window.Document.Path, window.Document.Name);

            if (VsShellUtilities.IsDocumentOpen(serviceProvider, fullPath, Guid.Empty, out _, out _, out var windowFrame))
            {
                var textView = VsShellUtilities.GetTextView(windowFrame);
                if (textView.GetBuffer(out var vsTextBuffer) == VSConstants.S_OK)
                {
                    return(vsTextBuffer);
                }
            }

            return(null);
        }
コード例 #17
0
        internal static IVsTextLines GetDocumentTextLines(string path)
        {
            IVsUIHierarchy uiHierarchy;
            uint           itemID;
            IVsWindowFrame windowFrame;

            if (VsShellUtilities.IsDocumentOpen(VSAsyncPackage.Instance, path, new Guid(LogicalViewID.TextView), out uiHierarchy, out itemID, out windowFrame))
            {
                IVsTextView  pView;
                IVsTextLines textLines;

                pView = VsShellUtilities.GetTextView(windowFrame);

                ErrorHandler.ThrowOnFailure(pView.GetBuffer(out textLines));

                return(textLines);
            }

            return(null);
        }
コード例 #18
0
        public IVsWindowFrame OpenFileInVisualStudio(string filePath)
        {
            if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
            {
                return(null);
            }

            IVsUIHierarchy hierarchy;
            uint           itemId;
            IVsWindowFrame frame;

            if (!VsShellUtilities.IsDocumentOpen(_serviceProvider, filePath,
                                                 VSConstants.LOGVIEWID_Primary, out hierarchy, out itemId, out frame))
            {
                VsShellUtilities.OpenDocument(_serviceProvider, filePath,
                                              VSConstants.LOGVIEWID_Primary, out hierarchy, out itemId, out frame);
            }

            frame?.Show();
            return(frame);
        }
コード例 #19
0
        public IVsTextView GetTextViewAndEnsureVisible(string fileName)
        {
            ServiceProvider serviceProvider = new ServiceProvider(GetServiceProvider());
            IVsUIHierarchy  hierarchy;
            uint            itemID;
            IVsWindowFrame  windowFrame;

            if (VsShellUtilities.IsDocumentOpen(serviceProvider, fileName, Guid.Empty, out hierarchy, out itemID, out windowFrame))
            {
                ErrorHandler.ThrowOnFailure(windowFrame.Show());
                return(VsShellUtilities.GetTextView(windowFrame));
            }

            OpenDocument(fileName);
            if (!VsShellUtilities.IsDocumentOpen(serviceProvider, fileName, Guid.Empty, out hierarchy, out itemID, out windowFrame))
            {
                return(null);
            }

            return(VsShellUtilities.GetTextView(windowFrame));
        }
コード例 #20
0
        private void Execute()
        {
            if (!_options.CloseDocuments)
            {
                return;
            }

            foreach (Document document in _dte.Documents)
            {
                string filePath = document.FullName;

                // Don't close pinned files
                if (VsShellUtilities.IsDocumentOpen(_serviceProvider, filePath, VSConstants.LOGVIEWID_Primary, out IVsUIHierarchy hierarchy, out uint itemId, out IVsWindowFrame frame))
                {
                    ErrorHandler.ThrowOnFailure(frame.GetProperty((int)__VSFPROPID5.VSFPROPID_IsPinned, out object propVal));

                    if (bool.TryParse(propVal.ToString(), out bool isPinned) && !isPinned)
                    {
                        document.Close(vsSaveChanges.vsSaveChangesPrompt);
                    }
                }
コード例 #21
0
        public override T OpenDocument <T>(string documentName)
        {
            Assert.ArgumentNotNull(documentName, nameof(documentName));

            documentName = EditorDocumentName.GetDocumentName(documentName);

            IVsWindowFrame frame;
            IVsUIHierarchy hierarchy;
            uint           itemId;

            if (VsShellUtilities.IsDocumentOpen(SitecorePackage.Instance, documentName, VSConstants.LOGVIEWID_Primary, out hierarchy, out itemId, out frame))
            {
                frame.Show();
                return(null);
            }

            var result = new T();

            FrameworkElement frameworkElement;

            var formsControls = result as Control;

            if (formsControls != null)
            {
                frameworkElement = new WindowsFormsHost
                {
                    Child = formsControls
                };
            }
            else
            {
                frameworkElement = result as FrameworkElement;
            }

            Assert.IsNotNull(frameworkElement, "Parameter 'control' must be of type FrameworkElement");

            EditorWindowFactory.CreateEditor(frameworkElement, documentName);

            return(result);
        }
コード例 #22
0
ファイル: EditorIntegration.cs プロジェクト: waodng/VSIX
        public void FormatDocument(string filePath)
        {
            IVsTextView    vsTextView;
            IVsUIHierarchy uiHierarchy;
            uint           itemID;
            IVsWindowFrame windowFrame;

            if (VsShellUtilities.IsDocumentOpen(visualStudio.ServiceProvider, filePath, Guid.Empty, out uiHierarchy, out itemID, out windowFrame))
            {
                vsTextView = VsShellUtilities.GetTextView(windowFrame);
            }
            else
            {
                Contract.Assert(false, "Failed to get the IVsTextView, is the document open in VS?");
                return;
            }

            IOleCommandTarget commandTarget = (IOleCommandTarget)vsTextView;

            Guid guid = typeof(VSConstants.VSStd2KCmdID).GUID;

            OLECMD[] commandStatus = new OLECMD[] { new OLECMD()
                                                    {
                                                        cmdID = (uint)VSConstants.VSStd2KCmdID.FORMATDOCUMENT
                                                    } };

            int hr = commandTarget.QueryStatus(ref guid, 1, commandStatus, IntPtr.Zero);

            Marshal.ThrowExceptionForHR(hr);

            if (commandStatus[0].cmdf == (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED))
            {
                hr = commandTarget.Exec(ref guid, (uint)VSConstants.VSStd2KCmdID.FORMATDOCUMENT, 0u, IntPtr.Zero, IntPtr.Zero);
                Marshal.ThrowExceptionForHR(hr);
            }
            else
            {
                Contract.Assert(false, "The format command can't be executed right now, we don't expect this to happen.");
            }
        }
コード例 #23
0
        /// <summary>
        ///     Executes the specified command for the open document.
        /// </summary>
        public static void ExecuteCommandForOpenDocument(this DTE dte, string fullFilePath, string command)
        {
            Debug.Assert(dte != null, "dte must not be null.");
            Debug.Assert(!string.IsNullOrWhiteSpace(fullFilePath), "fullFilePath must not be null or empty string.");

            var serviceProvider = new ServiceProvider((IServiceProvider)dte);

            IVsUIHierarchy hierarchy;
            uint           itemId;
            IVsWindowFrame windowFrame;

            if (VsShellUtilities.IsDocumentOpen(serviceProvider, fullFilePath, Guid.Empty, out hierarchy, out itemId, out windowFrame))
            {
                windowFrame.Show();
                dte.ExecuteCommand(command, "");
            }
            else
            {
                throw new InvalidOperationException(
                          string.Format("Executing command '{0}' failed. Document '{1}' not open.", command, fullFilePath));
            }
        }
コード例 #24
0
        /// <summary>
        /// Gets a value indicating whether the project item is open in a particular view type.
        /// </summary>
        /// <param name="viewKind">A Constants.vsViewKind* indicating the type of view to check./param>
        /// <returns>A Boolean value indicating true if the project is open in the given view type; false if not. </returns>
        public override bool get_IsOpen(string viewKind)
        {
            return(UIThread.DoOnUIThread(delegate()
            {
                if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed || this.Node.ProjectMgr.Site == null)
                {
                    throw new InvalidOperationException();
                }

                // Validate input params
                Guid logicalViewGuid = VSConstants.LOGVIEWID_Primary;
                try
                {
                    if (!(String.IsNullOrEmpty(viewKind)))
                    {
                        logicalViewGuid = new Guid(viewKind);
                    }
                }
                catch (FormatException)
                {
                    // Not a valid guid
                    throw new ArgumentException(SR.GetString(SR.ParameterMustBeAValidGuid, CultureInfo.CurrentUICulture), "viewKind");
                }

                bool isOpen = false;

                using (AutomationScope scope = new AutomationScope(this.Node.ProjectMgr.Site))
                {
                    IVsUIHierarchy hier;
                    uint itemid;

                    IVsWindowFrame windowFrame;

                    isOpen = VsShellUtilities.IsDocumentOpen(this.Node.ProjectMgr.Site, this.Node.Url, logicalViewGuid, out hier, out itemid, out windowFrame);
                }

                return isOpen;
            }));
        }
コード例 #25
0
        public static void SelectSpanInCodeWindow(FileLinePositionSpan span)
        {
            // If the path is not available we cannot jump to it
            if (string.IsNullOrEmpty(span.Path))
            {
                return;
            }

            // Check if the document is opened, if not open it.
            if (!VsShellUtilities.IsDocumentOpen(ServiceProvider.GlobalProvider, span.Path, VSConstants.LOGVIEWID_Any, out _, out _, out var windowFrame))
            {
                VsShellUtilities.OpenDocument(ServiceProvider.GlobalProvider, span.Path, VSConstants.LOGVIEWID_Primary, out _, out _, out windowFrame);
            }

            var window = VsShellUtilities.GetWindowObject(windowFrame);

            window.SetFocus();

            var textView = VsShellUtilities.GetTextView(windowFrame);

            textView.SetSelection(span.StartLinePosition.Line, span.StartLinePosition.Character, span.EndLinePosition.Line, span.EndLinePosition.Character);
        }
コード例 #26
0
        private async Task <IVsWindowFrame?> GetFrameFromIdentifierAsync(string identifier)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsWindowFrame?frame;

            // Tool Window
            if (Guid.TryParse(identifier, out Guid guid))
            {
                IVsUIShell uiShell = await VS.Services.GetUIShellAsync();

                uiShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref guid, out frame);
            }

            // Document window
            else if (VsShellUtilities.IsDocumentOpen(ServiceProvider.GlobalProvider, identifier, Guid.Empty, out _, out _, out frame))
            {
                // Do nothing, the 'frame' is assigned
            }

            return(frame);
        }
コード例 #27
0
        internal static void CreateDataTipViewFilter(IServiceProvider provider, IQNTextViewFilterOwner owner)
        {
            IVsUIHierarchy uiHierarchy;
            uint           itemID;
            IVsWindowFrame windowFrame;
            string         filepath = owner.Filepath;

            if (VsShellUtilities.IsDocumentOpen(
                    provider,
                    filepath,
                    Guid.Empty,
                    out uiHierarchy,
                    out itemID,
                    out windowFrame))
            {
                IVsTextView view = VsShellUtilities.GetTextView(windowFrame);
                if (owner.Filter == null || owner.Filter.TextView != view)
                {
                    owner.Filter = new SQTextViewFilter(provider, view);
                }
            }
        }
コード例 #28
0
        IDifferenceViewer FocusExistingDiffViewer(
            IPullRequestSession session,
            string mergeBase,
            string rightPath)
        {
            IVsUIHierarchy uiHierarchy;
            uint           itemID;
            IVsWindowFrame windowFrame;

            // Diff documents are indexed by the path on the right hand side of the comparison.
            if (VsShellUtilities.IsDocumentOpen(
                    serviceProvider,
                    rightPath,
                    Guid.Empty,
                    out uiHierarchy,
                    out itemID,
                    out windowFrame))
            {
                var diffViewer = GetDiffViewer(windowFrame);

                if (diffViewer != null)
                {
                    PullRequestTextBufferInfo leftBufferInfo;

                    if (diffViewer.LeftView.TextBuffer.Properties.TryGetProperty(
                            typeof(PullRequestTextBufferInfo),
                            out leftBufferInfo) &&
                        leftBufferInfo.Session.PullRequest.Number == session.PullRequest.Number &&
                        leftBufferInfo.CommitSha == mergeBase)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.Show());
                        return(diffViewer);
                    }
                }
            }

            return(null);
        }
コード例 #29
0
        public static IVsWindowFrame IsDocumentOpened(string filePath)
        {
            if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
            {
                return(null);
            }

            var dte2 = (EnvDTE80.DTE2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2;

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte2;
            Microsoft.VisualStudio.Shell.ServiceProvider        serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(sp);

            IVsUIHierarchy hierarchy;
            uint           itemId;
            IVsWindowFrame frame = null;

            if (VsShellUtilities.IsDocumentOpen(serviceProvider, filePath,
                                                VSConstants.LOGVIEWID_Primary, out hierarchy, out itemId, out frame))
            {
                return(frame);
            }
            return(null);
        }
コード例 #30
0
ファイル: OAFileItem.cs プロジェクト: Irwin1985/XSharpPublic
        /// <summary>
        /// Gets a value indicating whether the project item is open in a particular view type.
        /// </summary>
        /// <param name="viewKind">A Constants.vsViewKind* indicating the type of view to check./param>
        /// <returns>A Boolean value indicating true if the project is open in the given view type; false if not. </returns>
        public override bool get_IsOpen(string viewKind)
        {
            bool isOpen = false;

            ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                CheckProjectIsValid();

                // Validate input params
                Guid logicalViewGuid = VSConstants.LOGVIEWID_Primary;
                try
                {
                    if (!(String.IsNullOrEmpty(viewKind)))
                    {
                        logicalViewGuid = new Guid(viewKind);
                    }
                }
                catch (FormatException)
                {
                    // Not a valid guid
                    throw new ArgumentException(SR.GetString(SR.ParameterMustBeAValidGuid, CultureInfo.CurrentUICulture), "viewKind");
                }


                using (AutomationScope scope = new AutomationScope(this.Node.ProjectMgr.Site))
                {
                    IVsUIHierarchy hier;
                    uint itemid;

                    IVsWindowFrame windowFrame;

                    isOpen = VsShellUtilities.IsDocumentOpen(this.Node.ProjectMgr.Site, this.Node.Url, logicalViewGuid, out hier, out itemid, out windowFrame);
                }
            });
            return(isOpen);
        }