Implement PluginSearch TextBox & ContentControl Lazy Load

This commit is contained in:
Hongtao Zhang 2021-12-11 11:52:43 -06:00
parent 1f64dc8e94
commit ee0f8ef22a
4 changed files with 56 additions and 6 deletions

View file

@ -901,6 +901,7 @@
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="73" />
<RowDefinition Height="73" /> <RowDefinition Height="73" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
@ -912,12 +913,23 @@
Text="{DynamicResource plugin}" Text="{DynamicResource plugin}"
TextAlignment="left" /> TextAlignment="left" />
</Border> </Border>
<Border Grid.Row="1" Padding="5,18,0,0">
<TextBox
Name="pluginFilterTxb"
Margin="0,5,0,0"
FontSize="30"
Text=""
TextAlignment="left"
TextChanged="OnPluginSearchTextChanged"
/>
</Border>
<Border <Border
Grid.Row="1" Grid.Row="2"
Grid.Column="0" Grid.Column="0"
Padding="0,0,0,0" Padding="0,0,0,0"
Background="{DynamicResource Color01B}"> Background="{DynamicResource Color01B}">
<ListBox <ListBox
Name="pluginList"
Width="Auto" Width="Auto"
Margin="5,0,0,0" Margin="5,0,0,0"
Padding="0,0,7,0" Padding="0,0,7,0"
@ -942,7 +954,7 @@
Padding="0" Padding="0"
Background="Transparent" Background="Transparent"
FlowDirection="RightToLeft" FlowDirection="RightToLeft"
IsExpanded="{Binding Mode=TwoWay, Path=IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}" IsExpanded="{Binding Mode=TwoWay, Path=IsExpanded}"
Style="{StaticResource ExpanderStyle1}"> Style="{StaticResource ExpanderStyle1}">
<Expander.Header> <Expander.Header>
<Grid <Grid

View file

@ -13,6 +13,8 @@ using ModernWpf;
using System; using System;
using System.IO; using System.IO;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Interop; using System.Windows.Interop;
@ -41,9 +43,11 @@ namespace Flow.Launcher
DataContext = viewModel; DataContext = viewModel;
this.viewModel = viewModel; this.viewModel = viewModel;
API = api; API = api;
} }
#region General #region General
private void OnLoaded(object sender, RoutedEventArgs e) private void OnLoaded(object sender, RoutedEventArgs e)
{ {
RefreshMaximizeRestoreButton(); RefreshMaximizeRestoreButton();
@ -52,6 +56,9 @@ namespace Flow.Launcher
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource; HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
HwndTarget hwndTarget = hwndSource.CompositionTarget; HwndTarget hwndTarget = hwndSource.CompositionTarget;
hwndTarget.RenderMode = RenderMode.SoftwareOnly; hwndTarget.RenderMode = RenderMode.SoftwareOnly;
pluginListView = (CollectionView) CollectionViewSource.GetDefaultView(pluginList.ItemsSource);
pluginListView.Filter = PluginFilter;
} }
private void OnAutoStartupChecked(object sender, RoutedEventArgs e) private void OnAutoStartupChecked(object sender, RoutedEventArgs e)
@ -247,6 +254,7 @@ namespace Flow.Launcher
PluginManager.API.OpenDirectory(directory); PluginManager.API.OpenDirectory(directory);
} }
} }
#endregion #endregion
#region Proxy #region Proxy
@ -264,6 +272,7 @@ namespace Flow.Launcher
viewModel.UpdateApp(); // TODO: change to command viewModel.UpdateApp(); // TODO: change to command
} }
private void OnRequestNavigate(object sender, RequestNavigateEventArgs e) private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
{ {
API.OpenUrl(e.Uri.AbsoluteUri); API.OpenUrl(e.Uri.AbsoluteUri);
@ -307,7 +316,7 @@ namespace Flow.Launcher
private void OnExternalPluginInstallClick(object sender, RoutedEventArgs e) private void OnExternalPluginInstallClick(object sender, RoutedEventArgs e)
{ {
if(sender is Button { DataContext: UserPlugin plugin }) if (sender is Button { DataContext: UserPlugin plugin })
{ {
var pluginsManagerPlugin = PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7"); var pluginsManagerPlugin = PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7");
var actionKeyword = pluginsManagerPlugin.Metadata.ActionKeywords.Count == 0 ? "" : pluginsManagerPlugin.Metadata.ActionKeywords[0]; var actionKeyword = pluginsManagerPlugin.Metadata.ActionKeywords.Count == 0 ? "" : pluginsManagerPlugin.Metadata.ActionKeywords[0];
@ -326,7 +335,7 @@ namespace Flow.Launcher
textBox.MoveFocus(tRequest); textBox.MoveFocus(tRequest);
} }
private void ColorSchemeSelectedIndexChanged(object sender, EventArgs e) private void ColorSchemeSelectedIndexChanged(object sender, EventArgs e)
=> ThemeManager.Current.ApplicationTheme = settings.ColorScheme switch => ThemeManager.Current.ApplicationTheme = settings.ColorScheme switch
{ {
Constant.Light => ApplicationTheme.Light, Constant.Light => ApplicationTheme.Light,
@ -370,5 +379,22 @@ namespace Flow.Launcher
RefreshMaximizeRestoreButton(); RefreshMaximizeRestoreButton();
} }
private CollectionView pluginListView;
private bool PluginFilter(object item)
{
if (string.IsNullOrEmpty(pluginFilterTxb.Text))
return true;
if (item is PluginViewModel model)
{
return StringMatcher.FuzzySearch(pluginFilterTxb.Text, model.PluginPair.Metadata.Name).IsSearchPrecisionScoreMet();
}
return false;
}
private void OnPluginSearchTextChanged(object sender, TextChangedEventArgs e)
{
pluginListView.Refresh();
}
} }
} }

View file

@ -30,9 +30,20 @@ namespace Flow.Launcher.ViewModel
get => !PluginPair.Metadata.Disabled; get => !PluginPair.Metadata.Disabled;
set => PluginPair.Metadata.Disabled = !value; set => PluginPair.Metadata.Disabled = !value;
} }
public bool IsExpanded
{
get => _isExpanded;
set
{
_isExpanded = value;
OnPropertyChanged();
OnPropertyChanged(nameof(SettingControl));
}
}
private Control _settingControl; private Control _settingControl;
public Control SettingControl => _settingControl ??= PluginPair.Plugin is not ISettingProvider settingProvider ? new Control() : settingProvider.CreateSettingPanel(); private bool _isExpanded;
public Control SettingControl => IsExpanded ? _settingControl ??= PluginPair.Plugin is not ISettingProvider settingProvider ? new Control() : settingProvider.CreateSettingPanel() : null;
public Visibility ActionKeywordsVisibility => PluginPair.Metadata.ActionKeywords.Count == 1 ? Visibility.Visible : Visibility.Collapsed; public Visibility ActionKeywordsVisibility => PluginPair.Metadata.ActionKeywords.Count == 1 ? Visibility.Visible : Visibility.Collapsed;
public string InitilizaTime => PluginPair.Metadata.InitTime + "ms"; public string InitilizaTime => PluginPair.Metadata.InitTime + "ms";

View file

@ -19,6 +19,7 @@ using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin; using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedModels; using Flow.Launcher.Plugin.SharedModels;
using System.Windows.Data;
namespace Flow.Launcher.ViewModel namespace Flow.Launcher.ViewModel
{ {