2016-08-20 06:24:21 +08:00
|
|
|
|
using System.Windows;
|
2016-01-07 05:34:42 +08:00
|
|
|
|
using System.Windows.Forms;
|
2019-10-16 19:38:02 +08:00
|
|
|
|
using Wox.Plugin.Program.Views.Models;
|
|
|
|
|
using Wox.Plugin.Program.Views;
|
|
|
|
|
using System.Linq;
|
2015-04-21 08:32:10 +08:00
|
|
|
|
|
|
|
|
|
namespace Wox.Plugin.Program
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for AddProgramSource.xaml
|
|
|
|
|
/// </summary>
|
2015-04-22 21:22:55 +08:00
|
|
|
|
public partial class AddProgramSource
|
2015-04-21 08:32:10 +08:00
|
|
|
|
{
|
2018-12-22 14:07:42 +08:00
|
|
|
|
private PluginInitContext _context;
|
2016-08-20 08:17:28 +08:00
|
|
|
|
private Settings.ProgramSource _editing;
|
2016-04-21 08:53:21 +08:00
|
|
|
|
private Settings _settings;
|
2015-04-21 08:32:10 +08:00
|
|
|
|
|
2018-12-22 14:07:42 +08:00
|
|
|
|
public AddProgramSource(PluginInitContext context, Settings settings)
|
2015-04-21 08:32:10 +08:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2018-12-22 14:07:42 +08:00
|
|
|
|
_context = context;
|
2016-05-06 07:29:27 +08:00
|
|
|
|
_settings = settings;
|
|
|
|
|
Directory.Focus();
|
2015-04-21 08:32:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-20 08:17:28 +08:00
|
|
|
|
public AddProgramSource(Settings.ProgramSource edit, Settings settings)
|
2015-05-02 22:17:42 +08:00
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
_editing = edit;
|
2016-04-24 10:49:04 +08:00
|
|
|
|
_settings = settings;
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
2016-01-07 05:34:42 +08:00
|
|
|
|
Directory.Text = _editing.Location;
|
2015-05-02 22:17:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 08:32:10 +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();
|
2015-04-21 08:32:10 +08:00
|
|
|
|
if (result == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
Directory.Text = dialog.SelectedPath;
|
2015-04-21 08:32:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2018-12-22 14:07:42 +08:00
|
|
|
|
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)
|
2015-05-02 22:17:42 +08:00
|
|
|
|
{
|
2019-10-16 19:38:02 +08:00
|
|
|
|
if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == Directory.Text))
|
2015-05-02 22:17:42 +08:00
|
|
|
|
{
|
2019-10-16 19:38:02 +08:00
|
|
|
|
var source = new ProgramSource
|
|
|
|
|
{
|
|
|
|
|
Location = Directory.Text,
|
|
|
|
|
UniqueIdentifier = Directory.Text
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_settings.ProgramSources.Insert(0, source);
|
|
|
|
|
ProgramSetting.ProgramSettingDisplayList.Add(source);
|
|
|
|
|
}
|
2015-05-02 22:17:42 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
2015-04-21 08:32:10 +08:00
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
_editing.Location = Directory.Text;
|
2015-05-02 22:17:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 05:34:42 +08:00
|
|
|
|
DialogResult = true;
|
|
|
|
|
Close();
|
2015-04-21 08:32:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|