示例#1
0
 public TextAndAdornmentCollection(ITextAndAdornmentSequencer textAndAdornmentSequencer, IList <ISequenceElement> list)
     : base(list)
 {
     if (textAndAdornmentSequencer == null)
     {
         throw new ArgumentNullException(nameof(textAndAdornmentSequencer));
     }
     Sequencer = textAndAdornmentSequencer;
 }
示例#2
0
        public FormattedLineSource(ITextFormatterProvider textFormatterProvider, ITextParagraphPropertiesFactoryService textParagraphPropertiesFactoryService, ITextSnapshot sourceTextSnapshot, ITextSnapshot visualBufferSnapshot, int tabSize, double baseIndent, double wordWrapWidth, double maxAutoIndent, bool useDisplayMode, IClassifier aggregateClassifier, ITextAndAdornmentSequencer sequencer, IClassificationFormatMap classificationFormatMap, bool isViewWrapEnabled)
        {
            if (textFormatterProvider == null)
            {
                throw new ArgumentNullException(nameof(textFormatterProvider));
            }
            if (sourceTextSnapshot == null)
            {
                throw new ArgumentNullException(nameof(sourceTextSnapshot));
            }
            if (visualBufferSnapshot == null)
            {
                throw new ArgumentNullException(nameof(visualBufferSnapshot));
            }
            if (aggregateClassifier == null)
            {
                throw new ArgumentNullException(nameof(aggregateClassifier));
            }
            if (sequencer == null)
            {
                throw new ArgumentNullException(nameof(sequencer));
            }
            if (classificationFormatMap == null)
            {
                throw new ArgumentNullException(nameof(classificationFormatMap));
            }
            if (tabSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(tabSize));
            }
            if (sourceTextSnapshot != visualBufferSnapshot)
            {
                throw new NotSupportedException("Text snapshot must be identical to visual snapshot");
            }

            this.textFormatter      = textFormatterProvider.Create(useDisplayMode);
            this.formattedTextCache = new FormattedTextCache(useDisplayMode);
            this.textParagraphPropertiesFactoryService = textParagraphPropertiesFactoryService;
            SourceTextSnapshot                  = sourceTextSnapshot;
            TopTextSnapshot                     = visualBufferSnapshot;
            UseDisplayMode                      = useDisplayMode;
            TabSize                             = tabSize;
            BaseIndentation                     = baseIndent;
            WordWrapWidth                       = wordWrapWidth;
            MaxAutoIndent                       = Math.Round(maxAutoIndent);
            ColumnWidth                         = formattedTextCache.GetColumnWidth(classificationFormatMap.DefaultTextProperties);
            this.wrapGlyphWidth                 = isViewWrapEnabled ? 1.5 * ColumnWidth : 0;
            LineHeight                          = WpfTextViewLine.DEFAULT_TOP_SPACE + WpfTextViewLine.DEFAULT_BOTTOM_SPACE + formattedTextCache.GetLineHeight(classificationFormatMap.DefaultTextProperties);
            TextHeightAboveBaseline             = formattedTextCache.GetTextHeightAboveBaseline(classificationFormatMap.DefaultTextProperties);
            TextHeightBelowBaseline             = formattedTextCache.GetTextHeightBelowBaseline(classificationFormatMap.DefaultTextProperties);
            TextAndAdornmentSequencer           = textAndAdornmentSequencer;
            this.aggregateClassifier            = aggregateClassifier;
            this.textAndAdornmentSequencer      = sequencer;
            this.classificationFormatMap        = classificationFormatMap;
            this.defaultTextParagraphProperties = new TextFormattingParagraphProperties(classificationFormatMap.DefaultTextProperties, ColumnWidth * TabSize);
        }
		public IFormattedLineSource Create(ITextSnapshot sourceTextSnapshot, ITextSnapshot visualBufferSnapshot, int tabSize, double baseIndent, double wordWrapWidth, double maxAutoIndent, bool useDisplayMode, IClassifier aggregateClassifier, ITextAndAdornmentSequencer sequencer, IClassificationFormatMap classificationFormatMap, bool isViewWrapEnabled) {
			if (sourceTextSnapshot == null)
				throw new ArgumentNullException(nameof(sourceTextSnapshot));
			if (visualBufferSnapshot == null)
				throw new ArgumentNullException(nameof(visualBufferSnapshot));
			if (aggregateClassifier == null)
				throw new ArgumentNullException(nameof(aggregateClassifier));
			if (sequencer == null)
				throw new ArgumentNullException(nameof(sequencer));
			if (classificationFormatMap == null)
				throw new ArgumentNullException(nameof(classificationFormatMap));
			if (tabSize <= 0)
				throw new ArgumentOutOfRangeException(nameof(tabSize));
			var textParagraphPropertiesFactoryService = textParagraphPropertiesFactoryServiceSelector.Select(sourceTextSnapshot.TextBuffer.ContentType);
			return new FormattedLineSource(textFormatterProvider, textParagraphPropertiesFactoryService, sourceTextSnapshot, visualBufferSnapshot, tabSize, baseIndent, wordWrapWidth, maxAutoIndent, useDisplayMode, aggregateClassifier, sequencer, classificationFormatMap, isViewWrapEnabled);
		}
