validate path before save (fix #1869)

This commit is contained in:
jhdxr 2018-12-22 14:07:42 +08:00
parent 3dd7a82dcc
commit 3fddb77564
4 changed files with 15 additions and 3 deletions

View File

@ -9,12 +9,14 @@ namespace Wox.Plugin.Program
/// </summary>
public partial class AddProgramSource
{
private PluginInitContext _context;
private Settings.ProgramSource _editing;
private Settings _settings;
public AddProgramSource(Settings settings)
public AddProgramSource(PluginInitContext context, Settings settings)
{
InitializeComponent();
_context = context;
_settings = settings;
Directory.Focus();
}
@ -40,7 +42,13 @@ namespace Wox.Plugin.Program
private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
{
if(_editing == null)
string s = Directory.Text;
if (!System.IO.Directory.Exists(s))
{
System.Windows.MessageBox.Show(_context.API.GetTranslation("wox_plugin_program_invalid_path"));
return;
}
if (_editing == null)
{
var source = new Settings.ProgramSource
{

View File

@ -35,4 +35,6 @@
<system:String x:Key="wox_plugin_program_plugin_name">Program</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">Search programs in Wox</system:String>
<system:String x:Key="wox_plugin_program_invalid_path">Invalid Path</system:String>
</ResourceDictionary>

View File

@ -35,4 +35,6 @@
<system:String x:Key="wox_plugin_program_plugin_name">程序</system:String>
<system:String x:Key="wox_plugin_program_plugin_description">在Wox中搜索程序</system:String>
<system:String x:Key="wox_plugin_program_invalid_path">无效路径</system:String>
</ResourceDictionary>

View File

@ -42,7 +42,7 @@ namespace Wox.Plugin.Program
private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e)
{
var add = new AddProgramSource(_settings);
var add = new AddProgramSource(context, _settings);
if(add.ShowDialog() ?? false)
{
ReIndexing();