Skip to content

Commit 27c4d35

Browse files
authored
Merge pull request #4198 from nilvanlopes/feature/websearch-max-suggestions
Add max suggestions limit for web search plugin
2 parents 83883c4 + 6c1c9fe commit 27c4d35

File tree

6 files changed

+71
-24
lines changed

6 files changed

+71
-24
lines changed

Plugins/Flow.Launcher.Plugin.WebSearch/Flow.Launcher.Plugin.WebSearch.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
</None>
5151
</ItemGroup>
5252

53+
<ItemGroup>
54+
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.10.2.1" />
55+
</ItemGroup>
56+
5357
<ItemGroup>
5458
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
5559
</ItemGroup>

Plugins/Flow.Launcher.Plugin.WebSearch/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<system:String x:Key="flowlauncher_plugin_websearch_url">URL</system:String>
2222
<system:String x:Key="flowlauncher_plugin_websearch_search">Search</system:String>
2323
<system:String x:Key="flowlauncher_plugin_websearch_enable_suggestion">Use Search Query Autocomplete</system:String>
24+
<system:String x:Key="flowlauncher_plugin_websearch_max_suggestions">Max Suggestions</system:String>
2425
<system:String x:Key="flowlauncher_plugin_websearch_enable_suggestion_provider">Autocomplete Data from:</system:String>
2526
<system:String x:Key="flowlauncher_plugin_websearch_pls_select_web_search">Please select a web search</system:String>
2627
<system:String x:Key="flowlauncher_plugin_websearch_delete_warning">Are you sure you want to delete {0}?</system:String>

Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
@@ -91,6 +91,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
9191

9292
if (token.IsCancellationRequested)
9393
return null;
94+
9495
}
9596

9697
return results;
@@ -126,7 +127,7 @@ private async Task<IEnumerable<Result>> SuggestionsAsync(string keyword, string
126127

127128
token.ThrowIfCancellationRequested();
128129

129-
var resultsFromSuggestion = suggestions?.Select(o => new Result
130+
var resultsFromSuggestion = suggestions?.Take(_settings.MaxSuggestions).Select(o => new Result
130131
{
131132
Title = o,
132133
SubTitle = subtitle,

Plugins/Flow.Launcher.Plugin.WebSearch/Settings.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,23 @@ public bool EnableSuggestion
205205
}
206206
}
207207

208+
private int maxSuggestions = 1;
209+
public int MaxSuggestions
210+
{
211+
get => maxSuggestions;
212+
set
213+
{
214+
if (value > 0 && value <= 1000)
215+
{
216+
if (maxSuggestions != value)
217+
{
218+
maxSuggestions = value;
219+
OnPropertyChanged();
220+
}
221+
}
222+
}
223+
}
224+
208225
[JsonIgnore]
209226
public SuggestionSource[] Suggestions { get; set; } = {
210227
new Google(),

Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
67
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
79
xmlns:vm="clr-namespace:Flow.Launcher.Plugin.WebSearch"
810
d:DataContext="{d:DesignInstance vm:SettingsViewModel}"
911
d:DesignHeight="300"
@@ -45,17 +47,17 @@
4547
x:Name="SearchSourcesListView"
4648
Grid.Row="0"
4749
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
50+
AllowDrop="True"
4851
BorderBrush="DarkGray"
4952
BorderThickness="1"
53+
Drop="ListView_Drop"
5054
GridViewColumnHeader.Click="SortByColumn"
5155
ItemsSource="{Binding Settings.SearchSources}"
5256
MouseDoubleClick="MouseDoubleClickItem"
53-
SelectedItem="{Binding Settings.SelectedSearchSource}"
54-
SizeChanged="ListView_SizeChanged"
5557
PreviewMouseLeftButtonDown="ListView_PreviewMouseLeftButtonDown"
5658
PreviewMouseMove="ListView_PreviewMouseMove"
57-
AllowDrop="True"
58-
Drop="ListView_Drop"
59+
SelectedItem="{Binding Settings.SelectedSearchSource}"
60+
SizeChanged="ListView_SizeChanged"
5961
Style="{StaticResource {x:Static GridView.GridViewStyleKey}}">
6062
<ListView.View>
6163
<GridView>
@@ -146,31 +148,43 @@
146148

147149
<Separator Grid.Row="2" Style="{StaticResource SettingPanelSeparatorStyle}" />
148150

149-
<DockPanel
150-
Grid.Row="3"
151-
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
152-
HorizontalAlignment="Right">
153-
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal">
154-
<Label
155-
HorizontalAlignment="Right"
151+
<WrapPanel Grid.Row="3" HorizontalAlignment="Stretch">
152+
<StackPanel Orientation="Horizontal">
153+
<TextBlock
154+
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
156155
VerticalAlignment="Center"
157-
Content="{DynamicResource flowlauncher_plugin_websearch_enable_suggestion_provider}" />
156+
Text="{DynamicResource flowlauncher_plugin_websearch_max_suggestions}" />
157+
<ui:NumberBox
158+
Width="120"
159+
MinWidth="120"
160+
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
161+
Maximum="1000"
162+
Minimum="1"
163+
SmallChange="10"
164+
SpinButtonPlacementMode="Compact"
165+
ValidationMode="InvalidInputOverwritten"
166+
ValueChanged="NumberBox_ValueChanged"
167+
Value="{Binding Settings.MaxSuggestions, Mode=OneWay}" />
168+
</StackPanel>
169+
<CheckBox
170+
Name="EnableSuggestion"
171+
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
172+
VerticalAlignment="Center"
173+
Content="{DynamicResource flowlauncher_plugin_websearch_enable_suggestion}"
174+
IsChecked="{Binding Settings.EnableSuggestion}" />
175+
<StackPanel Orientation="Horizontal">
176+
<TextBlock
177+
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
178+
VerticalAlignment="Center"
179+
Text="{DynamicResource flowlauncher_plugin_websearch_enable_suggestion_provider}" />
158180
<ComboBox
159181
Height="30"
160-
Margin="{StaticResource SettingPanelItemLeftMargin}"
182+
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
161183
VerticalAlignment="Center"
162-
FontSize="11"
163184
IsEnabled="{Binding Settings.EnableSuggestion}"
164185
ItemsSource="{Binding Settings.Suggestions}"
165186
SelectedItem="{Binding Settings.SelectedSuggestion}" />
166-
<CheckBox
167-
Name="EnableSuggestion"
168-
Margin="{StaticResource SettingPanelItemLeftMargin}"
169-
HorizontalAlignment="Right"
170-
VerticalAlignment="Center"
171-
Content="{DynamicResource flowlauncher_plugin_websearch_enable_suggestion}"
172-
IsChecked="{Binding Settings.EnableSuggestion}" />
173187
</StackPanel>
174-
</DockPanel>
188+
</WrapPanel>
175189
</Grid>
176190
</UserControl>

Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,15 @@ private static T FindAncestor<T>(DependencyObject current) where T : DependencyO
240240
}
241241
return null;
242242
}
243+
244+
// This is used for NumberBox to force its value to be 1 when the user clears the value
245+
private void NumberBox_ValueChanged(iNKORE.UI.WPF.Modern.Controls.NumberBox sender, iNKORE.UI.WPF.Modern.Controls.NumberBoxValueChangedEventArgs args)
246+
{
247+
if (double.IsNaN(args.NewValue))
248+
{
249+
sender.Value = 1;
250+
_settings.MaxSuggestions = (int)sender.Value;
251+
}
252+
}
243253
}
244254
}

0 commit comments

Comments
 (0)