diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/Flow.Launcher.Plugin.WebSearch.csproj b/Plugins/Flow.Launcher.Plugin.WebSearch/Flow.Launcher.Plugin.WebSearch.csproj index 42176376b8f..3b3add10635 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/Flow.Launcher.Plugin.WebSearch.csproj +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/Flow.Launcher.Plugin.WebSearch.csproj @@ -50,6 +50,10 @@ + + + + diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml index 5d65e4462dd..2b2b06fae41 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml @@ -21,6 +21,7 @@ URL Search Use Search Query Autocomplete + Max Suggestions Autocomplete Data from: Please select a web search Are you sure you want to delete {0}? diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs index b9b8a0b19f5..299e27499ce 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -91,6 +91,7 @@ public async Task> QueryAsync(Query query, CancellationToken token) if (token.IsCancellationRequested) return null; + } return results; @@ -126,7 +127,7 @@ private async Task> SuggestionsAsync(string keyword, string token.ThrowIfCancellationRequested(); - var resultsFromSuggestion = suggestions?.Select(o => new Result + var resultsFromSuggestion = suggestions?.Take(_settings.MaxSuggestions).Select(o => new Result { Title = o, SubTitle = subtitle, diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/Settings.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/Settings.cs index 0c0ac4b8453..31540ad92eb 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/Settings.cs @@ -205,6 +205,23 @@ public bool EnableSuggestion } } + private int maxSuggestions = 1; + public int MaxSuggestions + { + get => maxSuggestions; + set + { + if (value > 0 && value <= 1000) + { + if (maxSuggestions != value) + { + maxSuggestions = value; + OnPropertyChanged(); + } + } + } + } + [JsonIgnore] public SuggestionSource[] Suggestions { get; set; } = { new Google(), diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml index 152558e812b..e4f3485cd52 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml @@ -3,7 +3,9 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" xmlns:vm="clr-namespace:Flow.Launcher.Plugin.WebSearch" d:DataContext="{d:DesignInstance vm:SettingsViewModel}" d:DesignHeight="300" @@ -45,17 +47,17 @@ x:Name="SearchSourcesListView" Grid.Row="0" Margin="{StaticResource SettingPanelItemTopBottomMargin}" + AllowDrop="True" BorderBrush="DarkGray" BorderThickness="1" + Drop="ListView_Drop" GridViewColumnHeader.Click="SortByColumn" ItemsSource="{Binding Settings.SearchSources}" MouseDoubleClick="MouseDoubleClickItem" - SelectedItem="{Binding Settings.SelectedSearchSource}" - SizeChanged="ListView_SizeChanged" PreviewMouseLeftButtonDown="ListView_PreviewMouseLeftButtonDown" PreviewMouseMove="ListView_PreviewMouseMove" - AllowDrop="True" - Drop="ListView_Drop" + SelectedItem="{Binding Settings.SelectedSearchSource}" + SizeChanged="ListView_SizeChanged" Style="{StaticResource {x:Static GridView.GridViewStyleKey}}"> @@ -146,31 +148,43 @@ - - - + \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs index 6dc766fffd0..1c1dd311618 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs @@ -240,5 +240,15 @@ private static T FindAncestor(DependencyObject current) where T : DependencyO } return null; } + + // This is used for NumberBox to force its value to be 1 when the user clears the value + private void NumberBox_ValueChanged(iNKORE.UI.WPF.Modern.Controls.NumberBox sender, iNKORE.UI.WPF.Modern.Controls.NumberBoxValueChangedEventArgs args) + { + if (double.IsNaN(args.NewValue)) + { + sender.Value = 1; + _settings.MaxSuggestions = (int)sender.Value; + } + } } }