forked from Flow-Launcher/Flow.Launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsPanePluginStore.xaml.cs
More file actions
106 lines (92 loc) · 3.79 KB
/
SettingsPanePluginStore.xaml.cs
File metadata and controls
106 lines (92 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System.ComponentModel;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Navigation;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.SettingPages.ViewModels;
using Flow.Launcher.ViewModel;
namespace Flow.Launcher.SettingPages.Views;
public partial class SettingsPanePluginStore
{
private SettingsPanePluginStoreViewModel _viewModel = null!;
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// Sometimes the navigation is not triggered by button click,
// so we need to reset the page type
_settingViewModel.PageType = typeof(SettingsPanePluginStore);
// If the navigation is not triggered by button click, view model will be null again
if (_viewModel == null)
{
_viewModel = Ioc.Default.GetRequiredService<SettingsPanePluginStoreViewModel>();
DataContext = _viewModel;
}
if (!IsInitialized)
{
InitializeComponent();
}
UpdateCategoryGrouping();
_viewModel.PropertyChanged += ViewModel_PropertyChanged;
base.OnNavigatedTo(e);
}
private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
// If SelectedSortMode changed, then we need to update the categories
if (e.PropertyName == nameof(SettingsPanePluginStoreViewModel.SelectedSortMode))
{
UpdateCategoryGrouping();
}
// Check if changed property requires PluginStoreCollectionView refresh
switch (e.PropertyName)
{
case nameof(SettingsPanePluginStoreViewModel.FilterText):
case nameof(SettingsPanePluginStoreViewModel.ShowDotNet):
case nameof(SettingsPanePluginStoreViewModel.ShowPython):
case nameof(SettingsPanePluginStoreViewModel.ShowNodeJs):
case nameof(SettingsPanePluginStoreViewModel.ShowExecutable):
case nameof(SettingsPanePluginStoreViewModel.SelectedSortMode):
((CollectionViewSource)FindResource("PluginStoreCollectionView")).View.Refresh();
break;
}
}
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
_viewModel.PropertyChanged -= ViewModel_PropertyChanged;
base.OnNavigatingFrom(e);
}
private void SettingsPanePlugins_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key is not Key.F || Keyboard.Modifiers is not ModifierKeys.Control) return;
PluginStoreFilterTextbox.Focus();
}
private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e)
{
App.API.OpenUrl(e.Uri.AbsoluteUri);
e.Handled = true;
}
private void PluginStoreCollectionView_OnFilter(object sender, FilterEventArgs e)
{
if (e.Item is not PluginStoreItemViewModel plugin)
{
e.Accepted = false;
return;
}
e.Accepted = _viewModel.SatisfiesFilter(plugin);
}
private void UpdateCategoryGrouping()
{
var collectionView = (CollectionViewSource)FindResource("PluginStoreCollectionView");
var groupDescriptions = collectionView.GroupDescriptions;
groupDescriptions.Clear();
// For default sorting mode we use the default categories
if (_viewModel.SelectedSortMode == PluginStoreSortMode.Default)
{
groupDescriptions.Add(new PropertyGroupDescription(nameof(PluginStoreItemViewModel.DefaultCategory)));
}
// Otherwise we only split by installed or not
else
{
groupDescriptions.Add(new PropertyGroupDescription(nameof(PluginStoreItemViewModel.InstallCategory)));
}
}
}