Skip to content

Commit c6da34b

Browse files
committed
PluginStoreSorting: Add sorting functionality
- Add GetSortedPlugins to handle different sorts based on the SelectedSortMode - Show only "None"/"Plugins" & "Installed" categories for sort modes other than default
1 parent b367cdb commit c6da34b

4 files changed

Lines changed: 67 additions & 9 deletions

File tree

Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginStoreViewModel.cs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public PluginStoreSortMode SelectedSortMode
3232
{
3333
_selectedSortMode = value;
3434
OnPropertyChanged();
35+
OnPropertyChanged(nameof(ExternalPlugins));
3536
}
3637
}
3738
}
@@ -106,13 +107,8 @@ public bool ShowExecutable
106107
}
107108
}
108109

109-
public IList<PluginStoreItemViewModel> ExternalPlugins => App.API.GetPluginManifest()
110-
.Select(p => new PluginStoreItemViewModel(p))
111-
.OrderByDescending(p => p.Category == PluginStoreItemViewModel.NewRelease)
112-
.ThenByDescending(p => p.Category == PluginStoreItemViewModel.RecentlyUpdated)
113-
.ThenByDescending(p => p.Category == PluginStoreItemViewModel.None)
114-
.ThenByDescending(p => p.Category == PluginStoreItemViewModel.Installed)
115-
.ToList();
110+
public IList<PluginStoreItemViewModel> ExternalPlugins => GetSortedPlugins(
111+
App.API.GetPluginManifest().Select(p => new PluginStoreItemViewModel(p)));
116112

117113
[RelayCommand]
118114
private async Task RefreshExternalPluginsAsync()
@@ -198,6 +194,36 @@ private void UpdateEnumDropdownLocalizations()
198194
DropdownDataGeneric<PluginStoreSortMode>.UpdateLabels(SortModes);
199195
}
200196

197+
private IList<PluginStoreItemViewModel> GetSortedPlugins(IEnumerable<PluginStoreItemViewModel> plugins)
198+
{
199+
return SelectedSortMode switch
200+
{
201+
PluginStoreSortMode.Name => plugins
202+
.OrderBy(p => p.LabelInstalled)
203+
.ThenBy(p => p.Name)
204+
.ToList(),
205+
206+
PluginStoreSortMode.ReleaseDate => plugins
207+
.OrderBy(p => p.LabelInstalled)
208+
.ThenByDescending(p => p.DateAdded.HasValue)
209+
.ThenByDescending(p => p.DateAdded)
210+
.ToList(),
211+
212+
PluginStoreSortMode.UpdatedDate => plugins
213+
.OrderBy(p => p.LabelInstalled)
214+
.ThenByDescending(p => p.UpdatedDate.HasValue)
215+
.ThenByDescending(p => p.UpdatedDate)
216+
.ToList(),
217+
218+
_ => plugins
219+
.OrderByDescending(p => p.DefaultCategory == PluginStoreItemViewModel.NewRelease)
220+
.ThenByDescending(p => p.DefaultCategory == PluginStoreItemViewModel.RecentlyUpdated)
221+
.ThenByDescending(p => p.DefaultCategory == PluginStoreItemViewModel.None)
222+
.ThenByDescending(p => p.DefaultCategory == PluginStoreItemViewModel.Installed)
223+
.ToList(),
224+
};
225+
}
226+
201227
}
202228

203229
public enum PluginStoreSortMode

Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
Filter="PluginStoreCollectionView_OnFilter"
2323
Source="{Binding ExternalPlugins}">
2424
<CollectionViewSource.GroupDescriptions>
25-
<PropertyGroupDescription PropertyName="Category" />
25+
<PropertyGroupDescription PropertyName="DefaultCategory" />
2626
</CollectionViewSource.GroupDescriptions>
2727
</CollectionViewSource>
2828
</ui:Page.Resources>

Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,28 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
2929
{
3030
InitializeComponent();
3131
}
32+
UpdateCategoryGrouping();
3233
_viewModel.PropertyChanged += ViewModel_PropertyChanged;
3334
base.OnNavigatedTo(e);
3435
}
3536

3637
private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
3738
{
39+
// If SelectedSortMode changed, then we need to update the categories
40+
if (e.PropertyName == nameof(SettingsPanePluginStoreViewModel.SelectedSortMode))
41+
{
42+
UpdateCategoryGrouping();
43+
}
44+
45+
// Check if changed property requires PluginStoreCollectionView refresh
3846
switch (e.PropertyName)
3947
{
4048
case nameof(SettingsPanePluginStoreViewModel.FilterText):
4149
case nameof(SettingsPanePluginStoreViewModel.ShowDotNet):
4250
case nameof(SettingsPanePluginStoreViewModel.ShowPython):
4351
case nameof(SettingsPanePluginStoreViewModel.ShowNodeJs):
4452
case nameof(SettingsPanePluginStoreViewModel.ShowExecutable):
53+
case nameof(SettingsPanePluginStoreViewModel.SelectedSortMode):
4554
((CollectionViewSource)FindResource("PluginStoreCollectionView")).View.Refresh();
4655
break;
4756
}
@@ -75,4 +84,23 @@ private void PluginStoreCollectionView_OnFilter(object sender, FilterEventArgs e
7584

7685
e.Accepted = _viewModel.SatisfiesFilter(plugin);
7786
}
87+
88+
private void UpdateCategoryGrouping()
89+
{
90+
var collectionView = (CollectionViewSource)FindResource("PluginStoreCollectionView");
91+
var groupDescriptions = collectionView.GroupDescriptions;
92+
93+
groupDescriptions.Clear();
94+
95+
// For default sorting mode we use the default categories
96+
if (_viewModel.SelectedSortMode == PluginStoreSortMode.Default)
97+
{
98+
groupDescriptions.Add(new PropertyGroupDescription(nameof(PluginStoreItemViewModel.DefaultCategory)));
99+
}
100+
101+
// Otherwise we only split by installed or not
102+
else{
103+
groupDescriptions.Add(new PropertyGroupDescription(nameof(PluginStoreItemViewModel.InstallCategory)));
104+
}
105+
}
78106
}

Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public PluginStoreItemViewModel(UserPlugin plugin)
2828
public string UrlDownload => _newPlugin.UrlDownload;
2929
public string UrlSourceCode => _newPlugin.UrlSourceCode;
3030
public string IcoPath => _newPlugin.IcoPath;
31+
public DateTime? DateAdded => _newPlugin.DateAdded;
32+
public DateTime? UpdatedDate => _newPlugin.LatestReleaseDate;
3133

3234
public bool LabelInstalled => _oldPluginPair != null;
3335
public bool LabelUpdate => LabelInstalled && new Version(_newPlugin.Version) > new Version(_oldPluginPair.Metadata.Version);
@@ -37,7 +39,9 @@ public PluginStoreItemViewModel(UserPlugin plugin)
3739
internal const string NewRelease = "NewRelease";
3840
internal const string Installed = "Installed";
3941

40-
public string Category
42+
public string InstallCategory => LabelInstalled ? Installed : None;
43+
44+
public string DefaultCategory
4145
{
4246
get
4347
{

0 commit comments

Comments
 (0)