mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
feature: supports to search stashes (#213)
This commit is contained in:
parent
3e54ab0227
commit
aee6df4132
3 changed files with 100 additions and 40 deletions
|
@ -169,7 +169,7 @@ namespace SourceGit.ViewModels
|
|||
[JsonIgnore]
|
||||
public int StashesCount
|
||||
{
|
||||
get => _stashesPage == null ? 0 : _stashesPage.Count;
|
||||
get => _stashesPage == null ? 0 : _stashesPage.Stashes.Count;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia.Controls;
|
||||
|
@ -10,20 +11,33 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
public class StashesPage : ObservableObject
|
||||
{
|
||||
public int Count
|
||||
{
|
||||
get => _stashes == null ? 0 : _stashes.Count;
|
||||
}
|
||||
|
||||
public List<Models.Stash> Stashes
|
||||
{
|
||||
get => _stashes;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _stashes, value))
|
||||
{
|
||||
RefreshVisible();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Models.Stash> VisibleStashes
|
||||
{
|
||||
get => _visibleStashes;
|
||||
private set
|
||||
{
|
||||
if (SetProperty(ref _visibleStashes, value))
|
||||
SelectedStash = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string SearchFilter
|
||||
{
|
||||
get => _searchFilter;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _searchFilter, value))
|
||||
RefreshVisible();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,10 +57,7 @@ namespace SourceGit.ViewModels
|
|||
Task.Run(() =>
|
||||
{
|
||||
var changes = new Commands.QueryStashChanges(_repo.FullPath, value.SHA).Result();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
Changes = changes;
|
||||
});
|
||||
Dispatcher.UIThread.Invoke(() => Changes = changes);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -59,9 +70,7 @@ namespace SourceGit.ViewModels
|
|||
private set
|
||||
{
|
||||
if (SetProperty(ref _changes, value))
|
||||
{
|
||||
SelectedChange = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,13 +82,9 @@ namespace SourceGit.ViewModels
|
|||
if (SetProperty(ref _selectedChange, value))
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
DiffContext = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption($"{_selectedStash.SHA}^", _selectedStash.SHA, value), _diffContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,13 +153,37 @@ namespace SourceGit.ViewModels
|
|||
public void Clear()
|
||||
{
|
||||
if (PopupHost.CanCreatePopup())
|
||||
{
|
||||
PopupHost.ShowPopup(new ClearStashes(_repo));
|
||||
}
|
||||
|
||||
public void ClearSearchFilter()
|
||||
{
|
||||
SearchFilter = string.Empty;
|
||||
}
|
||||
|
||||
private void RefreshVisible()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_searchFilter))
|
||||
{
|
||||
VisibleStashes = _stashes;
|
||||
}
|
||||
else
|
||||
{
|
||||
var visible = new List<Models.Stash>();
|
||||
foreach (var s in _stashes)
|
||||
{
|
||||
if (s.Message.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase))
|
||||
visible.Add(s);
|
||||
}
|
||||
|
||||
VisibleStashes = visible;
|
||||
}
|
||||
}
|
||||
|
||||
private Repository _repo = null;
|
||||
private List<Models.Stash> _stashes = null;
|
||||
private List<Models.Stash> _stashes = new List<Models.Stash>();
|
||||
private List<Models.Stash> _visibleStashes = new List<Models.Stash>();
|
||||
private string _searchFilter = string.Empty;
|
||||
private Models.Stash _selectedStash = null;
|
||||
private List<Models.Change> _changes = null;
|
||||
private Models.Change _selectedChange = null;
|
||||
|
|
|
@ -17,28 +17,59 @@
|
|||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Left -->
|
||||
<Grid Grid.Column="0" RowDefinitions="28,*,28,*">
|
||||
<Grid Grid.Column="0" RowDefinitions="28,36,*,28,*">
|
||||
<!-- Stash Bar -->
|
||||
<Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}">
|
||||
<Grid ColumnDefinitions="Auto,Auto,Auto,*,Auto">
|
||||
<Path Grid.Column="0" Margin="8,0,0,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.Stashes}"/>
|
||||
<TextBlock Grid.Column="1" Text="{DynamicResource Text.Stashes.Stashes}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="8,0,0,0"/>
|
||||
<TextBlock Grid.Column="2" Text="{Binding Stashes, Converter={x:Static c:ListConverters.ToCount}}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
|
||||
<Button Grid.Column="4"
|
||||
Classes="icon_button"
|
||||
Width="26" Height="14"
|
||||
Padding="0"
|
||||
Command="{Binding Clear}"
|
||||
IsEnabled="{Binding Stashes.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icons.Clean}"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid Grid.Row="0" ColumnDefinitions="Auto,Auto,Auto,*,Auto">
|
||||
<Path Grid.Column="0" Margin="8,0,0,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.Stashes}"/>
|
||||
<TextBlock Grid.Column="1" Text="{DynamicResource Text.Stashes.Stashes}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="8,0,0,0"/>
|
||||
<TextBlock Grid.Column="2" Text="{Binding Stashes, Converter={x:Static c:ListConverters.ToCount}}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
|
||||
<Button Grid.Column="4"
|
||||
Classes="icon_button"
|
||||
Width="26" Height="14"
|
||||
Padding="0"
|
||||
Command="{Binding Clear}"
|
||||
IsEnabled="{Binding Stashes.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icons.Clean}"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<!-- Search Bar -->
|
||||
<Border Grid.Row="1" BorderThickness="0,1" BorderBrush="{DynamicResource Brush.Border0}">
|
||||
<TextBox Grid.Row="1"
|
||||
Height="24"
|
||||
Margin="4,0"
|
||||
BorderThickness="1"
|
||||
CornerRadius="12"
|
||||
Text="{Binding SearchFilter, Mode=TwoWay}"
|
||||
BorderBrush="{DynamicResource Brush.Border2}"
|
||||
VerticalContentAlignment="Center">
|
||||
<TextBox.InnerLeftContent>
|
||||
<Path Width="14" Height="14"
|
||||
Margin="6,0,0,0"
|
||||
Fill="{DynamicResource Brush.FG2}"
|
||||
Data="{StaticResource Icons.Search}"/>
|
||||
</TextBox.InnerLeftContent>
|
||||
|
||||
<TextBox.InnerRightContent>
|
||||
<Button Classes="icon_button"
|
||||
Width="16"
|
||||
Margin="0,0,6,0"
|
||||
Command="{Binding ClearSearchFilter}"
|
||||
IsVisible="{Binding SearchFilter, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||
HorizontalAlignment="Right">
|
||||
<Path Width="14" Height="14"
|
||||
Margin="0,1,0,0"
|
||||
Fill="{DynamicResource Brush.FG1}"
|
||||
Data="{StaticResource Icons.Clear}"/>
|
||||
</Button>
|
||||
</TextBox.InnerRightContent>
|
||||
</TextBox>
|
||||
</Border>
|
||||
|
||||
<!-- Stash List -->
|
||||
<DataGrid Grid.Row="1"
|
||||
<DataGrid Grid.Row="2"
|
||||
Background="{DynamicResource Brush.Contents}"
|
||||
ItemsSource="{Binding Stashes}"
|
||||
ItemsSource="{Binding VisibleStashes}"
|
||||
SelectedItem="{Binding SelectedStash, Mode=TwoWay}"
|
||||
SelectionMode="Single"
|
||||
CanUserReorderColumns="False"
|
||||
|
@ -71,7 +102,7 @@
|
|||
</DataGrid>
|
||||
|
||||
<!-- Changes Bar -->
|
||||
<Border Grid.Row="2" BorderThickness="0,1" BorderBrush="{DynamicResource Brush.Border0}">
|
||||
<Border Grid.Row="3" BorderThickness="0,1" BorderBrush="{DynamicResource Brush.Border0}">
|
||||
<Grid ColumnDefinitions="Auto,Auto,*">
|
||||
<Path Grid.Column="0" Margin="8,0,0,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.File}"/>
|
||||
<TextBlock Grid.Column="1" Text="{DynamicResource Text.Stashes.Changes}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="8,0,0,0"/>
|
||||
|
@ -80,7 +111,7 @@
|
|||
</Border>
|
||||
|
||||
<!-- View Changes -->
|
||||
<DataGrid Grid.Row="3"
|
||||
<DataGrid Grid.Row="4"
|
||||
Background="{DynamicResource Brush.Contents}"
|
||||
ItemsSource="{Binding Changes}"
|
||||
SelectedItem="{Binding SelectedChange, Mode=TwoWay}"
|
||||
|
|
Loading…
Reference in a new issue