public override HexFormattedLineSource Create(double baseIndent, bool useDisplayMode, HexClassifier aggregateClassifier, HexAndAdornmentSequencer sequencer, VSTC.IClassificationFormatMap classificationFormatMap) {
			if (aggregateClassifier == null)
				throw new ArgumentNullException(nameof(aggregateClassifier));
			if (sequencer == null)
				throw new ArgumentNullException(nameof(sequencer));
			if (classificationFormatMap == null)
				throw new ArgumentNullException(nameof(classificationFormatMap));
			return new HexFormattedLineSourceImpl(textFormatterProvider, baseIndent, useDisplayMode, aggregateClassifier, sequencer, classificationFormatMap);
		}
Exemplo n.º 2
0
		public void Add(HexBufferLineProvider bufferLines, HexClassifier classifier, NormalizedHexBufferSpanCollection spans, CancellationToken cancellationToken) {
			if (bufferLines == null)
				throw new ArgumentNullException(nameof(bufferLines));
			if (classifier == null)
				throw new ArgumentNullException(nameof(classifier));
			if (spans == null)
				throw new ArgumentNullException(nameof(spans));
			if (spans.Count != 0 && spans[0].Buffer != bufferLines.Buffer)
				throw new ArgumentException();

			var classificationSpans = new List<HexClassificationSpan>();
			foreach (var span in spans) {
				if (spansCount > 0)
					htmlWriter.WriteRaw(delimiter);
				spansCount++;

				var pos = span.Start;
				for (;;) {
					classificationSpans.Clear();
					var line = bufferLines.GetLineFromPosition(pos);
					var text = line.GetText(span);
					var context = new HexClassificationContext(line, line.TextSpan);
					classifier.GetClassificationSpans(classificationSpans, context, cancellationToken);

					int textPos = 0;
					foreach (var tagSpan in classificationSpans) {
						if (textPos < tagSpan.Span.Start) {
							WriteCss(classificationFormatMap.DefaultTextProperties);
							htmlWriter.WriteSpan(cssWriter.ToString(), text, textPos, tagSpan.Span.Start - textPos);
						}
						WriteCss(classificationFormatMap.GetTextProperties(tagSpan.ClassificationType));
						htmlWriter.WriteSpan(cssWriter.ToString(), text, tagSpan.Span.Start, tagSpan.Span.Length);
						textPos = tagSpan.Span.End;
					}
					if (textPos < text.Length) {
						WriteCss(classificationFormatMap.DefaultTextProperties);
						htmlWriter.WriteSpan(cssWriter.ToString(), text, textPos, text.Length - textPos);
					}
					htmlWriter.WriteRaw("<br/>");

					pos = line.BufferEnd;
					if (pos >= span.End)
						break;
				}
			}
		}
        public HexFormattedLineSourceImpl(TF.ITextFormatterProvider textFormatterProvider, double baseIndent, bool useDisplayMode, HexClassifier aggregateClassifier, HexAndAdornmentSequencer sequencer, VSTC.IClassificationFormatMap classificationFormatMap)
        {
            if (textFormatterProvider is null)
            {
                throw new ArgumentNullException(nameof(textFormatterProvider));
            }
            if (classificationFormatMap is null)
            {
                throw new ArgumentNullException(nameof(classificationFormatMap));
            }

            textFormatter                  = textFormatterProvider.Create(useDisplayMode);
            formattedTextCache             = new TF.FormattedTextCache(useDisplayMode);
            UseDisplayMode                 = useDisplayMode;
            BaseIndentation                = baseIndent;
            ColumnWidth                    = formattedTextCache.GetColumnWidth(classificationFormatMap.DefaultTextProperties);
            LineHeight                     = HexFormattedLineImpl.DEFAULT_TOP_SPACE + HexFormattedLineImpl.DEFAULT_BOTTOM_SPACE + formattedTextCache.GetLineHeight(classificationFormatMap.DefaultTextProperties);
            TextHeightAboveBaseline        = formattedTextCache.GetTextHeightAboveBaseline(classificationFormatMap.DefaultTextProperties);
            TextHeightBelowBaseline        = formattedTextCache.GetTextHeightBelowBaseline(classificationFormatMap.DefaultTextProperties);
            HexAndAdornmentSequencer       = sequencer ?? throw new ArgumentNullException(nameof(sequencer));
            this.aggregateClassifier       = aggregateClassifier ?? throw new ArgumentNullException(nameof(aggregateClassifier));
            this.classificationFormatMap   = classificationFormatMap;
            defaultTextParagraphProperties = new VSTF.TextFormattingParagraphProperties(classificationFormatMap.DefaultTextProperties, ColumnWidth * TabSize);
        }
