Mk0.Software.ImageSorter/Mk0.Software.ImageSorter/Inpaint.cs
2024-08-17 08:44:36 +02:00

146 lines
5.2 KiB
C#

using CefSharp.WinForms;
using System;
using System.Windows.Forms;
using System.Collections.Specialized;
using CefSharp;
using System.IO;
namespace Mk0.Software.ImageSorter
{
public partial class Inpaint : Form
{
private readonly string url;
private readonly string file;
public ChromiumWebBrowser browser;
public Inpaint(string url, string file)
{
InitializeComponent();
this.url = url;
this.file = file;
InitializeChromium();
}
private void InitializeChromium()
{
#if ANYCPU
//Only required for PlatformTarget of AnyCPU
CefRuntime.SubscribeAnyCpuAssemblyResolver();
#endif
var settings = new CefSettings();
settings.LogSeverity = LogSeverity.Disable;
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);
if (!initialized)
{
MessageBox.Show("Cef.Initialized failed, check the log file for more details.");
//Shutdown();
}
}
browser = new ChromiumWebBrowser(url)
{
DownloadHandler = new DownloadHandler(),
MenuHandler = new MenuHandler(),
TabIndex = 0
};
this.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
}
private void Inpaint_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.lastWidthInpaint = Width;
Properties.Settings.Default.lastHeightInpaint = Height;
Properties.Settings.Default.lastTopInpaint = Top;
Properties.Settings.Default.lastLeftInpaint = Left;
Properties.Settings.Default.Save();
if (!File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "inpaint-tmp", Path.GetFileNameWithoutExtension(file) + "_cleanup" + Path.GetExtension(file))))
{
DialogResult res = MessageBox.Show("Sie haben kein bearbeitetes Bild heruntergeladen. Klicken sie dazu auf den Downloadbutton am unteren Fensterrand.\n\nWollen sie die bearbeitete Datei doch noch herunterladen (Ja)?\n\nFalls sie ihre Änderungen verwerfen wollen, Klicken sie (Nein).", "Inpaint Frage", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
switch (res)
{
case DialogResult.Yes:
{
e.Cancel = true;
break;
}
case DialogResult.No:
{
break;
}
}
}
}
private void Inpaint_Shown(object sender, EventArgs e)
{
if (Properties.Settings.Default.lastHeightInpaint >= MinimumSize.Height)
{
Height = Properties.Settings.Default.lastHeightInpaint;
}
if (Properties.Settings.Default.lastWidthInpaint >= MinimumSize.Width)
{
Width = Properties.Settings.Default.lastWidthInpaint;
}
if (Properties.Settings.Default.lastTopInpaint <= Screen.PrimaryScreen.Bounds.Height && Properties.Settings.Default.lastTopInpaint >= 0)
{
Top = Properties.Settings.Default.lastTopInpaint;
}
if (Properties.Settings.Default.lastLeftInpaint <= Screen.PrimaryScreen.Bounds.Width && Properties.Settings.Default.lastLeftInpaint >= 0)
{
Left = Properties.Settings.Default.lastLeftInpaint;
}
CopyPasteImage();
ToolTip t1 = new ToolTip
{
AutoPopDelay = 5000,
InitialDelay = 1000,
ReshowDelay = 500
};
t1.SetToolTip(buttonPaste, "Bild erneut in Inpaint laden/Zurücksetzen (F5)");
ToolTip t2 = new ToolTip
{
AutoPopDelay = 5000,
InitialDelay = 1000,
ReshowDelay = 500
};
t2.SetToolTip(buttonReload, "Inpaint neu laden (Strg + F5)");
}
private void CopyPasteImage()
{
System.Threading.Thread.Sleep(125);
StringCollection c = new StringCollection
{
file
};
Clipboard.SetFileDropList(c);
browser.Select();
browser.Focus();
SendKeys.Send("^{v}");
browser.Select();
browser.Focus();
SendKeys.Send("^{v}");
browser.Select();
browser.Focus();
SendKeys.Send("^{v}");
}
private void ButtonPaste_Click(object sender, EventArgs e)
{
CopyPasteImage();
}
private void ButtonReload_Click(object sender, EventArgs e)
{
browser.Reload();
CopyPasteImage();
}
}
}