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 string OriginalPath { get; set; } = "";
public ChangeDataForAmend DataForAmend { get; set; } = null; public ChangeDataForAmend DataForAmend { get; set; } = null;
public ConflictReason ConflictReason { get; set; } = ConflictReason.None; public ConflictReason ConflictReason { get; set; } = ConflictReason.None;
public bool IsConflicted => WorkTree == ChangeState.Conflicted; 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) public void Set(ChangeState index, ChangeState workTree = ChangeState.None)
{ {
@ -81,5 +84,28 @@ namespace SourceGit.Models
if (!string.IsNullOrEmpty(OriginalPath) && OriginalPath[0] == '"') if (!string.IsNullOrEmpty(OriginalPath) && OriginalPath[0] == '"')
OriginalPath = OriginalPath.Substring(1, OriginalPath.Length - 2); 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; get => Change == null;
} }
public bool ShowConflictMarker
{
get => Change is { IsConflicted: true };
}
public string ConflictMarker
{
get => Change?.ConflictMarker ?? string.Empty;
}
public bool IsExpanded public bool IsExpanded
{ {
get => _isExpanded; get => _isExpanded;

View file

@ -27,14 +27,12 @@ namespace SourceGit.ViewModels
{ {
public string Marker public string Marker
{ {
get; get => _change.ConflictMarker;
private set;
} }
public string Description public string Description
{ {
get; get => _change.ConflictDesc;
private set;
} }
public object Theirs public object Theirs
@ -67,51 +65,11 @@ namespace SourceGit.ViewModels
_change = change; _change = change;
var isSubmodule = repo.Submodules.Find(x => x.Path.Equals(change.Path, StringComparison.Ordinal)) != null; var isSubmodule = repo.Submodules.Find(x => x.Path.Equals(change.Path, StringComparison.Ordinal)) != null;
switch (change.ConflictReason) if (!isSubmodule && (_change.ConflictReason == Models.ConflictReason.BothAdded || _change.ConflictReason == Models.ConflictReason.BothModified))
{
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)
{ {
CanUseExternalMergeTool = true; CanUseExternalMergeTool = true;
IsResolved = new Commands.IsConflictResolved(repo.FullPath, change).Result(); 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; var context = wc.InProgressContext;
if (context is CherryPickInProgress cherryPick) if (context is CherryPickInProgress cherryPick)

View file

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

View file

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