mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
code_review: PR (#280)
* tooltip for swap button * move `Views.CompareTargetWorktree` to `Models.CompareTargetWorktree` * remove unused `Models.IObjectId` * fix swap not working when target is Worktree, because Commands.CompareRevisions's Args do not changed after swapping
This commit is contained in:
parent
8d4e010fc2
commit
1583b08892
10 changed files with 56 additions and 59 deletions
|
@ -13,7 +13,9 @@ namespace SourceGit.Commands
|
|||
{
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
Args = $"diff --name-status {start} {end}";
|
||||
|
||||
var based = string.IsNullOrEmpty(start) ? "-R" : start;
|
||||
Args = $"diff --name-status {based} {end}";
|
||||
}
|
||||
|
||||
public List<Models.Change> Result()
|
||||
|
|
|
@ -6,7 +6,7 @@ using Avalonia.Media;
|
|||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class Commit: IObjectId
|
||||
public class Commit
|
||||
{
|
||||
public static double OpacityForNotMerged
|
||||
{
|
||||
|
|
6
src/Models/CompareTargetWorktree.cs
Normal file
6
src/Models/CompareTargetWorktree.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace SourceGit.Models
|
||||
{
|
||||
public class CompareTargetWorktree
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
namespace SourceGit.Models
|
||||
{
|
||||
public interface IObjectId
|
||||
{
|
||||
string SHA { get; }
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
Commit,
|
||||
}
|
||||
|
||||
public class Object: IObjectId
|
||||
public class Object
|
||||
{
|
||||
public string SHA { get; set; }
|
||||
public ObjectType Type { get; set; }
|
||||
|
|
|
@ -189,7 +189,7 @@
|
|||
<x:String x:Key="Text.Diff.VisualLines.Incr" xml:space="preserve">Increase Number of Visible Lines</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">Reverse Commits</x:String>
|
||||
<x:String x:Key="Text.Diff.SwapCommits" xml:space="preserve">Swap</x:String>
|
||||
<x:String x:Key="Text.DiffWithMerger" xml:space="preserve">Open In Merge Tool</x:String>
|
||||
<x:String x:Key="Text.Discard" xml:space="preserve">Discard Changes</x:String>
|
||||
<x:String x:Key="Text.Discard.All" xml:space="preserve">All local changes in working copy.</x:String>
|
||||
|
|
|
@ -192,7 +192,7 @@
|
|||
<x:String x:Key="Text.Diff.VisualLines.Incr" 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>
|
||||
<x:String x:Key="Text.Diff.SwapCommits" xml:space="preserve">交换比对双方</x:String>
|
||||
<x:String x:Key="Text.DiffWithMerger" xml:space="preserve">使用外部比对工具查看</x:String>
|
||||
<x:String x:Key="Text.Discard" xml:space="preserve">放弃更改确认</x:String>
|
||||
<x:String x:Key="Text.Discard.All" xml:space="preserve">所有本地址未提交的修改。</x:String>
|
||||
|
|
|
@ -192,7 +192,7 @@
|
|||
<x:String x:Key="Text.Diff.VisualLines.Incr" 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>
|
||||
<x:String x:Key="Text.Diff.SwapCommits" xml:space="preserve">交換比對雙方</x:String>
|
||||
<x:String x:Key="Text.DiffWithMerger" xml:space="preserve">使用外部比對工具檢視</x:String>
|
||||
<x:String x:Key="Text.Discard" xml:space="preserve">放棄更改確認</x:String>
|
||||
<x:String x:Key="Text.Discard.All" xml:space="preserve">所有本地址未提交的修改。</x:String>
|
||||
|
|
|
@ -2,29 +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 sealed class CompareTargetWorktree : Models.IObjectId
|
||||
{
|
||||
public string SHA => string.Empty;
|
||||
}
|
||||
|
||||
public class RevisionCompare : ObservableObject
|
||||
{
|
||||
public Models.IObjectId StartPoint
|
||||
public object StartPoint
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
get => _startPoint;
|
||||
private set => SetProperty(ref _startPoint, value);
|
||||
}
|
||||
|
||||
public Models.IObjectId EndPoint
|
||||
public object EndPoint
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
get => _endPoint;
|
||||
private set => SetProperty(ref _endPoint, value);
|
||||
}
|
||||
|
||||
public List<Models.Change> VisibleChanges
|
||||
|
@ -41,9 +38,14 @@ namespace SourceGit.ViewModels
|
|||
if (SetProperty(ref _selectedChanges, value))
|
||||
{
|
||||
if (value != null && value.Count == 1)
|
||||
DiffContext = new DiffContext(_repo, new Models.DiffOption(StartPoint.SHA, EndPoint?.SHA ?? string.Empty, value[0]), _diffContext);
|
||||
{
|
||||
var option = new Models.DiffOption(GetSHA(_startPoint), GetSHA(_endPoint), value[0]);
|
||||
DiffContext = new DiffContext(_repo, option, _diffContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
DiffContext = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,16 +71,8 @@ namespace SourceGit.ViewModels
|
|||
public RevisionCompare(string repo, Models.Commit startPoint, Models.Commit endPoint)
|
||||
{
|
||||
_repo = repo;
|
||||
StartPoint = startPoint;
|
||||
|
||||
if (endPoint == null)
|
||||
{
|
||||
EndPoint = new CompareTargetWorktree();
|
||||
}
|
||||
else
|
||||
{
|
||||
EndPoint = endPoint;
|
||||
}
|
||||
_startPoint = (object)startPoint ?? new Models.CompareTargetWorktree();
|
||||
_endPoint = (object)endPoint ?? new Models.CompareTargetWorktree();
|
||||
|
||||
Task.Run(Refresh);
|
||||
}
|
||||
|
@ -86,6 +80,8 @@ namespace SourceGit.ViewModels
|
|||
public void Cleanup()
|
||||
{
|
||||
_repo = null;
|
||||
_startPoint = null;
|
||||
_endPoint = null;
|
||||
if (_changes != null)
|
||||
_changes.Clear();
|
||||
if (_visibleChanges != null)
|
||||
|
@ -102,6 +98,12 @@ namespace SourceGit.ViewModels
|
|||
repo?.NavigateToCommit(commitSHA);
|
||||
}
|
||||
|
||||
public void Swap()
|
||||
{
|
||||
(StartPoint, EndPoint) = (_endPoint, _startPoint);
|
||||
Task.Run(Refresh);
|
||||
}
|
||||
|
||||
public void ClearSearchFilter()
|
||||
{
|
||||
SearchFilter = string.Empty;
|
||||
|
@ -120,7 +122,7 @@ namespace SourceGit.ViewModels
|
|||
diffWithMerger.Icon = App.CreateMenuIcon("Icons.OpenWith");
|
||||
diffWithMerger.Click += (_, ev) =>
|
||||
{
|
||||
var opt = new Models.DiffOption(StartPoint.SHA, EndPoint?.SHA ?? string.Empty, change);
|
||||
var opt = new Models.DiffOption(GetSHA(_startPoint), GetSHA(_endPoint), change);
|
||||
var toolType = Preference.Instance.ExternalMergeToolType;
|
||||
var toolPath = Preference.Instance.ExternalMergeToolPath;
|
||||
|
||||
|
@ -191,7 +193,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
private void Refresh()
|
||||
{
|
||||
_changes = new Commands.CompareRevisions(_repo, StartPoint.SHA, EndPoint?.SHA ?? string.Empty).Result();
|
||||
_changes = new Commands.CompareRevisions(_repo, GetSHA(_startPoint), GetSHA(_endPoint)).Result();
|
||||
|
||||
var visible = _changes;
|
||||
if (!string.IsNullOrWhiteSpace(_searchFilter))
|
||||
|
@ -207,14 +209,14 @@ namespace SourceGit.ViewModels
|
|||
Dispatcher.UIThread.Invoke(() => VisibleChanges = visible);
|
||||
}
|
||||
|
||||
public void Swap()
|
||||
private string GetSHA(object obj)
|
||||
{
|
||||
(StartPoint, EndPoint) = (EndPoint, StartPoint);
|
||||
OnPropertyChanged(string.Empty);
|
||||
Task.Run(Refresh);
|
||||
return obj is Models.Commit commit ? commit.SHA : string.Empty;
|
||||
}
|
||||
|
||||
private string _repo;
|
||||
private object _startPoint = null;
|
||||
private object _endPoint = null;
|
||||
private List<Models.Change> _changes = null;
|
||||
private List<Models.Change> _visibleChanges = null;
|
||||
private List<Models.Change> _selectedChanges = null;
|
||||
|
|
|
@ -10,16 +10,12 @@
|
|||
x:Class="SourceGit.Views.RevisionCompare"
|
||||
x:DataType="vm:RevisionCompare"
|
||||
Background="{DynamicResource Brush.Window}">
|
||||
|
||||
<UserControl.Resources>
|
||||
<DataTemplate DataType="m:Commit"
|
||||
x:Key="CommitInfoTemplate">
|
||||
<!-- Template for Models.Commit -->
|
||||
<DataTemplate DataType="m:Commit" x:Key="CommitInfoTemplate">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto,Auto">
|
||||
<v:Avatar Width="16" Height="16"
|
||||
VerticalAlignment="Center"
|
||||
IsHitTestVisible="False"
|
||||
User="{Binding Author}"/>
|
||||
<v:Avatar Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
|
||||
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding Author.Name}" Margin="8,0,0,0"/>
|
||||
<Border Grid.Column="2" Background="{DynamicResource Brush.Accent}" CornerRadius="4" IsVisible="{Binding IsCurrentHead}">
|
||||
<TextBlock Text="HEAD" Classes="monospace" Margin="4,0" Foreground="#FFDDDDDD"/>
|
||||
|
@ -32,8 +28,8 @@
|
|||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:CompareTargetWorktree"
|
||||
x:Key="WorktreeTemplate">
|
||||
<!-- Template for Models.CompareTargetWorktree -->
|
||||
<DataTemplate DataType="m:CompareTargetWorktree" x:Key="WorktreeTemplate">
|
||||
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="{DynamicResource Brush.Accent}" CornerRadius="4">
|
||||
<TextBlock Text="{DynamicResource Text.Worktree}" Classes="monospace" Margin="4,2" Foreground="#FFDDDDDD"/>
|
||||
</Border>
|
||||
|
@ -41,7 +37,9 @@
|
|||
</UserControl.Resources>
|
||||
|
||||
<Grid RowDefinitions="50,*" Margin="4">
|
||||
<!-- Compare Revision Info -->
|
||||
<Grid Grid.Row="0" Margin="48,0,48,4" ColumnDefinitions="*,48,*">
|
||||
<!-- Base Revision -->
|
||||
<Border Grid.Column="0" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1" Background="{DynamicResource Brush.Contents}" CornerRadius="4" Padding="4">
|
||||
<ContentControl Content="{Binding StartPoint}">
|
||||
<ContentControl.DataTemplates>
|
||||
|
@ -51,17 +49,12 @@
|
|||
</ContentControl>
|
||||
</Border>
|
||||
|
||||
<Button Classes="icon_button"
|
||||
Command="{Binding Swap, Mode = OneTime}"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Center"
|
||||
ToolTip.Tip="{DynamicResource Text.Diff.SyntaxHighlight}">
|
||||
<Path Grid.Column="1" Width="16" Height="16"
|
||||
Fill="{DynamicResource Brush.FG2}"
|
||||
Data="{DynamicResource Icons.Compare}"
|
||||
/>
|
||||
<!-- Swap Button -->
|
||||
<Button Classes="icon_button" Command="{Binding Swap}" Grid.Column="1" HorizontalAlignment="Center" ToolTip.Tip="{DynamicResource Text.Diff.SwapCommits}">
|
||||
<Path Grid.Column="1" Width="16" Height="16" Fill="{DynamicResource Brush.FG2}" Data="{DynamicResource Icons.Compare}"/>
|
||||
</Button>
|
||||
|
||||
<!-- Right Revision -->
|
||||
<Border Grid.Column="2" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1" Background="{DynamicResource Brush.Contents}" CornerRadius="4" Padding="4">
|
||||
<ContentControl Content="{Binding EndPoint}">
|
||||
<ContentControl.DataTemplates>
|
||||
|
@ -72,6 +65,7 @@
|
|||
</Border>
|
||||
</Grid>
|
||||
|
||||
<!-- Changes View -->
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="256" MinWidth="200" MaxWidth="480"/>
|
||||
|
|
Loading…
Reference in a new issue