diff --git a/src/Views/Blame.axaml.cs b/src/Views/Blame.axaml.cs index 5492cba7..9de8a9cf 100644 --- a/src/Views/Blame.axaml.cs +++ b/src/Views/Blame.axaml.cs @@ -172,10 +172,7 @@ namespace SourceGit.Views { } _textMate = this.InstallTextMate(_registryOptions); - - if (BlameData != null) { - _textMate.SetGrammar(_registryOptions.GetScopeByExtension(Path.GetExtension(BlameData.File))); - } + UpdateGrammar(); } protected override void OnUnloaded(RoutedEventArgs e) { @@ -195,7 +192,7 @@ namespace SourceGit.Views { if (change.Property == BlameDataProperty) { if (BlameData != null) { Text = BlameData.Content; - if (_textMate != null) _textMate.SetGrammar(_registryOptions.GetScopeByExtension(Path.GetExtension(BlameData.File))); + UpdateGrammar(); } else { Text = string.Empty; } @@ -232,6 +229,17 @@ namespace SourceGit.Views { e.Handled = true; } + private void UpdateGrammar() { + if (_textMate == null || BlameData == null) return; + + var ext = Path.GetExtension(BlameData.File); + if (ext == ".h") { + _textMate.SetGrammar(_registryOptions.GetScopeByLanguageId("cpp")); + } else { + _textMate.SetGrammar(_registryOptions.GetScopeByExtension(ext)); + } + } + private RegistryOptions _registryOptions = null; private TextMate.Installation _textMate = null; } diff --git a/src/Views/RevisionFiles.axaml.cs b/src/Views/RevisionFiles.axaml.cs index 2e1778f3..013607a1 100644 --- a/src/Views/RevisionFiles.axaml.cs +++ b/src/Views/RevisionFiles.axaml.cs @@ -39,10 +39,7 @@ namespace SourceGit.Views { } _textMate = this.InstallTextMate(_registryOptions); - - if (DataContext != null && DataContext is Models.RevisionTextFile source) { - _textMate.SetGrammar(_registryOptions.GetScopeByExtension(Path.GetExtension(source.FileName))); - } + UpdateGrammar(); } protected override void OnUnloaded(RoutedEventArgs e) { @@ -60,7 +57,7 @@ namespace SourceGit.Views { var source = DataContext as Models.RevisionTextFile; if (source != null) { - if (_textMate != null) _textMate.SetGrammar(_registryOptions.GetScopeByExtension(Path.GetExtension(source.FileName))); + UpdateGrammar(); Text = source.Content; } } @@ -101,6 +98,20 @@ namespace SourceGit.Views { e.Handled = true; } + private void UpdateGrammar() { + if (_textMate == null) return; + + var src = DataContext as Models.RevisionTextFile; + if (src == null) return; + + var ext = Path.GetExtension(src.FileName); + if (ext == ".h") { + _textMate.SetGrammar(_registryOptions.GetScopeByLanguageId("cpp")); + } else { + _textMate.SetGrammar(_registryOptions.GetScopeByExtension(ext)); + } + } + private RegistryOptions _registryOptions = null; private TextMate.Installation _textMate = null; } diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 74990a36..69b0ac84 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -214,10 +214,7 @@ namespace SourceGit.Views { } _textMate = this.InstallTextMate(_registryOptions); - - if (DiffData != null) { - _textMate.SetGrammar(_registryOptions.GetScopeByExtension(Path.GetExtension(DiffData.File))); - } + UpdateGrammar(); } protected override void OnUnloaded(RoutedEventArgs e) { @@ -267,7 +264,7 @@ namespace SourceGit.Views { builder.AppendLine(line.Content); } - if (_textMate != null) _textMate.SetGrammar(_registryOptions.GetScopeByExtension(Path.GetExtension(DiffData.File))); + UpdateGrammar(); Text = builder.ToString(); } else { Text = string.Empty; @@ -281,6 +278,17 @@ namespace SourceGit.Views { } } + private void UpdateGrammar() { + if (_textMate == null || DiffData == null) return; + + var ext = Path.GetExtension(DiffData.File); + if (ext == ".h") { + _textMate.SetGrammar(_registryOptions.GetScopeByLanguageId("cpp")); + } else { + _textMate.SetGrammar(_registryOptions.GetScopeByExtension(ext)); + } + } + private RegistryOptions _registryOptions; private TextMate.Installation _textMate; } @@ -497,10 +505,7 @@ namespace SourceGit.Views { } _textMate = this.InstallTextMate(_registryOptions); - - if (DiffData != null) { - _textMate.SetGrammar(_registryOptions.GetScopeByExtension(Path.GetExtension(DiffData.File))); - } + UpdateGrammar(); } protected override void OnUnloaded(RoutedEventArgs e) { @@ -561,7 +566,7 @@ namespace SourceGit.Views { } } - if (_textMate != null) _textMate.SetGrammar(_registryOptions.GetScopeByExtension(Path.GetExtension(DiffData.File))); + UpdateGrammar(); Text = builder.ToString(); } else { Text = string.Empty; @@ -580,6 +585,17 @@ namespace SourceGit.Views { } } + private void UpdateGrammar() { + if (_textMate == null || DiffData == null) return; + + var ext = Path.GetExtension(DiffData.File); + if (ext == ".h") { + _textMate.SetGrammar(_registryOptions.GetScopeByLanguageId("cpp")); + } else { + _textMate.SetGrammar(_registryOptions.GetScopeByExtension(ext)); + } + } + private RegistryOptions _registryOptions; private TextMate.Installation _textMate; }