From f7782299cd9c8d3e5641eb14b119e3aeda104c17 Mon Sep 17 00:00:00 2001 From: RKrom Date: Fri, 28 Sep 2012 12:17:31 +0000 Subject: [PATCH] Removed some unused code, and fixed a Editor-reuse issue. (No focus, and resize issues) git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2106 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Destinations/EditorDestination.cs | 3 + Greenshot/Forms/ImageEditorForm.cs | 11 ++- Greenshot/Helpers/CaptureHelper.cs | 2 +- Greenshot/Helpers/DestinationHelper.cs | 9 +- Greenshot/Helpers/IECaptureHelper.cs | 47 +++++------ GreenshotPlugin/Core/WindowCapture.cs | 92 +++++++++++---------- GreenshotPlugin/Interfaces/Capture.cs | 37 +++++---- 7 files changed, 105 insertions(+), 96 deletions(-) diff --git a/Greenshot/Destinations/EditorDestination.cs b/Greenshot/Destinations/EditorDestination.cs index fbfaab185..6466ecbc6 100644 --- a/Greenshot/Destinations/EditorDestination.cs +++ b/Greenshot/Destinations/EditorDestination.cs @@ -96,6 +96,7 @@ namespace Greenshot.Destinations { GC.Collect(); GC.WaitForPendingFinalizers(); + bool modified = surface.Modified; if (editor == null) { if (editorConfiguration.ReuseEditor) { foreach(IImageEditor openedEditor in ImageEditorForm.Editors) { @@ -134,6 +135,8 @@ namespace Greenshot.Destinations { } } ProcessExport(exportInformation, surface); + // Workaround for the modified flag when using the editor. + surface.Modified = modified; return exportInformation; } } diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index be99b0e55..d0cccc4c5 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -108,6 +108,9 @@ namespace Greenshot { hideToolstripItems(); } + /// + /// Remove the current surface + /// private void RemoveSurface() { if (surface != null) { panel1.Controls.Remove(surface as Control); @@ -116,6 +119,10 @@ namespace Greenshot { } } + /// + /// Change the surface + /// + /// private void SetSurface(ISurface newSurface) { if (this.Surface != null && this.Surface.Modified) { throw new ApplicationException("Surface modified"); @@ -123,6 +130,8 @@ namespace Greenshot { RemoveSurface(); + panel1.Height = 10; + panel1.Width = 10; this.surface = newSurface as Surface; panel1.Controls.Add(surface as Surface); Image backgroundForTransparency = GreenshotPlugin.Core.GreenshotResources.getImage("Checkerboard.Image"); @@ -135,7 +144,6 @@ namespace Greenshot { surface.SurfaceSizeChanged += new SurfaceSizeChangeEventHandler(SurfaceSizeChanged); surface.SurfaceMessage += new SurfaceMessageEventHandler(SurfaceMessageReceived); surface.FieldAggregator.FieldChanged += new FieldChangedEventHandler(FieldAggregatorFieldChanged); - SurfaceSizeChanged(this.Surface); bindFieldControls(); @@ -144,6 +152,7 @@ namespace Greenshot { if (surface != null && surface.CaptureDetails != null && surface.CaptureDetails.Title != null) { this.Text = surface.CaptureDetails.Title + " - " + Language.GetString(LangKey.editor_title); } + WindowDetails.ToForeground(this.Handle); } private void updateUI() { diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs index f9e58f4c9..305b809c3 100644 --- a/Greenshot/Helpers/CaptureHelper.cs +++ b/Greenshot/Helpers/CaptureHelper.cs @@ -372,7 +372,7 @@ namespace Greenshot.Helpers { } // Move cursor, fixing bug #3569703 capture.MoveMouseLocation(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y); - capture.MoveElements(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y); + //capture.MoveElements(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y); capture.CaptureDetails.AddMetaData("source", "screen"); HandleCapture(); diff --git a/Greenshot/Helpers/DestinationHelper.cs b/Greenshot/Helpers/DestinationHelper.cs index dd023df41..5a151959f 100644 --- a/Greenshot/Helpers/DestinationHelper.cs +++ b/Greenshot/Helpers/DestinationHelper.cs @@ -131,14 +131,7 @@ namespace Greenshot.Helpers { public static ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails) { IDestination destination = GetDestination(designation); if (destination != null && destination.isActive) { - ExportInformation exportInformation = destination.ExportCapture(manuallyInitiated, surface, captureDetails); - if (exportInformation != null && exportInformation.ExportMade) { - // Export worked, set the modified flag to false if the export wasn't to the editor or picker - if (!EditorDestination.DESIGNATION.Equals(designation) && !PickerDestination.DESIGNATION.Equals(designation)) { - surface.Modified = false; - } - } - return exportInformation; + return destination.ExportCapture(manuallyInitiated, surface, captureDetails); } return null; } diff --git a/Greenshot/Helpers/IECaptureHelper.cs b/Greenshot/Helpers/IECaptureHelper.cs index 309c8bb91..c331eaa2b 100644 --- a/Greenshot/Helpers/IECaptureHelper.cs +++ b/Greenshot/Helpers/IECaptureHelper.cs @@ -372,30 +372,31 @@ namespace Greenshot.Helpers { } catch (Exception captureException) { LOG.Error("Exception found, ignoring and returning nothing! Error was: ", captureException); } + // TODO: Enable when the elements are usable again. // Capture the element on the page - try { - if (configuration.IEFieldCapture && capture.CaptureDetails.HasDestination("Editor")) { - // clear the current elements, as they are for the window itself - capture.Elements.Clear(); - CaptureElement documentCaptureElement = documentContainer.CreateCaptureElements(pageSize); - foreach(DocumentContainer frameDocument in documentContainer.Frames) { - try { - CaptureElement frameCaptureElement = frameDocument.CreateCaptureElements(Size.Empty); - if (frameCaptureElement != null) { - documentCaptureElement.Children.Add(frameCaptureElement); - } - } catch (Exception ex) { - LOG.Warn("An error occurred while creating the capture elements: ", ex); - } - } - capture.AddElement(documentCaptureElement); - // Offset the elements, as they are "back offseted" later... - Point windowLocation = documentContainer.ContentWindow.WindowRectangle.Location; - capture.MoveElements(-(capture.ScreenBounds.Location.X-windowLocation.X), -(capture.ScreenBounds.Location.Y-windowLocation.Y)); - } - } catch (Exception elementsException) { - LOG.Warn("An error occurred while creating the capture elements: ", elementsException); - } + //try { + // if (configuration.IEFieldCapture && capture.CaptureDetails.HasDestination("Editor")) { + // // clear the current elements, as they are for the window itself + // capture.Elements.Clear(); + // CaptureElement documentCaptureElement = documentContainer.CreateCaptureElements(pageSize); + // foreach(DocumentContainer frameDocument in documentContainer.Frames) { + // try { + // CaptureElement frameCaptureElement = frameDocument.CreateCaptureElements(Size.Empty); + // if (frameCaptureElement != null) { + // documentCaptureElement.Children.Add(frameCaptureElement); + // } + // } catch (Exception ex) { + // LOG.Warn("An error occurred while creating the capture elements: ", ex); + // } + // } + // capture.AddElement(documentCaptureElement); + // // Offset the elements, as they are "back offseted" later... + // Point windowLocation = documentContainer.ContentWindow.WindowRectangle.Location; + // capture.MoveElements(-(capture.ScreenBounds.Location.X-windowLocation.X), -(capture.ScreenBounds.Location.Y-windowLocation.Y)); + // } + //} catch (Exception elementsException) { + // LOG.Warn("An error occurred while creating the capture elements: ", elementsException); + //} if (returnBitmap == null) { diff --git a/GreenshotPlugin/Core/WindowCapture.cs b/GreenshotPlugin/Core/WindowCapture.cs index 9470112d8..79e7e2ca2 100644 --- a/GreenshotPlugin/Core/WindowCapture.cs +++ b/GreenshotPlugin/Core/WindowCapture.cs @@ -295,7 +295,8 @@ namespace GreenshotPlugin.Core { // Change mouse location according to the cropRegtangle (including screenbounds) offset MoveMouseLocation(-cropRectangle.Location.X, -cropRectangle.Location.Y); // Move all the elements - MoveElements(-cropRectangle.Location.X, -cropRectangle.Location.Y); + // TODO: Enable when the elements are usable again. + // MoveElements(-cropRectangle.Location.X, -cropRectangle.Location.Y); // Remove invisible elements List newElements = new List(); @@ -320,53 +321,54 @@ namespace GreenshotPlugin.Core { public void MoveMouseLocation(int x, int y) { cursorLocation.Offset(x, y); } - - /// - /// Apply a translate to the elements - /// e.g. needed for crop - /// - /// x coordinates to move the elements - /// y coordinates to move the elements - public void MoveElements(int x, int y) { - MoveElements(elements, x, y); - } - private void MoveElements(List listOfElements, int x, int y) { - foreach(ICaptureElement childElement in listOfElements) { - Rectangle bounds = childElement.Bounds; - bounds.Offset(x, y); - childElement.Bounds = bounds; - MoveElements(childElement.Children, x, y); - } - } + // TODO: Enable when the elements are usable again. + ///// + ///// Apply a translate to the elements + ///// e.g. needed for crop + ///// + ///// x coordinates to move the elements + ///// y coordinates to move the elements + //public void MoveElements(int x, int y) { + // MoveElements(elements, x, y); + //} + + //private void MoveElements(List listOfElements, int x, int y) { + // foreach(ICaptureElement childElement in listOfElements) { + // Rectangle bounds = childElement.Bounds; + // bounds.Offset(x, y); + // childElement.Bounds = bounds; + // MoveElements(childElement.Children, x, y); + // } + //} - /// - /// Add a new element to the capture - /// - /// CaptureElement - public void AddElement(ICaptureElement element) { - int match = elements.IndexOf(element); - if (match >= 0) { - if (elements[match].Children.Count < element.Children.Count) { - elements.RemoveAt(match); - elements.Add(element); - } - } else { - elements.Add(element); - } - } + ///// + ///// Add a new element to the capture + ///// + ///// CaptureElement + //public void AddElement(ICaptureElement element) { + // int match = elements.IndexOf(element); + // if (match >= 0) { + // if (elements[match].Children.Count < element.Children.Count) { + // elements.RemoveAt(match); + // elements.Add(element); + // } + // } else { + // elements.Add(element); + // } + //} - /// - /// Returns a list of rectangles which represent object that are on the capture - /// - public List Elements { - get { - return elements; - } - set { - elements = value; - } - } + ///// + ///// Returns a list of rectangles which represent object that are on the capture + ///// + //public List Elements { + // get { + // return elements; + // } + // set { + // elements = value; + // } + //} } diff --git a/GreenshotPlugin/Interfaces/Capture.cs b/GreenshotPlugin/Interfaces/Capture.cs index b020e7924..deeba330c 100644 --- a/GreenshotPlugin/Interfaces/Capture.cs +++ b/GreenshotPlugin/Interfaces/Capture.cs @@ -153,26 +153,27 @@ namespace Greenshot.Plugin { /// y coordinates to move the mouse void MoveMouseLocation(int x, int y); - /// - /// Apply a translate to the elements e.g. needed for crop - /// - /// x coordinates to move the elements - /// y coordinates to move the elements - void MoveElements(int x, int y); + // / TODO: Enable when the elements are usable again. + ///// + ///// Apply a translate to the elements e.g. needed for crop + ///// + ///// x coordinates to move the elements + ///// y coordinates to move the elements + //void MoveElements(int x, int y); - /// - /// Add a new element to the capture - /// - /// Rectangle - void AddElement(ICaptureElement element); + ///// + ///// Add a new element to the capture + ///// + ///// Rectangle + //void AddElement(ICaptureElement element); - /// - /// Returns a list of rectangles which represent objects that are "on" the capture - /// - List Elements { - get; - set; - } + ///// + ///// Returns a list of rectangles which represent objects that are "on" the capture + ///// + //List Elements { + // get; + // set; + //} } }