Beispiel #1
0
        void UpdateCommand(bool clearSearchText)
        {
            Debug.Assert(IsCommandMode);
            if (!IsCommandMode)
            {
                return;
            }

            var command = replCommands.SelectedCommand;

            if (command == null)
            {
                return;
            }

            MoveToEnd();
            var currentInput = CurrentInput;

            if (currentInput.Equals(command))
            {
                return;
            }

            wpfTextView.Selection.Clear();
            ReplEditorOperations.AddUserInput(Span.FromBounds(FilterOffset(OffsetOfPrompt.Value), wpfTextView.TextSnapshot.Length), command, clearSearchText);
        }
Beispiel #2
0
        void FlushScriptOutputUIThread()
        {
            dispatcher.VerifyAccess();
            if (wpfTextViewHost.IsClosed)
            {
                return;
            }

            var  caretPos             = wpfTextView.Caret.Position;
            bool caretIsInEditingArea = OffsetOfPrompt != null && CaretOffset >= OffsetOfPrompt.Value;

            ColorAndText[] newPendingOutput = null;
            var            sb = new StringBuilder();

            lock (pendingScriptOutputLock) {
                pendingScriptOutput_dispatching = false;
                newPendingOutput = pendingScriptOutput.ToArray();
                pendingScriptOutput.Clear();
            }

            string currentCommand = null;
            bool   isCommandMode  = IsCommandMode;

            if (isCommandMode)
            {
                currentCommand = CurrentInput;
                cachedColorsList.RemoveLastCachedTextColorsCollection();
                ClearCurrentInput(true);
            }
            if (newPendingOutput != null)
            {
                Debug.Assert(scriptOutputCachedTextColorsCollection != null);
                foreach (var info in newPendingOutput)
                {
                    sb.Append(info.Text);
                    scriptOutputCachedTextColorsCollection?.Append(info.Color, info.Text);
                }
            }
            RawAppend(sb.ToString());
            MoveToEnd();
            if (isCommandMode)
            {
                int posBeforeNewLine = wpfTextView.TextSnapshot.Length;
                CreateEmptyLastLineIfNeededAndMoveCaret();
                int extraLen = wpfTextView.TextSnapshot.Length - posBeforeNewLine;

                PrintPrompt();
                ReplEditorOperations.AddUserInput(currentCommand);

                if (caretIsInEditingArea)
                {
                    var newPos = new SnapshotPoint(wpfTextView.TextSnapshot, caretPos.BufferPosition.Position + sb.Length + extraLen);
                    wpfTextView.Caret.MoveTo(newPos, caretPos.Affinity);
                }
            }

            wpfTextView.Caret.EnsureVisible();
        }
Beispiel #3
0
        public ReplEditor(ReplEditorOptions options, IDsTextEditorFactoryService dsTextEditorFactoryService, IContentTypeRegistryService contentTypeRegistryService, ITextBufferFactoryService textBufferFactoryService, IEditorOperationsFactoryService editorOperationsFactoryService, IEditorOptionsFactoryService editorOptionsFactoryService, IClassificationTypeRegistryService classificationTypeRegistryService, IThemeClassificationTypeService themeClassificationTypeService, IPickSaveFilename pickSaveFilename)
        {
            this.dispatcher       = Dispatcher.CurrentDispatcher;
            this.pickSaveFilename = pickSaveFilename;
            options = options?.Clone() ?? new ReplEditorOptions();
            options.CreateGuidObjects     = CommonGuidObjectsProvider.Create(options.CreateGuidObjects, new GuidObjectsProvider(this));
            this.PrimaryPrompt            = options.PrimaryPrompt;
            this.SecondaryPrompt          = options.SecondaryPrompt;
            this.subBuffers               = new List <ReplSubBuffer>();
            this.cachedColorsList         = new CachedColorsList();
            TextClassificationType        = classificationTypeRegistryService.GetClassificationType(ThemeClassificationTypeNames.Text);
            ReplPrompt1ClassificationType = classificationTypeRegistryService.GetClassificationType(ThemeClassificationTypeNames.ReplPrompt1);
            ReplPrompt2ClassificationType = classificationTypeRegistryService.GetClassificationType(ThemeClassificationTypeNames.ReplPrompt2);

            var contentType = contentTypeRegistryService.GetContentType(options.ContentType, options.ContentTypeString) ?? textBufferFactoryService.TextContentType;
            var textBuffer  = textBufferFactoryService.CreateTextBuffer(contentType);

            CachedColorsListTaggerProvider.AddColorizer(textBuffer, cachedColorsList);
            var roles           = dsTextEditorFactoryService.CreateTextViewRoleSet(options.Roles);
            var textView        = dsTextEditorFactoryService.CreateTextView(textBuffer, roles, editorOptionsFactoryService.GlobalOptions, options);
            var wpfTextViewHost = dsTextEditorFactoryService.CreateTextViewHost(textView, false);

            this.wpfTextViewHost = wpfTextViewHost;
            this.wpfTextView     = wpfTextViewHost.TextView;
            ReplEditorUtils.AddInstance(this, wpfTextView);
            wpfTextView.Options.SetOptionValue(DefaultWpfViewOptions.AppearanceCategory, AppearanceCategoryConstants.REPL);
            wpfTextView.Options.SetOptionValue(DefaultTextViewOptions.DragDropEditingId, false);
            //TODO: ReplEditorOperations doesn't support virtual space
            wpfTextView.Options.SetOptionValue(DefaultTextViewOptions.UseVirtualSpaceId, false);
            //TODO: Support box selection
            wpfTextView.Options.SetOptionValue(DefaultDsTextViewOptions.AllowBoxSelectionId, false);
            wpfTextView.Options.OptionChanged         += Options_OptionChanged;
            wpfTextView.TextBuffer.ChangedLowPriority += TextBuffer_ChangedLowPriority;
            wpfTextView.Closed += WpfTextView_Closed;
            this.wpfTextView.TextBuffer.Changed += TextBuffer_Changed;
            AddNewDocument();
            WriteOffsetOfPrompt(null, true);
            ReplEditorOperations              = new ReplEditorOperations(this, wpfTextView, editorOperationsFactoryService);
            wpfTextView.VisualElement.Loaded += WpfTextView_Loaded;
            UpdateRefreshScreenOnChange();
            CustomLineNumberMargin.SetOwner(wpfTextView, new ReplCustomLineNumberMarginOwner(this, themeClassificationTypeService));
        }
