Skip to content

Commit

Permalink
Added service links to OCR form
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaex committed May 2, 2022
1 parent b50cd65 commit 855ddd6
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 5 deletions.
20 changes: 20 additions & 0 deletions ShareX/OCR/OCRForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions ShareX/OCR/OCRForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public OCRForm(Bitmap bmp, OCROptions options)

nudScaleFactor.SetValue((decimal)Options.ScaleFactor);

if (Options.ServiceLinks != null && Options.ServiceLinks.Count > 0)
{
cbServices.Items.AddRange(Options.ServiceLinks.ToArray());
cbServices.SelectedIndex = 0;
}
else
{
cbServices.Enabled = false;
}

txtResult.SupportSelectAll();

loaded = true;
Expand Down Expand Up @@ -127,5 +137,14 @@ private async void nudScaleFactor_ValueChanged(object sender, EventArgs e)
await OCR();
}
}

private void btnOpen_Click(object sender, EventArgs e)
{
if (cbServices.SelectedItem is ServiceLink serviceLink)
{
string input = txtResult.Text.Trim();
serviceLink.OpenLink(input);
}
}
}
}
61 changes: 56 additions & 5 deletions ShareX/OCR/OCRForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;lblLanguage.ZOrder" xml:space="preserve">
<value>5</value>
<value>7</value>
</data>
<data name="cbLanguages.Font" type="System.Drawing.Font, System.Drawing">
<value>Microsoft Sans Serif, 9.75pt</value>
Expand All @@ -171,7 +171,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;cbLanguages.ZOrder" xml:space="preserve">
<value>4</value>
<value>6</value>
</data>
<data name="lblResult.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
Expand Down Expand Up @@ -201,7 +201,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;lblResult.ZOrder" xml:space="preserve">
<value>3</value>
<value>5</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="txtResult.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
Expand Down Expand Up @@ -235,7 +235,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;txtResult.ZOrder" xml:space="preserve">
<value>2</value>
<value>4</value>
</data>
<data name="lblScaleFactor.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
Expand Down Expand Up @@ -265,7 +265,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;lblScaleFactor.ZOrder" xml:space="preserve">
<value>1</value>
<value>3</value>
</data>
<data name="nudScaleFactor.Font" type="System.Drawing.Font, System.Drawing">
<value>Microsoft Sans Serif, 9.75pt</value>
Expand All @@ -292,6 +292,57 @@
<value>$this</value>
</data>
<data name="&gt;&gt;nudScaleFactor.ZOrder" xml:space="preserve">
<value>2</value>
</data>
<data name="cbServices.Font" type="System.Drawing.Font, System.Drawing">
<value>Microsoft Sans Serif, 9.75pt</value>
</data>
<data name="cbServices.Location" type="System.Drawing.Point, System.Drawing">
<value>440, 20</value>
</data>
<data name="cbServices.Size" type="System.Drawing.Size, System.Drawing">
<value>168, 24</value>
</data>
<data name="cbServices.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
</data>
<data name="&gt;&gt;cbServices.Name" xml:space="preserve">
<value>cbServices</value>
</data>
<data name="&gt;&gt;cbServices.Type" xml:space="preserve">
<value>System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;cbServices.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;cbServices.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="btnOpen.Font" type="System.Drawing.Font, System.Drawing">
<value>Microsoft Sans Serif, 9.75pt</value>
</data>
<data name="btnOpen.Location" type="System.Drawing.Point, System.Drawing">
<value>440, 48</value>
</data>
<data name="btnOpen.Size" type="System.Drawing.Size, System.Drawing">
<value>168, 32</value>
</data>
<data name="btnOpen.TabIndex" type="System.Int32, mscorlib">
<value>8</value>
</data>
<data name="btnOpen.Text" xml:space="preserve">
<value>Open...</value>
</data>
<data name="&gt;&gt;btnOpen.Name" xml:space="preserve">
<value>btnOpen</value>
</data>
<data name="&gt;&gt;btnOpen.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;btnOpen.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;btnOpen.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
Expand Down
8 changes: 8 additions & 0 deletions ShareX/OCR/OCROptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ You should have received a copy of the GNU General Public License

#endregion License Information (GPL v3)

using System.Collections.Generic;

namespace ShareX
{
public class OCROptions
Expand All @@ -31,5 +33,11 @@ public class OCROptions
public float ScaleFactor { get; set; } = 2f;
public bool Silent { get; set; } = false;
public bool AutoCopy { get; set; } = false;
public List<ServiceLink> ServiceLinks { get; set; } = new List<ServiceLink>()
{
new ServiceLink("Google Translate", "https://translate.google.com/?sl=auto&tl=en&text={0}&op=translate"),
new ServiceLink("Google Search", "https://www.google.com/search?q={0}"),
new ServiceLink("Bing", "https://www.bing.com/search?q={0}")
};
}
}
67 changes: 67 additions & 0 deletions ShareX/OCR/ServiceLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#region License Information (GPL v3)

/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2022 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/

#endregion License Information (GPL v3)

using ShareX.HelpersLib;

namespace ShareX
{
public class ServiceLink
{
public string Name { get; set; }
public string URL { get; set; }

public ServiceLink(string name, string url)
{
Name = name;
URL = url;
}

public string GenerateLink(string input)
{
if (!string.IsNullOrEmpty(input))
{
string encodedInput = URLHelpers.URLEncode(input);
return string.Format(URL, encodedInput);
}

return null;
}

public void OpenLink(string input)
{
string link = GenerateLink(input);

if (!string.IsNullOrEmpty(link))
{
URLHelpers.OpenURL(link);
}
}

public override string ToString()
{
return Name;
}
}
}
1 change: 1 addition & 0 deletions ShareX/ShareX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
<Compile Include="OCR\OCRHelper.cs" />
<Compile Include="OCR\OCRLanguage.cs" />
<Compile Include="OCR\OCROptions.cs" />
<Compile Include="OCR\ServiceLink.cs" />
<Compile Include="SettingManager.cs" />
<Compile Include="Forms\BeforeUploadForm.cs">
<SubType>Form</SubType>
Expand Down

0 comments on commit 855ddd6

Please sign in to comment.