Example #1
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));
        }