diff --git a/src/Models/RevisionFile.cs b/src/Models/RevisionFile.cs index e2f4abb0..59868fcc 100644 --- a/src/Models/RevisionFile.cs +++ b/src/Models/RevisionFile.cs @@ -14,6 +14,7 @@ namespace SourceGit.Models public class RevisionTextFile { + public string FileName { get; set; } public string Content { get; set; } } diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index f01e333f..ae0e2cb9 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -183,7 +183,7 @@ namespace SourceGit.ViewModels } else { - var txt = new Models.RevisionTextFile() { Content = content }; + var txt = new Models.RevisionTextFile() { FileName = file.Path, Content = content }; Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = txt); } }); diff --git a/src/Views/RevisionFiles.axaml.cs b/src/Views/RevisionFiles.axaml.cs index 227c11a1..3ef430ad 100644 --- a/src/Views/RevisionFiles.axaml.cs +++ b/src/Views/RevisionFiles.axaml.cs @@ -9,6 +9,7 @@ using Avalonia.Media; using AvaloniaEdit; using AvaloniaEdit.Document; using AvaloniaEdit.Editing; +using AvaloniaEdit.TextMate; namespace SourceGit.Views { @@ -35,6 +36,7 @@ namespace SourceGit.Views base.OnLoaded(e); TextArea.TextView.ContextRequested += OnTextViewContextRequested; + UpdateTextMate(); } protected override void OnUnloaded(RoutedEventArgs e) @@ -42,6 +44,13 @@ namespace SourceGit.Views base.OnUnloaded(e); TextArea.TextView.ContextRequested -= OnTextViewContextRequested; + + if (_textMate != null) + { + _textMate.Dispose(); + _textMate = null; + } + GC.Collect(); } @@ -50,9 +59,14 @@ namespace SourceGit.Views base.OnDataContextChanged(e); if (DataContext is Models.RevisionTextFile source) + { + UpdateTextMate(); Text = source.Content; + } else + { Text = string.Empty; + } } private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e) @@ -85,6 +99,17 @@ namespace SourceGit.Views TextArea.TextView.OpenContextMenu(menu); 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