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;
|
|
|
|
|
using Wox.Infrastructure.Storage.UserSettings;
|
|
|
|
|
|
|
|
|
|
namespace Wox.Plugin.SystemPlugins
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for WebSearchesSetting.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class WebSearchesSetting : UserControl
|
|
|
|
|
{
|
|
|
|
|
public WebSearchesSetting()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
Loaded += Setting_Loaded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
webSearchView.ItemsSource = UserSettingStorage.Instance.WebSearches;
|
2014-07-21 22:27:57 +08:00
|
|
|
|
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 = "Baidu"},
|
|
|
|
|
};
|
|
|
|
|
ComboBoxItem selected = items.FirstOrDefault(o => o.Content.ToString() == UserSettingStorage.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)
|
|
|
|
|
{
|
|
|
|
|
WebSearchSetting webSearch = new WebSearchSetting(this);
|
|
|
|
|
webSearch.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2014-07-10 23:16:46 +08:00
|
|
|
|
WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch;
|
|
|
|
|
if (selectedWebSearch != null)
|
2014-03-29 16:13:36 +08:00
|
|
|
|
{
|
2014-07-10 23:16:46 +08:00
|
|
|
|
if (MessageBox.Show("Are your sure to delete " + selectedWebSearch.Title, "Delete WebSearch",
|
2014-07-10 22:52:18 +08:00
|
|
|
|
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
|
|
|
|
{
|
2014-07-10 23:16:46 +08:00
|
|
|
|
UserSettingStorage.Instance.WebSearches.Remove(selectedWebSearch);
|
2014-07-10 22:52:18 +08:00
|
|
|
|
webSearchView.Items.Refresh();
|
|
|
|
|
}
|
2014-03-29 16:13:36 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Please select a web search");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnEditWebSearch_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2014-07-10 23:16:46 +08:00
|
|
|
|
WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch;
|
|
|
|
|
if (selectedWebSearch != null)
|
2014-03-29 16:13:36 +08:00
|
|
|
|
{
|
|
|
|
|
WebSearchSetting webSearch = new WebSearchSetting(this);
|
2014-07-10 23:16:46 +08:00
|
|
|
|
webSearch.UpdateItem(selectedWebSearch);
|
2014-03-29 16:13:36 +08:00
|
|
|
|
webSearch.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Please select a web search");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-21 22:27:57 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2014-07-21 22:35:40 +08:00
|
|
|
|
if (e.AddedItems.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
UserSettingStorage.Instance.WebSearchSuggestionSource =
|
|
|
|
|
((ComboBoxItem) e.AddedItems[0]).Content.ToString();
|
|
|
|
|
UserSettingStorage.Instance.Save();
|
|
|
|
|
}
|
2014-07-21 22:27:57 +08:00
|
|
|
|
}
|
2014-03-29 16:13:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|