Flow.Launcher/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs

89 lines
2.8 KiB
C#
Raw Normal View History

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;
using System.Linq;
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Plugin.Program
{
/// <summary>
/// Interaction logic for AddProgramSource.xaml
/// </summary>
public partial class AddProgramSource : Window
{
2018-12-22 06:07:42 +00:00
private PluginInitContext _context;
private Settings.ProgramSource _updating;
private Settings _settings;
private bool update;
2018-12-22 06:07:42 +00:00
public AddProgramSource(PluginInitContext context, Settings settings)
{
InitializeComponent();
2018-12-22 06:07:42 +00:00
_context = context;
_settings = settings;
tbDirectory.Focus();
Chkbox.IsChecked = true;
update = false;
2022-10-18 11:28:12 +00:00
btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add");
}
public AddProgramSource(Settings.ProgramSource source, Settings settings)
2015-05-02 14:17:42 +00:00
{
2022-10-18 11:28:12 +00:00
InitializeComponent();
_updating = source;
2016-04-24 02:49:04 +00:00
_settings = settings;
update = true;
Chkbox.IsChecked = _updating.Enabled;
tbDirectory.Text = _updating.Location;
2015-05-02 14:17:42 +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();
if (result == System.Windows.Forms.DialogResult.OK)
{
tbDirectory.Text = dialog.SelectedPath;
}
}
2021-11-27 22:37:08 +00:00
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
{
Close();
}
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
{
string path = tbDirectory.Text;
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;
}
if (!update)
2015-05-02 14:17:42 +00:00
{
if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == path))
2015-05-02 14:17:42 +00:00
{
var source = new ProgramSource
{
Location = path,
UniqueIdentifier = path,
Enabled = Chkbox.IsChecked ?? true
};
_settings.ProgramSources.Insert(0, source);
ProgramSetting.ProgramSettingDisplayList.Add(source);
}
2015-05-02 14:17:42 +00:00
}
else
{
_updating.Location = path;
_updating.Enabled = Chkbox.IsChecked ?? true;
2015-05-02 14:17:42 +00:00
}
2016-01-06 21:34:42 +00:00
DialogResult = true;
Close();
}
}
}