mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #4198 from nilvanlopes/feature/websearch-max-suggestions
Add max suggestions limit for web search plugin
This commit is contained in:
commit
27c4d35a9b
6 changed files with 71 additions and 24 deletions
|
|
@ -50,6 +50,10 @@
|
|||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.10.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
<system:String x:Key="flowlauncher_plugin_websearch_url">URL</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_websearch_search">Search</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_websearch_enable_suggestion">Use Search Query Autocomplete</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_websearch_max_suggestions">Max Suggestions</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_websearch_enable_suggestion_provider">Autocomplete Data from:</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_websearch_pls_select_web_search">Please select a web search</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_websearch_delete_warning">Are you sure you want to delete {0}?</system:String>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -91,6 +91,7 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
|
||||
if (token.IsCancellationRequested)
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
return results;
|
||||
|
|
@ -126,7 +127,7 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
var resultsFromSuggestion = suggestions?.Select(o => new Result
|
||||
var resultsFromSuggestion = suggestions?.Take(_settings.MaxSuggestions).Select(o => new Result
|
||||
{
|
||||
Title = o,
|
||||
SubTitle = subtitle,
|
||||
|
|
|
|||
|
|
@ -205,6 +205,23 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
}
|
||||
}
|
||||
|
||||
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(),
|
||||
|
|
|
|||
|
|
@ -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}}">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
|
|
@ -146,31 +148,43 @@
|
|||
|
||||
<Separator Grid.Row="2" Style="{StaticResource SettingPanelSeparatorStyle}" />
|
||||
|
||||
<DockPanel
|
||||
Grid.Row="3"
|
||||
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
|
||||
HorizontalAlignment="Right">
|
||||
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal">
|
||||
<Label
|
||||
HorizontalAlignment="Right"
|
||||
<WrapPanel Grid.Row="3" HorizontalAlignment="Stretch">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
|
||||
VerticalAlignment="Center"
|
||||
Content="{DynamicResource flowlauncher_plugin_websearch_enable_suggestion_provider}" />
|
||||
Text="{DynamicResource flowlauncher_plugin_websearch_max_suggestions}" />
|
||||
<ui:NumberBox
|
||||
Width="120"
|
||||
MinWidth="120"
|
||||
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
|
||||
Maximum="1000"
|
||||
Minimum="1"
|
||||
SmallChange="10"
|
||||
SpinButtonPlacementMode="Compact"
|
||||
ValidationMode="InvalidInputOverwritten"
|
||||
ValueChanged="NumberBox_ValueChanged"
|
||||
Value="{Binding Settings.MaxSuggestions, Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
<CheckBox
|
||||
Name="EnableSuggestion"
|
||||
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
|
||||
VerticalAlignment="Center"
|
||||
Content="{DynamicResource flowlauncher_plugin_websearch_enable_suggestion}"
|
||||
IsChecked="{Binding Settings.EnableSuggestion}" />
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
|
||||
VerticalAlignment="Center"
|
||||
Text="{DynamicResource flowlauncher_plugin_websearch_enable_suggestion_provider}" />
|
||||
<ComboBox
|
||||
Height="30"
|
||||
Margin="{StaticResource SettingPanelItemLeftMargin}"
|
||||
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="11"
|
||||
IsEnabled="{Binding Settings.EnableSuggestion}"
|
||||
ItemsSource="{Binding Settings.Suggestions}"
|
||||
SelectedItem="{Binding Settings.SelectedSuggestion}" />
|
||||
<CheckBox
|
||||
Name="EnableSuggestion"
|
||||
Margin="{StaticResource SettingPanelItemLeftMargin}"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
Content="{DynamicResource flowlauncher_plugin_websearch_enable_suggestion}"
|
||||
IsChecked="{Binding Settings.EnableSuggestion}" />
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</WrapPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
@ -240,5 +240,15 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue