PowerToys/Plugins/Wox.Plugin.WebSearch/WebSearchesSetting.xaml.cs

119 lines
4.3 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using System.Windows;
2014-03-29 16:13:36 +08:00
using System.Windows.Controls;
using Wox.Core.UserSettings;
2014-03-29 16:13:36 +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
{
2015-01-07 18:45:55 +08:00
PluginInitContext context;
public WebSearchesSetting(PluginInitContext context)
2014-03-29 16:13:36 +08:00
{
2015-01-07 18:45:55 +08:00
this.context = context;
2014-03-29 16:13:36 +08:00
InitializeComponent();
Loaded += Setting_Loaded;
}
private void Setting_Loaded(object sender, RoutedEventArgs e)
{
webSearchView.ItemsSource = WebSearchStorage.Instance.WebSearches;
cbEnableWebSearchSuggestion.IsChecked = WebSearchStorage.Instance.EnableWebSearchSuggestion;
comboBoxSuggestionSource.Visibility = WebSearchStorage.Instance.EnableWebSearchSuggestion
? Visibility.Visible
: Visibility.Collapsed;
List<ComboBoxItem> items = new List<ComboBoxItem>()
{
new ComboBoxItem() {Content = "Google"},
new ComboBoxItem() {Content = "Baidu"},
};
ComboBoxItem selected = items.FirstOrDefault(o => o.Content.ToString() == WebSearchStorage.Instance.WebSearchSuggestionSource);
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)
{
2015-01-07 18:45:55 +08:00
WebSearchSetting webSearch = new WebSearchSetting(this,context);
2014-03-29 16:13:36 +08:00
webSearch.ShowDialog();
}
private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e)
{
WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch;
if (selectedWebSearch != null)
2014-03-29 16:13:36 +08:00
{
2015-01-07 18:45:55 +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)
{
WebSearchStorage.Instance.WebSearches.Remove(selectedWebSearch);
webSearchView.Items.Refresh();
}
2014-03-29 16:13:36 +08:00
}
else
{
2015-01-07 18:45:55 +08:00
string warning =context.API.GetTranslation("wox_plugin_websearch_pls_select_web_search");
MessageBox.Show(warning);
2014-03-29 16:13:36 +08:00
}
}
private void btnEditWebSearch_OnClick(object sender, RoutedEventArgs e)
{
WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch;
if (selectedWebSearch != null)
2014-03-29 16:13:36 +08:00
{
2015-01-07 18:45:55 +08:00
WebSearchSetting webSearch = new WebSearchSetting(this,context);
webSearch.UpdateItem(selectedWebSearch);
2014-03-29 16:13:36 +08:00
webSearch.ShowDialog();
}
else
{
2015-01-07 18:45:55 +08:00
string warning = context.API.GetTranslation("wox_plugin_websearch_pls_select_web_search");
MessageBox.Show(warning);
2014-03-29 16:13:36 +08:00
}
}
private void CbEnableWebSearchSuggestion_OnChecked(object sender, RoutedEventArgs e)
{
comboBoxSuggestionSource.Visibility = Visibility.Visible;
WebSearchStorage.Instance.EnableWebSearchSuggestion = true;
WebSearchStorage.Instance.Save();
}
private void CbEnableWebSearchSuggestion_OnUnchecked(object sender, RoutedEventArgs e)
{
comboBoxSuggestionSource.Visibility = Visibility.Collapsed;
WebSearchStorage.Instance.EnableWebSearchSuggestion = false;
WebSearchStorage.Instance.Save();
}
private void ComboBoxSuggestionSource_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
2014-07-21 22:35:40 +08:00
if (e.AddedItems.Count > 0)
{
WebSearchStorage.Instance.WebSearchSuggestionSource = ((ComboBoxItem) e.AddedItems[0]).Content.ToString();
2014-07-21 22:35:40 +08:00
UserSettingStorage.Instance.Save();
}
}
2014-03-29 16:13:36 +08:00
}
}