diff --git a/src/Commands/Diff.cs b/src/Commands/Diff.cs index 0f2ee626..ee79742f 100644 --- a/src/Commands/Diff.cs +++ b/src/Commands/Diff.cs @@ -8,6 +8,9 @@ namespace SourceGit.Commands { [GeneratedRegex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@")] private static partial Regex REG_INDICATOR(); + // NOTE: Git documentation doesn't explicitly tell the max value for "unified" property. + // We're assuming that a Diff File couldn't be more than 4000 for each change. + public const int MaxDiffUnified = 4000; private const string PREFIX_LFS_NEW = "+version https://git-lfs.github.com/spec/"; private const string PREFIX_LFS_DEL = "-version https://git-lfs.github.com/spec/"; private const string PREFIX_LFS_MODIFY = " version https://git-lfs.github.com/spec/"; diff --git a/src/Converters/IntConverters.cs b/src/Converters/IntConverters.cs index 765ff6ef..9542c5ad 100644 --- a/src/Converters/IntConverters.cs +++ b/src/Converters/IntConverters.cs @@ -8,9 +8,6 @@ namespace SourceGit.Converters public static readonly FuncValueConverter IsGreaterThanZero = new FuncValueConverter(v => v > 0); - public static readonly FuncValueConverter IsGreaterThanFour = - new FuncValueConverter(v => v > 4); - public static readonly FuncValueConverter IsZero = new FuncValueConverter(v => v == 0); diff --git a/src/Resources/Icons.axaml b/src/Resources/Icons.axaml index 8090e576..f473f3e8 100644 --- a/src/Resources/Icons.axaml +++ b/src/Resources/Icons.axaml @@ -61,6 +61,7 @@ M40 9 15 23 15 31 9 28 9 20 34 5 24 0 0 14 0 34 25 48 25 28 49 14zM26 29 26 48 49 34 49 15z M408 232C408 210 426 192 448 192h416a40 40 0 110 80H448a40 40 0 01-40-40zM408 512c0-22 18-40 40-40h416a40 40 0 110 80H448A40 40 0 01408 512zM448 752A40 40 0 00448 832h416a40 40 0 100-80H448zM32 480l132 0 0-128 64 0 0 128 132 0 0 64-132 0 0 128-64 0 0-128-132 0Z M408 232C408 210 426 192 448 192h416a40 40 0 110 80H448a40 40 0 01-40-40zM408 512c0-22 18-40 40-40h416a40 40 0 110 80H448A40 40 0 01408 512zM448 752A40 40 0 00448 832h416a40 40 0 100-80H448zM32 480l328 0 0 64-328 0Z + m-1567.5 40c0-22 18-40 40-40h416a40 40 0 1 1 0 80h-416a40 40 0 0 1-40-40zm0 280c0-22 18-40 40-40h416a40 40 0 1 1 0 80h-416a40 40 0 0 1-40-40zm40 240a40 40 0 0 0 0 80h416a40 40 0 1 0 0-80zm-245.79-550.23c-6.4625 0-12.925 3.3537-16.279 10.061l-58.443 116.89c-7.4789 14.958 3.3978 32.557 20.121 32.557h14.505v301.45h-14.505c-16.723 0-27.6 17.599-20.121 32.557l58.443 116.89c6.7071 13.414 25.85 13.414 32.557 0l58.442-116.89c7.4789-14.958-3.3978-32.557-20.121-32.557h-14.504v-301.45h14.504c16.723-2e-5 27.6-17.599 20.121-32.557l-58.442-116.89c-3.3535-6.7072-9.8161-10.061-16.279-10.061z M 968 418 l -95 94 c -59 59 -146 71 -218 37 L 874 331 a 64 64 0 0 0 0 -90 L 783 150 a 64 64 0 0 0 -90 0 L 475 368 c -34 -71 -22 -159 37 -218 l 94 -94 c 75 -75 196 -75 271 0 l 90 90 c 75 75 75 196 0 271 z M 332 693 a 64 64 0 0 1 0 -90 l 271 -271 c 25 -25 65 -25 90 0 s 25 65 0 90 L 422 693 a 64 64 0 0 1 -90 0 z M 151 783 l 90 90 a 64 64 0 0 0 90 0 l 218 -218 c 34 71 22 159 -37 218 l -86 94 a 192 192 0 0 1 -271 0 l -98 -98 a 192 192 0 0 1 0 -271 l 94 -86 c 59 -59 146 -71 218 -37 L 151 693 a 64 64 0 0 0 0 90 z M0 33h1024v160H0zM0 432h1024v160H0zM0 831h1024v160H0z M512 0C233 0 7 223 0 500C6 258 190 64 416 64c230 0 416 200 416 448c0 53 43 96 96 96s96-43 96-96c0-283-229-512-512-512zm0 1023c279 0 505-223 512-500c-6 242-190 436-416 436c-230 0-416-200-416-448c0-53-43-96-96-96s-96 43-96 96c0 283 229 512 512 512z diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 7f6a6a18..67245beb 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -209,6 +209,7 @@ Öffne in Merge Tool Weniger Zeilen anzeigen Mehr Zeilen anzeigen + Gesamte Datei anzeigen WÄHLE EINE DATEI AUS UM ÄNDERUNGEN ANZUZEIGEN Zeige versteckte Symbole Seiten wechseln diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index ab29d6eb..2e853e1d 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -208,6 +208,7 @@ Open in Merge Tool Decrease Number of Visible Lines Increase Number of Visible Lines + Visualize the Entire File SELECT FILE TO VIEW CHANGES Show hidden symbols Swap diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index 1b3dc48f..222c6c6f 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -205,6 +205,7 @@ Abrir na Ferramenta de Mesclagem Diminuir Número de Linhas Visíveis Aumentar Número de Linhas Visíveis + Visualizar Todo o Arquivo SELECIONE O ARQUIVO PARA VISUALIZAR AS MUDANÇAS Mostrar símbolos ocultos Trocar diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 3986e358..435775a8 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -211,6 +211,7 @@ 使用外部合并工具查看 减少可见的行数 增加可见的行数 + 可视化整个文件 请选择需要对比的文件 显示隐藏符号 交换比对双方 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 57f87926..186d39c1 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -211,6 +211,7 @@ 使用外部合併工具檢視 減少可見的行數 增加可見的行數 + 可視化整個文件 請選擇需要對比的檔案 顯示隱藏符號 交換比對雙方 diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 08499d89..5354405c 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -7,6 +7,7 @@ using Avalonia.Media.Imaging; using Avalonia.Threading; using CommunityToolkit.Mvvm.ComponentModel; +using SourceGit.Commands; namespace SourceGit.ViewModels { @@ -40,6 +41,45 @@ namespace SourceGit.ViewModels get => _content; private set => SetProperty(ref _content, value); } + + public bool IsIncUnifiedEnabled + { + get + { + return _isIncUnifiedEnabled; + } + private set + { + SetProperty(ref _isIncUnifiedEnabled, value && !_expandEntireFile); + } + } + + public bool IsDecUnifiedEnabled + { + get + { + return _isDecUnifiedEnabled; + } + private set + { + SetProperty(ref _isDecUnifiedEnabled, value && _unifiedLines > 4 && !_expandEntireFile ); + } + } + + public bool ExpandEntireFile + { + get + { + return _expandEntireFile; + } + set + { + _expandEntireFile = value; + IsIncUnifiedEnabled = !_expandEntireFile; + IsDecUnifiedEnabled = !_expandEntireFile; + LoadDiffContent(); + } + } public int UnifiedLines { @@ -70,12 +110,14 @@ namespace SourceGit.ViewModels public void IncrUnified() { UnifiedLines = _unifiedLines + 1; + IsDecUnifiedEnabled = UnifiedLines >= 4; LoadDiffContent(); } public void DecrUnified() { UnifiedLines = Math.Max(4, _unifiedLines - 1); + IsDecUnifiedEnabled = UnifiedLines >= 4; LoadDiffContent(); } @@ -96,9 +138,10 @@ namespace SourceGit.ViewModels return; } + var unified = _expandEntireFile ? Diff.MaxDiffUnified : _unifiedLines; Task.Run(() => { - var latest = new Commands.Diff(_repo, _option, _unifiedLines).Result(); + var latest = new Commands.Diff(_repo, _option, unified).Result(); var rs = null as object; if (latest.TextDiff != null) @@ -230,11 +273,14 @@ namespace SourceGit.ViewModels ".ico", ".bmp", ".jpg", ".png", ".jpeg", ".webp" }; + private bool _isIncUnifiedEnabled = true; + private bool _isDecUnifiedEnabled = false; private readonly string _repo; private readonly Models.DiffOption _option = null; private string _title; private string _fileModeChange = string.Empty; private int _unifiedLines = 4; + private bool _expandEntireFile = false; private bool _isLoading = true; private bool _isTextDiff = false; private object _content = null; diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index 07ed7a77..8c7636a7 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -38,7 +38,8 @@ Width="32" Command="{Binding IncrUnified}" IsVisible="{Binding IsTextDiff}" - ToolTip.Tip="{DynamicResource Text.Diff.VisualLines.Incr}"> + ToolTip.Tip="{DynamicResource Text.Diff.VisualLines.Incr}" + IsEnabled="{Binding IsIncUnifiedEnabled}"> @@ -47,10 +48,20 @@ Command="{Binding DecrUnified}" IsVisible="{Binding IsTextDiff}" ToolTip.Tip="{DynamicResource Text.Diff.VisualLines.Decr}" - IsEnabled="{Binding UnifiedLines, Converter={x:Static c:IntConverters.IsGreaterThanFour}}"> + IsEnabled="{Binding IsDecUnifiedEnabled}"> + + + +