implemented #13

This commit is contained in:
Manuel Kamper 2024-08-18 19:29:34 +02:00
parent 9873579362
commit 78f50c56e8

View File

@ -7,7 +7,7 @@ using System.IO;
namespace Mk0.Software.ImageSorter namespace Mk0.Software.ImageSorter
{ {
public partial class Inpaint : Form public partial class Inpaint : Form, IKeyboardHandler
{ {
private readonly string url; private readonly string url;
private readonly string file; private readonly string file;
@ -31,14 +31,11 @@ namespace Mk0.Software.ImageSorter
settings.LogSeverity = LogSeverity.Disable; settings.LogSeverity = LogSeverity.Disable;
if (!Cef.IsInitialized) if (!Cef.IsInitialized)
{ {
//Perform dependency check to make sure all relevant resources are in our output directory.
var initialized = Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); var initialized = Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
if (!initialized) if (!initialized)
{ {
MessageBox.Show("Cef.Initialized failed, check the log file for more details."); MessageBox.Show("Cef.Initialized failed, check the log file for more details.");
//Shutdown();
} }
} }
@ -46,6 +43,7 @@ namespace Mk0.Software.ImageSorter
{ {
DownloadHandler = new DownloadHandler(), DownloadHandler = new DownloadHandler(),
MenuHandler = new MenuHandler(), MenuHandler = new MenuHandler(),
KeyboardHandler = this,
TabIndex = 0 TabIndex = 0
}; };
this.Controls.Add(browser); this.Controls.Add(browser);
@ -109,7 +107,7 @@ namespace Mk0.Software.ImageSorter
InitialDelay = 1000, InitialDelay = 1000,
ReshowDelay = 500 ReshowDelay = 500
}; };
t2.SetToolTip(buttonReload, "Inpaint neu laden (Strg + F5)"); t2.SetToolTip(buttonReload, "Inpaint neu laden (F2)");
} }
private void CopyPasteImage() private void CopyPasteImage()
@ -132,14 +130,57 @@ namespace Mk0.Software.ImageSorter
} }
private void ButtonPaste_Click(object sender, EventArgs e) private void ButtonPaste_Click(object sender, EventArgs e)
{
Paste();
}
private void Paste()
{ {
CopyPasteImage(); CopyPasteImage();
} }
private void ButtonReload_Click(object sender, EventArgs e) private void ButtonReload_Click(object sender, EventArgs e)
{
Reload();
}
private void Reload()
{ {
browser.Reload(); browser.Reload();
CopyPasteImage(); CopyPasteImage();
} }
public bool OnPreKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
{
isKeyboardShortcut = true;
return false;
}
public bool OnKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
{
if (type == KeyType.KeyUp && Enum.IsDefined(typeof(Keys), windowsKeyCode))
{
var key = (Keys)windowsKeyCode;
switch (key)
{
case Keys.F2:
this.BeginInvoke(new Action(() => {
Reload();
}));
break;
case Keys.F5:
this.BeginInvoke(new Action(() => {
Paste();
}));
break;
case Keys.Escape:
this.BeginInvoke(new Action(() => {
this.Close();
}));
break;
}
}
return false;
}
} }
} }