2014-07-21 22:27:57 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
2014-03-29 16:13:36 +08:00
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
2015-01-03 15:20:34 +08:00
|
|
|
|
namespace Wox.Plugin.WebSearch
|
2014-03-29 16:13:36 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for WebSearchesSetting.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class WebSearchesSetting : UserControl
|
|
|
|
|
{
|
2016-04-21 08:53:21 +08:00
|
|
|
|
private Settings _settings;
|
2015-11-09 11:20:02 +08:00
|
|
|
|
public PluginInitContext Context { get; }
|
|
|
|
|
public WebSearchPlugin Plugin { get; }
|
2015-01-07 18:45:55 +08:00
|
|
|
|
|
2016-04-21 08:53:21 +08:00
|
|
|
|
public WebSearchesSetting(WebSearchPlugin plugin, Settings settings)
|
2014-03-29 16:13:36 +08:00
|
|
|
|
{
|
2015-11-09 11:20:02 +08:00
|
|
|
|
Context = plugin.Context;
|
|
|
|
|
Plugin = plugin;
|
2014-03-29 16:13:36 +08:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
Loaded += Setting_Loaded;
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings = settings;
|
2014-03-29 16:13:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
webSearchView.ItemsSource = _settings.WebSearches;
|
|
|
|
|
cbEnableWebSearchSuggestion.IsChecked = _settings.EnableWebSearchSuggestion;
|
|
|
|
|
comboBoxSuggestionSource.Visibility = _settings.EnableWebSearchSuggestion
|
2014-07-21 22:27:57 +08:00
|
|
|
|
? Visibility.Visible
|
|
|
|
|
: Visibility.Collapsed;
|
2015-11-09 11:20:02 +08:00
|
|
|
|
|
2016-01-07 05:34:42 +08:00
|
|
|
|
List<ComboBoxItem> items = new List<ComboBoxItem>
|
2014-07-21 22:27:57 +08:00
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
new ComboBoxItem {Content = "Google"},
|
|
|
|
|
new ComboBoxItem {Content = "Baidu"}
|
2014-07-21 22:27:57 +08:00
|
|
|
|
};
|
2016-03-28 10:09:57 +08:00
|
|
|
|
ComboBoxItem selected = items.FirstOrDefault(o => o.Content.ToString() == _settings.WebSearchSuggestionSource);
|
2014-07-21 22:27:57 +08:00
|
|
|
|
if (selected == null)
|
|
|
|
|
{
|
|
|
|
|
selected = items[0];
|
|
|
|
|
}
|
|
|
|
|
comboBoxSuggestionSource.ItemsSource = items;
|
|
|
|
|
comboBoxSuggestionSource.SelectedItem = selected;
|
2014-03-29 16:13:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ReloadWebSearchView()
|
|
|
|
|
{
|
|
|
|
|
webSearchView.Items.Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void btnAddWebSearch_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
WebSearchSetting webSearch = new WebSearchSetting(this, _settings);
|
2014-03-29 16:13:36 +08:00
|
|
|
|
webSearch.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2015-01-26 22:50:38 +08:00
|
|
|
|
WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch;
|
2014-07-10 23:16:46 +08:00
|
|
|
|
if (selectedWebSearch != null)
|
2014-03-29 16:13:36 +08:00
|
|
|
|
{
|
2015-11-09 11:20:02 +08:00
|
|
|
|
string msg = string.Format(Context.API.GetTranslation("wox_plugin_websearch_delete_warning"), selectedWebSearch.Title);
|
|
|
|
|
|
|
|
|
|
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
2014-07-10 22:52:18 +08:00
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.WebSearches.Remove(selectedWebSearch);
|
2014-07-10 22:52:18 +08:00
|
|
|
|
webSearchView.Items.Refresh();
|
|
|
|
|
}
|
2014-03-29 16:13:36 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-09 11:20:02 +08:00
|
|
|
|
string warning = Context.API.GetTranslation("wox_plugin_websearch_pls_select_web_search");
|
2015-01-07 18:45:55 +08:00
|
|
|
|
MessageBox.Show(warning);
|
2014-03-29 16:13:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnEditWebSearch_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2015-01-26 22:50:38 +08:00
|
|
|
|
WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch;
|
2014-07-10 23:16:46 +08:00
|
|
|
|
if (selectedWebSearch != null)
|
2014-03-29 16:13:36 +08:00
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
WebSearchSetting webSearch = new WebSearchSetting(this, _settings);
|
2014-07-10 23:16:46 +08:00
|
|
|
|
webSearch.UpdateItem(selectedWebSearch);
|
2014-03-29 16:13:36 +08:00
|
|
|
|
webSearch.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-09 11:20:02 +08:00
|
|
|
|
string warning = Context.API.GetTranslation("wox_plugin_websearch_pls_select_web_search");
|
2015-01-07 18:45:55 +08:00
|
|
|
|
MessageBox.Show(warning);
|
2014-03-29 16:13:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-21 22:27:57 +08:00
|
|
|
|
private void CbEnableWebSearchSuggestion_OnChecked(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
comboBoxSuggestionSource.Visibility = Visibility.Visible;
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.EnableWebSearchSuggestion = true;
|
2014-07-21 22:27:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CbEnableWebSearchSuggestion_OnUnchecked(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
comboBoxSuggestionSource.Visibility = Visibility.Collapsed;
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.EnableWebSearchSuggestion = false;
|
2014-07-21 22:27:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ComboBoxSuggestionSource_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
{
|
2014-07-21 22:35:40 +08:00
|
|
|
|
if (e.AddedItems.Count > 0)
|
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.WebSearchSuggestionSource = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();
|
2014-07-21 22:35:40 +08:00
|
|
|
|
}
|
2014-07-21 22:27:57 +08:00
|
|
|
|
}
|
2014-03-29 16:13:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|