mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
Refactoring. Move system plugins to seperate DLLs.
This commit is contained in:
112
Plugins/Wox.Plugin.WebSearch/WebSearchesSetting.xaml.cs
Normal file
112
Plugins/Wox.Plugin.WebSearch/WebSearchesSetting.xaml.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
/// <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;
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Infrastructure.Storage.UserSettings.WebSearch selectedWebSearch = webSearchView.SelectedItem as Infrastructure.Storage.UserSettings.WebSearch;
|
||||
if (selectedWebSearch != null)
|
||||
{
|
||||
if (MessageBox.Show("Are your sure to delete " + selectedWebSearch.Title, "Delete WebSearch",
|
||||
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
UserSettingStorage.Instance.WebSearches.Remove(selectedWebSearch);
|
||||
webSearchView.Items.Refresh();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Please select a web search");
|
||||
}
|
||||
}
|
||||
|
||||
private void btnEditWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Infrastructure.Storage.UserSettings.WebSearch selectedWebSearch = webSearchView.SelectedItem as Infrastructure.Storage.UserSettings.WebSearch;
|
||||
if (selectedWebSearch != null)
|
||||
{
|
||||
WebSearchSetting webSearch = new WebSearchSetting(this);
|
||||
webSearch.UpdateItem(selectedWebSearch);
|
||||
webSearch.ShowDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Please select a web search");
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (e.AddedItems.Count > 0)
|
||||
{
|
||||
UserSettingStorage.Instance.WebSearchSuggestionSource =
|
||||
((ComboBoxItem) e.AddedItems[0]).Content.ToString();
|
||||
UserSettingStorage.Instance.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user