Fixed some interface usage, also cleanup of the surface & editor code. This should theoretically allow usage of home made IDrawableContainer objects, which plug-ins supply.

Also made it possible to reuse the editor, currently only available editors which have a non modified surface can be reused. And only than if the configuration is set to do so.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2100 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-09-26 16:57:16 +00:00
commit f9abcac063
13 changed files with 233 additions and 154 deletions

View file

@ -38,7 +38,7 @@ namespace Greenshot.Destinations {
/// </summary>
public class EditorDestination : AbstractDestination {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(EditorDestination));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private static EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
public const string DESIGNATION = "Editor";
private IImageEditor editor = null;
private static Image greenshotIcon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon().ToBitmap();
@ -92,35 +92,46 @@ namespace Greenshot.Destinations {
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
// Make sure we collect the garbage before opening the screenshot
GC.Collect();
GC.WaitForPendingFinalizers();
if (editor == null) {
// Make sure we collect the garbage before opening the screenshot
GC.Collect();
GC.WaitForPendingFinalizers();
try {
ImageEditorForm editorForm = new ImageEditorForm(surface, !surface.Modified); // Output made??
if (!string.IsNullOrEmpty(captureDetails.Filename)) {
editorForm.SetImagePath(captureDetails.Filename);
if (editorConfiguration.ReuseEditor) {
foreach(IImageEditor openedEditor in ImageEditorForm.Editors) {
if (!openedEditor.Surface.Modified) {
openedEditor.Surface = surface;
exportInformation.ExportMade = true;
break;
}
}
}
if (!exportInformation.ExportMade) {
try {
ImageEditorForm editorForm = new ImageEditorForm(surface, !surface.Modified); // Output made??
if (!string.IsNullOrEmpty(captureDetails.Filename)) {
editorForm.SetImagePath(captureDetails.Filename);
}
editorForm.Show();
editorForm.Activate();
LOG.Debug("Finished opening Editor");
exportInformation.ExportMade = true;
} catch (Exception e) {
LOG.Error(e);
exportInformation.ErrorMessage = e.Message;
}
}
} else {
try {
using (Bitmap image = (Bitmap)surface.GetImageForExport()) {
editor.Surface.AddBitmapContainer(image, 10, 10);
}
editorForm.Show();
editorForm.Activate();
LOG.Debug("Finished opening Editor");
exportInformation.ExportMade = true;
} catch (Exception e) {
LOG.Error(e);
exportInformation.ErrorMessage = e.Message;
}
} else {
try {
using (Bitmap image = (Bitmap)surface.GetImageForExport()) {
editor.Surface.AddBitmapContainer(image, 10, 10);
}
exportInformation.ExportMade = true;
} catch (Exception e) {
LOG.Error(e);
exportInformation.ErrorMessage = e.Message;
}
}
ProcessExport(exportInformation, surface);
return exportInformation;