Skip to content

Commit 75015d5

Browse files
committed
ux: show conflict short format in changes view
Signed-off-by: leo <[email protected]>
1 parent e40ca4b commit 75015d5

File tree

5 files changed

+64
-62
lines changed

5 files changed

+64
-62
lines changed

src/Models/Change.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public class Change
4949
public string OriginalPath { get; set; } = "";
5050
public ChangeDataForAmend DataForAmend { get; set; } = null;
5151
public ConflictReason ConflictReason { get; set; } = ConflictReason.None;
52+
5253
public bool IsConflicted => WorkTree == ChangeState.Conflicted;
54+
public string ConflictMarker => CONFLICT_MARKERS[(int)ConflictReason];
55+
public string ConflictDesc => CONFLICT_DESCS[(int)ConflictReason];
5356

5457
public void Set(ChangeState index, ChangeState workTree = ChangeState.None)
5558
{
@@ -81,5 +84,28 @@ public void Set(ChangeState index, ChangeState workTree = ChangeState.None)
8184
if (!string.IsNullOrEmpty(OriginalPath) && OriginalPath[0] == '"')
8285
OriginalPath = OriginalPath.Substring(1, OriginalPath.Length - 2);
8386
}
87+
88+
private static readonly string[] CONFLICT_MARKERS =
89+
[
90+
string.Empty,
91+
"DD",
92+
"AU",
93+
"UD",
94+
"UA",
95+
"DU",
96+
"AA",
97+
"UU"
98+
];
99+
private static readonly string[] CONFLICT_DESCS =
100+
[
101+
string.Empty,
102+
"Both deleted",
103+
"Added by us",
104+
"Deleted by them",
105+
"Added by them",
106+
"Deleted by us",
107+
"Both added",
108+
"Both modified"
109+
];
84110
}
85111
}

src/ViewModels/ChangeTreeNode.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ public bool IsFolder
1717
get => Change == null;
1818
}
1919

20+
public bool ShowConflictMarker
21+
{
22+
get => Change is { IsConflicted: true };
23+
}
24+
25+
public string ConflictMarker
26+
{
27+
get => Change?.ConflictMarker ?? string.Empty;
28+
}
29+
2030
public bool IsExpanded
2131
{
2232
get => _isExpanded;

src/ViewModels/Conflict.cs

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ public class Conflict
2727
{
2828
public string Marker
2929
{
30-
get;
31-
private set;
30+
get => _change.ConflictMarker;
3231
}
3332

3433
public string Description
3534
{
36-
get;
37-
private set;
35+
get => _change.ConflictDesc;
3836
}
3937

4038
public object Theirs
@@ -67,50 +65,10 @@ public Conflict(Repository repo, WorkingCopy wc, Models.Change change)
6765
_change = change;
6866

6967
var isSubmodule = repo.Submodules.Find(x => x.Path.Equals(change.Path, StringComparison.Ordinal)) != null;
70-
switch (change.ConflictReason)
68+
if (!isSubmodule && (_change.ConflictReason == Models.ConflictReason.BothAdded || _change.ConflictReason == Models.ConflictReason.BothModified))
7169
{
72-
case Models.ConflictReason.BothDeleted:
73-
Marker = "DD";
74-
Description = "Both deleted";
75-
break;
76-
case Models.ConflictReason.AddedByUs:
77-
Marker = "AU";
78-
Description = "Added by us";
79-
break;
80-
case Models.ConflictReason.DeletedByThem:
81-
Marker = "UD";
82-
Description = "Deleted by them";
83-
break;
84-
case Models.ConflictReason.AddedByThem:
85-
Marker = "UA";
86-
Description = "Added by them";
87-
break;
88-
case Models.ConflictReason.DeletedByUs:
89-
Marker = "DU";
90-
Description = "Deleted by us";
91-
break;
92-
case Models.ConflictReason.BothAdded:
93-
Marker = "AA";
94-
Description = "Both added";
95-
if (!isSubmodule)
96-
{
97-
CanUseExternalMergeTool = true;
98-
IsResolved = new Commands.IsConflictResolved(repo.FullPath, change).Result();
99-
}
100-
break;
101-
case Models.ConflictReason.BothModified:
102-
Marker = "UU";
103-
Description = "Both modified";
104-
if (!isSubmodule)
105-
{
106-
CanUseExternalMergeTool = true;
107-
IsResolved = new Commands.IsConflictResolved(repo.FullPath, change).Result();
108-
}
109-
break;
110-
default:
111-
Marker = string.Empty;
112-
Description = string.Empty;
113-
break;
70+
CanUseExternalMergeTool = true;
71+
IsResolved = new Commands.IsConflictResolved(repo.FullPath, change).Result();
11472
}
11573

11674
var context = wc.InProgressContext;

src/Views/ChangeCollectionView.axaml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
SelectionChanged="OnRowSelectionChanged">
3838
<ListBox.ItemTemplate>
3939
<DataTemplate DataType="vm:ChangeTreeNode">
40-
<Grid ColumnDefinitions="16,Auto,Auto,*"
40+
<Grid ColumnDefinitions="16,Auto,Auto,Auto"
4141
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
4242
Background="Transparent"
4343
DoubleTapped="OnRowDoubleTapped"
@@ -58,8 +58,16 @@
5858
IsChecked="{Binding IsExpanded}"
5959
IsVisible="{Binding IsFolder}"/>
6060

61-
<v:ChangeStatusIcon Grid.Column="1" Width="14" Height="14" IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}" Change="{Binding Change}" IsVisible="{Binding !IsFolder}"/>
62-
<TextBlock Grid.Column="2" Classes="primary" Text="{Binding FullPath, Converter={x:Static c:PathConverters.PureFileName}}" Margin="6,0,0,0"/>
61+
<v:ChangeStatusIcon Grid.Column="1"
62+
Width="14" Height="14"
63+
IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}"
64+
Change="{Binding Change}"
65+
IsVisible="{Binding !IsFolder}"/>
66+
67+
<StackPanel Grid.Column="3" Orientation="Horizontal" Margin="4,0,0,0">
68+
<TextBlock Classes="primary" Text="{Binding ConflictMarker}" Foreground="DarkOrange" FontWeight="Bold" Margin="0,0,4,0" IsVisible="{Binding ShowConflictMarker}"/>
69+
<TextBlock Classes="primary" Text="{Binding FullPath, Converter={x:Static c:PathConverters.PureFileName}}"/>
70+
</StackPanel>
6371
</Grid>
6472
</DataTemplate>
6573
</ListBox.ItemTemplate>
@@ -84,10 +92,10 @@
8492
IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}"
8593
Change="{Binding}" />
8694

