mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 11:39:16 +08:00
105 lines
3.6 KiB
C#
105 lines
3.6 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace Wox.Plugin.Program
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ProgramSetting.xaml
|
|
/// </summary>
|
|
public partial class ProgramSetting : UserControl
|
|
{
|
|
public ProgramSetting()
|
|
{
|
|
InitializeComponent();
|
|
Loaded += Setting_Loaded;
|
|
}
|
|
|
|
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
programSourceView.ItemsSource = ProgramStorage.Instance.ProgramSources;
|
|
}
|
|
|
|
private void ReIndexing()
|
|
{
|
|
programSourceView.Items.Refresh();
|
|
ThreadPool.QueueUserWorkItem(t =>
|
|
{
|
|
Dispatcher.Invoke(new Action(() => { indexingPanel.Visibility = Visibility.Visible; }));
|
|
Programs.IndexPrograms();
|
|
Dispatcher.Invoke(new Action(() => { indexingPanel.Visibility = Visibility.Hidden; }));
|
|
});
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
private void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
|
|
if (selectedProgramSource != null)
|
|
{
|
|
if (MessageBox.Show("Are your sure to delete " + selectedProgramSource.Location, "Delete ProgramSource",
|
|
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
|
{
|
|
ProgramStorage.Instance.ProgramSources.Remove(selectedProgramSource);
|
|
ProgramStorage.Instance.Save();
|
|
ReIndexing();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Please select a program source");
|
|
}
|
|
}
|
|
|
|
private void btnEditProgramSource_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
|
|
if (selectedProgramSource != null)
|
|
{
|
|
//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();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Please select a program source");
|
|
}
|
|
}
|
|
|
|
private void btnReindex_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ReIndexing();
|
|
}
|
|
|
|
private void BtnProgramSuffixes_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
ProgramSuffixes p = new ProgramSuffixes();
|
|
p.ShowDialog();
|
|
}
|
|
}
|
|
} |