Skip to content

Commit ee0f8ef

Browse files
committed
Implement PluginSearch TextBox & ContentControl Lazy Load
1 parent 1f64dc8 commit ee0f8ef

File tree

4 files changed

+56
-6
lines changed

4 files changed

+56
-6
lines changed

Flow.Launcher/SettingWindow.xaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@
901901
<ColumnDefinition />
902902
</Grid.ColumnDefinitions>
903903
<Grid.RowDefinitions>
904+
<RowDefinition Height="73" />
904905
<RowDefinition Height="73" />
905906
<RowDefinition Height="*" />
906907
</Grid.RowDefinitions>
@@ -912,12 +913,23 @@
912913
Text="{DynamicResource plugin}"
913914
TextAlignment="left" />
914915
</Border>
916+
<Border Grid.Row="1" Padding="5,18,0,0">
917+
<TextBox
918+
Name="pluginFilterTxb"
919+
Margin="0,5,0,0"
920+
FontSize="30"
921+
Text=""
922+
TextAlignment="left"
923+
TextChanged="OnPluginSearchTextChanged"
924+
/>
925+
</Border>
915926
<Border
916-
Grid.Row="1"
927+
Grid.Row="2"
917928
Grid.Column="0"
918929
Padding="0,0,0,0"
919930
Background="{DynamicResource Color01B}">
920931
<ListBox
932+
Name="pluginList"
921933
Width="Auto"
922934
Margin="5,0,0,0"
923935
Padding="0,0,7,0"
@@ -942,7 +954,7 @@
942954
Padding="0"
943955
Background="Transparent"
944956
FlowDirection="RightToLeft"
945-
IsExpanded="{Binding Mode=TwoWay, Path=IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}"
957+
IsExpanded="{Binding Mode=TwoWay, Path=IsExpanded}"
946958
Style="{StaticResource ExpanderStyle1}">
947959
<Expander.Header>
948960
<Grid

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using System;
1414
using System.IO;
1515
using System.Windows;
16+
using System.Windows.Controls;
17+
using System.Windows.Data;
1618
using System.Windows.Forms;
1719
using System.Windows.Input;
1820
using System.Windows.Interop;
@@ -41,9 +43,11 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
4143
DataContext = viewModel;
4244
this.viewModel = viewModel;
4345
API = api;
46+
4447
}
4548

4649
#region General
50+
4751
private void OnLoaded(object sender, RoutedEventArgs e)
4852
{
4953
RefreshMaximizeRestoreButton();
@@ -52,6 +56,9 @@ private void OnLoaded(object sender, RoutedEventArgs e)
5256
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
5357
HwndTarget hwndTarget = hwndSource.CompositionTarget;
5458
hwndTarget.RenderMode = RenderMode.SoftwareOnly;
59+
60+
pluginListView = (CollectionView) CollectionViewSource.GetDefaultView(pluginList.ItemsSource);
61+
pluginListView.Filter = PluginFilter;
5562
}
5663

5764
private void OnAutoStartupChecked(object sender, RoutedEventArgs e)
@@ -247,6 +254,7 @@ private void OnPluginDirecotyClick(object sender, MouseButtonEventArgs e)
247254
PluginManager.API.OpenDirectory(directory);
248255
}
249256
}
257+
250258
#endregion
251259

252260
#region Proxy
@@ -264,6 +272,7 @@ private async void OnCheckUpdates(object sender, RoutedEventArgs e)
264272
viewModel.UpdateApp(); // TODO: change to command
265273
}
266274

275+
267276
private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
268277
{
269278
API.OpenUrl(e.Uri.AbsoluteUri);
@@ -307,7 +316,7 @@ private void OnPluginStoreRefreshClick(object sender, RoutedEventArgs e)
307316

308317
private void OnExternalPluginInstallClick(object sender, RoutedEventArgs e)
309318
{
310-
if(sender is Button { DataContext: UserPlugin plugin })
319+
if (sender is Button { DataContext: UserPlugin plugin })
311320
{
312321
var pluginsManagerPlugin = PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7");
313322
var actionKeyword = pluginsManagerPlugin.Metadata.ActionKeywords.Count == 0 ? "" : pluginsManagerPlugin.Metadata.ActionKeywords[0];
@@ -326,7 +335,7 @@ private void OnExternalPluginInstallClick(object sender, RoutedEventArgs e)
326335
textBox.MoveFocus(tRequest);
327336
}
328337

329-
private void ColorSchemeSelectedIndexChanged(object sender, EventArgs e)
338+
private void ColorSchemeSelectedIndexChanged(object sender, EventArgs e)
330339
=> ThemeManager.Current.ApplicationTheme = settings.ColorScheme switch
331340
{
332341
Constant.Light => ApplicationTheme.Light,
@@ -370,5 +379,22 @@ private void Window_StateChanged(object sender, EventArgs e)
370379
RefreshMaximizeRestoreButton();
371380
}
372381

382+
private CollectionView pluginListView;
383+
384+
private bool PluginFilter(object item)
385+
{
386+
if (string.IsNullOrEmpty(pluginFilterTxb.Text))
387+
return true;
388+
if (item is PluginViewModel model)
389+
{
390+
return StringMatcher.FuzzySearch(pluginFilterTxb.Text, model.PluginPair.Metadata.Name).IsSearchPrecisionScoreMet();
391+
}
392+
return false;
393+
}
394+
395+
private void OnPluginSearchTextChanged(object sender, TextChangedEventArgs e)
396+
{
397+
pluginListView.Refresh();
398+
}
373399
}
374-
}
400+
}

Flow.Launcher/ViewModel/PluginViewModel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,20 @@ public bool PluginState
3030
get => !PluginPair.Metadata.Disabled;
3131
set => PluginPair.Metadata.Disabled = !value;
3232
}
33+
public bool IsExpanded
34+
{
35+
get => _isExpanded;
36+
set
37+
{
38+
_isExpanded = value;
39+
OnPropertyChanged();
40+
OnPropertyChanged(nameof(SettingControl));
41+
}
42+
}
3343

3444
private Control _settingControl;
35-
public Control SettingControl => _settingControl ??= PluginPair.Plugin is not ISettingProvider settingProvider ? new Control() : settingProvider.CreateSettingPanel();
45+
private bool _isExpanded;
46+
public Control SettingControl => IsExpanded ? _settingControl ??= PluginPair.Plugin is not ISettingProvider settingProvider ? new Control() : settingProvider.CreateSettingPanel() : null;
3647

3748
public Visibility ActionKeywordsVisibility => PluginPair.Metadata.ActionKeywords.Count == 1 ? Visibility.Visible : Visibility.Collapsed;
3849
public string InitilizaTime => PluginPair.Metadata.InitTime + "ms";

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Flow.Launcher.Infrastructure.UserSettings;
2020
using Flow.Launcher.Plugin;
2121
using Flow.Launcher.Plugin.SharedModels;
22+
using System.Windows.Data;
2223

2324
namespace Flow.Launcher.ViewModel
2425
{

0 commit comments

Comments
 (0)