Skip to content

Commit ede96c2

Browse files
committed
code_review: review PR #68
* use Converters.ListConverters.ToCount instead of adding two properties to get the count of list. * adding a new TextBlock to show number of files
1 parent 0e2da21 commit ede96c2

File tree

3 files changed

+17
-53
lines changed

3 files changed

+17
-53
lines changed

src/Converters/ListConverters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace SourceGit.Converters
77
public static class ListConverters
88
{
99
public static readonly FuncValueConverter<IList, string> ToCount =
10-
new FuncValueConverter<IList, string>(v => $" ({v.Count})");
10+
new FuncValueConverter<IList, string>(v => v == null ? " (0)" : $" ({v.Count})");
1111

1212
public static readonly FuncValueConverter<IList, bool> IsNotNullOrEmpty =
1313
new FuncValueConverter<IList, bool>(v => v != null && v.Count > 0);

src/ViewModels/WorkingCopy.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,20 @@ public bool UseAmend
4646
public List<Models.Change> Unstaged
4747
{
4848
get => _unstaged;
49-
private set
50-
{
51-
if (SetProperty(ref _unstaged, value))
52-
{
53-
OnPropertyChanged(nameof(UnstagedCount));
54-
}
55-
}
49+
private set => SetProperty(ref _unstaged, value);
5650
}
5751

5852
public List<Models.Change> Staged
5953
{
6054
get => _staged;
61-
private set
62-
{
63-
if (SetProperty(ref _staged, value))
64-
{
65-
OnPropertyChanged(nameof(StagedCount));
66-
}
67-
}
55+
private set => SetProperty(ref _staged, value);
6856
}
6957

7058
public int Count
7159
{
7260
get => _count;
7361
}
7462

75-
public int UnstagedCount
76-
{
77-
get => _unstaged.Count;
78-
}
79-
80-
public int StagedCount
81-
{
82-
get => _staged.Count;
83-
}
84-
8563
public Models.Change SelectedUnstagedChange
8664
{
8765
get => _selectedUnstagedChange;

src/Views/WorkingCopy.axaml

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,33 @@
2020
<Grid Grid.Column="0" RowDefinitions="28,*,28,*">
2121
<!-- Unstaged Toolbar -->
2222
<Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}">
23-
<Grid ColumnDefinitions="Auto,Auto,Auto,*,Auto,Auto,Auto,Auto">
23+
<Grid ColumnDefinitions="Auto,Auto,Auto,Auto,*,Auto,Auto,Auto,Auto">
2424
<v:ChangeViewModeSwitcher Grid.Column="0" Width="14" Height="14" Margin="8,0,0,0" ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=UnstagedChangeViewMode, Mode=TwoWay}"/>
25-
<TextBlock Grid.Column="1"
26-
Foreground="{DynamicResource Brush.FG2}"
27-
FontWeight="Bold"
28-
Margin="8,0,0,0">
29-
<Run Text="{DynamicResource Text.WorkingCopy.Unstaged}" />
30-
<Run Text="(" />
31-
<Run Text="{Binding UnstagedCount}" />
32-
<Run Text=")" />
33-
</TextBlock>
34-
<Path Grid.Column="2" Classes="rotating" Width="14" Height="14" Data="{StaticResource Icons.Loading}" Margin="8,0,0,0" IsVisible="{Binding IsStaging}"/>
25+
<TextBlock Grid.Column="1" Text="{DynamicResource Text.WorkingCopy.Unstaged}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="8,0,0,0"/>
26+
<TextBlock Grid.Column="2" FontWeight="Bold" Foreground="{DynamicResource Brush.FG2}" Text="{Binding Unstaged, Converter={x:Static c:ListConverters.ToCount}}"/>
27+
<Path Grid.Column="3" Classes="rotating" Width="14" Height="14" Data="{StaticResource Icons.Loading}" Margin="8,0,0,0" IsVisible="{Binding IsStaging}"/>
3528