Exemplo n.º 4
0
#pragma warning restore 0169

		public WpfHexViewImpl(HexBuffer buffer, VSTE.ITextViewRoleSet roles, VSTE.IEditorOptions parentOptions, HexEditorOptionsFactoryService hexEditorOptionsFactoryService, ICommandService commandService, FormattedHexSourceFactoryService formattedHexSourceFactoryService, HexViewClassifierAggregatorService hexViewClassifierAggregatorService, HexAndAdornmentSequencerFactoryService hexAndAdornmentSequencerFactoryService, HexBufferLineFormatterFactoryService bufferLineProviderFactoryService, HexClassificationFormatMapService classificationFormatMapService, HexEditorFormatMapService editorFormatMapService, HexAdornmentLayerDefinitionService adornmentLayerDefinitionService, HexLineTransformProviderService lineTransformProviderService, HexSpaceReservationStackProvider spaceReservationStackProvider, Lazy<WpfHexViewCreationListener, IDeferrableTextViewRoleMetadata>[] wpfHexViewCreationListeners, VSTC.IClassificationTypeRegistryService classificationTypeRegistryService, Lazy<HexCursorProviderFactory, ITextViewRoleMetadata>[] hexCursorProviderFactories) {
			if (buffer == null)
				throw new ArgumentNullException(nameof(buffer));
			if (roles == null)
				throw new ArgumentNullException(nameof(roles));
			if (parentOptions == null)
				throw new ArgumentNullException(nameof(parentOptions));
			if (hexEditorOptionsFactoryService == null)
				throw new ArgumentNullException(nameof(hexEditorOptionsFactoryService));
			if (commandService == null)
				throw new ArgumentNullException(nameof(commandService));
			if (formattedHexSourceFactoryService == null)
				throw new ArgumentNullException(nameof(formattedHexSourceFactoryService));
			if (hexViewClassifierAggregatorService == null)
				throw new ArgumentNullException(nameof(hexViewClassifierAggregatorService));
			if (hexAndAdornmentSequencerFactoryService == null)
				throw new ArgumentNullException(nameof(hexAndAdornmentSequencerFactoryService));
			if (bufferLineProviderFactoryService == null)
				throw new ArgumentNullException(nameof(bufferLineProviderFactoryService));
			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 (wpfHexViewCreationListeners == null)
				throw new ArgumentNullException(nameof(wpfHexViewCreationListeners));
			if (classificationTypeRegistryService == null)
				throw new ArgumentNullException(nameof(classificationTypeRegistryService));
			if (hexCursorProviderFactories == null)
				throw new ArgumentNullException(nameof(hexCursorProviderFactories));
			canvas = new HexViewCanvas(this);
			Buffer = buffer;
			thisHexLineTransformSource = new MyHexLineTransformSource(this);
			this.bufferLineProviderFactoryService = bufferLineProviderFactoryService;
			mouseHoverHelper = new MouseHoverHelper(this);
			physicalLineCache = new PhysicalLineCache(32);
			visiblePhysicalLines = new List<PhysicalLine>();
			invalidatedRegions = new List<HexBufferSpan>();
			this.formattedHexSourceFactoryService = formattedHexSourceFactoryService;
			zoomLevel = VSTE.ZoomConstants.DefaultZoom;
			DsImage.SetZoom(VisualElement, zoomLevel / 100);
			this.adornmentLayerDefinitionService = adornmentLayerDefinitionService;
			this.lineTransformProviderService = lineTransformProviderService;
			this.wpfHexViewCreationListeners = wpfHexViewCreationListeners.Where(a => roles.ContainsAny(a.Metadata.TextViewRoles)).ToArray();
			recreateLineTransformProvider = true;
			normalAdornmentLayerCollection = new HexAdornmentLayerCollection(this, HexLayerKind.Normal);
			overlayAdornmentLayerCollection = new HexAdornmentLayerCollection(this, HexLayerKind.Overlay);
			underlayAdornmentLayerCollection = new HexAdornmentLayerCollection(this, HexLayerKind.Underlay);
			canvas.IsVisibleChanged += WpfHexView_IsVisibleChanged;
			Roles = roles;
			Options = hexEditorOptionsFactoryService.GetOptions(this);
			Options.Parent = parentOptions;
			ViewScroller = new HexViewScrollerImpl(this);
			hasKeyboardFocus = canvas.IsKeyboardFocusWithin;
			oldViewState = new HexViewState(this);
			aggregateClassifier = hexViewClassifierAggregatorService.GetClassifier(this);
			hexAndAdornmentSequencer = hexAndAdornmentSequencerFactoryService.Create(this);
			classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(this);
			editorFormatMap = editorFormatMapService.GetEditorFormatMap(this);
			spaceReservationStack = spaceReservationStackProvider.Create(this);

			textLayer = new TextLayer(GetAdornmentLayer(PredefinedHexAdornmentLayers.Text));
			HexSelection = new HexSelectionImpl(this, GetAdornmentLayer(PredefinedHexAdornmentLayers.Selection), editorFormatMap);
			HexCaret = new HexCaretImpl(this, GetAdornmentLayer(PredefinedHexAdornmentLayers.Caret), classificationFormatMap, classificationTypeRegistryService);

			canvas.Children.Add(underlayAdornmentLayerCollection);
			canvas.Children.Add(normalAdornmentLayerCollection);
			canvas.Children.Add(overlayAdornmentLayerCollection);
			canvas.Focusable = true;
			canvas.FocusVisualStyle = null;
			InitializeOptions();

			Options.OptionChanged += EditorOptions_OptionChanged;
			Buffer.ChangedLowPriority += HexBuffer_ChangedLowPriority;
			Buffer.BufferSpanInvalidated += Buffer_BufferSpanInvalidated;
			aggregateClassifier.ClassificationChanged += AggregateClassifier_ClassificationChanged;
			hexAndAdornmentSequencer.SequenceChanged += HexAndAdornmentSequencer_SequenceChanged;
			classificationFormatMap.ClassificationFormatMappingChanged += ClassificationFormatMap_ClassificationFormatMappingChanged;
			editorFormatMap.FormatMappingChanged += EditorFormatMap_FormatMappingChanged;
			spaceReservationStack.GotAggregateFocus += SpaceReservationStack_GotAggregateFocus;
			spaceReservationStack.LostAggregateFocus += SpaceReservationStack_LostAggregateFocus;

			UpdateBackground();
			CreateFormattedLineSource(ViewportWidth);
			var dummy = BufferLines;
			HexSelection.Initialize();
			HexCaret.Initialize();
			InitializeZoom();
			UpdateRemoveExtraTextLineVerticalPixels();

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

			hexCursorProviderInfoCollection = new HexCursorProviderInfoCollection(CreateCursorProviders(hexCursorProviderFactories), Cursors.IBeam);
			hexCursorProviderInfoCollection.CursorChanged += HexCursorProviderInfoCollection_CursorChanged;
			canvas.Cursor = hexCursorProviderInfoCollection.Cursor;

			NotifyHexViewCreated();
		}
 /// <summary>
 /// Creates a <see cref="HexFormattedLineSource"/>
 /// </summary>
 /// <param name="baseIndent">Base indentation</param>
 /// <param name="useDisplayMode">true to use display mode, false to use ideal mode</param>
 /// <param name="aggregateClassifier">Classifier</param>
 /// <param name="sequencer">Sequencer</param>
 /// <param name="classificationFormatMap">Classification format map</param>
 /// <returns></returns>
 public abstract HexFormattedLineSource Create(double baseIndent, bool useDisplayMode, HexClassifier aggregateClassifier, HexAndAdornmentSequencer sequencer, VSTC.IClassificationFormatMap classificationFormatMap);
		/// <summary>
		/// Creates a <see cref="HexFormattedLineSource"/>
		/// </summary>
		/// <param name="baseIndent">Base indentation</param>
		/// <param name="useDisplayMode">true to use display mode, false to use ideal mode</param>
		/// <param name="aggregateClassifier">Classifier</param>
		/// <param name="sequencer">Sequencer</param>
		/// <param name="classificationFormatMap">Classification format map</param>
		/// <returns></returns>
		public abstract HexFormattedLineSource Create(double baseIndent, bool useDisplayMode, HexClassifier aggregateClassifier, HexAndAdornmentSequencer sequencer, VSTC.IClassificationFormatMap classificationFormatMap);
