Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Commands/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public partial class Diff : Command
{
[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/";
Expand Down
3 changes: 0 additions & 3 deletions src/Converters/IntConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ public static class IntConverters
public static readonly FuncValueConverter<int, bool> IsGreaterThanZero =
new FuncValueConverter<int, bool>(v => v > 0);

public static readonly FuncValueConverter<int, bool> IsGreaterThanFour =
new FuncValueConverter<int, bool>(v => v > 4);

public static readonly FuncValueConverter<int, bool> IsZero =
new FuncValueConverter<int, bool>(v => v == 0);

Expand Down
1 change: 1 addition & 0 deletions src/Resources/Icons.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<StreamGeometry x:Key="Icons.LFS">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</StreamGeometry>
<StreamGeometry x:Key="Icons.Lines.Incr">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</StreamGeometry>
<StreamGeometry x:Key="Icons.Lines.Decr">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</StreamGeometry>
<StreamGeometry x:Key="Icons.Lines.Expand">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</StreamGeometry>
<StreamGeometry x:Key="Icons.Link">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</StreamGeometry>
<StreamGeometry x:Key="Icons.List">M0 33h1024v160H0zM0 432h1024v160H0zM0 831h1024v160H0z</StreamGeometry>
<StreamGeometry x:Key="Icons.Loading">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</StreamGeometry>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/de_DE.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">Öffne in Merge Tool</x:String>
<x:String x:Key="Text.Diff.VisualLines.Decr" xml:space="preserve">Weniger Zeilen anzeigen</x:String>
<x:String x:Key="Text.Diff.VisualLines.Incr" xml:space="preserve">Mehr Zeilen anzeigen</x:String>
<x:String x:Key="Text.Diff.VisualLines.Expand" xml:space="preserve">Gesamte Datei anzeigen</x:String>
<x:String x:Key="Text.Diff.Welcome" xml:space="preserve">WÄHLE EINE DATEI AUS UM ÄNDERUNGEN ANZUZEIGEN</x:String>
<x:String x:Key="Text.Diff.ShowHiddenSymbols" xml:space="preserve">Zeige versteckte Symbole</x:String>
<x:String x:Key="Text.Diff.SwapCommits" xml:space="preserve">Seiten wechseln</x:String>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">Open in Merge Tool</x:String>
<x:String x:Key="Text.Diff.VisualLines.Decr" xml:space="preserve">Decrease Number of Visible Lines</x:String>
<x:String x:Key="Text.Diff.VisualLines.Incr" xml:space="preserve">Increase Number of Visible Lines</x:String>
<x:String x:Key="Text.Diff.VisualLines.Expand" xml:space="preserve">Visualize the Entire File</x:String>
<x:String x:Key="Text.Diff.Welcome" xml:space="preserve">SELECT FILE TO VIEW CHANGES</x:String>
<x:String x:Key="Text.Diff.ShowHiddenSymbols" xml:space="preserve">Show hidden symbols</x:String>
<x:String x:Key="Text.Diff.SwapCommits" xml:space="preserve">Swap</x:String>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/pt_BR.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">Abrir na Ferramenta de Mesclagem</x:String>
<x:String x:Key="Text.Diff.VisualLines.Decr" xml:space="preserve">Diminuir Número de Linhas Visíveis</x:String>
<x:String x:Key="Text.Diff.VisualLines.Incr" xml:space="preserve">Aumentar Número de Linhas Visíveis</x:String>
<x:String x:Key="Text.Diff.VisualLines.Expand" xml:space="preserve">Visualizar Todo o Arquivo</x:String>
<x:String x:Key="Text.Diff.Welcome" xml:space="preserve">SELECIONE O ARQUIVO PARA VISUALIZAR AS MUDANÇAS</x:String>
<x:String x:Key="Text.Diff.ShowHiddenSymbols" xml:space="preserve">Mostrar símbolos ocultos</x:String>
<x:String x:Key="Text.Diff.SwapCommits" xml:space="preserve">Trocar</x:String>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/zh_CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">使用外部合并工具查看</x:String>
<x:String x:Key="Text.Diff.VisualLines.Decr" xml:space="preserve">减少可见的行数</x:String>
<x:String x:Key="Text.Diff.VisualLines.Incr" xml:space="preserve">增加可见的行数</x:String>
<x:String x:Key="Text.Diff.VisualLines.Expand" xml:space="preserve">可视化整个文件</x:String>
<x:String x:Key="Text.Diff.Welcome" xml:space="preserve">请选择需要对比的文件</x:String>
<x:String x:Key="Text.Diff.ShowHiddenSymbols" xml:space="preserve">显示隐藏符号</x:String>
<x:String x:Key="Text.Diff.SwapCommits" xml:space="preserve">交换比对双方</x:String>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/zh_TW.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">使用外部合併工具檢視</x:String>
<x:String x:Key="Text.Diff.VisualLines.Decr" xml:space="preserve">減少可見的行數</x:String>
<x:String x:Key="Text.Diff.VisualLines.Incr" xml:space="preserve">增加可見的行數</x:String>
<x:String x:Key="Text.Diff.VisualLines.Expand" xml:space="preserve">可視化整個文件</x:String>
<x:String x:Key="Text.Diff.Welcome" xml:space="preserve">請選擇需要對比的檔案</x:String>
<x:String x:Key="Text.Diff.ShowHiddenSymbols" xml:space="preserve">顯示隱藏符號</x:String>
<x:String x:Key="Text.Diff.SwapCommits" xml:space="preserve">交換比對雙方</x:String>
Expand Down
48 changes: 47 additions & 1 deletion src/ViewModels/DiffContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Avalonia.Threading;

using CommunityToolkit.Mvvm.ComponentModel;
using SourceGit.Commands;

namespace SourceGit.ViewModels
{
Expand Down Expand Up @@ -40,6 +41,45 @@ public object Content
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
{
Expand Down Expand Up @@ -70,12 +110,14 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
public void IncrUnified()
{
UnifiedLines = _unifiedLines + 1;
IsDecUnifiedEnabled = UnifiedLines >= 4;
LoadDiffContent();
}

public void DecrUnified()
{
UnifiedLines = Math.Max(4, _unifiedLines - 1);
IsDecUnifiedEnabled = UnifiedLines >= 4;
LoadDiffContent();
}

Expand All @@ -96,9 +138,10 @@ private void LoadDiffContent()
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)
Expand Down Expand Up @@ -230,11 +273,14 @@ private Models.RevisionSubmodule QuerySubmoduleRevision(string repo, string sha)
".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;
Expand Down
15 changes: 13 additions & 2 deletions src/Views/DiffView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
<Path Width="12" Height="12" Stretch="Uniform" Margin="0,6,0,0" Data="{StaticResource Icons.Lines.Incr}"/>
</Button>

Expand All @@ -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}">
<Path Width="12" Height="12" Stretch="Uniform" Margin="0,6,0,0" Data="{StaticResource Icons.Lines.Decr}"/>
</Button>

<ToggleButton Classes="line_path"
Width="32" Height="18"
Background="Transparent"
Padding="9,6"
IsChecked="{Binding ExpandEntireFile}"
IsVisible="{Binding IsTextDiff}"
ToolTip.Tip="{DynamicResource Text.Diff.VisualLines.Expand}">
<Path Width="13" Height="13" Data="{StaticResource Icons.Lines.Expand}" Margin="0,3,0,0"/>
</ToggleButton>

<ToggleButton Classes="line_path"
Width="32" Height="18"
Background="Transparent"
Expand Down