@@ -12,6 +12,31 @@ namespace Flow.Launcher.SettingPages.ViewModels;
1212
1313public partial class SettingsPanePluginStoreViewModel : BaseModel
1414{
15+ public class SortModeData : DropdownDataGeneric < PluginStoreSortMode > { }
16+
17+ public List < SortModeData > SortModes { get ; } =
18+ DropdownDataGeneric < PluginStoreSortMode > . GetValues < SortModeData > ( "PluginStoreSortMode" ) ;
19+
20+ public SettingsPanePluginStoreViewModel ( )
21+ {
22+ UpdateEnumDropdownLocalizations ( ) ;
23+ }
24+
25+ private PluginStoreSortMode _selectedSortMode = PluginStoreSortMode . Default ;
26+ public PluginStoreSortMode SelectedSortMode
27+ {
28+ get => _selectedSortMode ;
29+ set
30+ {
31+ if ( _selectedSortMode != value )
32+ {
33+ _selectedSortMode = value ;
34+ OnPropertyChanged ( ) ;
35+ OnPropertyChanged ( nameof ( ExternalPlugins ) ) ;
36+ }
37+ }
38+ }
39+
1540 private string filterText = string . Empty ;
1641 public string FilterText
1742 {
@@ -82,13 +107,8 @@ public bool ShowExecutable
82107 }
83108 }
84109
85- public IList < PluginStoreItemViewModel > ExternalPlugins => App . API . GetPluginManifest ( )
86- . Select ( p => new PluginStoreItemViewModel ( p ) )
87- . OrderByDescending ( p => p . Category == PluginStoreItemViewModel . NewRelease )
88- . ThenByDescending ( p => p . Category == PluginStoreItemViewModel . RecentlyUpdated )
89- . ThenByDescending ( p => p . Category == PluginStoreItemViewModel . None )
90- . ThenByDescending ( p => p . Category == PluginStoreItemViewModel . Installed )
91- . ToList ( ) ;
110+ public IList < PluginStoreItemViewModel > ExternalPlugins => GetSortedPlugins (
111+ App . API . GetPluginManifest ( ) . Select ( p => new PluginStoreItemViewModel ( p ) ) ) ;
92112
93113 [ RelayCommand ]
94114 private async Task RefreshExternalPluginsAsync ( )
@@ -168,4 +188,48 @@ public bool SatisfiesFilter(PluginStoreItemViewModel plugin)
168188 App . API . FuzzySearch ( FilterText , plugin . Name ) . IsSearchPrecisionScoreMet ( ) ||
169189 App . API . FuzzySearch ( FilterText , plugin . Description ) . IsSearchPrecisionScoreMet ( ) ;
170190 }
191+
192+ private void UpdateEnumDropdownLocalizations ( )
193+ {
194+ DropdownDataGeneric < PluginStoreSortMode > . UpdateLabels ( SortModes ) ;
195+ }
196+
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+
227+ }
228+
229+ public enum PluginStoreSortMode
230+ {
231+ Default ,
232+ Name ,
233+ ReleaseDate ,
234+ UpdatedDate
171235}
0 commit comments