mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
#129 Make web search suggestion optional and add baidu suggeestion source.
This commit is contained in:
@@ -32,7 +32,7 @@ namespace Wox.Plugin.SystemPlugins
|
||||
title = subtitle;
|
||||
subtitle = null;
|
||||
}
|
||||
context.API.PushResults(query,context.CurrentPluginMetadata, new List<Result>()
|
||||
context.API.PushResults(query, context.CurrentPluginMetadata, new List<Result>()
|
||||
{
|
||||
new Result()
|
||||
{
|
||||
@@ -48,24 +48,29 @@ namespace Wox.Plugin.SystemPlugins
|
||||
}
|
||||
});
|
||||
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
if (UserSettingStorage.Instance.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
ISuggestionSource sugg = new Google();
|
||||
var result = sugg.GetSuggestions(keyword);
|
||||
if (result != null)
|
||||
ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(
|
||||
UserSettingStorage.Instance.WebSearchSuggestionSource);
|
||||
if (sugg != null)
|
||||
{
|
||||
context.API.PushResults(query,context.CurrentPluginMetadata, result.Select(o => new Result()
|
||||
var result = sugg.GetSuggestions(keyword);
|
||||
if (result != null)
|
||||
{
|
||||
Title = o,
|
||||
SubTitle = subtitle,
|
||||
Score = 5,
|
||||
IcoPath = webSearch.IconPath,
|
||||
Action = (c) =>
|
||||
{
|
||||
Process.Start(webSearch.Url.Replace("{q}", o));
|
||||
return true;
|
||||
}
|
||||
}).ToList());
|
||||
context.API.PushResults(query, context.CurrentPluginMetadata,
|
||||
result.Select(o => new Result()
|
||||
{
|
||||
Title = o,
|
||||
SubTitle = subtitle,
|
||||
Score = 5,
|
||||
IcoPath = webSearch.IconPath,
|
||||
Action = (c) =>
|
||||
{
|
||||
Process.Start(webSearch.Url.Replace("{q}", o));
|
||||
return true;
|
||||
}
|
||||
}).ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,16 @@
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="42"/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="50"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ListView x:Name="webSearchView" Grid.Row="0">
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="0">
|
||||
<CheckBox x:Name="cbEnableWebSearchSuggestion" Unchecked="CbEnableWebSearchSuggestion_OnUnchecked" Checked="CbEnableWebSearchSuggestion_OnChecked" Margin="0 10 10 10">Enable search suggestions</CheckBox>
|
||||
<ComboBox x:Name="comboBoxSuggestionSource" SelectionChanged="ComboBoxSuggestionSource_OnSelectionChanged" Margin="10">
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
<ListView x:Name="webSearchView" Grid.Row="1">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="ActionWord" Width="180">
|
||||
@@ -30,7 +36,7 @@
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<Button x:Name="btnDeleteWebSearch" Click="btnDeleteWebSearch_OnClick" Width="100" Margin="10" Content="Delete"/>
|
||||
<Button x:Name="btnEditWebSearch" Click="btnEditWebSearch_OnClick" Width="100" Margin="10" Content="Edit"/>
|
||||
<Button x:Name="btnAddWebSearch" Click="btnAddWebSearch_OnClick" Width="100" Margin="10" Content="Add"/>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Windows;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
@@ -19,6 +21,24 @@ namespace Wox.Plugin.SystemPlugins
|
||||
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
webSearchView.ItemsSource = UserSettingStorage.Instance.WebSearches;
|
||||
cbEnableWebSearchSuggestion.IsChecked = UserSettingStorage.Instance.EnableWebSearchSuggestion;
|
||||
comboBoxSuggestionSource.Visibility = UserSettingStorage.Instance.EnableWebSearchSuggestion
|
||||
? Visibility.Visible
|
||||
: Visibility.Collapsed;
|
||||
|
||||
List<ComboBoxItem> items = new List<ComboBoxItem>()
|
||||
{
|
||||
new ComboBoxItem() {Content = "Google"},
|
||||
new ComboBoxItem() {Content = "Bing" },
|
||||
new ComboBoxItem() {Content = "Baidu"},
|
||||
};
|
||||
ComboBoxItem selected = items.FirstOrDefault(o => o.Content.ToString() == UserSettingStorage.Instance.WebSearchSuggestionSource);
|
||||
if (selected == null)
|
||||
{
|
||||
selected = items[0];
|
||||
}
|
||||
comboBoxSuggestionSource.ItemsSource = items;
|
||||
comboBoxSuggestionSource.SelectedItem = selected;
|
||||
}
|
||||
|
||||
public void ReloadWebSearchView()
|
||||
@@ -66,5 +86,24 @@ namespace Wox.Plugin.SystemPlugins
|
||||
}
|
||||
}
|
||||
|
||||
private void CbEnableWebSearchSuggestion_OnChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
comboBoxSuggestionSource.Visibility = Visibility.Visible;
|
||||
UserSettingStorage.Instance.EnableWebSearchSuggestion = true;
|
||||
UserSettingStorage.Instance.Save();
|
||||
}
|
||||
|
||||
private void CbEnableWebSearchSuggestion_OnUnchecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
comboBoxSuggestionSource.Visibility = Visibility.Collapsed;
|
||||
UserSettingStorage.Instance.EnableWebSearchSuggestion = false;
|
||||
UserSettingStorage.Instance.Save();
|
||||
}
|
||||
|
||||
private void ComboBoxSuggestionSource_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
UserSettingStorage.Instance.WebSearchSuggestionSource = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();
|
||||
UserSettingStorage.Instance.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user