Pass a dictionary with the color map instead an interface
This commit is contained in:
Родитель
2a07c6ea07
Коммит
228bb5e4f0
|
@ -17,8 +17,7 @@ namespace AvaloniaEdit.TextMate
|
|||
{
|
||||
public class TextMateColoringTransformer :
|
||||
GenericLineTransformer,
|
||||
IModelTokensChangedListener,
|
||||
ForegroundTextTransformation.IColorMap
|
||||
IModelTokensChangedListener
|
||||
{
|
||||
private Theme _theme;
|
||||
private IGrammar _grammar;
|
||||
|
@ -77,6 +76,7 @@ namespace AvaloniaEdit.TextMate
|
|||
public void Dispose()
|
||||
{
|
||||
_textView.VisualLinesChanged -= TextView_VisualLinesChanged;
|
||||
_brushes.Clear();
|
||||
}
|
||||
|
||||
public void SetTheme(Theme theme)
|
||||
|
@ -105,15 +105,6 @@ namespace AvaloniaEdit.TextMate
|
|||
}
|
||||
}
|
||||
|
||||
IBrush ForegroundTextTransformation.IColorMap.GetBrush(int colorId)
|
||||
{
|
||||
if (_brushes == null)
|
||||
return null;
|
||||
|
||||
_brushes.TryGetValue(colorId, out IBrush result);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override void TransformLine(DocumentLine line, ITextRunConstructionContext context)
|
||||
{
|
||||
try
|
||||
|
@ -190,7 +181,7 @@ namespace AvaloniaEdit.TextMate
|
|||
if (transformations[i] == null)
|
||||
transformations[i] = new ForegroundTextTransformation();
|
||||
|
||||
transformations[i].ColorMap = this;
|
||||
transformations[i].ColorMap = _brushes;
|
||||
transformations[i].ExceptionHandler = _exceptionHandler;
|
||||
transformations[i].StartOffset = lineOffset + startIndex;
|
||||
transformations[i].EndOffset = lineOffset + endIndex;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using AvaloniaEdit.Document;
|
||||
|
||||
|
@ -13,12 +14,7 @@ namespace AvaloniaEdit.TextMate
|
|||
|
||||
public class ForegroundTextTransformation : TextTransformation
|
||||
{
|
||||
public interface IColorMap
|
||||
{
|
||||
AM.IBrush GetBrush(int color);
|
||||
}
|
||||
|
||||
public IColorMap ColorMap { get; set; }
|
||||
public Dictionary<int, AM.IBrush> ColorMap { get; set; }
|
||||
public Action<Exception> ExceptionHandler { get; set; }
|
||||
public int ForegroundColor { get; set; }
|
||||
public int BackgroundColor { get; set; }
|
||||
|
@ -47,13 +43,13 @@ namespace AvaloniaEdit.TextMate
|
|||
}
|
||||
|
||||
transformer.SetTextStyle(line, formattedOffset, endOffset - line.Offset - formattedOffset,
|
||||
ColorMap.GetBrush(ForegroundColor),
|
||||
ColorMap.GetBrush(BackgroundColor),
|
||||
GetFontStyle(),
|
||||
GetFontWeight(),
|
||||
IsUnderline());
|
||||
GetBrush(ForegroundColor),
|
||||
GetBrush(BackgroundColor),
|
||||
GetFontStyle(),
|
||||
GetFontWeight(),
|
||||
IsUnderline());
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionHandler?.Invoke(ex);
|
||||
}
|
||||
|
@ -85,5 +81,14 @@ namespace AvaloniaEdit.TextMate
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
AM.IBrush GetBrush(int colorId)
|
||||
{
|
||||
if (ColorMap == null)
|
||||
return null;
|
||||
|
||||
ColorMap.TryGetValue(colorId, out AM.IBrush result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче