2014-08-10 22:22:54 +08:00
|
|
|
|
using System;
|
|
|
|
|
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;
|
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 =>
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(new Action(() => { indexingPanel.Visibility = Visibility.Visible; }));
|
2014-08-14 22:21:07 +08:00
|
|
|
|
Programs.IndexPrograms();
|
2014-08-10 22:22:54 +08:00
|
|
|
|
Dispatcher.Invoke(new Action(() => { indexingPanel.Visibility = Visibility.Hidden; }));
|
|
|
|
|
});
|
2014-03-29 14:42:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2014-08-10 22:22:54 +08:00
|
|
|
|
var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
|
|
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
string path = folderBrowserDialog.SelectedPath;
|
|
|
|
|
|
2015-01-05 22:41:17 +08:00
|
|
|
|
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource()
|
2014-08-10 22:22:54 +08:00
|
|
|
|
{
|
|
|
|
|
Location = path,
|
|
|
|
|
Type = "FileSystemProgramSource",
|
|
|
|
|
Enabled = true
|
|
|
|
|
});
|
2015-01-05 22:41:17 +08:00
|
|
|
|
ProgramStorage.Instance.Save();
|
2014-08-10 22:22:54 +08:00
|
|
|
|
ReIndexing();
|
|
|
|
|
}
|
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
|
|
|
|
{
|
2014-08-10 22:22:54 +08:00
|
|
|
|
//todo: update
|
|
|
|
|
var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
|
|
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
string path = folderBrowserDialog.SelectedPath;
|
|
|
|
|
selectedProgramSource.Location = path;
|
2015-01-05 22:41:17 +08:00
|
|
|
|
ProgramStorage.Instance.Save();
|
2014-08-10 22:22:54 +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
|
|
|
|
}
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (System.IO.Directory.Exists(s) == true)
|
|
|
|
|
{
|
|
|
|
|
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource()
|
|
|
|
|
{
|
|
|
|
|
Location = s,
|
|
|
|
|
Type = "FileSystemProgramSource",
|
|
|
|
|
Enabled = true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ProgramStorage.Instance.Save();
|
|
|
|
|
ReIndexing();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-29 14:42:43 +08:00
|
|
|
|
}
|
2014-08-10 22:22:54 +08:00
|
|
|
|
}
|