PowerToys/Plugins/Wox.Plugin.Program/AddProgramSource.xaml.cs
bao-qian 92f45567d7 Focuses first textbox on load
fix #516
thanks @staff0rd for idea!
2016-05-06 00:29:27 +01:00

76 lines
2.2 KiB
C#

using System.Collections.Generic;
using System.Windows;
using System.Windows.Forms;
namespace Wox.Plugin.Program
{
/// <summary>
/// Interaction logic for AddProgramSource.xaml
/// </summary>
public partial class AddProgramSource
{
private ProgramSource _editing;
private Settings _settings;
public AddProgramSource(Settings settings)
{
InitializeComponent();
_settings = settings;
Suffixes.Text = string.Join(";", settings.ProgramSuffixes);
Directory.Focus();
}
public AddProgramSource(ProgramSource edit, Settings settings)
{
_editing = edit;
_settings = settings;
InitializeComponent();
Directory.Text = _editing.Location;
MaxDepth.Text = _editing.MaxDepth.ToString();
Suffixes.Text = string.Join(";", _editing.Suffixes);
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
var dialog = new FolderBrowserDialog();
DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
Directory.Text = dialog.SelectedPath;
}
}
private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
{
int max;
if(!int.TryParse(MaxDepth.Text, out max))
{
max = -1;
}
if(_editing == null)
{
var source = new ProgramSource
{
Location = Directory.Text,
MaxDepth = max,
Suffixes = Suffixes.Text.Split(ProgramSource.SuffixSeperator),
Type = "FileSystemProgramSource",
Enabled = true
};
_settings.ProgramSources.Add(source);
}
else
{
_editing.Location = Directory.Text;
_editing.MaxDepth = max;
_editing.Suffixes = Suffixes.Text.Split(ProgramSource.SuffixSeperator);
}
DialogResult = true;
Close();
}
}
}