mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
feature: enable syntax highlighting in revision files view (#333)
This commit is contained in:
parent
1ab0ea27df
commit
6bd0920d71
3 changed files with 27 additions and 1 deletions
|
@ -14,6 +14,7 @@ namespace SourceGit.Models
|
||||||
|
|
||||||
public class RevisionTextFile
|
public class RevisionTextFile
|
||||||
{
|
{
|
||||||
|
public string FileName { get; set; }
|
||||||
public string Content { get; set; }
|
public string Content { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var txt = new Models.RevisionTextFile() { Content = content };
|
var txt = new Models.RevisionTextFile() { FileName = file.Path, Content = content };
|
||||||
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = txt);
|
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = txt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,6 +9,7 @@ using Avalonia.Media;
|
||||||
using AvaloniaEdit;
|
using AvaloniaEdit;
|
||||||
using AvaloniaEdit.Document;
|
using AvaloniaEdit.Document;
|
||||||
using AvaloniaEdit.Editing;
|
using AvaloniaEdit.Editing;
|
||||||
|
using AvaloniaEdit.TextMate;
|
||||||
|
|
||||||
namespace SourceGit.Views
|
namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
|
@ -35,6 +36,7 @@ namespace SourceGit.Views
|
||||||
base.OnLoaded(e);
|
base.OnLoaded(e);
|
||||||
|
|
||||||
TextArea.TextView.ContextRequested += OnTextViewContextRequested;
|
TextArea.TextView.ContextRequested += OnTextViewContextRequested;
|
||||||
|
UpdateTextMate();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnUnloaded(RoutedEventArgs e)
|
protected override void OnUnloaded(RoutedEventArgs e)
|
||||||
|
@ -42,6 +44,13 @@ namespace SourceGit.Views
|
||||||
base.OnUnloaded(e);
|
base.OnUnloaded(e);
|
||||||
|
|
||||||
TextArea.TextView.ContextRequested -= OnTextViewContextRequested;
|
TextArea.TextView.ContextRequested -= OnTextViewContextRequested;
|
||||||
|
|
||||||
|
if (_textMate != null)
|
||||||
|
{
|
||||||
|
_textMate.Dispose();
|
||||||
|
_textMate = null;
|
||||||
|
}
|
||||||
|
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,9 +59,14 @@ namespace SourceGit.Views
|
||||||
base.OnDataContextChanged(e);
|
base.OnDataContextChanged(e);
|
||||||
|
|
||||||
if (DataContext is Models.RevisionTextFile source)
|
if (DataContext is Models.RevisionTextFile source)
|
||||||
|
{
|
||||||
|
UpdateTextMate();
|
||||||
Text = source.Content;
|
Text = source.Content;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Text = string.Empty;
|
Text = string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
||||||
|
@ -85,6 +99,17 @@ namespace SourceGit.Views
|
||||||
TextArea.TextView.OpenContextMenu(menu);
|
TextArea.TextView.OpenContextMenu(menu);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateTextMate()
|
||||||
|
{
|
||||||
|
if (_textMate == null)
|
||||||
|
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
||||||
|
|
||||||
|
if (DataContext is Models.RevisionTextFile file)
|
||||||
|
Models.TextMateHelper.SetGrammarByFileName(_textMate, file.FileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TextMate.Installation _textMate = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class RevisionFiles : UserControl
|
public partial class RevisionFiles : UserControl
|
||||||
|
|
Loading…
Reference in a new issue