Beispiel #4
0
		public ReplEditor(ReplEditorOptions options, IDsTextEditorFactoryService dsTextEditorFactoryService, IContentTypeRegistryService contentTypeRegistryService, ITextBufferFactoryService textBufferFactoryService, IEditorOperationsFactoryService editorOperationsFactoryService, IEditorOptionsFactoryService editorOptionsFactoryService, IClassificationTypeRegistryService classificationTypeRegistryService, IThemeClassificationTypeService themeClassificationTypeService, IPickSaveFilename pickSaveFilename, ITextViewUndoManagerProvider textViewUndoManagerProvider) {
			dispatcher = Dispatcher.CurrentDispatcher;
			this.pickSaveFilename = pickSaveFilename;
			options = options?.Clone() ?? new ReplEditorOptions();
			options.CreateGuidObjects = CommonGuidObjectsProvider.Create(options.CreateGuidObjects, new GuidObjectsProvider(this));
			PrimaryPrompt = options.PrimaryPrompt;
			SecondaryPrompt = options.SecondaryPrompt;
			subBuffers = new List<ReplSubBuffer>();
			cachedColorsList = new CachedColorsList();
			TextClassificationType = classificationTypeRegistryService.GetClassificationType(ThemeClassificationTypeNames.Text);
			ReplPrompt1ClassificationType = classificationTypeRegistryService.GetClassificationType(ThemeClassificationTypeNames.ReplPrompt1);
			ReplPrompt2ClassificationType = classificationTypeRegistryService.GetClassificationType(ThemeClassificationTypeNames.ReplPrompt2);

			var contentType = contentTypeRegistryService.GetContentType(options.ContentType, options.ContentTypeString) ?? textBufferFactoryService.TextContentType;
			var textBuffer = textBufferFactoryService.CreateTextBuffer(contentType);
			CachedColorsListTaggerProvider.AddColorizer(textBuffer, cachedColorsList);
			var roles = dsTextEditorFactoryService.CreateTextViewRoleSet(options.Roles);
			var textView = dsTextEditorFactoryService.CreateTextView(textBuffer, roles, editorOptionsFactoryService.GlobalOptions, options);
			var wpfTextViewHost = dsTextEditorFactoryService.CreateTextViewHost(textView, false);
			this.wpfTextViewHost = wpfTextViewHost;
			wpfTextView = wpfTextViewHost.TextView;
			textViewUndoManager = textViewUndoManagerProvider.GetTextViewUndoManager(wpfTextView);
			ReplEditorUtils.AddInstance(this, wpfTextView);
			wpfTextView.Options.SetOptionValue(DefaultWpfViewOptions.AppearanceCategory, AppearanceCategoryConstants.TextEditor);
			wpfTextView.Options.SetOptionValue(DefaultTextViewOptions.DragDropEditingId, false);
			//TODO: ReplEditorOperations doesn't support virtual space
			wpfTextView.Options.SetOptionValue(DefaultTextViewOptions.UseVirtualSpaceId, false);
			//TODO: Support box selection
			wpfTextView.Options.SetOptionValue(DefaultDsTextViewOptions.AllowBoxSelectionId, false);
			wpfTextView.Options.OptionChanged += Options_OptionChanged;
			wpfTextView.TextBuffer.ChangedLowPriority += TextBuffer_ChangedLowPriority;
			wpfTextView.Closed += WpfTextView_Closed;
			wpfTextView.TextBuffer.Changed += TextBuffer_Changed;
			AddNewDocument();
			WriteOffsetOfPrompt(null, true);
			ReplEditorOperations = new ReplEditorOperations(this, wpfTextView, editorOperationsFactoryService);
			wpfTextView.VisualElement.Loaded += WpfTextView_Loaded;
			UpdateRefreshScreenOnChange();
			CustomLineNumberMargin.SetOwner(wpfTextView, new ReplCustomLineNumberMarginOwner(this, themeClassificationTypeService));
		}