Skip to content

Commit aee6df4

Browse files
committed
feature: supports to search stashes (#213)
1 parent 3e54ab0 commit aee6df4

File tree

3 files changed

+100
-40
lines changed

3 files changed

+100
-40
lines changed

src/ViewModels/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public int WorkingCopyChangesCount
169169
[JsonIgnore]
170170
public int StashesCount
171171
{
172-
get => _stashesPage == null ? 0 : _stashesPage.Count;
172+
get => _stashesPage == null ? 0 : _stashesPage.Stashes.Count;
173173
}
174174

175175
[JsonIgnore]

src/ViewModels/StashesPage.cs

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Threading.Tasks;
34

45
using Avalonia.Controls;
@@ -10,20 +11,33 @@ namespace SourceGit.ViewModels
1011
{
1112
public class StashesPage : ObservableObject
1213
{
13-
public int Count
14-
{
15-
get => _stashes == null ? 0 : _stashes.Count;
16-
}
17-
1814
public List<Models.Stash> Stashes
1915
{
2016
get => _stashes;
2117
set
2218
{
2319
if (SetProperty(ref _stashes, value))
24-
{
20+
RefreshVisible();
21+
}
22+
}
23+
24+
public List<Models.Stash> VisibleStashes
25+
{
26+
get => _visibleStashes;
27+
private set
28+
{
29+
if (SetProperty(ref _visibleStashes, value))
2530
SelectedStash = null;
26-
}
31+
}
32+
}
33+
34+
public string SearchFilter
35+
{
36+
get => _searchFilter;
37+
set
38+
{
39+
if (SetProperty(ref _searchFilter, value))
40+
RefreshVisible();
2741
}
2842
}
2943

@@ -43,10 +57,7 @@ public Models.Stash SelectedStash
4357
Task.Run(() =>
4458
{
4559
var changes = new Commands.QueryStashChanges(_repo.FullPath, value.SHA).Result();
46-
Dispatcher.UIThread.Invoke(() =>
47-
{
48-
Changes = changes;
49-
});
60+
Dispatcher.UIThread.Invoke(() => Changes = changes);
5061
});
5162
}
5263
}
@@ -59,9 +70,7 @@ public List<Models.Change> Changes
5970
private set
6071
{
6172
if (SetProperty(ref _changes, value))
62-
{
6373
SelectedChange = null;
64-
}
6574
}
6675
}
6776

@@ -73,13 +82,9 @@ public Models.Change SelectedChange
7382
if (SetProperty(ref _selectedChange, value))
7483
{
7584
if (value == null)
76-
{
7785
DiffContext = null;
78-
}
7986
else
80-
{
8187
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption($"{_selectedStash.SHA}^", _selectedStash.SHA, value), _diffContext);
82-
}
8388
}
8489
}
8590
}
@@ -148,13 +153,37 @@ public ContextMenu MakeContextMenu(Models.Stash stash)
148153
public void Clear()
149154
{
150155
if (PopupHost.CanCreatePopup())
151-
{
152156
PopupHost.ShowPopup(new ClearStashes(_repo));
157+
}
158+
159+
public void ClearSearchFilter()
160+
{
161+
SearchFilter = string.Empty;
162+
}
163+
164+
private void RefreshVisible()
165+
{
166+
if (string.IsNullOrEmpty(_searchFilter))
167+
{
168+
VisibleStashes = _stashes;
169+
}
170+
else
171+
{
172+
var visible = new List<Models.Stash>();
173+
foreach (var s in _stashes)
174+
{
175+
if (s.Message.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase))
176+
visible.Add(s);
177+
}
178+
179+
VisibleStashes = visible;
153180
}
154181
}
155182

156183
private Repository _repo = null;
157-
private List<Models.Stash> _stashes = null;
184+
private List<Models.Stash> _stashes = new List<Models.Stash>();
185+
private List<Models.Stash> _visibleStashes = new List<Models.Stash>();
186+
private string _searchFilter = string.Empty;
158187
private Models.Stash _selectedStash = null;
159188
private List<Models.Change> _changes = null;
160189
private Models.Change _selectedChange = null;

src/Views/StashesPage.axaml

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,59 @@
1717
</Grid.ColumnDefinitions>
1818

