From 635db8b3b361aec21e18457bc178d07e0f198e19 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 20 Mar 2024 20:17:20 +0800 Subject: [PATCH] feature: allow user to control whether or not to enable syntax highlighting in DiffView. --- src/SourceGit/Resources/Icons.axaml | 1 + src/SourceGit/Resources/Locales.Designer.cs | 9 +++ src/SourceGit/Resources/Locales.en.resx | 3 + src/SourceGit/Resources/Locales.resx | 3 + src/SourceGit/Resources/Locales.zh.resx | 3 + src/SourceGit/ViewModels/Preference.cs | 7 ++ src/SourceGit/Views/DiffView.axaml | 13 ++- src/SourceGit/Views/TextDiffView.axaml | 5 +- src/SourceGit/Views/TextDiffView.axaml.cs | 90 +++++++++++++++++++-- 9 files changed, 123 insertions(+), 11 deletions(-) diff --git a/src/SourceGit/Resources/Icons.axaml b/src/SourceGit/Resources/Icons.axaml index 6aaef5f6..71e8ab02 100644 --- a/src/SourceGit/Resources/Icons.axaml +++ b/src/SourceGit/Resources/Icons.axaml @@ -85,4 +85,5 @@ M296 912H120c-4.4 0-8-3.6-8-8V520c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v384c0 4.4-3.6 8-8 8zM600 912H424c-4.4 0-8-3.6-8-8V121c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v783c0 4.4-3.6 8-8 8zM904 912H728c-4.4 0-8-3.6-8-8V280c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v624c0 4.4-3.6 8-8 8z M512 0C229.216 0 0 229.216 0 512c0 282.752 229.216 512 512 512s512-229.248 512-512c0-282.784-229.216-512-512-512z m0 957.92C266.112 957.92 66.08 757.888 66.08 512S266.112 66.08 512 66.08 957.92 266.112 957.92 512 757.888 957.92 512 957.92zM192 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32H192a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM384 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM576 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM832 320h-64a32 32 0 0 0-32 32v128h-160a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h256a32 32 0 0 0 32-32v-192a32 32 0 0 0-32-32zM320 544v-32a32 32 0 0 0-32-32H192a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h96a32 32 0 0 0 32-32zM384 576h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM800 640H256a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h544a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32z M875 117H149C109 117 75 151 75 192v640c0 41 34 75 75 75h725c41 0 75-34 75-75V192c0-41-34-75-75-75zM139 832V192c0-6 4-11 11-11h331v661H149c-6 0-11-4-11-11zm747 0c0 6-4 11-11 11H544v-661H875c6 0 11 4 11 11v640z + M875 128h-725A107 107 0 0043 235v555A107 107 0 00149 896h725a107 107 0 00107-107v-555A107 107 0 00875 128zm-115 640h-183v-58l25-3c15 0 19-8 14-24l-22-61H419l-28 82 39 2V768h-166v-58l18-3c18-2 22-11 26-24l125-363-40-4V256h168l160 448 39 3zM506 340l-72 218h145l-71-218h-2z diff --git a/src/SourceGit/Resources/Locales.Designer.cs b/src/SourceGit/Resources/Locales.Designer.cs index af8765f6..2efb66fd 100644 --- a/src/SourceGit/Resources/Locales.Designer.cs +++ b/src/SourceGit/Resources/Locales.Designer.cs @@ -1284,6 +1284,15 @@ namespace SourceGit.Resources { } } + /// + /// Looks up a localized string similar to Syntax Highlighting. + /// + public static string Text_Diff_SyntaxHighlight { + get { + return ResourceManager.GetString("Text.Diff.SyntaxHighlight", resourceCulture); + } + } + /// /// Looks up a localized string similar to Open With Merge Tool. /// diff --git a/src/SourceGit/Resources/Locales.en.resx b/src/SourceGit/Resources/Locales.en.resx index 0aa081eb..10b2942f 100644 --- a/src/SourceGit/Resources/Locales.en.resx +++ b/src/SourceGit/Resources/Locales.en.resx @@ -1287,4 +1287,7 @@ Cut + + Syntax Highlighting + \ No newline at end of file diff --git a/src/SourceGit/Resources/Locales.resx b/src/SourceGit/Resources/Locales.resx index 25e4a2d8..d327e8a4 100644 --- a/src/SourceGit/Resources/Locales.resx +++ b/src/SourceGit/Resources/Locales.resx @@ -1287,4 +1287,7 @@ Cut + + Syntax Highlighting + \ No newline at end of file diff --git a/src/SourceGit/Resources/Locales.zh.resx b/src/SourceGit/Resources/Locales.zh.resx index 96568f31..75cdd061 100644 --- a/src/SourceGit/Resources/Locales.zh.resx +++ b/src/SourceGit/Resources/Locales.zh.resx @@ -1287,4 +1287,7 @@ 剪切 + + 语法高亮 + \ No newline at end of file diff --git a/src/SourceGit/ViewModels/Preference.cs b/src/SourceGit/ViewModels/Preference.cs index fdb31713..3b6fb7db 100644 --- a/src/SourceGit/ViewModels/Preference.cs +++ b/src/SourceGit/ViewModels/Preference.cs @@ -114,6 +114,12 @@ namespace SourceGit.ViewModels set => SetProperty(ref _useSideBySideDiff, value); } + public bool UseSyntaxHighlighting + { + get => _useSyntaxHighlighting; + set => SetProperty(ref _useSyntaxHighlighting, value); + } + public Models.ChangeViewMode UnstagedChangeViewMode { get => _unstagedChangeViewMode; @@ -351,6 +357,7 @@ namespace SourceGit.ViewModels private bool _useFixedTabWidth = true; private bool _useTwoColumnsLayoutInHistories = false; private bool _useSideBySideDiff = false; + private bool _useSyntaxHighlighting = false; private Models.ChangeViewMode _unstagedChangeViewMode = Models.ChangeViewMode.List; private Models.ChangeViewMode _stagedChangeViewMode = Models.ChangeViewMode.List; diff --git a/src/SourceGit/Views/DiffView.axaml b/src/SourceGit/Views/DiffView.axaml index d08f80bd..c6b8956a 100644 --- a/src/SourceGit/Views/DiffView.axaml +++ b/src/SourceGit/Views/DiffView.axaml @@ -26,14 +26,23 @@ - + + + + + - +