Inheritance: IViewScroller
Exemplo n.º 1
0
#pragma warning restore 0169

        public WpfTextView(ITextViewModel textViewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, IEditorOptionsFactoryService editorOptionsFactoryService, ICommandManager commandManager, ISmartIndentationService smartIndentationService, IFormattedTextSourceFactoryService formattedTextSourceFactoryService, IViewClassifierAggregatorService viewClassifierAggregatorService, ITextAndAdornmentSequencerFactoryService textAndAdornmentSequencerFactoryService, IClassificationFormatMapService classificationFormatMapService, IEditorFormatMapService editorFormatMapService, IAdornmentLayerDefinitionService adornmentLayerDefinitionService, ILineTransformProviderService lineTransformProviderService, Lazy <IWpfTextViewCreationListener, IDeferrableContentTypeAndTextViewRoleMetadata>[] wpfTextViewCreationListeners)
        {
            if (textViewModel == null)
            {
                throw new ArgumentNullException(nameof(textViewModel));
            }
            if (roles == null)
            {
                throw new ArgumentNullException(nameof(roles));
            }
            if (parentOptions == null)
            {
                throw new ArgumentNullException(nameof(parentOptions));
            }
            if (editorOptionsFactoryService == null)
            {
                throw new ArgumentNullException(nameof(editorOptionsFactoryService));
            }
            if (commandManager == null)
            {
                throw new ArgumentNullException(nameof(commandManager));
            }
            if (smartIndentationService == null)
            {
                throw new ArgumentNullException(nameof(smartIndentationService));
            }
            if (formattedTextSourceFactoryService == null)
            {
                throw new ArgumentNullException(nameof(formattedTextSourceFactoryService));
            }
            if (viewClassifierAggregatorService == null)
            {
                throw new ArgumentNullException(nameof(viewClassifierAggregatorService));
            }
            if (textAndAdornmentSequencerFactoryService == null)
            {
                throw new ArgumentNullException(nameof(textAndAdornmentSequencerFactoryService));
            }
            if (classificationFormatMapService == null)
            {
                throw new ArgumentNullException(nameof(classificationFormatMapService));
            }
            if (editorFormatMapService == null)
            {
                throw new ArgumentNullException(nameof(editorFormatMapService));
            }
            if (adornmentLayerDefinitionService == null)
            {
                throw new ArgumentNullException(nameof(adornmentLayerDefinitionService));
            }
            if (lineTransformProviderService == null)
            {
                throw new ArgumentNullException(nameof(lineTransformProviderService));
            }
            if (wpfTextViewCreationListeners == null)
            {
                throw new ArgumentNullException(nameof(wpfTextViewCreationListeners));
            }
            this.mouseHoverHelper     = new MouseHoverHelper(this);
            this.physicalLineCache    = new PhysicalLineCache(32);
            this.visiblePhysicalLines = new List <PhysicalLine>();
            this.invalidatedRegions   = new List <SnapshotSpan>();
            this.formattedTextSourceFactoryService = formattedTextSourceFactoryService;
            this.zoomLevel = ZoomConstants.DefaultZoom;
            this.adornmentLayerDefinitionService  = adornmentLayerDefinitionService;
            this.lineTransformProviderService     = lineTransformProviderService;
            this.wpfTextViewCreationListeners     = wpfTextViewCreationListeners.Where(a => roles.ContainsAny(a.Metadata.TextViewRoles)).ToArray();
            this.recreateLineTransformProvider    = true;
            this.normalAdornmentLayerCollection   = new AdornmentLayerCollection(this, LayerKind.Normal);
            this.overlayAdornmentLayerCollection  = new AdornmentLayerCollection(this, LayerKind.Overlay);
            this.underlayAdornmentLayerCollection = new AdornmentLayerCollection(this, LayerKind.Underlay);
            Properties                     = new PropertyCollection();
            TextViewModel                  = textViewModel;
            Roles                          = roles;
            Options                        = editorOptionsFactoryService.GetOptions(this);
            Options.Parent                 = parentOptions;
            ViewScroller                   = new ViewScroller(this);
            hasKeyboardFocus               = this.IsKeyboardFocusWithin;
            oldViewState                   = new ViewState(this);
            this.aggregateClassifier       = viewClassifierAggregatorService.GetClassifier(this);
            this.textAndAdornmentSequencer = textAndAdornmentSequencerFactoryService.Create(this);
            this.classificationFormatMap   = classificationFormatMapService.GetClassificationFormatMap(this);
            this.editorFormatMap           = editorFormatMapService.GetEditorFormatMap(this);

            this.textLayer = new TextLayer(GetAdornmentLayer(PredefinedAdornmentLayers.Text));
            Selection      = new TextSelection(this, GetAdornmentLayer(PredefinedAdornmentLayers.Selection), editorFormatMap);
            TextCaret      = new TextCaret(this, GetAdornmentLayer(PredefinedAdornmentLayers.Caret), smartIndentationService, classificationFormatMap);

            Children.Add(underlayAdornmentLayerCollection);
            Children.Add(normalAdornmentLayerCollection);
            Children.Add(overlayAdornmentLayerCollection);
            this.Cursor           = Cursors.IBeam;
            this.Focusable        = true;
            this.FocusVisualStyle = null;
            InitializeOptions();

            Options.OptionChanged         += EditorOptions_OptionChanged;
            TextBuffer.ChangedLowPriority += TextBuffer_ChangedLowPriority;
            TextViewModel.DataModel.ContentTypeChanged += DataModel_ContentTypeChanged;
            aggregateClassifier.ClassificationChanged  += AggregateClassifier_ClassificationChanged;
            textAndAdornmentSequencer.SequenceChanged  += TextAndAdornmentSequencer_SequenceChanged;
            classificationFormatMap.ClassificationFormatMappingChanged += ClassificationFormatMap_ClassificationFormatMappingChanged;
            editorFormatMap.FormatMappingChanged += EditorFormatMap_FormatMappingChanged;

            UpdateBackground();
            CreateFormattedLineSource(ViewportWidth);
            InitializeZoom();
            UpdateRemoveExtraTextLineVerticalPixels();

            if (Roles.Contains(PredefinedTextViewRoles.Interactive))
            {
                RegisteredCommandElement = commandManager.Register(VisualElement, this);
            }
            else
            {
                RegisteredCommandElement = NullRegisteredCommandElement.Instance;
            }

            NotifyTextViewCreated(TextViewModel.DataModel.ContentType, null);
        }