1919
<!-- Left -->
20-
<Grid Grid.Column="0" RowDefinitions="28,*,28,*">
20+
<Grid Grid.Column="0" RowDefinitions="28,36,*,28,*">
2121
<!-- Stash Bar -->
22-
<Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}">
23-
<Grid ColumnDefinitions="Auto,Auto,Auto,*,Auto">
24-
<Path Grid.Column="0" Margin="8,0,0,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.Stashes}"/>
25-
<TextBlock Grid.Column="1" Text="{DynamicResource Text.Stashes.Stashes}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="8,0,0,0"/>
26-
<TextBlock Grid.Column="2" Text="{Binding Stashes, Converter={x:Static c:ListConverters.ToCount}}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
27-
<Button Grid.Column="4"
28-
Classes="icon_button"
29-
Width="26" Height="14"
30-
Padding="0"
31-
Command="{Binding Clear}"
32-
IsEnabled="{Binding Stashes.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
33-
<Path Width="14" Height="14" Data="{StaticResource Icons.Clean}"/>
34-
</Button>
35-
</Grid>
22+
<Grid Grid.Row="0" ColumnDefinitions="Auto,Auto,Auto,*,Auto">
23+
<Path Grid.Column="0" Margin="8,0,0,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.Stashes}"/>
24+
<TextBlock Grid.Column="1" Text="{DynamicResource Text.Stashes.Stashes}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="8,0,0,0"/>
25+
<TextBlock Grid.Column="2" Text="{Binding Stashes, Converter={x:Static c:ListConverters.ToCount}}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
26+
<Button Grid.Column="4"
27+
Classes="icon_button"
28+
Width="26" Height="14"
29+
Padding="0"
30+
Command="{Binding Clear}"
31+
IsEnabled="{Binding Stashes.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
32+
<Path Width="14" Height="14" Data="{StaticResource Icons.Clean}"/>
33+
</Button>
34+
</Grid>
35+
36+
<!-- Search Bar -->
37+
<Border Grid.Row="1" BorderThickness="0,1" BorderBrush="{DynamicResource Brush.Border0}">
38+
<TextBox Grid.Row="1"
39+
Height="24"
40+
Margin="4,0"
41+
BorderThickness="1"
42+
CornerRadius="12"
43+
Text="{Binding SearchFilter, Mode=TwoWay}"
44+
BorderBrush="{DynamicResource Brush.Border2}"
45+
VerticalContentAlignment="Center">
46+
<TextBox.InnerLeftContent>
47+
<Path Width="14" Height="14"
48+
Margin="6,0,0,0"
49+
Fill="{DynamicResource Brush.FG2}"
50+
Data="{StaticResource Icons.Search}"/>
51+
</TextBox.InnerLeftContent>
52+
53+
<TextBox.InnerRightContent>
54+
<Button Classes="icon_button"
55+
Width="16"
56+
Margin="0,0,6,0"
57+
Command="{Binding ClearSearchFilter}"
58+
IsVisible="{Binding SearchFilter, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
59+
HorizontalAlignment="Right">
60+
<Path Width="14" Height="14"
61+
Margin="0,1,0,0"
62+
Fill="{DynamicResource Brush.FG1}"
63+
Data="{StaticResource Icons.Clear}"/>
64+
</Button>
65+
</TextBox.InnerRightContent>
66+
</TextBox>
3667
</Border>
3768

3869
<!-- Stash List -->
39-
<DataGrid Grid.Row="1"
70+
<DataGrid Grid.Row="2"
4071
Background="{DynamicResource Brush.Contents}"
41-
ItemsSource="{Binding Stashes}"
72+
ItemsSource="{Binding VisibleStashes}"
4273
SelectedItem="{Binding SelectedStash, Mode=TwoWay}"
4374
SelectionMode="Single"
4475
CanUserReorderColumns="False"
@@ -71,7 +102,7 @@
71102
</DataGrid>
72103

73104
<!-- Changes Bar -->
74-
<Border Grid.Row="2" BorderThickness="0,1" BorderBrush="{DynamicResource Brush.Border0}">
105+
<Border Grid.Row="3" BorderThickness="0,1" BorderBrush="{DynamicResource Brush.Border0}">
75106
<Grid ColumnDefinitions="Auto,Auto,*">
76107
<Path Grid.Column="0" Margin="8,0,0,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.File}"/>
77108
<TextBlock Grid.Column="1" Text="{DynamicResource Text.Stashes.Changes}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="8,0,0,0"/>
@@ -80,7 +111,7 @@
80111
</Border>
81112

82113
<!-- View Changes -->
83-
<DataGrid Grid.Row="3"
114+
<DataGrid Grid.Row="4"
84115
Background="{DynamicResource Brush.Contents}"
85116
ItemsSource="{Binding Changes}"
86117
SelectedItem="{Binding SelectedChange, Mode=TwoWay}"

0 commit comments

Comments
 (0)