示例#4
0
		public FormattedLineSource(ITextFormatterProvider textFormatterProvider, ITextParagraphPropertiesFactoryService textParagraphPropertiesFactoryService, ITextSnapshot sourceTextSnapshot, ITextSnapshot visualBufferSnapshot, int tabSize, double baseIndent, double wordWrapWidth, double maxAutoIndent, bool useDisplayMode, IClassifier aggregateClassifier, ITextAndAdornmentSequencer sequencer, IClassificationFormatMap classificationFormatMap, bool isViewWrapEnabled) {
			if (textFormatterProvider == null)
				throw new ArgumentNullException(nameof(textFormatterProvider));
			if (sourceTextSnapshot == null)
				throw new ArgumentNullException(nameof(sourceTextSnapshot));
			if (visualBufferSnapshot == null)
				throw new ArgumentNullException(nameof(visualBufferSnapshot));
			if (aggregateClassifier == null)
				throw new ArgumentNullException(nameof(aggregateClassifier));
			if (sequencer == null)
				throw new ArgumentNullException(nameof(sequencer));
			if (classificationFormatMap == null)
				throw new ArgumentNullException(nameof(classificationFormatMap));
			if (tabSize <= 0)
				throw new ArgumentOutOfRangeException(nameof(tabSize));
			if (sourceTextSnapshot != visualBufferSnapshot)
				throw new NotSupportedException("Text snapshot must be identical to visual snapshot");

			textFormatter = textFormatterProvider.Create(useDisplayMode);
			formattedTextCache = new FormattedTextCache(useDisplayMode);
			this.textParagraphPropertiesFactoryService = textParagraphPropertiesFactoryService;
			SourceTextSnapshot = sourceTextSnapshot;
			TopTextSnapshot = visualBufferSnapshot;
			UseDisplayMode = useDisplayMode;
			TabSize = tabSize;
			BaseIndentation = baseIndent;
			WordWrapWidth = wordWrapWidth;
			MaxAutoIndent = Math.Round(maxAutoIndent);
			ColumnWidth = formattedTextCache.GetColumnWidth(classificationFormatMap.DefaultTextProperties);
			wrapGlyphWidth = isViewWrapEnabled ? 1.5 * ColumnWidth : 0;
			LineHeight = WpfTextViewLine.DEFAULT_TOP_SPACE + WpfTextViewLine.DEFAULT_BOTTOM_SPACE + formattedTextCache.GetLineHeight(classificationFormatMap.DefaultTextProperties);
			TextHeightAboveBaseline = formattedTextCache.GetTextHeightAboveBaseline(classificationFormatMap.DefaultTextProperties);
			TextHeightBelowBaseline = formattedTextCache.GetTextHeightBelowBaseline(classificationFormatMap.DefaultTextProperties);
			TextAndAdornmentSequencer = sequencer;
			this.aggregateClassifier = aggregateClassifier;
			this.classificationFormatMap = classificationFormatMap;
			defaultTextParagraphProperties = new TextFormattingParagraphProperties(classificationFormatMap.DefaultTextProperties, ColumnWidth * TabSize);
		}
示例#5
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);
        }
示例#6
0
        public IFormattedLineSource Create(ITextSnapshot sourceTextSnapshot, ITextSnapshot visualBufferSnapshot, int tabSize, double baseIndent, double wordWrapWidth, double maxAutoIndent, bool useDisplayMode, IClassifier aggregateClassifier, ITextAndAdornmentSequencer sequencer, IClassificationFormatMap classificationFormatMap, bool isViewWrapEnabled)
        {
            if (sourceTextSnapshot is null)
            {
                throw new ArgumentNullException(nameof(sourceTextSnapshot));
            }
            if (visualBufferSnapshot is null)
            {
                throw new ArgumentNullException(nameof(visualBufferSnapshot));
            }
            if (aggregateClassifier is null)
            {
                throw new ArgumentNullException(nameof(aggregateClassifier));
            }
            if (sequencer is null)
            {
                throw new ArgumentNullException(nameof(sequencer));
            }
            if (classificationFormatMap is null)
            {
                throw new ArgumentNullException(nameof(classificationFormatMap));
            }
            if (tabSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(tabSize));
            }
            var textParagraphPropertiesFactoryService = textParagraphPropertiesFactoryServiceSelector.Select(sourceTextSnapshot.TextBuffer.ContentType);

            return(new FormattedLineSource(textFormatterProvider, textParagraphPropertiesFactoryService, sourceTextSnapshot, visualBufferSnapshot, tabSize, baseIndent, wordWrapWidth, maxAutoIndent, useDisplayMode, aggregateClassifier, sequencer, classificationFormatMap, isViewWrapEnabled));
        }
示例#7
0
 public IFormattedLineSource Create(ITextSnapshot sourceTextSnapshot, ITextSnapshot visualBufferSnapshot, int tabSize, double baseIndent, double wordWrapWidth, double maxAutoIndent, bool useDisplayMode, IClassifier aggregateClassifier, ITextAndAdornmentSequencer sequencer, IClassificationFormatMap classificationFormatMap) =>
 Create(sourceTextSnapshot, visualBufferSnapshot, tabSize, baseIndent, wordWrapWidth, maxAutoIndent, useDisplayMode, aggregateClassifier, sequencer, classificationFormatMap, false);
		public IFormattedLineSource Create(ITextSnapshot sourceTextSnapshot, ITextSnapshot visualBufferSnapshot, int tabSize, double baseIndent, double wordWrapWidth, double maxAutoIndent, bool useDisplayMode, IClassifier aggregateClassifier, ITextAndAdornmentSequencer sequencer, IClassificationFormatMap classificationFormatMap) =>
			Create(sourceTextSnapshot, visualBufferSnapshot, tabSize, baseIndent, wordWrapWidth, maxAutoIndent, useDisplayMode, aggregateClassifier, sequencer, classificationFormatMap, false);
示例#9
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);
		}