ux: show conflict short format in changes view

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-05-30 10:42:02 +08:00
parent e40ca4bbe0
commit 75015d550c
No known key found for this signature in database
5 changed files with 64 additions and 62 deletions

View file

@ -49,7 +49,10 @@ namespace SourceGit.Models
public string OriginalPath { get; set; } = "";
public ChangeDataForAmend DataForAmend { get; set; } = null;
public ConflictReason ConflictReason { get; set; } = ConflictReason.None;
public bool IsConflicted => WorkTree == ChangeState.Conflicted;
public string ConflictMarker => CONFLICT_MARKERS[(int)ConflictReason];
public string ConflictDesc => CONFLICT_DESCS[(int)ConflictReason];
public void Set(ChangeState index, ChangeState workTree = ChangeState.None)
{
@ -81,5 +84,28 @@ namespace SourceGit.Models
if (!string.IsNullOrEmpty(OriginalPath) && OriginalPath[0] == '"')
OriginalPath = OriginalPath.Substring(1, OriginalPath.Length - 2);
}
private static readonly string[] CONFLICT_MARKERS =
[
string.Empty,
"DD",
"AU",
"UD",
"UA",
"DU",
"AA",
"UU"
];
private static readonly string[] CONFLICT_DESCS =
[
string.Empty,
"Both deleted",
"Added by us",
"Deleted by them",
"Added by them",
"Deleted by us",
"Both added",
"Both modified"
];
}
}

View file

@ -17,6 +17,16 @@ namespace SourceGit.ViewModels
get => Change == null;
}
public bool ShowConflictMarker
{
get => Change is { IsConflicted: true };
}
public string ConflictMarker
{
get => Change?.ConflictMarker ?? string.Empty;
}
public bool IsExpanded
{
get => _isExpanded;

View file

@ -27,14 +27,12 @@ namespace SourceGit.ViewModels
{
public string Marker
{
get;
private set;
get => _change.ConflictMarker;
}
public string Description
{
get;
private set;
get => _change.ConflictDesc;
}
public object Theirs
@ -67,51 +65,11 @@ namespace SourceGit.ViewModels
_change = change;
var isSubmodule = repo.Submodules.Find(x => x.Path.Equals(change.Path, StringComparison.Ordinal)) != null;
switch (change.ConflictReason)
{
case Models.ConflictReason.BothDeleted:
Marker = "DD";
Description = "Both deleted";
break;
case Models.ConflictReason.AddedByUs:
Marker = "AU";
Description = "Added by us";
break;
case Models.ConflictReason.DeletedByThem:
Marker = "UD";
Description = "Deleted by them";
break;
case Models.ConflictReason.AddedByThem:
Marker = "UA";
Description = "Added by them";
break;
case Models.ConflictReason.DeletedByUs:
Marker = "DU";
Description = "Deleted by us";
break;
case Models.ConflictReason.BothAdded:
Marker = "AA";
Description = "Both added";
if (!isSubmodule)
if (!isSubmodule && (_change.ConflictReason == Models.ConflictReason.BothAdded || _change.ConflictReason == Models.ConflictReason.BothModified))
{
CanUseExternalMergeTool = true;
IsResolved = new Commands.IsConflictResolved(repo.FullPath, change).Result();
}
break;
case Models.ConflictReason.BothModified:
Marker = "UU";
Description = "Both modified";
if (!isSubmodule)
{
CanUseExternalMergeTool = true;
IsResolved = new Commands.IsConflictResolved(repo.FullPath, change).Result();
}
break;
default:
Marker = string.Empty;
Description = string.Empty;
break;
}
var context = wc.InProgressContext;
if (context is CherryPickInProgress cherryPick)

View file

@ -37,7 +37,7 @@
SelectionChanged="OnRowSelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate DataType="vm:ChangeTreeNode">
<Grid ColumnDefinitions="16,Auto,Auto,*"
<Grid ColumnDefinitions="16,Auto,Auto,Auto"
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
Background="Transparent"
DoubleTapped="OnRowDoubleTapped"
@ -58,8 +58,16 @@
IsChecked="{Binding IsExpanded}"
IsVisible="{Binding IsFolder}"/>
<v:ChangeStatusIcon Grid.Column="1" Width="14" Height="14" IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}" Change="{Binding Change}" IsVisible="{Binding !IsFolder}"/>
<TextBlock Grid.Column="2" Classes="primary" Text="{Binding FullPath, Converter={x:Static c:PathConverters.PureFileName}}" Margin="6,0,0,0"/>
<v:ChangeStatusIcon Grid.Column="1"
Width="14" Height="14"
IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}"
Change="{Binding Change}"
IsVisible="{Binding !IsFolder}"/>
<StackPanel Grid.Column="3" Orientation="Horizontal" Margin="4,0,0,0">
<TextBlock Classes="primary" Text="{Binding ConflictMarker}" Foreground="DarkOrange" FontWeight="Bold" Margin="0,0,4,0" IsVisible="{Binding ShowConflictMarker}"/>
<TextBlock Classes="primary" Text="{Binding FullPath, Converter={x:Static c:PathConverters.PureFileName}}"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
@ -84,10 +92,10 @@
IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}"
Change="{Binding}" />
<TextBlock Grid.Column="1"
Classes="primary"
Text="{Binding Path, Converter={x:Static c:PathConverters.PureFileName}}"
Margin="4,0"/>
<StackPanel Grid.Column="1" Orientation="Horizontal" Margin="4,0">
<TextBlock Classes="primary" Text="{Binding ConflictMarker}" Foreground="DarkOrange" FontWeight="Bold" Margin="0,0,4,0" IsVisible="{Binding IsConflicted}"/>
<TextBlock Classes="primary" Text="{Binding Path, Converter={x:Static c:PathConverters.PureFileName}}"/>
</StackPanel>
<TextBlock Grid.Column="2"
Classes="primary"
@ -117,10 +125,10 @@
IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}"
Change="{Binding}" />
<TextBlock Grid.Column="1"
Classes="primary"
Text="{Binding Path}"
Margin="4,0"/>
<StackPanel Grid.Column="1" Orientation="Horizontal" Margin="4,0">
<TextBlock Classes="primary" Text="{Binding ConflictMarker}" Foreground="DarkOrange" FontWeight="Bold" Margin="0,0,4,0" IsVisible="{Binding IsConflicted}"/>
<TextBlock Classes="primary" Text="{Binding Path}"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>

View file

@ -105,10 +105,10 @@
</Border.IsVisible>
<Grid Margin="8,0,0,0" RowDefinitions="32,32" ColumnDefinitions="Auto,*">
<TextBlock Grid.Row="0" Grid.Column="0" Classes="info_label" Text="THEIRS"/>
<ContentControl Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Content="{Binding Theirs}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" Text="MINE"/>
<ContentControl Grid.Row="1" Grid.Column="1" Margin="16,0,0,0" Content="{Binding Mine}"/>
<TextBlock Grid.Row="0" Grid.Column="0" Classes="info_label" Text="MINE"/>
<ContentControl Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Content="{Binding Mine}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" Text="THEIRS"/>
<ContentControl Grid.Row="1" Grid.Column="1" Margin="16,0,0,0" Content="{Binding Theirs}"/>
</Grid>
</Border>