diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index 38436fe3..6a5dcc74 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -6,7 +6,7 @@ using Avalonia.Media; namespace SourceGit.Models { - public class Commit + public class Commit: IObjectId { public static double OpacityForNotMerged { diff --git a/src/Models/IObjectId.cs b/src/Models/IObjectId.cs new file mode 100644 index 00000000..a812f871 --- /dev/null +++ b/src/Models/IObjectId.cs @@ -0,0 +1,7 @@ +namespace SourceGit.Models +{ + public interface IObjectId + { + string SHA { get; } + } +} diff --git a/src/Models/Object.cs b/src/Models/Object.cs index 119177ee..c929b30c 100644 --- a/src/Models/Object.cs +++ b/src/Models/Object.cs @@ -9,7 +9,7 @@ Commit, } - public class Object + public class Object: IObjectId { public string SHA { get; set; } public ObjectType Type { get; set; } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index b5c6a4d3..8172242e 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -189,6 +189,7 @@ Increase Number of Visible Lines SELECT FILE TO VIEW CHANGES Show hidden symbols + Reverse Commits Open In Merge Tool Discard Changes All local changes in working copy. diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 38592803..11015a88 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -192,6 +192,7 @@ 增加可见的行数 请选择需要对比的文件 显示隐藏符号 + 反向提交 使用外部比对工具查看 放弃更改确认 所有本地址未提交的修改。 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 0c34de95..da6d0a9d 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -192,6 +192,7 @@ 增加可見的行數 請選擇需要對比的檔案 顯示隱藏符號 + 反向提交 使用外部比對工具檢視 放棄更改確認 所有本地址未提交的修改。 diff --git a/src/ViewModels/RevisionCompare.cs b/src/ViewModels/RevisionCompare.cs index 98b185c0..d9940752 100644 --- a/src/ViewModels/RevisionCompare.cs +++ b/src/ViewModels/RevisionCompare.cs @@ -2,28 +2,26 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; - using Avalonia.Controls; using Avalonia.Threading; - using CommunityToolkit.Mvvm.ComponentModel; namespace SourceGit.ViewModels { - public class CompareTargetWorktree + public sealed class CompareTargetWorktree : Models.IObjectId { public string SHA => string.Empty; } public class RevisionCompare : ObservableObject { - public Models.Commit StartPoint + public Models.IObjectId StartPoint { get; private set; } - public object EndPoint + public Models.IObjectId EndPoint { get; private set; @@ -43,7 +41,7 @@ namespace SourceGit.ViewModels if (SetProperty(ref _selectedChanges, value)) { if (value != null && value.Count == 1) - DiffContext = new DiffContext(_repo, new Models.DiffOption(StartPoint.SHA, _endPoint, value[0]), _diffContext); + DiffContext = new DiffContext(_repo, new Models.DiffOption(StartPoint.SHA, EndPoint?.SHA ?? string.Empty, value[0]), _diffContext); else DiffContext = null; } @@ -76,31 +74,13 @@ namespace SourceGit.ViewModels if (endPoint == null) { EndPoint = new CompareTargetWorktree(); - _endPoint = string.Empty; } else { EndPoint = endPoint; - _endPoint = endPoint.SHA; } - Task.Run(() => - { - _changes = new Commands.CompareRevisions(_repo, startPoint.SHA, _endPoint).Result(); - - var visible = _changes; - if (!string.IsNullOrWhiteSpace(_searchFilter)) - { - visible = new List(); - foreach (var c in _changes) - { - if (c.Path.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase)) - visible.Add(c); - } - } - - Dispatcher.UIThread.Invoke(() => VisibleChanges = visible); - }); + Task.Run(Refresh); } public void Cleanup() @@ -140,7 +120,7 @@ namespace SourceGit.ViewModels diffWithMerger.Icon = App.CreateMenuIcon("Icons.OpenWith"); diffWithMerger.Click += (_, ev) => { - var opt = new Models.DiffOption(StartPoint.SHA, _endPoint, change); + var opt = new Models.DiffOption(StartPoint.SHA, EndPoint?.SHA ?? string.Empty, change); var toolType = Preference.Instance.ExternalMergeToolType; var toolPath = Preference.Instance.ExternalMergeToolPath; @@ -209,8 +189,32 @@ namespace SourceGit.ViewModels } } + private void Refresh() + { + _changes = new Commands.CompareRevisions(_repo, StartPoint.SHA, EndPoint?.SHA ?? string.Empty).Result(); + + var visible = _changes; + if (!string.IsNullOrWhiteSpace(_searchFilter)) + { + visible = []; + foreach (var c in _changes) + { + if (c.Path.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase)) + visible.Add(c); + } + } + + Dispatcher.UIThread.Invoke(() => VisibleChanges = visible); + } + + public void Swap() + { + (StartPoint, EndPoint) = (EndPoint, StartPoint); + OnPropertyChanged(string.Empty); + Task.Run(Refresh); + } + private string _repo; - private string _endPoint; private List _changes = null; private List _visibleChanges = null; private List _selectedChanges = null; diff --git a/src/Views/RevisionCompare.axaml b/src/Views/RevisionCompare.axaml index 630f9752..e25342bd 100644 --- a/src/Views/RevisionCompare.axaml +++ b/src/Views/RevisionCompare.axaml @@ -10,56 +10,63 @@ x:Class="SourceGit.Views.RevisionCompare" x:DataType="vm:RevisionCompare" Background="{DynamicResource Brush.Window}"> + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + - + - - - - - - - - - - - - - - - - - - - - - + +