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-20 08:15:56 +00:00
|
|
|
|
private ProgramSource _editing;
|
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;
|
|
|
|
|
|
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-25 06:41:46 +00:00
|
|
|
|
public AddProgramSource(ProgramSource source, Settings settings)
|
2015-05-02 14:17:42 +00:00
|
|
|
|
{
|
2016-04-24 02:49:04 +00:00
|
|
|
|
InitializeComponent();
|
2022-10-25 06:41:46 +00:00
|
|
|
|
_editing = source;
|
2016-04-24 02:49:04 +00:00
|
|
|
|
_settings = settings;
|
2022-10-18 06:51:13 +00:00
|
|
|
|
update = true;
|
2022-10-25 06:41:46 +00:00
|
|
|
|
Chkbox.IsChecked = _editing.Enabled;
|
|
|
|
|
|
Directory.Text = _editing.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)
|
|
|
|
|
|
{
|
2016-01-06 21:34:42 +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-25 09:39:01 +00:00
|
|
|
|
bool modified = false;
|
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-25 06:20:01 +00:00
|
|
|
|
if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.InvariantCultureIgnoreCase)))
|
2015-05-02 14:17:42 +00:00
|
|
|
|
{
|
2022-10-25 06:20:01 +00:00
|
|
|
|
var source = new ProgramSource(path);
|
2022-10-25 09:39:01 +00:00
|
|
|
|
modified = 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-25 09:39:01 +00:00
|
|
|
|
modified = _editing.Location != path || _editing.Enabled != Chkbox.IsChecked;
|
|
|
|
|
|
if (modified)
|
|
|
|
|
|
{
|
|
|
|
|
|
_editing.SetLocation(path);
|
|
|
|
|
|
_editing.Enabled = Chkbox.IsChecked ?? true;
|
|
|
|
|
|
}
|
2015-05-02 14:17:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-25 09:39:01 +00:00
|
|
|
|
DialogResult = modified;
|
2016-01-06 21:34:42 +00:00
|
|
|
|
Close();
|
2015-04-21 00:32:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|