optimize<TextEditor>: trait all .h file as C++ header file instead of C

This commit is contained in:
leo 2024-02-22 20:47:43 +08:00
parent b934049dba
commit ba355a7d59
3 changed files with 55 additions and 20 deletions

View file

@ -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;
}