Exemplo n.º 2
0
#pragma warning restore 0169

		public WpfTextView(ITextViewModel textViewModel, ITextViewRoleSet roles, IEditorOptions parentOptions, IEditorOptionsFactoryService editorOptionsFactoryService, ICommandService commandService, ISmartIndentationService smartIndentationService, IFormattedTextSourceFactoryService formattedTextSourceFactoryService, IViewClassifierAggregatorService viewClassifierAggregatorService, ITextAndAdornmentSequencerFactoryService textAndAdornmentSequencerFactoryService, IClassificationFormatMapService classificationFormatMapService, IEditorFormatMapService editorFormatMapService, IAdornmentLayerDefinitionService adornmentLayerDefinitionService, ILineTransformProviderService lineTransformProviderService, ISpaceReservationStackProvider spaceReservationStackProvider, IWpfTextViewConnectionListenerServiceProvider wpfTextViewConnectionListenerServiceProvider, IBufferGraphFactoryService bufferGraphFactoryService, Lazy<IWpfTextViewCreationListener, IDeferrableContentTypeAndTextViewRoleMetadata>[] wpfTextViewCreationListeners) {
			if (textViewModel == null)
				throw new ArgumentNullException(nameof(textViewModel));
			if (roles == null)
				throw new ArgumentNullException(nameof(roles));
			if (parentOptions == null)
				throw new ArgumentNullException(nameof(parentOptions));
			if (editorOptionsFactoryService == null)
				throw new ArgumentNullException(nameof(editorOptionsFactoryService));
			if (commandService == null)
				throw new ArgumentNullException(nameof(commandService));
			if (smartIndentationService == null)
				throw new ArgumentNullException(nameof(smartIndentationService));
			if (formattedTextSourceFactoryService == null)
				throw new ArgumentNullException(nameof(formattedTextSourceFactoryService));
			if (viewClassifierAggregatorService == null)
				throw new ArgumentNullException(nameof(viewClassifierAggregatorService));
			if (textAndAdornmentSequencerFactoryService == null)
				throw new ArgumentNullException(nameof(textAndAdornmentSequencerFactoryService));
			if (classificationFormatMapService == null)
				throw new ArgumentNullException(nameof(classificationFormatMapService));
			if (editorFormatMapService == null)
				throw new ArgumentNullException(nameof(editorFormatMapService));
			if (adornmentLayerDefinitionService == null)
				throw new ArgumentNullException(nameof(adornmentLayerDefinitionService));
			if (lineTransformProviderService == null)
				throw new ArgumentNullException(nameof(lineTransformProviderService));
			if (spaceReservationStackProvider == null)
				throw new ArgumentNullException(nameof(spaceReservationStackProvider));
			if (wpfTextViewCreationListeners == null)
				throw new ArgumentNullException(nameof(wpfTextViewCreationListeners));
			if (wpfTextViewConnectionListenerServiceProvider == null)
				throw new ArgumentNullException(nameof(wpfTextViewConnectionListenerServiceProvider));
			if (bufferGraphFactoryService == null)
				throw new ArgumentNullException(nameof(bufferGraphFactoryService));
			mouseHoverHelper = new MouseHoverHelper(this);
			physicalLineCache = new PhysicalLineCache(32);
			visiblePhysicalLines = new List<PhysicalLine>();
			invalidatedRegions = new List<SnapshotSpan>();
			this.formattedTextSourceFactoryService = formattedTextSourceFactoryService;
			zoomLevel = ZoomConstants.DefaultZoom;
			DsImage.SetZoom(VisualElement, zoomLevel / 100);
			this.adornmentLayerDefinitionService = adornmentLayerDefinitionService;
			this.lineTransformProviderService = lineTransformProviderService;
			this.wpfTextViewCreationListeners = wpfTextViewCreationListeners.Where(a => roles.ContainsAny(a.Metadata.TextViewRoles)).ToArray();
			recreateLineTransformProvider = true;
			normalAdornmentLayerCollection = new AdornmentLayerCollection(this, LayerKind.Normal);
			overlayAdornmentLayerCollection = new AdornmentLayerCollection(this, LayerKind.Overlay);
			underlayAdornmentLayerCollection = new AdornmentLayerCollection(this, LayerKind.Underlay);
			IsVisibleChanged += WpfTextView_IsVisibleChanged;
			Properties = new PropertyCollection();
			TextViewModel = textViewModel;
			BufferGraph = bufferGraphFactoryService.CreateBufferGraph(TextViewModel.VisualBuffer);
			Roles = roles;
			Options = editorOptionsFactoryService.GetOptions(this);
			Options.Parent = parentOptions;
			ViewScroller = new ViewScroller(this);
			hasKeyboardFocus = IsKeyboardFocusWithin;
			oldViewState = new ViewState(this);
			aggregateClassifier = viewClassifierAggregatorService.GetClassifier(this);
			textAndAdornmentSequencer = textAndAdornmentSequencerFactoryService.Create(this);
			classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(this);
			editorFormatMap = editorFormatMapService.GetEditorFormatMap(this);
			spaceReservationStack = spaceReservationStackProvider.Create(this);

			textLayer = new TextLayer(GetAdornmentLayer(PredefinedAdornmentLayers.Text));
			Selection = new TextSelection(this, GetAdornmentLayer(PredefinedAdornmentLayers.Selection), editorFormatMap);
			TextCaret = new TextCaret(this, GetAdornmentLayer(PredefinedAdornmentLayers.Caret), smartIndentationService, classificationFormatMap);

			Children.Add(underlayAdornmentLayerCollection);
			Children.Add(normalAdornmentLayerCollection);
			Children.Add(overlayAdornmentLayerCollection);
			Cursor = Cursors.IBeam;
			Focusable = true;
			FocusVisualStyle = null;
			InitializeOptions();

			Options.OptionChanged += EditorOptions_OptionChanged;
			TextBuffer.ChangedLowPriority += TextBuffer_ChangedLowPriority;
			TextViewModel.DataModel.ContentTypeChanged += DataModel_ContentTypeChanged;
			aggregateClassifier.ClassificationChanged += AggregateClassifier_ClassificationChanged;
			textAndAdornmentSequencer.SequenceChanged += TextAndAdornmentSequencer_SequenceChanged;
			classificationFormatMap.ClassificationFormatMappingChanged += ClassificationFormatMap_ClassificationFormatMappingChanged;
			editorFormatMap.FormatMappingChanged += EditorFormatMap_FormatMappingChanged;
			spaceReservationStack.GotAggregateFocus += SpaceReservationStack_GotAggregateFocus;
			spaceReservationStack.LostAggregateFocus += SpaceReservationStack_LostAggregateFocus;

			UpdateBackground();
			CreateFormattedLineSource(ViewportWidth);
			InitializeZoom();
			UpdateRemoveExtraTextLineVerticalPixels();

			if (Roles.Contains(PredefinedTextViewRoles.Interactive))
				RegisteredCommandElement = commandService.Register(VisualElement, this);
			else
				RegisteredCommandElement = NullRegisteredCommandElement.Instance;

			wpfTextViewConnectionListenerServiceProvider.Create(this);
			NotifyTextViewCreated(TextViewModel.DataModel.ContentType, null);
		}