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

146 lines
5.0 KiB
C#
Raw Normal View History

using System;
using System.Threading;
using System.Windows;
2014-03-29 14:42:43 +08:00
using System.Windows.Controls;
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)
{
programSourceView.ItemsSource = ProgramStorage.Instance.ProgramSources;
2014-03-29 14:42:43 +08:00
}
private void ReIndexing()
2014-03-29 14:42:43 +08:00
{
programSourceView.Items.Refresh();
ThreadPool.QueueUserWorkItem(t =>
{
Dispatcher.Invoke(new Action(() => { indexingPanel.Visibility = Visibility.Visible; }));
Programs.IndexPrograms();
Dispatcher.Invoke(new Action(() => { indexingPanel.Visibility = Visibility.Hidden; }));
});
2014-03-29 14:42:43 +08:00
}
private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e)
{
var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string path = folderBrowserDialog.SelectedPath;
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource()
{
Location = path,
Type = "FileSystemProgramSource",
Enabled = true
});
ProgramStorage.Instance.Save();
ReIndexing();
}
2014-03-29 14:42:43 +08:00
}
private void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e)
{
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)
{
ProgramStorage.Instance.ProgramSources.Remove(selectedProgramSource);
ProgramStorage.Instance.Save();
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)
{
ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
if (selectedProgramSource != null)
2014-03-29 14:42:43 +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;
ProgramStorage.Instance.Save();
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)
{
2015-01-06 23:24:11 +08:00
ProgramSuffixes p = new ProgramSuffixes(context);
p.ShowDialog();
}
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
}
}