If service links are not changed then reset them to default

This commit is contained in:
Jaex 2022-07-11 11:38:31 +03:00
parent 53ed4fb34d
commit 82ffe63f45
2 changed files with 18 additions and 1 deletions

View file

@ -83,7 +83,12 @@ public OCRForm(Bitmap bmp, OCROptions options)
nudScaleFactor.SetValue((decimal)Options.ScaleFactor);
if (Options.ServiceLinks != null && Options.ServiceLinks.Count > 0)
if (Options.ServiceLinks == null || Options.IsDefaultServiceLinks())
{
Options.ServiceLinks = OCROptions.DefaultServiceLinks;
}
if (Options.ServiceLinks.Count > 0)
{
cbServices.Items.AddRange(Options.ServiceLinks.ToArray());
cbServices.SelectedIndex = Options.SelectedServiceLink;

View file

@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
using System.Collections.Generic;
using System.Linq;
namespace ShareX
{
@ -36,6 +37,17 @@ public class OCROptions
public List<ServiceLink> ServiceLinks { get; set; } = DefaultServiceLinks;
public int SelectedServiceLink { get; set; } = 0;
public bool IsDefaultServiceLinks()
{
if (ServiceLinks != null && ServiceLinks.Count > 0)
{
List<ServiceLink> defaultServiceLinks = DefaultServiceLinks;
return ServiceLinks.All(x => defaultServiceLinks.Any(y => x.Name == y.Name));
}
return false;
}
public static List<ServiceLink> DefaultServiceLinks => new List<ServiceLink>()
{
new ServiceLink("Google Translate", "https://translate.google.com/?sl=auto&tl=en&text={0}&op=translate"),