87-
<TextBlock Grid.Column="1"
88-
Classes="primary"
89-
Text="{Binding Path, Converter={x:Static c:PathConverters.PureFileName}}"
90-
Margin="4,0"/>
95+
<StackPanel Grid.Column="1" Orientation="Horizontal" Margin="4,0">
96+
<TextBlock Classes="primary" Text="{Binding ConflictMarker}" Foreground="DarkOrange" FontWeight="Bold" Margin="0,0,4,0" IsVisible="{Binding IsConflicted}"/>
97+
<TextBlock Classes="primary" Text="{Binding Path, Converter={x:Static c:PathConverters.PureFileName}}"/>
98+
</StackPanel>
9199

92100
<TextBlock Grid.Column="2"
93101
Classes="primary"
@@ -117,10 +125,10 @@
117125
IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}"
118126
Change="{Binding}" />
119127

120-
<TextBlock Grid.Column="1"
121-
Classes="primary"
122-
Text="{Binding Path}"
123-
Margin="4,0"/>
128+
<StackPanel Grid.Column="1" Orientation="Horizontal" Margin="4,0">
129+
<TextBlock Classes="primary" Text="{Binding ConflictMarker}" Foreground="DarkOrange" FontWeight="Bold" Margin="0,0,4,0" IsVisible="{Binding IsConflicted}"/>
130+
<TextBlock Classes="primary" Text="{Binding Path}"/>
131+
</StackPanel>
124132
</Grid>
125133
</DataTemplate>
126134
</ListBox.ItemTemplate>

src/Views/Conflict.axaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@
105105
</Border.IsVisible>
106106

107107
<Grid Margin="8,0,0,0" RowDefinitions="32,32" ColumnDefinitions="Auto,*">
108-
<TextBlock Grid.Row="0" Grid.Column="0" Classes="info_label" Text="THEIRS"/>
109-
<ContentControl Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Content="{Binding Theirs}"/>
110-
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" Text="MINE"/>
111-
<ContentControl Grid.Row="1" Grid.Column="1" Margin="16,0,0,0" Content="{Binding Mine}"/>
108+
<TextBlock Grid.Row="0" Grid.Column="0" Classes="info_label" Text="MINE"/>
109+
<ContentControl Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Content="{Binding Mine}"/>
110+
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" Text="THEIRS"/>
111+
<ContentControl Grid.Row="1" Grid.Column="1" Margin="16,0,0,0" Content="{Binding Theirs}"/>
112112
</Grid>
113113
</Border>
114114

0 commit comments

Comments
 (0)