2016-08-19 22:24:21 +00:00
|
|
|
|
using System.Windows;
|
2016-01-06 21:34:42 +00:00
|
|
|
|
using System.Windows.Forms;
|
2020-04-21 09:12:17 +00:00
|
|
|
|
using Flow.Launcher.Plugin.Program.Views.Models;
|
|
|
|
|
|
using Flow.Launcher.Plugin.Program.Views;
|
2019-10-16 11:38:02 +00:00
|
|
|
|
using System.Linq;
|
2015-04-21 00:32:10 +00:00
|
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
|
namespace Flow.Launcher.Plugin.Program
|
2015-04-21 00:32:10 +00:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Interaction logic for AddProgramSource.xaml
|
|
|
|
|
|
/// </summary>
|
2022-10-18 06:51:13 +00:00
|
|
|
|
public partial class AddProgramSource : Window
|
2015-04-21 00:32:10 +00:00
|
|
|
|
{
|
2018-12-22 06:07:42 +00:00
|
|
|
|
private PluginInitContext _context;
|
2022-10-18 06:51:13 +00:00
|
|
|
|
private Settings.ProgramSource _updating;
|
2016-04-21 00:53:21 +00:00
|
|
|
|
private Settings _settings;
|
2022-10-18 06:51:13 +00:00
|
|
|
|
private bool update;
|
2015-04-21 00:32:10 +00:00
|
|
|
|
|
2018-12-22 06:07:42 +00:00
|
|
|
|
public AddProgramSource(PluginInitContext context, Settings settings)
|
2015-04-21 00:32:10 +00:00
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2018-12-22 06:07:42 +00:00
|
|
|
|
_context = context;
|
2016-05-05 23:29:27 +00:00
|
|
|
|
_settings = settings;
|
2022-10-24 15:31:53 +00:00
|
|
|
|
Directory.Focus();
|
2022-10-18 06:51:13 +00:00
|
|
|
|
Chkbox.IsChecked = true;
|
|
|
|
|
|
update = false;
|
2022-10-18 11:28:12 +00:00
|
|
|
|
btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add");
|
2015-04-21 00:32:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-18 06:51:13 +00:00
|
|
|
|
public AddProgramSource(Settings.ProgramSource source, Settings settings)
|
2015-05-02 14:17:42 +00:00
|
|
|
|
{
|
2022-10-18 11:28:12 +00:00
|
|
|
|
InitializeComponent();
|
2022-10-18 06:51:13 +00:00
|
|
|
|
_updating = source;
|
2016-04-24 02:49:04 +00:00
|
|
|
|
_settings = settings;
|
2022-10-18 06:51:13 +00:00
|
|
|
|
update = true;
|
|
|
|
|
|
Chkbox.IsChecked = _updating.Enabled;
|
2022-10-24 15:31:53 +00:00
|
|
|
|
Directory.Text = _updating.Location;
|
2015-05-02 14:17:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-21 00:32:10 +00:00
|
|
|
|
private void BrowseButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2016-01-06 21:34:42 +00:00
|
|
|
|
var dialog = new FolderBrowserDialog();
|
|
|
|
|
|
DialogResult result = dialog.ShowDialog();
|
2015-04-21 00:32:10 +00:00
|
|
|
|
if (result == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
|
{
|
2022-10-24 15:31:53 +00:00
|
|
|
|
Directory.Text = dialog.SelectedPath;
|
2015-04-21 00:32:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-27 22:37:08 +00:00
|
|
|
|
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-18 06:51:13 +00:00
|
|
|
|
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
|
2015-04-21 00:32:10 +00:00
|
|
|
|
{
|
2022-10-24 15:31:53 +00:00
|
|
|
|
string path = Directory.Text;
|
2022-10-18 06:51:13 +00:00
|
|
|
|
if (!System.IO.Directory.Exists(path))
|
2018-12-22 06:07:42 +00:00
|
|
|
|
{
|
2020-04-21 12:54:41 +00:00
|
|
|
|
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_invalid_path"));
|
2018-12-22 06:07:42 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-10-18 06:51:13 +00:00
|
|
|
|
if (!update)
|
2015-05-02 14:17:42 +00:00
|
|
|
|
{
|
2022-10-18 06:51:13 +00:00
|
|
|
|
if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == path))
|
2015-05-02 14:17:42 +00:00
|
|
|
|
{
|
2019-10-16 11:38:02 +00:00
|
|
|
|
var source = new ProgramSource
|
|
|
|
|
|
{
|
2022-10-18 06:51:13 +00:00
|
|
|
|
Location = path,
|
|
|
|
|
|
UniqueIdentifier = path,
|
|
|
|
|
|
Enabled = Chkbox.IsChecked ?? true
|
2019-10-16 11:38:02 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_settings.ProgramSources.Insert(0, source);
|
|
|
|
|
|
ProgramSetting.ProgramSettingDisplayList.Add(source);
|
|
|
|
|
|
}
|
2015-05-02 14:17:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2015-04-21 00:32:10 +00:00
|
|
|
|
{
|
2022-10-18 06:51:13 +00:00
|
|
|
|
_updating.Location = path;
|
2022-10-24 15:31:02 +00:00
|
|
|
|
_updating.Enabled = Chkbox.IsChecked ?? true; // Fixme, need to add to disabled source if not custom source
|
2015-05-02 14:17:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-01-06 21:34:42 +00:00
|
|
|
|
DialogResult = true;
|
|
|
|
|
|
Close();
|
2015-04-21 00:32:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|