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
This commit is contained in:
RKrom 2012-09-28 12:17:31 +00:00
commit f7782299cd
7 changed files with 105 additions and 96 deletions

View file

@ -96,6 +96,7 @@ namespace Greenshot.Destinations {
GC.Collect(); GC.Collect();
GC.WaitForPendingFinalizers(); GC.WaitForPendingFinalizers();
bool modified = surface.Modified;
if (editor == null) { if (editor == null) {
if (editorConfiguration.ReuseEditor) { if (editorConfiguration.ReuseEditor) {
foreach(IImageEditor openedEditor in ImageEditorForm.Editors) { foreach(IImageEditor openedEditor in ImageEditorForm.Editors) {
@ -134,6 +135,8 @@ namespace Greenshot.Destinations {
} }
} }
ProcessExport(exportInformation, surface); ProcessExport(exportInformation, surface);
// Workaround for the modified flag when using the editor.
surface.Modified = modified;
return exportInformation; return exportInformation;
} }
} }

View file

@ -108,6 +108,9 @@ namespace Greenshot {
hideToolstripItems(); hideToolstripItems();
} }
/// <summary>
/// Remove the current surface
/// </summary>
private void RemoveSurface() { private void RemoveSurface() {
if (surface != null) { if (surface != null) {
panel1.Controls.Remove(surface as Control); panel1.Controls.Remove(surface as Control);
@ -116,6 +119,10 @@ namespace Greenshot {
} }
} }
/// <summary>
/// Change the surface
/// </summary>
/// <param name="newSurface"></param>
private void SetSurface(ISurface newSurface) { private void SetSurface(ISurface newSurface) {
if (this.Surface != null && this.Surface.Modified) { if (this.Surface != null && this.Surface.Modified) {
throw new ApplicationException("Surface modified"); throw new ApplicationException("Surface modified");
@ -123,6 +130,8 @@ namespace Greenshot {
RemoveSurface(); RemoveSurface();
panel1.Height = 10;
panel1.Width = 10;
this.surface = newSurface as Surface; this.surface = newSurface as Surface;
panel1.Controls.Add(surface as Surface); panel1.Controls.Add(surface as Surface);
Image backgroundForTransparency = GreenshotPlugin.Core.GreenshotResources.getImage("Checkerboard.Image"); Image backgroundForTransparency = GreenshotPlugin.Core.GreenshotResources.getImage("Checkerboard.Image");
@ -135,7 +144,6 @@ namespace Greenshot {
surface.SurfaceSizeChanged += new SurfaceSizeChangeEventHandler(SurfaceSizeChanged); surface.SurfaceSizeChanged += new SurfaceSizeChangeEventHandler(SurfaceSizeChanged);
surface.SurfaceMessage += new SurfaceMessageEventHandler(SurfaceMessageReceived); surface.SurfaceMessage += new SurfaceMessageEventHandler(SurfaceMessageReceived);
surface.FieldAggregator.FieldChanged += new FieldChangedEventHandler(FieldAggregatorFieldChanged); surface.FieldAggregator.FieldChanged += new FieldChangedEventHandler(FieldAggregatorFieldChanged);
SurfaceSizeChanged(this.Surface); SurfaceSizeChanged(this.Surface);
bindFieldControls(); bindFieldControls();
@ -144,6 +152,7 @@ namespace Greenshot {
if (surface != null && surface.CaptureDetails != null && surface.CaptureDetails.Title != null) { if (surface != null && surface.CaptureDetails != null && surface.CaptureDetails.Title != null) {
this.Text = surface.CaptureDetails.Title + " - " + Language.GetString(LangKey.editor_title); this.Text = surface.CaptureDetails.Title + " - " + Language.GetString(LangKey.editor_title);
} }
WindowDetails.ToForeground(this.Handle);
} }
private void updateUI() { private void updateUI() {

View file

@ -372,7 +372,7 @@ namespace Greenshot.Helpers {
} }
// Move cursor, fixing bug #3569703 // Move cursor, fixing bug #3569703
capture.MoveMouseLocation(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y); 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"); capture.CaptureDetails.AddMetaData("source", "screen");
HandleCapture(); HandleCapture();

View file

@ -131,14 +131,7 @@ namespace Greenshot.Helpers {
public static ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails) { public static ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails) {
IDestination destination = GetDestination(designation); IDestination destination = GetDestination(designation);
if (destination != null && destination.isActive) { if (destination != null && destination.isActive) {
ExportInformation exportInformation = destination.ExportCapture(manuallyInitiated, surface, captureDetails); return 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 null; return null;
} }

View file

@ -372,30 +372,31 @@ namespace Greenshot.Helpers {
} catch (Exception captureException) { } catch (Exception captureException) {
LOG.Error("Exception found, ignoring and returning nothing! Error was: ", 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 // Capture the element on the page
try { //try {
if (configuration.IEFieldCapture && capture.CaptureDetails.HasDestination("Editor")) { // if (configuration.IEFieldCapture && capture.CaptureDetails.HasDestination("Editor")) {
// clear the current elements, as they are for the window itself // // clear the current elements, as they are for the window itself
capture.Elements.Clear(); // capture.Elements.Clear();
CaptureElement documentCaptureElement = documentContainer.CreateCaptureElements(pageSize); // CaptureElement documentCaptureElement = documentContainer.CreateCaptureElements(pageSize);
foreach(DocumentContainer frameDocument in documentContainer.Frames) { // foreach(DocumentContainer frameDocument in documentContainer.Frames) {
try { // try {
CaptureElement frameCaptureElement = frameDocument.CreateCaptureElements(Size.Empty); // CaptureElement frameCaptureElement = frameDocument.CreateCaptureElements(Size.Empty);
if (frameCaptureElement != null) { // if (frameCaptureElement != null) {
documentCaptureElement.Children.Add(frameCaptureElement); // documentCaptureElement.Children.Add(frameCaptureElement);
} // }
} catch (Exception ex) { // } catch (Exception ex) {
LOG.Warn("An error occurred while creating the capture elements: ", ex); // LOG.Warn("An error occurred while creating the capture elements: ", ex);
} // }
} // }
capture.AddElement(documentCaptureElement); // capture.AddElement(documentCaptureElement);
// Offset the elements, as they are "back offseted" later... // // Offset the elements, as they are "back offseted" later...
Point windowLocation = documentContainer.ContentWindow.WindowRectangle.Location; // Point windowLocation = documentContainer.ContentWindow.WindowRectangle.Location;
capture.MoveElements(-(capture.ScreenBounds.Location.X-windowLocation.X), -(capture.ScreenBounds.Location.Y-windowLocation.Y)); // capture.MoveElements(-(capture.ScreenBounds.Location.X-windowLocation.X), -(capture.ScreenBounds.Location.Y-windowLocation.Y));
} // }
} catch (Exception elementsException) { //} catch (Exception elementsException) {
LOG.Warn("An error occurred while creating the capture elements: ", elementsException); // LOG.Warn("An error occurred while creating the capture elements: ", elementsException);
} //}
if (returnBitmap == null) { if (returnBitmap == null) {

View file

@ -295,7 +295,8 @@ namespace GreenshotPlugin.Core {
// Change mouse location according to the cropRegtangle (including screenbounds) offset // Change mouse location according to the cropRegtangle (including screenbounds) offset
MoveMouseLocation(-cropRectangle.Location.X, -cropRectangle.Location.Y); MoveMouseLocation(-cropRectangle.Location.X, -cropRectangle.Location.Y);
// Move all the elements // 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 // Remove invisible elements
List <ICaptureElement> newElements = new List<ICaptureElement>(); List <ICaptureElement> newElements = new List<ICaptureElement>();
@ -320,53 +321,54 @@ namespace GreenshotPlugin.Core {
public void MoveMouseLocation(int x, int y) { public void MoveMouseLocation(int x, int y) {
cursorLocation.Offset(x, y); cursorLocation.Offset(x, y);
} }
/// <summary>
/// Apply a translate to the elements
/// e.g. needed for crop
/// </summary>
/// <param name="x">x coordinates to move the elements</param>
/// <param name="y">y coordinates to move the elements</param>
public void MoveElements(int x, int y) {
MoveElements(elements, x, y);
}
private void MoveElements(List<ICaptureElement> listOfElements, int x, int y) { // TODO: Enable when the elements are usable again.
foreach(ICaptureElement childElement in listOfElements) { ///// <summary>
Rectangle bounds = childElement.Bounds; ///// Apply a translate to the elements
bounds.Offset(x, y); ///// e.g. needed for crop
childElement.Bounds = bounds; ///// </summary>
MoveElements(childElement.Children, x, y); ///// <param name="x">x coordinates to move the elements</param>
} ///// <param name="y">y coordinates to move the elements</param>
} //public void MoveElements(int x, int y) {
// MoveElements(elements, x, y);
//}
//private void MoveElements(List<ICaptureElement> 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);
// }
//}
/// <summary> ///// <summary>
/// Add a new element to the capture ///// Add a new element to the capture
/// </summary> ///// </summary>
/// <param name="element">CaptureElement</param> ///// <param name="element">CaptureElement</param>
public void AddElement(ICaptureElement element) { //public void AddElement(ICaptureElement element) {
int match = elements.IndexOf(element); // int match = elements.IndexOf(element);
if (match >= 0) { // if (match >= 0) {
if (elements[match].Children.Count < element.Children.Count) { // if (elements[match].Children.Count < element.Children.Count) {
elements.RemoveAt(match); // elements.RemoveAt(match);
elements.Add(element); // elements.Add(element);
} // }
} else { // } else {
elements.Add(element); // elements.Add(element);
} // }
} //}
/// <summary> ///// <summary>
/// Returns a list of rectangles which represent object that are on the capture ///// Returns a list of rectangles which represent object that are on the capture
/// </summary> ///// </summary>
public List<ICaptureElement> Elements { //public List<ICaptureElement> Elements {
get { // get {
return elements; // return elements;
} // }
set { // set {
elements = value; // elements = value;
} // }
} //}
} }

View file

@ -153,26 +153,27 @@ namespace Greenshot.Plugin {
/// <param name="y">y coordinates to move the mouse</param> /// <param name="y">y coordinates to move the mouse</param>
void MoveMouseLocation(int x, int y); void MoveMouseLocation(int x, int y);
/// <summary> // / TODO: Enable when the elements are usable again.
/// Apply a translate to the elements e.g. needed for crop ///// <summary>
/// </summary> ///// Apply a translate to the elements e.g. needed for crop
/// <param name="x">x coordinates to move the elements</param> ///// </summary>
/// <param name="y">y coordinates to move the elements</param> ///// <param name="x">x coordinates to move the elements</param>
void MoveElements(int x, int y); ///// <param name="y">y coordinates to move the elements</param>
//void MoveElements(int x, int y);
/// <summary> ///// <summary>
/// Add a new element to the capture ///// Add a new element to the capture
/// </summary> ///// </summary>
/// <param name="element">Rectangle</param> ///// <param name="element">Rectangle</param>
void AddElement(ICaptureElement element); //void AddElement(ICaptureElement element);
/// <summary> ///// <summary>
/// Returns a list of rectangles which represent objects that are "on" the capture ///// Returns a list of rectangles which represent objects that are "on" the capture
/// </summary> ///// </summary>
List<ICaptureElement> Elements { //List<ICaptureElement> Elements {
get; // get;
set; // set;
} //}
} }
} }