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

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

View file

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

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