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

77 lines
2.9 KiB
C#
Raw Permalink Normal View History

using System;
2022-10-23 10:50:38 +00:00
using System.Collections.Generic;
using System.Windows;
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Plugin.Program
{
public partial class ProgramSuffixes
{
2015-01-06 15:24:11 +00:00
private PluginInitContext context;
2022-10-23 14:09:22 +00:00
private Settings _settings;
public Dictionary<string, bool> SuffixesStatus { get; set; }
public Dictionary<string, bool> ProtocolsStatus { get; set; }
public bool UseCustomSuffixes { get; set; }
public bool UseCustomProtocols { get; set; }
2015-01-06 15:24:11 +00:00
public ProgramSuffixes(PluginInitContext context, Settings settings)
{
2015-01-06 15:24:11 +00:00
this.context = context;
_settings = settings;
2022-10-23 14:09:22 +00:00
SuffixesStatus = new Dictionary<string, bool>(_settings.BuiltinSuffixesStatus);
ProtocolsStatus = new Dictionary<string, bool>(_settings.BuiltinProtocolsStatus);
UseCustomSuffixes = _settings.UseCustomSuffixes;
UseCustomProtocols = _settings.UseCustomProtocols;
2022-10-23 10:50:38 +00:00
InitializeComponent();
2022-10-23 14:09:22 +00:00
tbSuffixes.Text = string.Join(Settings.SuffixSeparator, _settings.CustomSuffixes);
tbProtocols.Text = string.Join(Settings.SuffixSeparator, _settings.CustomProtocols);
}
2022-10-23 09:29:37 +00:00
2021-11-27 22:37:08 +00:00
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
{
Close();
}
2022-10-23 09:29:37 +00:00
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
{
2022-10-23 14:09:22 +00:00
var suffixes = tbSuffixes.Text.Split(Settings.SuffixSeparator, StringSplitOptions.RemoveEmptyEntries);
var protocols = tbProtocols.Text.Split(Settings.SuffixSeparator, StringSplitOptions.RemoveEmptyEntries);
2022-10-23 14:09:22 +00:00
if (suffixes.Length == 0 && UseCustomSuffixes)
2014-08-14 11:45:48 +00:00
{
2020-04-21 12:54:41 +00:00
string warning = context.API.GetTranslation("flowlauncher_plugin_program_suffixes_cannot_empty");
2015-01-06 15:24:11 +00:00
MessageBox.Show(warning);
2014-08-14 11:45:48 +00:00
return;
}
2022-10-23 14:09:22 +00:00
if (protocols.Length == 0 && UseCustomProtocols)
2022-10-23 12:01:18 +00:00
{
2022-10-23 12:05:51 +00:00
string warning = context.API.GetTranslation("flowlauncher_plugin_protocols_cannot_empty");
2022-10-23 12:01:18 +00:00
MessageBox.Show(warning);
return;
}
2022-10-23 12:01:18 +00:00
_settings.CustomSuffixes = suffixes;
_settings.CustomProtocols = protocols;
2022-10-23 14:09:22 +00:00
_settings.BuiltinSuffixesStatus = new Dictionary<string, bool>(SuffixesStatus);
_settings.BuiltinProtocolsStatus = new Dictionary<string, bool>(ProtocolsStatus);
_settings.UseCustomSuffixes = UseCustomSuffixes;
_settings.UseCustomProtocols = UseCustomProtocols;
DialogResult = true;
}
2022-10-23 09:29:37 +00:00
private void BtnReset_OnClick(object sender, RoutedEventArgs e)
{
2022-10-23 10:50:38 +00:00
apprefMS.IsChecked = true;
exe.IsChecked = true;
lnk.IsChecked = true;
CustomFiles.IsChecked = false;
2022-10-23 09:29:37 +00:00
2022-10-23 12:01:18 +00:00
steam.IsChecked = true;
epic.IsChecked = true;
http.IsChecked = false;
CustomProtocol.IsChecked = false;
2022-10-23 09:29:37 +00:00
}
}
2022-10-22 09:02:20 +00:00
}