mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 13:14:59 +00:00
feature: allow user to control whether or not to enable syntax highlighting in DiffView.
This commit is contained in:
parent
8fc25e312d
commit
635db8b3b3
9 changed files with 123 additions and 11 deletions
|
@ -224,6 +224,15 @@ namespace SourceGit.Views
|
|||
set => SetValue(SyncScrollOffsetProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> UseSyntaxHighlightingProperty =
|
||||
AvaloniaProperty.Register<SingleSideTextDiffPresenter, bool>(nameof(UseSyntaxHighlighting), false);
|
||||
|
||||
public bool UseSyntaxHighlighting
|
||||
{
|
||||
get => GetValue(UseSyntaxHighlightingProperty);
|
||||
set => SetValue(UseSyntaxHighlightingProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(TextEditor);
|
||||
|
||||
public CombinedTextDiffPresenter() : base(new TextArea(), new TextDocument())
|
||||
|
@ -241,16 +250,15 @@ namespace SourceGit.Views
|
|||
|
||||
TextArea.TextView.Margin = new Thickness(4, 0);
|
||||
TextArea.TextView.BackgroundRenderers.Add(new LineBackgroundRenderer(this));
|
||||
TextArea.TextView.LineTransformers.Add(_lineStyleTransformer);
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
|
||||
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
||||
if (DiffData != null) Models.TextMateHelper.SetGrammarByFileName(_textMate, DiffData.File);
|
||||
UpdateTextMate();
|
||||
|
||||
TextArea.TextView.LineTransformers.Add(_lineStyleTransformer);
|
||||
TextArea.TextView.ContextRequested += OnTextViewContextRequested;
|
||||
TextArea.TextView.ScrollOffsetChanged += OnTextViewScrollOffsetChanged;
|
||||
}
|
||||
|
@ -259,7 +267,6 @@ namespace SourceGit.Views
|
|||
{
|
||||
base.OnUnloaded(e);
|
||||
|
||||
TextArea.TextView.LineTransformers.Remove(_lineStyleTransformer);
|
||||
TextArea.TextView.ContextRequested -= OnTextViewContextRequested;
|
||||
TextArea.TextView.ScrollOffsetChanged -= OnTextViewScrollOffsetChanged;
|
||||
|
||||
|
@ -333,12 +340,42 @@ namespace SourceGit.Views
|
|||
scrollable.Offset = SyncScrollOffset;
|
||||
}
|
||||
}
|
||||
else if (change.Property == UseSyntaxHighlightingProperty)
|
||||
{
|
||||
UpdateTextMate();
|
||||
}
|
||||
else if (change.Property.Name == "ActualThemeVariant" && change.NewValue != null)
|
||||
{
|
||||
Models.TextMateHelper.SetThemeByApp(_textMate);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTextMate()
|
||||
{
|
||||
if (UseSyntaxHighlighting)
|
||||
{
|
||||
if (_textMate == null)
|
||||
{
|
||||
TextArea.TextView.LineTransformers.Remove(_lineStyleTransformer);
|
||||
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
||||
TextArea.TextView.LineTransformers.Add(_lineStyleTransformer);
|
||||
|
||||
if (DiffData != null) Models.TextMateHelper.SetGrammarByFileName(_textMate, DiffData.File);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_textMate != null)
|
||||
{
|
||||
_textMate.Dispose();
|
||||
_textMate = null;
|
||||
GC.Collect();
|
||||
|
||||
TextArea.TextView.Redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TextMate.Installation _textMate;
|
||||
private LineStyleTransformer _lineStyleTransformer = null;
|
||||
}
|
||||
|
@ -557,6 +594,15 @@ namespace SourceGit.Views
|
|||
set => SetValue(SyncScrollOffsetProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> UseSyntaxHighlightingProperty =
|
||||
AvaloniaProperty.Register<SingleSideTextDiffPresenter, bool>(nameof(UseSyntaxHighlighting), false);
|
||||
|
||||
public bool UseSyntaxHighlighting
|
||||
{
|
||||
get => GetValue(UseSyntaxHighlightingProperty);
|
||||
set => SetValue(UseSyntaxHighlightingProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(TextEditor);
|
||||
|
||||
public SingleSideTextDiffPresenter() : base(new TextArea(), new TextDocument())
|
||||
|
@ -571,6 +617,7 @@ namespace SourceGit.Views
|
|||
TextArea.LeftMargins.Add(new VerticalSeperatorMargin(this));
|
||||
TextArea.TextView.Margin = new Thickness(4, 0);
|
||||
TextArea.TextView.BackgroundRenderers.Add(new LineBackgroundRenderer(this));
|
||||
TextArea.TextView.LineTransformers.Add(_lineStyleTransformer);
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
|
@ -584,10 +631,8 @@ namespace SourceGit.Views
|
|||
_scrollViewer.ScrollChanged += OnTextViewScrollChanged;
|
||||
}
|
||||
|
||||
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
||||
if (DiffData != null) Models.TextMateHelper.SetGrammarByFileName(_textMate, DiffData.File);
|
||||
UpdateTextMate();
|
||||
|
||||
TextArea.TextView.LineTransformers.Add(_lineStyleTransformer);
|
||||
TextArea.TextView.ContextRequested += OnTextViewContextRequested;
|
||||
}
|
||||
|
||||
|
@ -607,7 +652,6 @@ namespace SourceGit.Views
|
|||
_textMate = null;
|
||||
}
|
||||
|
||||
TextArea.TextView.LineTransformers.Remove(_lineStyleTransformer);
|
||||
TextArea.TextView.ContextRequested -= OnTextViewContextRequested;
|
||||
|
||||
GC.Collect();
|
||||
|
@ -703,12 +747,42 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (change.Property == UseSyntaxHighlightingProperty)
|
||||
{
|
||||
UpdateTextMate();
|
||||
}
|
||||
else if (change.Property.Name == "ActualThemeVariant" && change.NewValue != null)
|
||||
{
|
||||
Models.TextMateHelper.SetThemeByApp(_textMate);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTextMate()
|
||||
{
|
||||
if (UseSyntaxHighlighting)
|
||||
{
|
||||
if (_textMate == null)
|
||||
{
|
||||
TextArea.TextView.LineTransformers.Remove(_lineStyleTransformer);
|
||||
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
||||
TextArea.TextView.LineTransformers.Add(_lineStyleTransformer);
|
||||
|
||||
if (DiffData != null) Models.TextMateHelper.SetGrammarByFileName(_textMate, DiffData.File);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_textMate != null)
|
||||
{
|
||||
_textMate.Dispose();
|
||||
_textMate = null;
|
||||
GC.Collect();
|
||||
|
||||
TextArea.TextView.Redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TextMate.Installation _textMate;
|
||||
private LineStyleTransformer _lineStyleTransformer = null;
|
||||
private ScrollViewer _scrollViewer = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue