2016-01-07 05:34:42 +08:00
|
|
|
|
using System.IO;
|
2014-08-10 22:22:54 +08:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
2014-03-29 14:42:43 +08:00
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
2015-01-03 15:20:34 +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;
|
|
|
|
|
|
|
|
|
|
public ProgramSetting(PluginInitContext context)
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2015-01-05 22:41:17 +08:00
|
|
|
|
programSourceView.ItemsSource = ProgramStorage.Instance.ProgramSources;
|
2015-05-02 21:47:03 +08:00
|
|
|
|
StartMenuEnabled.IsChecked = ProgramStorage.Instance.EnableStartMenuSource;
|
|
|
|
|
RegistryEnabled.IsChecked = ProgramStorage.Instance.EnableRegistrySource;
|
2014-03-29 14:42:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-10 22:22:54 +08:00
|
|
|
|
private void ReIndexing()
|
2014-03-29 14:42:43 +08:00
|
|
|
|
{
|
|
|
|
|
programSourceView.Items.Refresh();
|
2014-08-10 22:22:54 +08:00
|
|
|
|
ThreadPool.QueueUserWorkItem(t =>
|
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Visible; });
|
2014-08-14 22:21:07 +08:00
|
|
|
|
Programs.IndexPrograms();
|
2016-01-07 05:34:42 +08:00
|
|
|
|
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Hidden; });
|
2014-08-10 22:22:54 +08:00
|
|
|
|
});
|
2014-03-29 14:42:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2015-05-02 22:17:42 +08:00
|
|
|
|
var add = new AddProgramSource();
|
|
|
|
|
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)
|
|
|
|
|
{
|
2014-07-10 23:16:46 +08:00
|
|
|
|
ProgramSource selectedProgramSource = programSourceView.SelectedItem as 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)
|
2014-07-10 23:06:50 +08:00
|
|
|
|
{
|
2015-01-05 22:41:17 +08:00
|
|
|
|
ProgramStorage.Instance.ProgramSources.Remove(selectedProgramSource);
|
|
|
|
|
ProgramStorage.Instance.Save();
|
2014-08-10 22:22:54 +08:00
|
|
|
|
ReIndexing();
|
2014-07-10 23:06:50 +08:00
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
2014-07-10 23:16:46 +08:00
|
|
|
|
ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
|
|
|
|
|
if (selectedProgramSource != null)
|
2014-03-29 14:42:43 +08:00
|
|
|
|
{
|
2015-05-02 22:17:42 +08:00
|
|
|
|
var add = new AddProgramSource(selectedProgramSource);
|
|
|
|
|
if (add.ShowDialog() ?? false)
|
2014-08-10 22:22:54 +08:00
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
ReIndexing();
|
2014-08-10 22:22:54 +08:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-12 23:07:54 +08:00
|
|
|
|
|
|
|
|
|
private void btnReindex_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ReIndexing();
|
|
|
|
|
}
|
2014-08-13 23:16:45 +08:00
|
|
|
|
|
|
|
|
|
private void BtnProgramSuffixes_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2015-01-06 23:24:11 +08:00
|
|
|
|
ProgramSuffixes p = new ProgramSuffixes(context);
|
2014-08-13 23:16:45 +08:00
|
|
|
|
p.ShowDialog();
|
|
|
|
|
}
|
2015-01-09 10:23:48 +08:00
|
|
|
|
|
|
|
|
|
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))
|
2015-01-09 10:23:48 +08:00
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource
|
2015-01-09 10:23:48 +08:00
|
|
|
|
{
|
|
|
|
|
Location = s,
|
|
|
|
|
Type = "FileSystemProgramSource",
|
|
|
|
|
Enabled = true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ProgramStorage.Instance.Save();
|
|
|
|
|
ReIndexing();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-02 21:47:03 +08:00
|
|
|
|
|
|
|
|
|
private void StartMenuEnabled_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ProgramStorage.Instance.EnableStartMenuSource = StartMenuEnabled.IsChecked ?? false;
|
|
|
|
|
ProgramStorage.Instance.Save();
|
|
|
|
|
ReIndexing();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RegistryEnabled_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ProgramStorage.Instance.EnableRegistrySource = RegistryEnabled.IsChecked ?? false;
|
|
|
|
|
ProgramStorage.Instance.Save();
|
|
|
|
|
ReIndexing();
|
|
|
|
|
}
|
2014-03-29 14:42:43 +08:00
|
|
|
|
}
|
2014-08-10 22:22:54 +08:00
|
|
|
|
}
|