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

68 lines
1.8 KiB
C#
Raw Normal View History

2015-10-31 07:17:34 +08:00
using System.Windows;
2016-01-07 05:34:42 +08:00
using System.Windows.Forms;
namespace Wox.Plugin.Program
{
/// <summary>
/// Interaction logic for AddProgramSource.xaml
/// </summary>
2015-04-22 21:22:55 +08:00
public partial class AddProgramSource
{
2015-05-02 22:17:42 +08:00
private ProgramSource _editing;
2015-05-02 22:17:42 +08:00
public AddProgramSource()
{
InitializeComponent();
}
2015-05-02 22:17:42 +08:00
public AddProgramSource(ProgramSource edit) : this()
{
2016-01-07 05:34:42 +08:00
_editing = edit;
Directory.Text = _editing.Location;
MaxDepth.Text = _editing.MaxDepth.ToString();
Suffixes.Text = _editing.Suffixes;
2015-05-02 22:17:42 +08:00
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
2016-01-07 05:34:42 +08:00
var dialog = new FolderBrowserDialog();
DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
2016-01-07 05:34:42 +08:00
Directory.Text = dialog.SelectedPath;
}
}
private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
{
int max;
2016-01-07 05:34:42 +08:00
if(!int.TryParse(MaxDepth.Text, out max))
{
max = -1;
}
2015-05-02 22:17:42 +08:00
2016-01-07 05:34:42 +08:00
if(_editing == null)
2015-05-02 22:17:42 +08:00
{
2016-01-07 05:34:42 +08:00
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource
2015-05-02 22:17:42 +08:00
{
2016-01-07 05:34:42 +08:00
Location = Directory.Text,
2015-05-02 22:17:42 +08:00
MaxDepth = max,
2016-01-07 05:34:42 +08:00
Suffixes = Suffixes.Text,
2015-05-02 22:17:42 +08:00
Type = "FileSystemProgramSource",
Enabled = true
});
}
else
{
2016-01-07 05:34:42 +08:00
_editing.Location = Directory.Text;
_editing.MaxDepth = max;
_editing.Suffixes = Suffixes.Text;
2015-05-02 22:17:42 +08:00
}
ProgramStorage.Instance.Save();
2016-01-07 05:34:42 +08:00
DialogResult = true;
Close();
}
}
}