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

88 lines
3.1 KiB
C#
Raw Normal View History

using Microsoft.Win32;
using System.Windows;
2014-03-29 16:13:36 +08:00
using System.Windows.Controls;
using Wox.Core.Plugin;
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 SettingsControl : UserControl
2014-03-29 16:13:36 +08:00
{
private readonly Settings _settings;
private readonly PluginInitContext _context;
2015-01-07 18:45:55 +08:00
public SettingsControl(PluginInitContext context, SettingsViewModel viewModel)
2014-03-29 16:13:36 +08:00
{
InitializeComponent();
_context = context;
_settings = viewModel.Settings;
DataContext = viewModel;
2019-11-12 04:22:03 +08:00
browserPathBox.Text = _settings.BrowserPath;
NewWindowBrowser.IsChecked = _settings.OpenInNewBrowser;
NewTabInBrowser.IsChecked = !_settings.OpenInNewBrowser;
2014-03-29 16:13:36 +08:00
}
private void OnAddSearchSearchClick(object sender, RoutedEventArgs e)
2014-03-29 16:13:36 +08:00
{
var setting = new SearchSourceSettingWindow(_settings.SearchSources, _context);
setting.ShowDialog();
2014-03-29 16:13:36 +08:00
}
private void OnDeleteSearchSearchClick(object sender, RoutedEventArgs e)
2014-03-29 16:13:36 +08:00
{
if (_settings.SelectedSearchSource != null)
2014-03-29 16:13:36 +08:00
{
var selected = _settings.SelectedSearchSource;
var warning = _context.API.GetTranslation("wox_plugin_websearch_delete_warning");
var formated = string.Format(warning, selected.Title);
var result = MessageBox.Show(formated, string.Empty, MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
var id = _context.CurrentPluginMetadata.ID;
PluginManager.RemoveActionKeyword(id, selected.ActionKeyword);
_settings.SearchSources.Remove(selected);
}
2014-03-29 16:13:36 +08:00
}
}
private void OnEditSearchSourceClick(object sender, RoutedEventArgs e)
2014-03-29 16:13:36 +08:00
{
if (_settings.SelectedSearchSource != null)
{
var webSearch = new SearchSourceSettingWindow
2016-06-21 07:18:35 +08:00
(
_settings.SearchSources, _context, _settings.SelectedSearchSource
2016-06-21 07:18:35 +08:00
);
webSearch.ShowDialog();
}
}
private void OnNewBrowserWindowClick(object sender, RoutedEventArgs e)
{
_settings.OpenInNewBrowser = true;
}
private void OnNewTabClick(object sender, RoutedEventArgs e)
{
_settings.OpenInNewBrowser = false;
}
private void OnChooseClick(object sender, RoutedEventArgs e)
{
var fileBrowserDialog = new OpenFileDialog();
fileBrowserDialog.Filter = "Application(*.exe)|*.exe|All files|*.*";
fileBrowserDialog.CheckFileExists = true;
fileBrowserDialog.CheckPathExists = true;
if (fileBrowserDialog.ShowDialog() == true)
{
browserPathBox.Text = fileBrowserDialog.FileName;
_settings.BrowserPath = fileBrowserDialog.FileName;
}
}
2014-03-29 16:13:36 +08:00
}
}