Exemplo n.º 1
0
		public OutputBufferVM(IEditorOperationsFactoryService editorOperationsFactoryService, Guid guid, string name, ILogEditor logEditor) {
			editorOperations = editorOperationsFactoryService.GetEditorOperations(logEditor.TextView);
			Guid = guid;
			Name = name;
			this.logEditor = logEditor;
			index = -1;
			needTimestamp = true;
		}
Exemplo n.º 2
0
		public IncrementalSearch(ITextView textView, ITextSearchService textSearchService, IEditorOperationsFactoryService editorOperationsFactoryService) {
			if (textView == null)
				throw new ArgumentNullException(nameof(textView));
			if (textSearchService == null)
				throw new ArgumentNullException(nameof(textSearchService));
			if (editorOperationsFactoryService == null)
				throw new ArgumentNullException(nameof(editorOperationsFactoryService));
			TextView = textView;
			this.textSearchService = textSearchService;
			editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
			SearchString = string.Empty;
		}
 public BraceCompletionSession(
     ITextView textView, ITextBuffer subjectBuffer,
     SnapshotPoint openingPoint, char openingBrace, char closingBrace, ITextUndoHistory undoHistory,
     IEditorOperationsFactoryService editorOperationsFactoryService, IEditorBraceCompletionSession session)
 {
     this.TextView = textView;
     this.SubjectBuffer = subjectBuffer;
     this.OpeningBrace = openingBrace;
     this.ClosingBrace = closingBrace;
     this.ClosingPoint = SubjectBuffer.CurrentSnapshot.CreateTrackingPoint(openingPoint.Position, PointTrackingMode.Positive);
     _undoHistory = undoHistory;
     _editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
     _session = session;
 }
        public bool ExecuteCommand(ReturnKeyCommandArgs args, CommandExecutionContext context)
        {
            // Check to see if the current line starts with exterior trivia. If so, we'll take over.
            // If not, let the nextHandler run.

            var originalPosition = -1;

            // The original position should be a position that is consistent with the syntax tree, even
            // after Enter is pressed. Thus, we use the start of the first selection if there is one.
            // Otherwise, getting the tokens to the right or the left might return unexpected results.

            if (args.TextView.Selection.SelectedSpans.Count > 0)
            {
                var selectedSpan = args.TextView.Selection
                                   .GetSnapshotSpansOnBuffer(args.SubjectBuffer)
                                   .FirstOrNull();

                originalPosition = selectedSpan != null
                    ? selectedSpan.Value.Start
                    : args.TextView.GetCaretPoint(args.SubjectBuffer) ?? -1;
            }

            if (originalPosition < 0)
            {
                return(false);
            }

            if (!CurrentLineStartsWithExteriorTrivia(args.SubjectBuffer, originalPosition))
            {
                return(false);
            }

            // According to JasonMal, the text undo history is associated with the surface buffer
            // in projection buffer scenarios, so the following line's usage of the surface buffer
            // is correct.
            using (var transaction = _undoHistoryRegistry.GetHistory(args.TextView.TextBuffer).CreateTransaction(EditorFeaturesResources.Insert_new_line))
            {
                var editorOperations = _editorOperationsFactoryService.GetEditorOperations(args.TextView);
                editorOperations.InsertNewLine();

                CompleteComment(args.SubjectBuffer, args.TextView, originalPosition, InsertOnEnterTyped, CancellationToken.None);

                // Since we're wrapping the ENTER key undo transaction, we always complete
                // the transaction -- even if we didn't generate anything.
                transaction.Complete();
            }

            return(true);
        }
 public BraceCompletionSession(
     ITextView textView, ITextBuffer subjectBuffer,
     SnapshotPoint openingPoint, char openingBrace, char closingBrace, ITextUndoHistory undoHistory,
     IEditorOperationsFactoryService editorOperationsFactoryService, IBraceCompletionService service,
     IThreadingContext threadingContext)
     : base(threadingContext, assertIsForeground: true)
 {
     this.TextView      = textView;
     this.SubjectBuffer = subjectBuffer;
     this.OpeningBrace  = openingBrace;
     this.ClosingBrace  = closingBrace;
     this.ClosingPoint  = SubjectBuffer.CurrentSnapshot.CreateTrackingPoint(openingPoint.Position, PointTrackingMode.Positive);
     _undoHistory       = undoHistory;
     _editorOperations  = editorOperationsFactoryService.GetEditorOperations(textView);
     _service           = service;
 }
Exemplo n.º 6
0
        public void ReplWindowCreated(IReplWindow window)
        {
            var textView   = window.TextView;
            var editFilter = new EditFilter(
                textView,
                _editorOperationsFactory.GetEditorOperations(textView),
                _editorOptionsFactory.GetOptions(textView),
                _compModel.GetService <IIntellisenseSessionStackMapService>().GetStackForTextView(textView),
                _compModel
                );
            IntellisenseController controller = IntellisenseControllerProvider.GetOrCreateController(_compModel, textView);

            controller.AttachKeyboardFilter();

            editFilter.AttachKeyboardFilter(_adaptersFactory.GetViewAdapter(window.TextView));
        }
        public CaretPreservingEditTransaction(
            string description,
            ITextView textView,
            ITextUndoHistoryRegistry undoHistoryRegistry,
            IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            _editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
            _undoHistory      = undoHistoryRegistry.GetHistory(textView.TextBuffer);
            _active           = true;

            if (_undoHistory != null)
            {
                _transaction = new HACK_TextUndoTransactionThatRollsBackProperly(_undoHistory.CreateTransaction(description));
                _editorOperations.AddBeforeTextBufferChangePrimitive();
            }
        }
        public CaretPreservingEditTransaction(
            string description,
            ITextView textView,
            ITextUndoHistoryRegistry undoHistoryRegistry,
            IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            _editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
            _undoHistory = undoHistoryRegistry.GetHistory(textView.TextBuffer);
            _active = true;

            if (_undoHistory != null)
            {
                _transaction = new HACK_TextUndoTransactionThatRollsBackProperly(_undoHistory.CreateTransaction(description));
                _editorOperations.AddBeforeTextBufferChangePrimitive();
            }
        }
 public BraceCompletionSession(
     ITextView textView, ITextBuffer subjectBuffer,
     SnapshotPoint openingPoint, char openingBrace, char closingBrace, ITextUndoHistory undoHistory,
     IEditorOperationsFactoryService editorOperationsFactoryService, IBraceCompletionService service,
     IGlobalOptionService globalOptions, IThreadingContext threadingContext)
 {
     TextView          = textView;
     SubjectBuffer     = subjectBuffer;
     OpeningBrace      = openingBrace;
     ClosingBrace      = closingBrace;
     ClosingPoint      = SubjectBuffer.CurrentSnapshot.CreateTrackingPoint(openingPoint.Position, PointTrackingMode.Positive);
     _undoHistory      = undoHistory;
     _editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
     _service          = service;
     _threadingContext = threadingContext;
     _globalOptions    = globalOptions;
 }
Exemplo n.º 10
0
        private void CopyToWindow(
            IInteractiveWindow window,
            CopyToInteractiveCommandArgs args,
            CommandExecutionContext context
            )
        {
            var buffer = window.CurrentLanguageBuffer;

            Debug.Assert(buffer != null);

            using (var edit = buffer.CreateEdit())
                using (
                    var waitScope = context.OperationContext.AddScope(
                        allowCancellation: true,
                        EditorFeaturesWpfResources.Copying_selection_to_Interactive_Window
                        )
                    )
                {
                    var text = GetSelectedText(args, context.OperationContext.UserCancellationToken);

                    // If the last line isn't empty in the existing submission buffer, we will prepend a
                    // newline
                    var lastLine = buffer.CurrentSnapshot.GetLineFromLineNumber(
                        buffer.CurrentSnapshot.LineCount - 1
                        );
                    if (lastLine.Extent.Length > 0)
                    {
                        var editorOptions = _editorOptionsFactoryService.GetOptions(args.SubjectBuffer);
                        text = editorOptions.GetNewLineCharacter() + text;
                    }

                    edit.Insert(buffer.CurrentSnapshot.Length, text);
                    edit.Apply();
                }

            // Move the caret to the end
            var editorOperations = _editorOperationsFactoryService.GetEditorOperations(
                window.TextView
                );
            var endPoint = new VirtualSnapshotPoint(
                window.TextView.TextBuffer.CurrentSnapshot,
                window.TextView.TextBuffer.CurrentSnapshot.Length
                );

            editorOperations.SelectAndMoveCaret(endPoint, endPoint);
        }
Exemplo n.º 11
0
        public TextUndoTransaction(
            string description,
            ITextView textView,
            ITextUndoHistoryRegistry undoHistoryRegistry,
            IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            _inTransaction    = true;
            _editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);

            var undoHistory = undoHistoryRegistry.GetHistory(textView.TextBuffer);

            if (undoHistory != null)
            {
                _transaction = undoHistory.CreateTransaction(description);
                _editorOperations.AddBeforeTextBufferChangePrimitive();
            }
        }
Exemplo n.º 12
0
        private bool StartNewModelComputation(
            CompletionService completionService,
            CompletionTrigger trigger,
            bool filterItems,
            bool dismissIfEmptyAllowed)
        {
            AssertIsForeground();
            Contract.ThrowIfTrue(sessionOpt != null);

            if (this.TextView.Selection.Mode == TextSelectionMode.Box)
            {
                // No completion with multiple selection
                return(false);
            }

            // The caret may no longer be mappable into our subject buffer.
            var caret = TextView.GetCaretPoint(SubjectBuffer);

            if (!caret.HasValue)
            {
                return(false);
            }

            if (this.TextView.Caret.Position.VirtualBufferPosition.IsInVirtualSpace)
            {
                // Convert any virtual whitespace to real whitespace by doing an empty edit at the caret position.
                _editorOperationsFactoryService.GetEditorOperations(TextView).InsertText("");
            }

            var computation = new ModelComputation <Model>(this, PrioritizedTaskScheduler.AboveNormalInstance);

            this.sessionOpt = new Session(this, computation, Presenter.CreateSession(TextView, SubjectBuffer, null));

            sessionOpt.ComputeModel(completionService, trigger, _roles, GetOptions());

            var filterReason = trigger.Kind == CompletionTriggerKind.Deletion
                ? CompletionFilterReason.BackspaceOrDelete
                : trigger.Kind == CompletionTriggerKind.Other
                    ? CompletionFilterReason.Other
                    : CompletionFilterReason.TypeChar;

            FilterToSomeOrAllItems(filterItems, dismissIfEmptyAllowed, filterReason);

            return(true);
        }
