Exemplo n.º 1
0
        public void OpenDocument(VirtualTextDocument document)
        {
            Filename   = document.Path;
            IsReadOnly = document.Source == DocumentSource.VPK;

            scintilla1.Text = document.Text;
        }
Exemplo n.º 2
0
        private async System.Threading.Tasks.Task <IWpfTextView> AssertWpfTextViewAsync(Uri fileUri, bool forceOpen = false)
        {
            var textViewCache = _componentModel.GetService <IWpfTextViewCache>();

            if (forceOpen == true || !textViewCache.TryGetValue(VirtualTextDocument.FromUri(fileUri), out var wpfTextView))
            {
                var view = _componentModel.GetService <IEditorService>().GetActiveTextEditor();
                if (view == null || !view.Uri.EqualsIgnoreCase(fileUri))
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken.None);

                    var           localPath = fileUri.ToLocalPath();
                    EnvDTE.Window window    = TryOpenFile(localPath);
                    if (window == null)
                    {
                        return(null);
                    }
                    // the TextView/WpfTextView may not be immediately available -- try to get it.
                    wpfTextView = TryGetPendingWpfTextView(localPath);
                }
                else
                {
                    wpfTextView = view?.WpfTextView;
                }
            }

            return(wpfTextView);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the active wpfTextView based on the provided uri
 /// </summary>
 /// <param name="uri"></param>
 /// <returns>the ActiveTextEditor if that uri is part of an open document</returns>
 public ActiveTextEditor GetActiveTextEditorFromUri(Uri uri)
 {
     try {
         var textViewCache = _componentModel.GetService <IWpfTextViewCache>();
         if (textViewCache.TryGetValue(VirtualTextDocument.FromUri(uri), out IWpfTextView wpfTextView) && wpfTextView != null)
         {
             return(CreateActiveTextEditor(wpfTextView));
         }
     }
     catch (Exception ex) {
         Log.Error(ex, $"{nameof(GetActiveTextEditorFromUri)} {uri}");
     }
     return(null);
 }
        /// <summary>
        /// Don't get a textDocument if our secret LSP file is trying to be opened
        /// </summary>
        /// <param name="textDocumentFactoryService"></param>
        /// <param name="textBuffer"></param>
        /// <param name="textDocument"></param>
        /// <returns></returns>
        public static bool TryGetTextDocument(this ITextDocumentFactoryService textDocumentFactoryService, ITextBuffer textBuffer, out IVirtualTextDocument textDocument)
        {
            textDocument = null;
            if (!textDocumentFactoryService.TryGetTextDocument(textBuffer, out ITextDocument td))
            {
                return(false);
            }

            textDocument = VirtualTextDocument.FromTextDocument(td);
            if (textDocument == null)
            {
                return(false);
            }

            return(!td.FilePath.EndsWithIgnoreCase(Core.Constants.CodeStreamCodeStream));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Scrolls an editor, only if it is already open
        /// </summary>
        /// <param name="fileUri"></param>
        /// <param name="scrollTo"></param>
        /// <param name="atTop"></param>
        public void ScrollEditor(Uri fileUri, int?scrollTo = null, int?deltaPixels = null, bool?atTop = false)
        {
            if (scrollTo == null || scrollTo.Value < 0)
            {
                return;
            }

            using (var metrics = Log.WithMetrics($"{nameof(ScrollEditor)} {fileUri} scrollTo={scrollTo} atTop={atTop}")) {
                try {
                    var textViewCache = _componentModel.GetService <IWpfTextViewCache>();
                    if (!textViewCache.TryGetValue(VirtualTextDocument.FromUri(fileUri), out var wpfTextView) || wpfTextView == null)
                    {
                        return;
                    }

                    if (deltaPixels != null)
                    {
                        wpfTextView.ViewScroller.ScrollViewportVerticallyByPixels(-deltaPixels.Value);
                        return;
                    }

                    var scrollToLine = scrollTo.Value;

                    if (atTop == true)
                    {
                        using (metrics.Measure("ScrollViewportVerticallyByPixels")) {
                            ScrollViewportVerticallyByPixels(wpfTextView, scrollToLine);
                        }
                    }
                    else
                    {
                        EnsureTargetSpanVisible(wpfTextView, scrollToLine);
                    }
                }
                catch (Exception ex) {
                    Log.Error(ex, $"{nameof(ScrollEditor)} failed for {fileUri}");
                }
            }
        }