diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index cc44231c..d4bffa0d 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -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] diff --git a/src/ViewModels/StashesPage.cs b/src/ViewModels/StashesPage.cs index 487e08e1..9071300a 100644 --- a/src/ViewModels/StashesPage.cs +++ b/src/ViewModels/StashesPage.cs @@ -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 Stashes { get => _stashes; set { if (SetProperty(ref _stashes, value)) - { + RefreshVisible(); + } + } + + public List 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(); + foreach (var s in _stashes) + { + if (s.Message.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase)) + visible.Add(s); + } + + VisibleStashes = visible; } } private Repository _repo = null; - private List _stashes = null; + private List _stashes = new List(); + private List _visibleStashes = new List(); + private string _searchFilter = string.Empty; private Models.Stash _selectedStash = null; private List _changes = null; private Models.Change _selectedChange = null; diff --git a/src/Views/StashesPage.axaml b/src/Views/StashesPage.axaml index 89b4fd13..b9767ab6 100644 --- a/src/Views/StashesPage.axaml +++ b/src/Views/StashesPage.axaml @@ -17,28 +17,59 @@ - + - - - - - - - + + + + + + + + + + + + + + + + + + - - + @@ -80,7 +111,7 @@ -