From a249eed1ac3028123a04310afff791269b63bd4a Mon Sep 17 00:00:00 2001 From: Gadfly Date: Fri, 12 Apr 2024 21:38:36 +0800 Subject: [PATCH 1/5] feat: show git file mode change if exist --- src/Commands/Diff.cs | 17 +++++++++++++++++ src/Converters/ObjectConverters.cs | 13 +++++++++++++ src/Models/DiffResult.cs | 7 +++++++ src/Resources/Locales/en_US.axaml | 1 + src/Resources/Locales/zh_CN.axaml | 1 + src/ViewModels/DiffContext.cs | 13 +++++++++++++ src/Views/DiffView.axaml | 11 +++++++++-- 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/Converters/ObjectConverters.cs diff --git a/src/Commands/Diff.cs b/src/Commands/Diff.cs index 090eba98..4984e3db 100644 --- a/src/Commands/Diff.cs +++ b/src/Commands/Diff.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text.RegularExpressions; +using SourceGit.Models; namespace SourceGit.Commands { @@ -46,6 +47,22 @@ namespace SourceGit.Commands protected override void OnReadline(string line) { + if (line.StartsWith("old mode ", StringComparison.Ordinal)) + { + _result.FileModeDiff ??= new FileModeDiff(); + + _result.FileModeDiff.Old = line.Substring(9); + return; + } + + if (line.StartsWith("new mode ", StringComparison.Ordinal)) + { + _result.FileModeDiff ??= new FileModeDiff(); + + _result.FileModeDiff.New = line.Substring(9); + return; + } + if (_result.IsBinary) return; diff --git a/src/Converters/ObjectConverters.cs b/src/Converters/ObjectConverters.cs new file mode 100644 index 00000000..8b11ef93 --- /dev/null +++ b/src/Converters/ObjectConverters.cs @@ -0,0 +1,13 @@ +using Avalonia.Data.Converters; + +namespace SourceGit.Converters +{ + public static class ObjectConverters + { + public static readonly FuncValueConverter IsNull = + new FuncValueConverter(v => v == null); + + public static readonly FuncValueConverter IsNotNull = + new FuncValueConverter(v => v != null); + } +} diff --git a/src/Models/DiffResult.cs b/src/Models/DiffResult.cs index 8cceced8..3325a841 100644 --- a/src/Models/DiffResult.cs +++ b/src/Models/DiffResult.cs @@ -576,11 +576,18 @@ namespace SourceGit.Models { } + public class FileModeDiff + { + public string Old { get; set; } = string.Empty; + public string New { get; set; } = string.Empty; + } + public class DiffResult { public bool IsBinary { get; set; } = false; public bool IsLFS { get; set; } = false; public TextDiff TextDiff { get; set; } = null; public LFSDiff LFSDiff { get; set; } = null; + public FileModeDiff FileModeDiff { get; set; } = null; } } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 870868ac..10d632f6 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -131,6 +131,7 @@ NEW OLD Copy + File Mode Changed : LFS OBJECT CHANGE Next Difference NO CHANGES OR ONLY EOL CHANGES diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 330961f9..ede3aa65 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -131,6 +131,7 @@ 当前大小 原始大小 复制 + 文件权限已变化 : LFS对象变更 下一个差异 没有变更或仅有换行符差异 diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 17514656..19449cc9 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.Models; namespace SourceGit.ViewModels { @@ -66,6 +67,12 @@ namespace SourceGit.ViewModels set => SetProperty(ref _syncScrollOffset, value); } + public Models.FileModeDiff FileModeDiff + { + get => _fileModeDiff; + set => SetProperty(ref _fileModeDiff, value); + } + public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null) { _repo = repo; @@ -86,6 +93,11 @@ namespace SourceGit.ViewModels var latest = new Commands.Diff(repo, option).Result(); var rs = null as object; + if (latest.FileModeDiff != null) + { + FileModeDiff = latest.FileModeDiff; + } + if (latest.TextDiff != null) { latest.TextDiff.File = _option.Path; @@ -180,5 +192,6 @@ namespace SourceGit.ViewModels private bool _isTextDiff = false; private object _content = null; private Vector _syncScrollOffset = Vector.Zero; + private Models.FileModeDiff _fileModeDiff = null; } } diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index 04fff7a9..571098c1 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -13,7 +13,7 @@ - + @@ -26,7 +26,14 @@ - + + + + + + + + Date: Fri, 12 Apr 2024 21:58:54 +0800 Subject: [PATCH 2/5] fix: change file mode status postion to right --- src/Views/DiffView.axaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index 571098c1..fdbf4169 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -13,7 +13,7 @@ - + From f7dd856e497b699e6d08a8c78be1e94ac5240dbe Mon Sep 17 00:00:00 2001 From: Gadfly Date: Sat, 13 Apr 2024 01:33:44 +0800 Subject: [PATCH 3/5] fix: enhance diff view by truncating long file paths with ellipsis and adding tooltips for full path display --- src/Views/DiffView.axaml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index fdbf4169..80e9f56c 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -20,11 +20,12 @@ - - - - - + + + + + From f4e1e0fb6bf860324d0af334bcf4bca4fecbbde8 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Sat, 13 Apr 2024 02:05:26 +0800 Subject: [PATCH 4/5] fix: use TextTrimming alternative PathConverters --- src/ViewModels/DiffContext.cs | 7 +++++++ src/Views/DiffView.axaml | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 19449cc9..7c2aab14 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -3,6 +3,7 @@ using System.IO; using System.Threading.Tasks; using Avalonia; +using Avalonia.Media; using Avalonia.Media.Imaging; using Avalonia.Threading; @@ -73,6 +74,11 @@ namespace SourceGit.ViewModels set => SetProperty(ref _fileModeDiff, value); } + public TextTrimming PathTrimming + { + get => _pathTrimming; + } + public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null) { _repo = repo; @@ -193,5 +199,6 @@ namespace SourceGit.ViewModels private object _content = null; private Vector _syncScrollOffset = Vector.Zero; private Models.FileModeDiff _fileModeDiff = null; + private TextTrimming _pathTrimming = new TextLeadingPrefixTrimming("...", 20); } } diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index 80e9f56c..cb56de34 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -22,8 +22,8 @@ - + From 54c95529855d4c887ec598555976ebe06999bfba Mon Sep 17 00:00:00 2001 From: Gadfly Date: Sat, 13 Apr 2024 18:54:46 +0800 Subject: [PATCH 5/5] refactor: remove duplicate ObjectConverters, remove unused using --- src/Converters/ObjectConverters.cs | 13 ------------- src/ViewModels/DiffContext.cs | 7 +------ src/Views/DiffView.axaml | 2 +- 3 files changed, 2 insertions(+), 20 deletions(-) delete mode 100644 src/Converters/ObjectConverters.cs diff --git a/src/Converters/ObjectConverters.cs b/src/Converters/ObjectConverters.cs deleted file mode 100644 index 8b11ef93..00000000 --- a/src/Converters/ObjectConverters.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Avalonia.Data.Converters; - -namespace SourceGit.Converters -{ - public static class ObjectConverters - { - public static readonly FuncValueConverter IsNull = - new FuncValueConverter(v => v == null); - - public static readonly FuncValueConverter IsNotNull = - new FuncValueConverter(v => v != null); - } -} diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 7c2aab14..e0c9de25 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -8,7 +8,6 @@ using Avalonia.Media.Imaging; using Avalonia.Threading; using CommunityToolkit.Mvvm.ComponentModel; -using SourceGit.Models; namespace SourceGit.ViewModels { @@ -74,10 +73,7 @@ namespace SourceGit.ViewModels set => SetProperty(ref _fileModeDiff, value); } - public TextTrimming PathTrimming - { - get => _pathTrimming; - } + public TextTrimming PathTrimming { get; } = new TextLeadingPrefixTrimming("...", 20); public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null) { @@ -199,6 +195,5 @@ namespace SourceGit.ViewModels private object _content = null; private Vector _syncScrollOffset = Vector.Zero; private Models.FileModeDiff _fileModeDiff = null; - private TextTrimming _pathTrimming = new TextLeadingPrefixTrimming("...", 20); } } diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index cb56de34..568d47b8 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -27,7 +27,7 @@ - +