Exemplo n.º 13
0
        public void VsTextViewCreated(VisualStudio.TextManager.Interop.IVsTextView textViewAdapter)
        {
            var textView   = _adaptersFactory.GetWpfTextView(textViewAdapter);
            var editFilter = new EditFilter(
                textView,
                _editorOperationsFactory.GetEditorOperations(textView),
                _editorOptionsFactory.GetOptions(textView),
                _compModel.GetService <IIntellisenseSessionStackMapService>().GetStackForTextView(textView),
                _compModel
                );
            IntellisenseController controller;

            if (textView.Properties.TryGetProperty <IntellisenseController>(typeof(IntellisenseController), out controller))
            {
                controller.AttachKeyboardFilter();
            }
            editFilter.AttachKeyboardFilter(textViewAdapter);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="textSearchService"></param>
        /// <param name="IEditorOperationsFactoryService"></param>
        /// <param name="IEditorFormatMapService"></param>
        /// <param name="ITextStructureNavigator"></param>
        public Selector(
            IWpfTextView view,
            ITextSearchService textSearchService,
            IEditorOperationsFactoryService editorOperationsService,
            IEditorFormatMapService formatMapService       = null,
            ITextStructureNavigator textStructureNavigator = null
            )
        {
            this.view = view;

            // Services
            this.textSearchService      = textSearchService ?? throw new ArgumentNullException("textSearchService");
            this.editorOperations       = editorOperationsService.GetEditorOperations(this.view);
            this.textStructureNavigator = textStructureNavigator;
            this.Dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;

            this.Selections     = new List <Selection>();
            this.SavedClipboard = new List <String>();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="textSearchService"></param>
        /// <param name="editorOperationsService"></param>
        /// <param name="textStructureNavigator"></param>
        /// <param name="outliningManagerService"></param>
        public Selector(
            IWpfTextView view,
            ITextSearchService textSearchService,
            IEditorOperationsFactoryService editorOperationsService,
            ITextStructureNavigator textStructureNavigator,
            IOutliningManagerService outliningManagerService)
        {
            this.view = view;

            // Services
            this.textSearchService      = textSearchService;
            this.EditorOperations       = editorOperationsService.GetEditorOperations(this.view);
            this.textStructureNavigator = textStructureNavigator;
            this.outliningManager       = outliningManagerService?.GetOutliningManager(this.view);
            this.Dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;

            this.Selections     = new List <Selection>();
            this.historyManager = new HistoryManager();
        }
Exemplo n.º 16
0
 public IncrementalSearch(ITextView textView, ITextSearchService textSearchService, IEditorOperationsFactoryService editorOperationsFactoryService)
 {
     if (textView == null)
     {
         throw new ArgumentNullException(nameof(textView));
     }
     if (textSearchService == null)
     {
         throw new ArgumentNullException(nameof(textSearchService));
     }
     if (editorOperationsFactoryService == null)
     {
         throw new ArgumentNullException(nameof(editorOperationsFactoryService));
     }
     TextView = textView;
     this.textSearchService = textSearchService;
     this.editorOperations  = editorOperationsFactoryService.GetEditorOperations(textView);
     SearchString           = string.Empty;
 }
        public void ExecuteCommand(ReturnKeyCommandArgs args, Action nextHandler)
        {
            // Check to see if the current line starts with exterior trivia. If so, we'll take over.
            // If not, let the nextHandler run.

            var caretPosition = args.TextView.GetCaretPoint(args.SubjectBuffer) ?? -1;

            if (caretPosition < 0)
            {
                nextHandler();
                return;
            }

            if (!CurrentLineStartsWithExteriorTrivia(args.SubjectBuffer, caretPosition))
            {
                nextHandler();
                return;
            }

            // Finally, wait and see if completion is computing. If it is, we want to allow
            // the list to pop up rather than insert a blank line in the buffer.
            if (_completionService.WaitForComputation(args.TextView, args.SubjectBuffer))
            {
                nextHandler();
                return;
            }

            // According to JasonMal, the text undo history is associated with the surface buffer
            // in projection buffer scenarios, so the following line's usage of the surface buffer
            // is correct.
            using (var transaction = _undoHistoryRegistry.GetHistory(args.TextView.TextBuffer).CreateTransaction(EditorFeaturesResources.InsertNewLine))
            {
                var editorOperations = _editorOperationsFactoryService.GetEditorOperations(args.TextView);
                editorOperations.InsertNewLine();

                CompleteComment(args.SubjectBuffer, args.TextView, caretPosition, InsertOnEnterTyped, CancellationToken.None);

                // Since we're wrapping the ENTER key undo transaction, we always complete
                // the transaction -- even if we didn't generate anything.
                transaction.Complete();
            }
        }
Exemplo n.º 18
0
        private bool StartNewModelComputation(ICompletionService completionService, CompletionTriggerInfo triggerInfo, bool filterItems, bool dismissIfEmptyAllowed = true)
        {
            AssertIsForeground();
            Contract.ThrowIfTrue(sessionOpt != null);

            if (this.TextView.Selection.Mode == TextSelectionMode.Box)
            {
                // No completion with multiple selection
                return(false);
            }

            if (this.TextView.Caret.Position.VirtualBufferPosition.IsInVirtualSpace)
            {
                // Convert any virtual whitespace to real whitespace by doing an empty edit at the caret position.
                _editorOperationsFactoryService.GetEditorOperations(TextView).InsertText("");
            }

            var computation = new ModelComputation <Model>(this, PrioritizedTaskScheduler.AboveNormalInstance);

            this.sessionOpt = new Session(this, computation, GetCompletionRules(), Presenter.CreateSession(TextView, SubjectBuffer, null));

            var completionProviders = triggerInfo.TriggerReason == CompletionTriggerReason.Snippets
                ? GetSnippetCompletionProviders()
                : GetCompletionProviders();

            sessionOpt.ComputeModel(completionService, triggerInfo, GetOptions(), completionProviders);

            var filterReason = triggerInfo.TriggerReason == CompletionTriggerReason.BackspaceOrDeleteCommand
                ? CompletionFilterReason.BackspaceOrDelete
                : CompletionFilterReason.TypeChar;

            if (filterItems)
            {
                sessionOpt.FilterModel(filterReason, dismissIfEmptyAllowed: dismissIfEmptyAllowed);
            }
            else
            {
                sessionOpt.IdentifyBestMatchAndFilterToAllItems(filterReason, dismissIfEmptyAllowed: dismissIfEmptyAllowed);
            }

            return(true);
        }
Exemplo n.º 19
0
        public IWpfTextViewMargin CreateMargin(IWpfTextViewHost textViewHost, IWpfTextViewMargin containerMargin)
        {
            IWpfTextView view = textViewHost.TextView;

            // Files larger than 1 MB should be skipped to avoid hangs.
            if (view.TextSnapshot.Length > (1024 * 1024))
            {
                return(null);
            }

            ITextDocument document;

            if (!_TextDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
            {
                return(null);
            }

            IVsExtensionManager manager = _serviceProvider.GetService(typeof(SVsExtensionManager)) as IVsExtensionManager;

            if (manager == null)
            {
                return(null);
            }

            IInstalledExtension extension;

            manager.TryGetInstalledExtension("FixMixedTabs", out extension);
            if (extension != null)
            {
                return(null);
            }

            ITextUndoHistory history;

            if (!_UndoHistoryRegistry.TryGetHistory(view.TextBuffer, out history))
            {
                Debug.Fail("Unexpected: couldn't get an undo history for the given text buffer");
                return(null);
            }

            return(new InformationBarMargin(view, document, _OperationsFactory.GetEditorOperations(view), history));
        }
Exemplo n.º 20
0
        private void SelectSpan(ITextView textView, SnapshotSpan snapshotSpan)
        {
            var source = textView.BufferGraph.MapUpToSnapshot(snapshotSpan, SpanTrackingMode.EdgeExclusive,
                                                              textView.TextSnapshot);
            var span = source.First <SnapshotSpan>();

            if (_outliningManagerService != null)
            {
                var outliningManager = _outliningManagerService.GetOutliningManager(textView);
                if (outliningManager != null)
                {
                    outliningManager.ExpandAll(span, (_) => true);
                }
            }
            var virtualSnapshotSpan = new VirtualSnapshotSpan(span);

            _editorOperationsFactory.GetEditorOperations(textView).SelectAndMoveCaret(
                virtualSnapshotSpan.Start, virtualSnapshotSpan.End,
                TextSelectionMode.Stream, EnsureSpanVisibleOptions.AlwaysCenter);
        }
Exemplo n.º 21
0
        protected override void OnMouseWheel(MouseWheelEventArgs e)
        {
            if (!IsClosed)
            {
                e.Handled = true;
                if (e.Delta == 0)
                {
                    return;
                }

                if ((Keyboard.Modifiers & ModifierKeys.Control) != 0 && CanMouseWheelZoom)
                {
                    var editorOperations = editorOperationsFactoryService.GetEditorOperations(TextView);
                    if (e.Delta > 0)
                    {
                        editorOperations.ZoomIn();
                    }
                    else
                    {
                        editorOperations.ZoomOut();
                    }
                }
                else
                {
                    int lines     = GetScrollWheelLines();
                    var direction = e.Delta < 0 ? ScrollDirection.Down : ScrollDirection.Up;
                    if (lines >= 0)
                    {
                        TextView.ViewScroller.ScrollViewportVerticallyByLines(direction, lines);
                    }
                    else
                    {
                        TextView.ViewScroller.ScrollViewportVerticallyByPage(direction);
                    }
                }
            }
            else
            {
                base.OnMouseWheel(e);
            }
        }
Exemplo n.º 22
0
        private bool StartNewModelComputation(
            CompletionService completionService,
            RoslynCompletionTrigger trigger)
        {
            AssertIsForeground();
            Contract.ThrowIfTrue(sessionOpt != null);

            if (completionService == null)
            {
                return(false);
            }

            if (this.TextView.Selection.Mode == TextSelectionMode.Box)
            {
                // No completion with multiple selection
                return(false);
            }

            // The caret may no longer be mappable into our subject buffer.
            var caret = TextView.GetCaretPoint(SubjectBuffer);

            if (!caret.HasValue)
            {
                return(false);
            }

            if (this.TextView.Caret.Position.VirtualBufferPosition.IsInVirtualSpace)
            {
                // Convert any virtual whitespace to real whitespace by doing an empty edit at the caret position.
                _editorOperationsFactoryService.GetEditorOperations(TextView).InsertText("");
            }

            var computation = new ModelComputation <Model>(ThreadingContext, this, PrioritizedTaskScheduler.AboveNormalInstance);

            this.sessionOpt = new Session(this, computation, Presenter.CreateSession(TextView, SubjectBuffer, null));

            sessionOpt.ComputeModel(completionService, trigger, _roles, GetOptions());
            sessionOpt.FilterModel(trigger.GetFilterReason(), filterState: null);

            return(true);
        }
Exemplo n.º 23
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView   = editorAdaptersFactory.GetWpfTextView(textViewAdapter);
            var operations = editorOperationsFactory.GetEditorOperations(textView);
            var navigator  = textStructureNavigatorFacrtory.GetTextStructureNavigator(textView.TextBuffer);

            if (textView == null)
            {
                Debug.Fail("Unable to get IWpfTextView from text view adapter.");
                return;
            }

            var commandFilter = new SubwordNavigationCommandFilter(textView, operations, navigator);

            var hr = textViewAdapter.AddCommandFilter(commandFilter, out IOleCommandTarget next);

            if (ErrorHandler.Succeeded(hr))
            {
                commandFilter.Next = next;
            }
        }
Exemplo n.º 24
0
        public bool ExecuteCommand(PasteCommandArgs args, CommandExecutionContext executionContext)
        {
            if (_site.GetPythonToolsService().FormattingOptions.PasteRemovesReplPrompts)
            {
                var beforePaste = args.TextView.TextSnapshot;
                if (_editOperationsFactory.GetEditorOperations(args.TextView).Paste())
                {
                    var afterPaste = args.TextView.TextSnapshot;
                    var um         = _undoManagerFactory.GetTextBufferUndoManager(afterPaste.TextBuffer);
                    using (var undo = um.TextBufferUndoHistory.CreateTransaction(Strings.RemoveReplPrompts)) {
                        if (ReplPromptHelpers.RemovePastedPrompts(beforePaste, afterPaste))
                        {
                            undo.Complete();
                        }
                    }
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 25
0
        public void ReplWindowCreated(IReplWindow window)
        {
            var model      = _serviceProvider.GetComponentModel();
            var textView   = window.TextView;
            var vsTextView = _adapterFact.GetViewAdapter(textView);

            if (window.Evaluator is PythonReplEvaluator)
            {
                textView.Properties.AddProperty(typeof(PythonReplEvaluator), (PythonReplEvaluator)window.Evaluator);
            }

            var editFilter             = new EditFilter(window.TextView, _editorOpsFactory.GetEditorOperations(textView), _serviceProvider);
            var intellisenseController = IntellisenseControllerProvider.GetOrCreateController(
                _serviceProvider,
                model,
                textView
                );

            editFilter.AttachKeyboardFilter(vsTextView);
            intellisenseController.AttachKeyboardFilter();
        }
Exemplo n.º 26
0
        private static string AdjustForVirtualSpace(TextChange textChange, ITextView textView, IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            var newText = textChange.NewText;

            var caretPoint        = textView.Caret.Position.BufferPosition;
            var virtualCaretPoint = textView.Caret.Position.VirtualBufferPosition;

            if (textChange.Span.IsEmpty &&
                textChange.Span.Start == caretPoint &&
                virtualCaretPoint.IsInVirtualSpace)
            {
                // They're in virtual space and the text change is specified against the cursor
                // position that isn't in virtual space.  In this case, add the virtual spaces to the
                // thing we're adding.
                var editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
                var whitespace       = editorOperations.GetWhitespaceForVirtualSpace(virtualCaretPoint);
                return(whitespace + newText);
            }

            return(newText);
        }
Exemplo n.º 27
0
        public IOleCommandTarget GetCommandTarget(IWpfTextView textView, IOleCommandTarget nextTarget)
        {
            EditFilter filter;

            if (!textView.Properties.TryGetProperty <EditFilter>(typeof(EditFilter), out filter))
            {
                textView.Properties[typeof(EditFilter)] = filter = new EditFilter(
                    textView,
                    _editorOpsFactory.GetEditorOperations(textView),
                    _serviceProvider
                    );
                var intellisenseController = IntellisenseControllerProvider.GetOrCreateController(
                    _serviceProvider,
                    (IComponentModel)_serviceProvider.GetService(typeof(SComponentModel)),
                    textView
                    );
                intellisenseController._oldTarget = nextTarget;
                filter._next = intellisenseController;
            }
            return(filter);
        }
        public IMouseProcessor GetAssociatedMouseProcessor(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin margin)
        {
            var aggregator = AggregatorFactory.CreateTagAggregator <$safeitemname$Tag>(wpfTextViewHost.TextView);
            var operations = OperationsFactory.GetEditorOperations(wpfTextViewHost.TextView);

            string commentString;

            if (wpfTextViewHost.TextView.TextDataModel.ContentType.IsOfType("basic"))
            {
                commentString = "' TODO: ";
            }
            else if (wpfTextViewHost.TextView.TextDataModel.ContentType.IsOfType("html"))
            {
                commentString = "<!-- TODO: -->";
            }
            else
            {
                commentString = "// TODO: ";
            }

            return(new GlyphMouseProcessor(commentString, wpfTextViewHost.TextView, margin, operations, aggregator));
        }
Exemplo n.º 29
0
        public IWpfTextViewMargin CreateMargin(IWpfTextViewHost textViewHost, IWpfTextViewMargin containerMargin)
        {
            IWpfTextView view = textViewHost.TextView;

            ITextDocument document;

            if (!TextDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
            {
                return(null);
            }


            ITextUndoHistory history;

            if (!UndoHistoryRegistry.TryGetHistory(view.TextBuffer, out history))
            {
                Debug.Fail("Unexpected: couldn't get an undo history for the given text buffer");
                return(null);
            }

            return(new InformationBarMargin(view, document, OperationsFactory.GetEditorOperations(view), history));
        }
        /// <summary>
        /// Realizes the virtual space and updates session's applicable to span.
        /// We invoke this method after the session has triggered, because we don't want to act if there would be no completion.
        /// </summary>
        private void RealizeVirtualSpaceUpdateApplicableToSpan(IAsyncCompletionSessionOperations session, ITextView textView)
        {
            if (session == null || // We may only act if we have internal reference to the session
                !textView.Caret.InVirtualSpace || // We only act if caret is in virtual space
                !session.ApplicableToSpan.GetSpan(textView.TextSnapshot).IsEmpty)    // We only act if the applicable to span is of zero length (at the beginning of the line)
            {
                return;
            }

            // Realize the virtual space before triggering the session by inserting nothing through the editor opertaions.
            IEditorOperations editorOperations = EditorOperationsFactoryService.GetEditorOperations(textView);

            editorOperations?.InsertText("");

            // ApplicableToSpan just grew to include the realized white space.
            // We know that ApplicableToSpan was zero length, so let's recreate a zero length span at the caret location.
            // This method executed synchronously, and therefore we know that it is safe to modify the applicable to span.
            session.ApplicableToSpan = textView.TextSnapshot.CreateTrackingSpan(
                start: textView.Caret.Position.BufferPosition.Position,
                length: 0,
                trackingMode: SpanTrackingMode.EdgeInclusive);
        }
Exemplo n.º 31
0
        private bool TryHandleReturnKey(ITextBuffer subjectBuffer, ITextView textView)
        {
            if (
                !subjectBuffer.GetFeatureOnOffOption(
                    FeatureOnOffOptions.AutoInsertBlockCommentStartString
                    )
                )
            {
                return(false);
            }

            var caretPosition = textView.GetCaretPoint(subjectBuffer);

            if (caretPosition == null)
            {
                return(false);
            }

            var textToInsert = GetTextToInsert(caretPosition.Value);

            if (textToInsert == null)
            {
                return(false);
            }

            using var transaction = _undoHistoryRegistry
                                    .GetHistory(textView.TextBuffer)
                                    .CreateTransaction(EditorFeaturesResources.Insert_new_line);

            var editorOperations = _editorOperationsFactoryService.GetEditorOperations(textView);

            editorOperations.ReplaceText(GetReplacementSpan(caretPosition.Value), textToInsert);

            transaction.Complete();
            return(true);
        }
Exemplo n.º 32
0
		public ReplEditorOperations(IReplEditor2 replEditor, IWpfTextView wpfTextView, IEditorOperationsFactoryService editorOperationsFactoryService) {
			this.replEditor = replEditor;
			this.wpfTextView = wpfTextView;
			EditorOperations = editorOperationsFactoryService.GetEditorOperations(wpfTextView);
		}
Exemplo n.º 33
0
 public ReplEditorOperations(IReplEditor2 replEditor, IWpfTextView wpfTextView, IEditorOperationsFactoryService editorOperationsFactoryService)
 {
     this.replEditor  = replEditor;
     this.wpfTextView = wpfTextView;
     EditorOperations = editorOperationsFactoryService.GetEditorOperations(wpfTextView);
 }
 public DefaultTextViewMouseProcessor(IWpfTextView wpfTextView, IEditorOperationsFactoryService editorOperationsFactoryService)
 {
     this.wpfTextView = wpfTextView ?? throw new ArgumentNullException(nameof(wpfTextView));
     editorOperations = editorOperationsFactoryService.GetEditorOperations(wpfTextView);
 }
Exemplo n.º 35
0
        public InteractiveWindow(
            IInteractiveWindowEditorFactoryService host,
            IContentTypeRegistryService contentTypeRegistry,
            ITextBufferFactoryService bufferFactory,
            IProjectionBufferFactoryService projectionBufferFactory,
            IEditorOperationsFactoryService editorOperationsFactory,
            ITextEditorFactoryService editorFactory,
            IRtfBuilderService rtfBuilderService,
            IIntellisenseSessionStackMapService intellisenseSessionStackMap,
            ISmartIndentationService smartIndenterService,
            IInteractiveEvaluator evaluator)
        {
            if (evaluator == null)
            {
                throw new ArgumentNullException(nameof(evaluator));
            }

            _dangerous_uiOnly = new UIThreadOnly(this, host);

            this.Properties = new PropertyCollection();
            _history        = new History();

            _intellisenseSessionStackMap = intellisenseSessionStackMap;
            _smartIndenterService        = smartIndenterService;

            var replContentType       = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveContentTypeName);
            var replOutputContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveOutputContentTypeName);

            _outputBuffer              = bufferFactory.CreateTextBuffer(replOutputContentType);
            _standardInputBuffer       = bufferFactory.CreateTextBuffer();
            _promptBuffer              = bufferFactory.CreateTextBuffer();
            _secondaryPromptBuffer     = bufferFactory.CreateTextBuffer();
            _standardInputPromptBuffer = bufferFactory.CreateTextBuffer();
            _outputLineBreakBuffer     = bufferFactory.CreateTextBuffer();

            var projBuffer = projectionBufferFactory.CreateProjectionBuffer(
                new EditResolver(this),
                Array.Empty <object>(),
                ProjectionBufferOptions.None,
                replContentType);

            projBuffer.Properties.AddProperty(typeof(InteractiveWindow), this);

            _projectionBuffer = projBuffer;
            _dangerous_uiOnly.AppendNewOutputProjectionBuffer(); // Constructor runs on UI thread.
            projBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(ProjectionBufferChanged);

            var roleSet = editorFactory.CreateTextViewRoleSet(
                PredefinedTextViewRoles.Analyzable,
                PredefinedTextViewRoles.Editable,
                PredefinedTextViewRoles.Interactive,
                PredefinedTextViewRoles.Zoomable,
                PredefinedInteractiveTextViewRoles.InteractiveTextViewRole);

            _textView = host.CreateTextView(this, projBuffer, roleSet);

            _textView.Caret.PositionChanged += CaretPositionChanged;

            _textView.Options.SetOptionValue(DefaultTextViewHostOptions.HorizontalScrollBarId, false);
            _textView.Options.SetOptionValue(DefaultTextViewHostOptions.LineNumberMarginId, false);
            _textView.Options.SetOptionValue(DefaultTextViewHostOptions.OutliningMarginId, false);
            _textView.Options.SetOptionValue(DefaultTextViewHostOptions.GlyphMarginId, false);
            _textView.Options.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, WordWrapStyles.WordWrap);

            _lineBreakString = _textView.Options.GetNewLineCharacter();
            _dangerous_uiOnly.EditorOperations = editorOperationsFactory.GetEditorOperations(_textView); // Constructor runs on UI thread.

            _buffer       = new OutputBuffer(this);
            _outputWriter = new InteractiveWindowWriter(this, spans: null);

            SortedSpans errorSpans = new SortedSpans();

            _errorOutputWriter = new InteractiveWindowWriter(this, errorSpans);
            OutputClassifierProvider.AttachToBuffer(_outputBuffer, errorSpans);

            _rtfBuilderService = rtfBuilderService;

            RequiresUIThread();
            evaluator.CurrentWindow = this;
            _evaluator = evaluator;
        }
Exemplo n.º 36
0
        internal VsSimulation(IVimBufferCoordinator bufferCoordinator, bool simulateResharper, bool simulateStandardKeyMappings, IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            _wpfTextView = (IWpfTextView)bufferCoordinator.VimBuffer.TextView;
            _factory = new MockRepository(MockBehavior.Strict);
            _defaultKeyboardDevice = new DefaultKeyboardDevice(InputManager.Current);
            _testableSynchronizationContext = new TestableSynchronizationContext();

            // Create the IVsAdapter and pick reasonable defaults here.  Consumers can modify
            // this via an exposed property
            _vsAdapter = _factory.Create<IVsAdapter>();
            _vsAdapter.SetupGet(x => x.InAutomationFunction).Returns(false);
            _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(_defaultKeyboardDevice);
            _vsAdapter.Setup(x => x.IsReadOnly(It.IsAny<ITextBuffer>())).Returns(false);
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(_wpfTextView)).Returns(false);

            _resharperUtil = _factory.Create<IResharperUtil>();
            _resharperUtil.SetupGet(x => x.IsInstalled).Returns(simulateResharper);

            _displayWindowBroker = _factory.Create<IDisplayWindowBroker>();
            _displayWindowBroker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsSmartTagSessionActive).Returns(false);

            _defaultCommandTarget = new DefaultCommandTarget(
                bufferCoordinator.VimBuffer.TextView,
                editorOperationsFactoryService.GetEditorOperations(bufferCoordinator.VimBuffer.TextView));

            // Visual Studio hides the default IOleCommandTarget inside of the IWpfTextView property
            // bag.  The default KeyProcessor implementation looks here for IOleCommandTarget to
            // process text input
            _wpfTextView.Properties[typeof(IOleCommandTarget)] = _defaultCommandTarget;

            // Create the VsCommandTarget.  It's next is the final and default Visual Studio
            // command target
            var vsTextView = _factory.Create<IVsTextView>();
            IOleCommandTarget nextCommandTarget = _defaultCommandTarget;
            vsTextView.Setup(x => x.AddCommandFilter(It.IsAny<IOleCommandTarget>(), out nextCommandTarget)).Returns(VSConstants.S_OK);
            var vsCommandTarget = VsCommandTarget.Create(
                bufferCoordinator,
                vsTextView.Object,
                _vsAdapter.Object,
                _displayWindowBroker.Object,
                _resharperUtil.Object).Value;

            // Time to setup the start command target.  If we are simulating R# then put them ahead of VsVim
            // on the IOleCommandTarget chain.  VsVim doesn't try to fight R# and prefers instead to be
            // behind them
            if (simulateResharper)
            {
                var resharperCommandTarget = new ResharperCommandTarget(_wpfTextView, vsCommandTarget);
                _commandTarget = resharperCommandTarget;
            }
            else
            {
                _commandTarget = vsCommandTarget;
            }

            // Create the input controller.  Make sure that the VsVim one is ahead in the list
            // from the default Visual Studio one.  We can guarantee this is true due to MEF
            // ordering of the components
            var keyProcessors = new List<Microsoft.VisualStudio.Text.Editor.KeyProcessor>();
            keyProcessors.Add(new VsKeyProcessor(_vsAdapter.Object, bufferCoordinator));
            keyProcessors.Add(new SimulationKeyProcessor(bufferCoordinator.VimBuffer.TextView));
            _defaultInputController = new DefaultInputController(bufferCoordinator.VimBuffer.TextView, keyProcessors);
        }
		public DefaultTextViewMouseProcessor(IWpfTextView wpfTextView, IEditorOperationsFactoryService editorOperationsFactoryService) {
			if (wpfTextView == null)
				throw new ArgumentNullException(nameof(wpfTextView));
			this.wpfTextView = wpfTextView;
			editorOperations = editorOperationsFactoryService.GetEditorOperations(wpfTextView);
		}
Exemplo n.º 38
0
        internal VsSimulation(IVimBufferCoordinator bufferCoordinator, bool simulateResharper, bool simulateStandardKeyMappings, IEditorOperationsFactoryService editorOperationsFactoryService, IKeyUtil keyUtil)
        {
            _keyUtil = keyUtil;
            _wpfTextView = (IWpfTextView)bufferCoordinator.VimBuffer.TextView;
            _factory = new MockRepository(MockBehavior.Strict);
            _vsKeyboardInputSimulation = new VsKeyboardInputSimulation(this, _wpfTextView);
            _testableSynchronizationContext = new TestableSynchronizationContext();
            _simulateStandardKeyMappings = simulateStandardKeyMappings;

            // Create the IVsAdapter and pick reasonable defaults here.  Consumers can modify 
            // this via an exposed property
            _vsAdapter = _factory.Create<IVsAdapter>();
            _vsAdapter.SetupGet(x => x.InAutomationFunction).Returns(false);
            _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(_vsKeyboardInputSimulation.KeyBoardDevice);
            _vsAdapter.Setup(x => x.IsReadOnly(It.IsAny<ITextBuffer>())).Returns(false);
            _vsAdapter.Setup(x => x.IsReadOnly(It.IsAny<ITextView>())).Returns(false);
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(_wpfTextView)).Returns(false);

            _reportDesignerUtil = _factory.Create<IReportDesignerUtil>();
            _reportDesignerUtil.Setup(x => x.IsExpressionView(_wpfTextView)).Returns(false);

            _displayWindowBroker = _factory.Create<IDisplayWindowBroker>();
            _displayWindowBroker.SetupGet(x => x.IsCompletionActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsQuickInfoActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsSignatureHelpActive).Returns(false);
            _displayWindowBroker.SetupGet(x => x.IsSmartTagSessionActive).Returns(false);

            _vimApplicationSettings = _factory.Create<IVimApplicationSettings>();
            _vimApplicationSettings.SetupGet(x => x.UseEditorDefaults).Returns(true);
            _vimApplicationSettings.SetupGet(x => x.UseEditorIndent).Returns(true);
            _vimApplicationSettings.SetupGet(x => x.UseEditorTabAndBackspace).Returns(true);

            _vsSimulationCommandTarget = new SimulationCommandTarget(
                bufferCoordinator.VimBuffer.TextView,
                editorOperationsFactoryService.GetEditorOperations(bufferCoordinator.VimBuffer.TextView));

            var textManager = _factory.Create<ITextManager>();
            var commandTargets = new List<ICommandTarget>();
            if (simulateResharper)
            {
                commandTargets.Add(ReSharperKeyUtil.GetOrCreate(bufferCoordinator));
            }
            commandTargets.Add(new StandardCommandTarget(bufferCoordinator, textManager.Object, _displayWindowBroker.Object, _vsSimulationCommandTarget));

            // Create the VsCommandTarget.  It's next is the final and default Visual Studio 
            // command target
            _vsCommandTarget = new VsCommandTarget(
                bufferCoordinator,
                textManager.Object,
                _vsAdapter.Object,
                _displayWindowBroker.Object,
                _keyUtil,
                _vimApplicationSettings.Object,
                _vsSimulationCommandTarget,
                commandTargets.ToReadOnlyCollectionShallow());

            // Time to setup the start command target.  If we are simulating R# then put them ahead of VsVim
            // on the IOleCommandTarget chain.  VsVim doesn't try to fight R# and prefers instead to be 
            // behind them
            if (simulateResharper)
            {
                _reSharperCommandTarget = new ReSharperCommandTargetSimulation(_wpfTextView, _vsCommandTarget);
                _commandTarget = _reSharperCommandTarget;
            }
            else
            {
                _commandTarget = _vsCommandTarget;
            }

            // Visual Studio hides the default IOleCommandTarget inside of the IWpfTextView property
            // bag.  The default KeyProcessor implementation looks here for IOleCommandTarget to 
            // process text input.  
            //
            // This should always point to the head of the IOleCommandTarget chain.  In the implementation
            // it actually points to the IVsTextView implementation which then immediately routes to the
            // IOleCommandTarget head
            _wpfTextView.Properties[typeof(IOleCommandTarget)] = _commandTarget;

            // Create the input controller.  Make sure that the VsVim one is ahead in the list
            // from the default Visual Studio one.  We can guarantee this is true due to MEF 
            // ordering of the components
            if (simulateResharper)
            {
                _vsKeyboardInputSimulation.KeyProcessors.Add(ReSharperKeyUtil.GetOrCreate(bufferCoordinator));
            }
            _vsKeyboardInputSimulation.KeyProcessors.Add(new VsVimKeyProcessor(_vsAdapter.Object, bufferCoordinator, _keyUtil, _reportDesignerUtil.Object));
            _vsKeyboardInputSimulation.KeyProcessors.Add((KeyProcessor)bufferCoordinator);
            _vsKeyboardInputSimulation.KeyProcessors.Add(new SimulationKeyProcessor(bufferCoordinator.VimBuffer.TextView));
        }
            public UIThreadOnly(
                InteractiveWindow window,
                IInteractiveWindowEditorFactoryService factory,
                IContentTypeRegistryService contentTypeRegistry,
                ITextBufferFactoryService bufferFactory,
                IProjectionBufferFactoryService projectionBufferFactory,
                IEditorOperationsFactoryService editorOperationsFactory,
                ITextEditorFactoryService editorFactory,
                IRtfBuilderService rtfBuilderService,
                IIntellisenseSessionStackMapService intellisenseSessionStackMap,
                ISmartIndentationService smartIndenterService,
                IInteractiveEvaluator evaluator,
                IWaitIndicator waitIndicator)
            {
                _window = window;
                _factory = factory;
                _rtfBuilderService = (IRtfBuilderService2)rtfBuilderService;
                _intellisenseSessionStackMap = intellisenseSessionStackMap;
                _smartIndenterService = smartIndenterService;
                _waitIndicator = waitIndicator;
                Evaluator = evaluator;

                var replContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveContentTypeName);
                var replOutputContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveOutputContentTypeName);

                OutputBuffer = bufferFactory.CreateTextBuffer(replOutputContentType);
                StandardInputBuffer = bufferFactory.CreateTextBuffer();
                _inertType = bufferFactory.InertContentType;

                _projectionBuffer = projectionBufferFactory.CreateProjectionBuffer(
                    new EditResolver(window),
                    Array.Empty<object>(),
                    ProjectionBufferOptions.None,
                    replContentType);

                _projectionBuffer.Properties.AddProperty(typeof(InteractiveWindow), window);

                AppendNewOutputProjectionBuffer();
                _projectionBuffer.Changed += new EventHandler<TextContentChangedEventArgs>(ProjectionBufferChanged);

                var roleSet = editorFactory.CreateTextViewRoleSet(
                    PredefinedTextViewRoles.Analyzable,
                    PredefinedTextViewRoles.Editable,
                    PredefinedTextViewRoles.Interactive,
                    PredefinedTextViewRoles.Zoomable,
                    PredefinedInteractiveTextViewRoles.InteractiveTextViewRole);

                TextView = factory.CreateTextView(window, _projectionBuffer, roleSet);
                TextView.Caret.PositionChanged += CaretPositionChanged;

                var options = TextView.Options;
                options.SetOptionValue(DefaultTextViewHostOptions.HorizontalScrollBarId, true);
                options.SetOptionValue(DefaultTextViewHostOptions.LineNumberMarginId, false);
                options.SetOptionValue(DefaultTextViewHostOptions.OutliningMarginId, false);
                options.SetOptionValue(DefaultTextViewHostOptions.GlyphMarginId, false);
                options.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, WordWrapStyles.None);

                _lineBreakString = options.GetNewLineCharacter();
                EditorOperations = editorOperationsFactory.GetEditorOperations(TextView);

                _buffer = new OutputBuffer(window);
                OutputWriter = new InteractiveWindowWriter(window, spans: null);

                SortedSpans errorSpans = new SortedSpans();
                ErrorOutputWriter = new InteractiveWindowWriter(window, errorSpans);
                OutputClassifierProvider.AttachToBuffer(OutputBuffer, errorSpans);
            }
		public DefaultTextViewCommandTarget(ITextView textView, IEditorOperationsFactoryService editorOperationsFactoryService) {
			if (textView == null)
				throw new ArgumentNullException(nameof(textView));
			this.textView = textView;
			EditorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
		}
        public InteractiveWindow(
            IInteractiveWindowEditorFactoryService host,
            IContentTypeRegistryService contentTypeRegistry,
            ITextBufferFactoryService bufferFactory,
            IProjectionBufferFactoryService projectionBufferFactory,
            IEditorOperationsFactoryService editorOperationsFactory,
            ITextEditorFactoryService editorFactory,
            IIntellisenseSessionStackMapService intellisenseSessionStackMap,
            ISmartIndentationService smartIndenterService,
            IInteractiveEvaluator evaluator)
        {
            if (evaluator == null)
            {
                throw new ArgumentNullException(nameof(evaluator));
            }

            _dangerous_uiOnly = new UIThreadOnly(this, host);

            this.Properties = new PropertyCollection();
            _history = new History();

            _intellisenseSessionStackMap = intellisenseSessionStackMap;
            _smartIndenterService = smartIndenterService;

            var textContentType = contentTypeRegistry.GetContentType("text");
            var replContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveContentTypeName);
            var replOutputContentType = contentTypeRegistry.GetContentType(PredefinedInteractiveContentTypes.InteractiveOutputContentTypeName);

            _outputBuffer = bufferFactory.CreateTextBuffer(replOutputContentType);
            _standardInputBuffer = bufferFactory.CreateTextBuffer();

            var projBuffer = projectionBufferFactory.CreateProjectionBuffer(
                new EditResolver(this),
                Array.Empty<object>(),
                ProjectionBufferOptions.None,
                replContentType);

            // we need to set IReplPromptProvider property before TextViewHost is instantiated so that ReplPromptTaggerProvider can bind to it 
            projBuffer.Properties.AddProperty(typeof(InteractiveWindow), this);

            _projectionBuffer = projBuffer;
            _dangerous_uiOnly.AppendNewOutputProjectionBuffer(); // Constructor runs on UI thread.
            projBuffer.Changed += new EventHandler<TextContentChangedEventArgs>(ProjectionBufferChanged);

            var roleSet = editorFactory.CreateTextViewRoleSet(
                PredefinedTextViewRoles.Analyzable,
                PredefinedTextViewRoles.Editable,
                PredefinedTextViewRoles.Interactive,
                PredefinedTextViewRoles.Zoomable,
                PredefinedInteractiveTextViewRoles.InteractiveTextViewRole);

            _textView = host.CreateTextView(this, projBuffer, roleSet);

            _textView.Caret.PositionChanged += CaretPositionChanged;

            _textView.Options.SetOptionValue(DefaultTextViewHostOptions.HorizontalScrollBarId, false);
            _textView.Options.SetOptionValue(DefaultTextViewHostOptions.LineNumberMarginId, false);
            _textView.Options.SetOptionValue(DefaultTextViewHostOptions.OutliningMarginId, false);
            _textView.Options.SetOptionValue(DefaultTextViewHostOptions.GlyphMarginId, false);
            _textView.Options.SetOptionValue(DefaultTextViewOptions.WordWrapStyleId, WordWrapStyles.WordWrap);

            _lineBreakString = _textView.Options.GetNewLineCharacter();
            _dangerous_uiOnly.EditorOperations = editorOperationsFactory.GetEditorOperations(_textView); // Constructor runs on UI thread.

            _buffer = new OutputBuffer(this);
            _outputWriter = new InteractiveWindowWriter(this, spans: null);

            SortedSpans errorSpans = new SortedSpans();
            _errorOutputWriter = new InteractiveWindowWriter(this, errorSpans);
            OutputClassifierProvider.AttachToBuffer(_outputBuffer, errorSpans);

            RequiresUIThread();
            evaluator.CurrentWindow = this;
            _evaluator = evaluator;
        }
