From ab26bb83e9573b30c55a3beb923b805c8ed79d9c Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 14 Apr 2024 12:27:09 +0800 Subject: [PATCH] refactor: re-design toolbar of Views.DiffView --- src/Commands/Diff.cs | 6 ++-- src/Converters/PathConverters.cs | 8 ----- src/Models/DiffResult.cs | 5 ++- src/Resources/Locales/en_US.axaml | 2 +- src/Resources/Locales/zh_CN.axaml | 2 +- src/ViewModels/DiffContext.cs | 42 +++++++++---------------- src/Views/DiffView.axaml | 51 +++++++++++++++---------------- 7 files changed, 47 insertions(+), 69 deletions(-) diff --git a/src/Commands/Diff.cs b/src/Commands/Diff.cs index 3846e4bb..e92b2234 100644 --- a/src/Commands/Diff.cs +++ b/src/Commands/Diff.cs @@ -48,15 +48,13 @@ namespace SourceGit.Commands { if (line.StartsWith("old mode ", StringComparison.Ordinal)) { - _result.FileModeDiff ??= new Models.FileModeDiff(); - _result.FileModeDiff.Old = line.Substring(9); + _result.OldMode = line.Substring(9); return; } if (line.StartsWith("new mode ", StringComparison.Ordinal)) { - _result.FileModeDiff ??= new Models.FileModeDiff(); - _result.FileModeDiff.New = line.Substring(9); + _result.NewMode = line.Substring(9); return; } diff --git a/src/Converters/PathConverters.cs b/src/Converters/PathConverters.cs index fcd9f174..6f10b66d 100644 --- a/src/Converters/PathConverters.cs +++ b/src/Converters/PathConverters.cs @@ -11,13 +11,5 @@ namespace SourceGit.Converters public static readonly FuncValueConverter PureDirectoryName = new FuncValueConverter(fullpath => Path.GetDirectoryName(fullpath) ?? ""); - - public static readonly FuncValueConverter TruncateIfTooLong = - new FuncValueConverter(fullpath => - { - if (fullpath.Length <= 50) - return fullpath; - return fullpath.Substring(0, 20) + ".../" + Path.GetFileName(fullpath); - }); } } diff --git a/src/Models/DiffResult.cs b/src/Models/DiffResult.cs index 3325a841..70219dcf 100644 --- a/src/Models/DiffResult.cs +++ b/src/Models/DiffResult.cs @@ -586,8 +586,11 @@ namespace SourceGit.Models { public bool IsBinary { get; set; } = false; public bool IsLFS { get; set; } = false; + public string OldMode { get; set; } = string.Empty; + public string NewMode { get; set; } = string.Empty; public TextDiff TextDiff { get; set; } = null; public LFSDiff LFSDiff { get; set; } = null; - public FileModeDiff FileModeDiff { get; set; } = null; + + public string FileModeChange => string.IsNullOrEmpty(OldMode) ? string.Empty : $"{OldMode} → {NewMode}"; } } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 10d632f6..9752f0d6 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -131,7 +131,7 @@ NEW OLD Copy - File Mode Changed : + 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 ede3aa65..a6fdb67f 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -131,7 +131,7 @@ 当前大小 原始大小 复制 - 文件权限已变化 : + 文件权限已变化 LFS对象变更 下一个差异 没有变更或仅有换行符差异 diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index e0c9de25..18c03936 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -3,7 +3,6 @@ using System.IO; using System.Threading.Tasks; using Avalonia; -using Avalonia.Media; using Avalonia.Media.Imaging; using Avalonia.Threading; @@ -28,19 +27,16 @@ namespace SourceGit.ViewModels get => _option.IsUnstaged; } - public string FilePath + public string Title { - get => _option.Path; + get => _title; + private set => SetProperty(ref _title, value); } - public bool IsOrgFilePathVisible + public string FileModeChange { - get => !string.IsNullOrWhiteSpace(_option.OrgPath) && _option.OrgPath != "/dev/null"; - } - - public string OrgFilePath - { - get => _option.OrgPath; + get => _fileModeChange; + private set => SetProperty(ref _fileModeChange, value); } public bool IsLoading @@ -67,14 +63,6 @@ namespace SourceGit.ViewModels set => SetProperty(ref _syncScrollOffset, value); } - public Models.FileModeDiff FileModeDiff - { - get => _fileModeDiff; - set => SetProperty(ref _fileModeDiff, value); - } - - public TextTrimming PathTrimming { get; } = new TextLeadingPrefixTrimming("...", 20); - public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null) { _repo = repo; @@ -86,20 +74,11 @@ namespace SourceGit.ViewModels _content = previous._content; } - OnPropertyChanged(nameof(FilePath)); - OnPropertyChanged(nameof(IsOrgFilePathVisible)); - OnPropertyChanged(nameof(OrgFilePath)); - Task.Run(() => { 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; @@ -154,6 +133,12 @@ namespace SourceGit.ViewModels Dispatcher.UIThread.Post(() => { + if (string.IsNullOrEmpty(_option.OrgPath)) + Title = _option.Path; + else + Title = $"{_option.OrgPath} → {_option.Path}"; + + FileModeChange = latest.FileModeChange; Content = rs; IsTextDiff = latest.TextDiff != null; IsLoading = false; @@ -190,10 +175,11 @@ namespace SourceGit.ViewModels private readonly string _repo = string.Empty; private readonly Models.DiffOption _option = null; + private string _title = string.Empty; + private string _fileModeChange = string.Empty; private bool _isLoading = true; 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 568d47b8..5ba5a211 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -13,34 +13,33 @@ - - - - - - + + + - - - - - + + + + - - - - - - + + - + + @@ -50,11 +49,11 @@ Background="Transparent" Padding="9,6" IsChecked="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=TwoWay}" - IsVisible="{Binding IsTextDiff}" + IsVisible="{Binding IsTextDiff}" ToolTip.Tip="{DynamicResource Text.Diff.SideBySide}"> - + @@ -135,18 +134,18 @@ - + - + -