Skip to content

Commit

Permalink
Allow pasting of images and image files into account setup window
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-green committed Aug 12, 2022
1 parent 79f0de7 commit 79deb12
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/Authentiqr.NET/frmAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,40 @@ private void txtAccountName_KeyDown(object sender, KeyEventArgs e)
if ((e.Control && e.KeyCode == Keys.V) ||
(e.Shift && e.KeyCode == Keys.Insert))
{
var text = Clipboard.GetText();
try
{
if (Clipboard.ContainsText())
{
var text = Clipboard.GetText();

if (ParseOtpAuth(text))
{
e.SuppressKeyPress = true;
}
}
else if (Clipboard.ContainsImage())
{
var image = Clipboard.GetImage();

ReadBitmap(new Bitmap(image));

if (ParseOtpAuth(text))
e.SuppressKeyPress = true;
}
else if (Clipboard.ContainsFileDropList())
{
var files = Clipboard.GetFileDropList();
var filename = files[0];

using var image = Image.FromFile(filename);
using var bitmap = new Bitmap(image);
ReadBitmap(bitmap);

e.SuppressKeyPress = true;
}
}
catch (Exception ex)
{
e.SuppressKeyPress = true;
MessageBox.Show(ex.Message, "Failed to paste from clipboard", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
Expand All @@ -190,7 +219,7 @@ private void frmAddAccount_DragDrop(object sender, DragEventArgs e)
{
var filename = ((string[])e.Data.GetData("FileDrop"))[0];

using var image = Bitmap.FromFile(filename);
using var image = Image.FromFile(filename);
using var bitmap = new Bitmap(image);
ReadBitmap(bitmap);
}
Expand Down

0 comments on commit 79deb12

Please sign in to comment.