Flow.Launcher/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsControl.xaml.cs

93 lines
3.2 KiB
C#
Raw Normal View History

using Microsoft.Win32;
using System.Windows;
2014-03-29 08:13:36 +00:00
using System.Windows.Controls;
2020-04-21 09:12:17 +00:00
using Flow.Launcher.Core.Plugin;
2014-03-29 08:13:36 +00:00
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Plugin.WebSearch
2014-03-29 08:13:36 +00:00
{
/// <summary>
/// Interaction logic for WebSearchesSetting.xaml
/// </summary>
public partial class SettingsControl : UserControl
2014-03-29 08:13:36 +00:00
{
private readonly Settings _settings;
private readonly PluginInitContext _context;
2015-01-07 10:45:55 +00:00
public SettingsControl(PluginInitContext context, SettingsViewModel viewModel)
2014-03-29 08:13:36 +00:00
{
InitializeComponent();
_context = context;
_settings = viewModel.Settings;
DataContext = viewModel;
2019-11-11 20:22:03 +00:00
browserPathBox.Text = _settings.BrowserPath;
NewWindowBrowser.IsChecked = _settings.OpenInNewBrowser;
NewTabInBrowser.IsChecked = !_settings.OpenInNewBrowser;
2014-03-29 08:13:36 +00:00
}
private void OnAddSearchSearchClick(object sender, RoutedEventArgs e)
2014-03-29 08:13:36 +00:00
{
var setting = new SearchSourceSettingWindow(_settings.SearchSources, _context);
setting.ShowDialog();
2014-03-29 08:13:36 +00:00
}
private void OnDeleteSearchSearchClick(object sender, RoutedEventArgs e)
2014-03-29 08:13:36 +00:00
{
if (_settings.SelectedSearchSource != null)
2014-03-29 08:13:36 +00:00
{
var selected = _settings.SelectedSearchSource;
2020-04-21 12:54:41 +00:00
var warning = _context.API.GetTranslation("flowlauncher_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 08:13:36 +00:00
}
}
private void OnEditSearchSourceClick(object sender, RoutedEventArgs e)
2014-03-29 08:13:36 +00:00
{
if (_settings.SelectedSearchSource != null)
{
var webSearch = new SearchSourceSettingWindow
2016-06-20 23:18:35 +00:00
(
_settings.SearchSources, _context, _settings.SelectedSearchSource
2016-06-20 23:18:35 +00: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;
}
}
private void OnBrowserPathTextChanged(object sender, TextChangedEventArgs e)
{
_settings.BrowserPath = browserPathBox.Text;
}
2014-03-29 08:13:36 +00:00
}
}