Exemplo n.º 7
0
        public void Add(HexBufferLineFormatter bufferLines, HexClassifier classifier, NormalizedHexBufferSpanCollection spans, CancellationToken cancellationToken)
        {
            if (bufferLines == null)
            {
                throw new ArgumentNullException(nameof(bufferLines));
            }
            if (classifier == null)
            {
                throw new ArgumentNullException(nameof(classifier));
            }
            if (spans == null)
            {
                throw new ArgumentNullException(nameof(spans));
            }
            if (spans.Count != 0 && spans[0].Buffer != bufferLines.Buffer)
            {
                throw new ArgumentException();
            }

            var classificationSpans = new List <HexClassificationSpan>();

            foreach (var span in spans)
            {
                if (spansCount > 0)
                {
                    htmlWriter.WriteRaw(delimiter);
                }
                spansCount++;

                var pos = span.Start;
                for (;;)
                {
                    classificationSpans.Clear();
                    var line    = bufferLines.GetLineFromPosition(pos);
                    var text    = line.GetText(span);
                    var context = new HexClassificationContext(line, line.TextSpan);
                    classifier.GetClassificationSpans(classificationSpans, context, cancellationToken);

                    int textPos = 0;
                    foreach (var tagSpan in classificationSpans)
                    {
                        if (textPos < tagSpan.Span.Start)
                        {
                            WriteCss(classificationFormatMap.DefaultTextProperties);
                            htmlWriter.WriteSpan(cssWriter.ToString(), text, textPos, tagSpan.Span.Start - textPos);
                        }
                        WriteCss(classificationFormatMap.GetTextProperties(tagSpan.ClassificationType));
                        htmlWriter.WriteSpan(cssWriter.ToString(), text, tagSpan.Span.Start, tagSpan.Span.Length);
                        textPos = tagSpan.Span.End;
                    }
                    if (textPos < text.Length)
                    {
                        WriteCss(classificationFormatMap.DefaultTextProperties);
                        htmlWriter.WriteSpan(cssWriter.ToString(), text, textPos, text.Length - textPos);
                    }
                    htmlWriter.WriteRaw("<br/>");

                    pos = line.BufferEnd;
                    if (pos >= span.End)
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 8
0
 public override HexFormattedLineSource Create(double baseIndent, bool useDisplayMode, HexClassifier aggregateClassifier, HexAndAdornmentSequencer sequencer, VSTC.IClassificationFormatMap classificationFormatMap)
 {
     if (aggregateClassifier == null)
     {
         throw new ArgumentNullException(nameof(aggregateClassifier));
     }
     if (sequencer == null)
     {
         throw new ArgumentNullException(nameof(sequencer));
     }
     if (classificationFormatMap == null)
     {
         throw new ArgumentNullException(nameof(classificationFormatMap));
     }
     return(new HexFormattedLineSourceImpl(textFormatterProvider, baseIndent, useDisplayMode, aggregateClassifier, sequencer, classificationFormatMap));
 }