Exemplo n.º 42
0
		public SearchService(IWpfTextView wpfTextView, ITextSearchService2 textSearchService2, ISearchSettings searchSettings, IMessageBoxService messageBoxService, ITextStructureNavigator textStructureNavigator, Lazy<IReplaceListenerProvider>[] replaceListenerProviders, IEditorOperationsFactoryService editorOperationsFactoryService) {
			if (wpfTextView == null)
				throw new ArgumentNullException(nameof(wpfTextView));
			if (textSearchService2 == null)
				throw new ArgumentNullException(nameof(textSearchService2));
			if (searchSettings == null)
				throw new ArgumentNullException(nameof(searchSettings));
			if (messageBoxService == null)
				throw new ArgumentNullException(nameof(messageBoxService));
			if (textStructureNavigator == null)
				throw new ArgumentNullException(nameof(textStructureNavigator));
			if (replaceListenerProviders == null)
				throw new ArgumentNullException(nameof(replaceListenerProviders));
			this.wpfTextView = wpfTextView;
			editorOperations = editorOperationsFactoryService.GetEditorOperations(wpfTextView);
			this.textSearchService2 = textSearchService2;
			this.searchSettings = searchSettings;
			this.messageBoxService = messageBoxService;
			this.textStructureNavigator = textStructureNavigator;
			this.replaceListenerProviders = replaceListenerProviders;
			listeners = new List<ITextMarkerListener>();
			searchString = string.Empty;
			replaceString = string.Empty;
			searchKind = SearchKind.None;
			searchControlPosition = SearchControlPosition.Default;
			wpfTextView.VisualElement.CommandBindings.Add(new CommandBinding(ApplicationCommands.Find, (s, e) => ShowFind()));
			wpfTextView.VisualElement.CommandBindings.Add(new CommandBinding(ApplicationCommands.Replace, (s, e) => ShowReplace()));
			wpfTextView.Closed += WpfTextView_Closed;
			UseGlobalSettings(true);
		}