Skip to content

Commit

Permalink
plugin manager search (#12560)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegiacometti committed Aug 12, 2021
1 parent 05f12dc commit 29d3f47
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Windows.Input;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;

namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
Expand All @@ -25,6 +27,8 @@ public class PowerLauncherViewModel : Observable
private bool _isPrimaryMonitorPositionRadioButtonChecked;
private bool _isFocusPositionRadioButtonChecked;

private string _searchText;

private GeneralSettings GeneralSettingsConfig { get; set; }

private PowerLauncherSettings settings;
Expand Down Expand Up @@ -99,6 +103,8 @@ public PowerLauncherViewModel(PowerLauncherSettings settings, ISettingsRepositor
{
plugin.PropertyChanged += OnPluginInfoChange;
}

SearchPluginsCommand = new RelayCommand(SearchPlugins);
}

private void OnPluginInfoChange(object sender, PropertyChangedEventArgs e)
Expand Down Expand Up @@ -304,6 +310,25 @@ public bool IsFocusPositionRadioButtonChecked
}
}

public string SearchText
{
get
{
return _searchText;
}

set
{
if (_searchText != value)
{
_searchText = value;
OnPropertyChanged(nameof(SearchText));
}
}
}

public ICommand SearchPluginsCommand { get; }

public HotkeySettings OpenPowerLauncher
{
get
Expand Down Expand Up @@ -452,5 +477,20 @@ public bool IsUpToDate(PowerLauncherSettings settings)
{
return this.settings.Equals(settings);
}

public void SearchPlugins()
{
if (!string.IsNullOrWhiteSpace(SearchText))
{
var plugins = settings.Plugins.Where(p => p.Name.StartsWith(SearchText, StringComparison.OrdinalIgnoreCase) || p.Name.IndexOf($" {SearchText}", StringComparison.OrdinalIgnoreCase) > 0);
_plugins = new ObservableCollection<PowerLauncherPluginViewModel>(plugins.Select(x => new PowerLauncherPluginViewModel(x, isDark)));
}
else
{
_plugins = null;
}

OnPropertyChanged(nameof(Plugins));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1394,4 +1394,7 @@ From there, simply click on a Markdown file or SVG icon in the File Explorer and
<data name="ColorPicker_ColorFormat_ToggleSwitch.AutomationProperties.Name" xml:space="preserve">
<value>Show format in editor</value>
</data>
<data name="PowerLauncher_SearchList.PlaceholderText" xml:space="preserve">
<value>Search this list</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
xmlns:i="using:Microsoft.Xaml.Interactivity"
x:Class="Microsoft.PowerToys.Settings.UI.Views.PowerLauncherPage"
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
Expand All @@ -24,7 +26,7 @@

<StackPanel Orientation="Vertical">
<ToggleSwitch x:Uid="PowerLauncher_EnablePowerLauncher"
IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.EnablePowerLauncher}"/>
IsOn="{x:Bind Mode=TwoWay, Path=ViewModel.EnablePowerLauncher}" />

<TextBlock x:Uid="Shortcuts"
Style="{StaticResource SettingsGroupTitleStyle}"
Expand Down Expand Up @@ -176,7 +178,18 @@
Margin="{StaticResource SmallTopMargin}"
Opacity="{x:Bind Mode=OneWay, Path=ViewModel.EnablePowerLauncher, Converter={StaticResource ModuleEnabledToOpacityConverter}}"
TextWrapping="Wrap"/>


<AutoSuggestBox x:Uid="PowerLauncher_SearchList"
QueryIcon="Find"
Text="{x:Bind ViewModel.SearchText, Mode=TwoWay}"
Margin="{StaticResource SmallTopMargin}">
<i:Interaction.Behaviors>
<ic:EventTriggerBehavior EventName="TextChanged">
<ic:InvokeCommandAction Command="{x:Bind ViewModel.SearchPluginsCommand}" />
</ic:EventTriggerBehavior>
</i:Interaction.Behaviors>
</AutoSuggestBox>

<TextBlock x:Uid="Run_AllPluginsDisabled"
Foreground="{ThemeResource SystemControlErrorTextForegroundBrush}"
Visibility="{x:Bind ViewModel.ShowAllPluginsDisabledWarning, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}"
Expand All @@ -187,8 +200,8 @@
Visibility="{x:Bind ViewModel.ShowPluginsLoadingMessage, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}"
TextWrapping="Wrap"
Margin="{StaticResource SmallTopMargin}"/>

<ListView ItemsSource="{x:Bind Path=ViewModel.Plugins, Mode=OneWay}"
<ListView ItemsSource="{x:Bind Path=ViewModel.Plugins, Mode=OneWay}"
MinHeight="512"
IsItemClickEnabled="True"
SelectionChanged="PluginsListView_SelectionChanged"
x:Name="PluginsListView"
Expand Down

0 comments on commit 29d3f47

Please sign in to comment.