36-
<Button Grid.Column="4"
29+
<Button Grid.Column="5"
3730
Classes="icon_button"
3831
Width="26" Height="14"
3932
Padding="0"
4033
ToolTip.Tip="{DynamicResource Text.WorkingCopy.Unstaged.ViewAssumeUnchaged}"
4134
Click="ViewAssumeUnchanged">
4235
<Path Width="14" Height="14" Data="{StaticResource Icons.File.Ignore}"/>
4336
</Button>
44-
<ToggleButton Grid.Column="5"
37+
<ToggleButton Grid.Column="6"
4538
Classes="toggle_untracked"
4639
Width="26" Height="14"
4740
ToolTip.Tip="{DynamicResource Text.WorkingCopy.IncludeUntracked}"
4841
IsChecked="{Binding $parent[v:Repository].DataContext.(vm:Repository).IncludeUntracked, Mode=TwoWay}"/>
49-
<Button Grid.Column="6"
42+
<Button Grid.Column="7"
5043
Classes="icon_button"
5144
Width="26" Height="14"
5245
Padding="0"
5346
ToolTip.Tip="{DynamicResource Text.WorkingCopy.Unstaged.Stage}" Click="StageSelected">
5447
<Path Width="14" Height="14" Margin="0,6,0,0" Data="{StaticResource Icons.Down}"/>
5548
</Button>
56-
<Button Grid.Column="7"
49+
<Button Grid.Column="8"
5750
Classes="icon_button"
5851
Width="26" Height="14"
5952
Padding="0"
@@ -175,22 +168,15 @@
175168

176169
<!-- Staged Toolbar -->
177170
<Border Grid.Row="2" BorderThickness="0,1" BorderBrush="{DynamicResource Brush.Border0}">
178-
<Grid ColumnDefinitions="Auto,Auto,Auto,*,Auto,Auto">
171+
<Grid ColumnDefinitions="Auto,Auto,Auto,Auto,*,Auto,Auto">
179172
<v:ChangeViewModeSwitcher Grid.Column="0" Width="14" Height="14" Margin="8,0,0,0" ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=StagedChangeViewMode, Mode=TwoWay}"/>
180-
<TextBlock Grid.Column="1"
181-
Foreground="{DynamicResource Brush.FG2}"
182-
FontWeight="Bold"
183-
Margin="8,0,0,0">
184-
<Run Text="{DynamicResource Text.WorkingCopy.Staged}" />
185-
<Run Text="(" />
186-
<Run Text="{Binding StagedCount}" />
187-
<Run Text=")" />
188-
</TextBlock>
189-
<Path Grid.Column="2" Classes="rotating" Width="14" Height="14" Data="{StaticResource Icons.Loading}" Margin="8,0,0,0" IsVisible="{Binding IsUnstaging}"/>
190-
<Button Grid.Column="4" Classes="icon_button" Width="26" Height="14" Padding="0" ToolTip.Tip="{DynamicResource Text.WorkingCopy.Staged.Unstage}" Click="UnstageSelected">
173+
<TextBlock Grid.Column="1" Text="{DynamicResource Text.WorkingCopy.Staged}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="8,0,0,0"/>
174+
<TextBlock Grid.Column="2" FontWeight="Bold" Foreground="{DynamicResource Brush.FG2}" Text="{Binding Staged, Converter={x:Static c:ListConverters.ToCount}}"/>
175+
<Path Grid.Column="3" Classes="rotating" Width="14" Height="14" Data="{StaticResource Icons.Loading}" Margin="8,0,0,0" IsVisible="{Binding IsUnstaging}"/>
176+
<Button Grid.Column="5" Classes="icon_button" Width="26" Height="14" Padding="0" ToolTip.Tip="{DynamicResource Text.WorkingCopy.Staged.Unstage}" Click="UnstageSelected">
191177
<Path Width="14" Height="14" Margin="0,6,0,0" Data="{StaticResource Icons.Up}"/>
192178
</Button>
193-
<Button Grid.Column="5" Classes="icon_button" Width="26" Height="14" Padding="0" ToolTip.Tip="{DynamicResource Text.WorkingCopy.Staged.UnstageAll}" Click="UnstageAll">
179+
<Button Grid.Column="6" Classes="icon_button" Width="26" Height="14" Padding="0" ToolTip.Tip="{DynamicResource Text.WorkingCopy.Staged.UnstageAll}" Click="UnstageAll">
194180
<Path Width="14" Height="14" Data="{StaticResource Icons.DoubleUp}"/>
195181
</Button>
196182
</Grid>

0 commit comments

Comments
 (0)