PowerToys/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs

149 lines
4.8 KiB
C#
Raw Normal View History

2016-01-07 05:34:42 +08:00
using System.IO;
using System.Threading.Tasks;
using System.Windows;
2014-03-29 14:42:43 +08:00
using System.Windows.Controls;
2016-08-20 08:17:28 +08:00
using Wox.Plugin.Program.Programs;
2014-03-29 14:42:43 +08:00
namespace Wox.Plugin.Program
2014-03-29 14:42:43 +08:00
{
/// <summary>
/// Interaction logic for ProgramSetting.xaml
/// </summary>
public partial class ProgramSetting : UserControl
{
2015-01-06 23:24:11 +08:00
private PluginInitContext context;
private Settings _settings;
2015-01-06 23:24:11 +08:00
public ProgramSetting(PluginInitContext context, Settings settings)
2014-03-29 14:42:43 +08:00
{
2015-01-06 23:24:11 +08:00
this.context = context;
2014-03-29 14:42:43 +08:00
InitializeComponent();
Loaded += Setting_Loaded;
_settings = settings;
2014-03-29 14:42:43 +08:00
}
private void Setting_Loaded(object sender, RoutedEventArgs e)
{
programSourceView.ItemsSource = _settings.ProgramSources;
StartMenuEnabled.IsChecked = _settings.EnableStartMenuSource;
RegistryEnabled.IsChecked = _settings.EnableRegistrySource;
2014-03-29 14:42:43 +08:00
}
private void ReIndexing()
2014-03-29 14:42:43 +08:00
{
programSourceView.Items.Refresh();
Task.Run(() =>
{
2016-01-07 05:34:42 +08:00
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Visible; });
2016-05-07 10:55:09 +08:00
Main.IndexPrograms();
2016-01-07 05:34:42 +08:00
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Hidden; });
});
2014-03-29 14:42:43 +08:00
}
private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e)
{
2018-12-22 14:07:42 +08:00
var add = new AddProgramSource(context, _settings);
2015-05-02 22:17:42 +08:00
if(add.ShowDialog() ?? false)
{
2016-01-07 05:34:42 +08:00
ReIndexing();
2015-05-02 22:17:42 +08:00
}
2014-03-29 14:42:43 +08:00
}
private void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e)
{
2016-08-20 08:17:28 +08:00
var selectedProgramSource = programSourceView.SelectedItem as Settings.ProgramSource;
if (selectedProgramSource != null)
2014-03-29 14:42:43 +08:00
{
2015-01-06 23:24:11 +08:00
string msg = string.Format(context.API.GetTranslation("wox_plugin_program_delete_program_source"), selectedProgramSource.Location);
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
_settings.ProgramSources.Remove(selectedProgramSource);
ReIndexing();
}
2014-03-29 14:42:43 +08:00
}
else
{
2015-01-06 23:24:11 +08:00
string msg = context.API.GetTranslation("wox_plugin_program_pls_select_program_source");
MessageBox.Show(msg);
2014-03-29 14:42:43 +08:00
}
}
private void btnEditProgramSource_OnClick(object sender, RoutedEventArgs e)
{
2016-08-20 08:17:28 +08:00
var selectedProgramSource = programSourceView.SelectedItem as Settings.ProgramSource;
if (selectedProgramSource != null)
2014-03-29 14:42:43 +08:00
{
var add = new AddProgramSource(selectedProgramSource, _settings);
2015-05-02 22:17:42 +08:00
if (add.ShowDialog() ?? false)
{
2016-01-07 05:34:42 +08:00
ReIndexing();
}
2014-03-29 14:42:43 +08:00
}
else
{
2015-01-06 23:24:11 +08:00
string msg = context.API.GetTranslation("wox_plugin_program_pls_select_program_source");
MessageBox.Show(msg);
2014-03-29 14:42:43 +08:00
}
}
private void btnReindex_Click(object sender, RoutedEventArgs e)
{
ReIndexing();
}
private void BtnProgramSuffixes_OnClick(object sender, RoutedEventArgs e)
{
var p = new ProgramSuffixes(context, _settings);
if (p.ShowDialog() ?? false)
{
ReIndexing();
}
}
private void programSourceView_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effects = DragDropEffects.Link;
}
else
{
e.Effects = DragDropEffects.None;
}
}
private void programSourceView_Drop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files != null && files.Length > 0)
{
foreach (string s in files)
{
2016-01-07 05:34:42 +08:00
if (Directory.Exists(s))
{
2016-08-20 08:17:28 +08:00
_settings.ProgramSources.Add(new Settings.ProgramSource
{
2016-08-20 06:24:21 +08:00
Location = s
});
ReIndexing();
}
}
}
}
private void StartMenuEnabled_Click(object sender, RoutedEventArgs e)
{
_settings.EnableStartMenuSource = StartMenuEnabled.IsChecked ?? false;
ReIndexing();
}
private void RegistryEnabled_Click(object sender, RoutedEventArgs e)
{
_settings.EnableRegistrySource = RegistryEnabled.IsChecked ?? false;
ReIndexing();
}
2014-03-29 14:42:43 +08:00
}
}