mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Mainly code cleanup, added a lot of comments. Also making sure the element which was selected while being removed is re-selected again when undo is used. Not really happy with the solution as the the container should handle this somehow itself without work-around, for now it should be enough.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2311 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
3d62f9c279
commit
46e9ea0e59
10 changed files with 246 additions and 60 deletions
|
@ -181,7 +181,7 @@ namespace Greenshot.Drawing {
|
||||||
/// the brush which is used for transparent backgrounds, set by the editor, do not serialize
|
/// the brush which is used for transparent backgrounds, set by the editor, do not serialize
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private TextureBrush transparencyBackgroundBrush;
|
private Brush transparencyBackgroundBrush;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The buffer is only for drawing on it when using filters (to supply access)
|
/// The buffer is only for drawing on it when using filters (to supply access)
|
||||||
|
@ -225,7 +225,6 @@ namespace Greenshot.Drawing {
|
||||||
/// The image is the actual captured image, needed with serialization
|
/// The image is the actual captured image, needed with serialization
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Image image = null;
|
private Image image = null;
|
||||||
|
|
||||||
public Image Image {
|
public Image Image {
|
||||||
get {
|
get {
|
||||||
return image;
|
return image;
|
||||||
|
@ -235,6 +234,10 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The field aggregator is that which is used to have access to all the fields inside the currently selected elements.
|
||||||
|
/// e.g. used to decided if and which line thickness is shown when multiple elements are selected.
|
||||||
|
/// </summary>
|
||||||
public FieldAggregator FieldAggregator {
|
public FieldAggregator FieldAggregator {
|
||||||
get {
|
get {
|
||||||
return fieldAggregator;
|
return fieldAggregator;
|
||||||
|
@ -244,24 +247,36 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The cursor container has it's own accessor so we can find and remove this (when needed)
|
||||||
|
/// </summary>
|
||||||
public IDrawableContainer CursorContainer {
|
public IDrawableContainer CursorContainer {
|
||||||
get {
|
get {
|
||||||
return cursorContainer;
|
return cursorContainer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A simple getter to ask if this surface has a cursor
|
||||||
|
/// </summary>
|
||||||
public bool HasCursor {
|
public bool HasCursor {
|
||||||
get {
|
get {
|
||||||
return cursorContainer != null;
|
return cursorContainer != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A simple helper method to remove the cursor from the surface
|
||||||
|
/// </summary>
|
||||||
public void RemoveCursor() {
|
public void RemoveCursor() {
|
||||||
RemoveElement(cursorContainer, true);
|
RemoveElement(cursorContainer, true);
|
||||||
cursorContainer = null;
|
cursorContainer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextureBrush TransparencyBackgroundBrush {
|
/// <summary>
|
||||||
|
/// The brush which is used to draw the transparent background
|
||||||
|
/// </summary>
|
||||||
|
public Brush TransparencyBackgroundBrush {
|
||||||
get {
|
get {
|
||||||
return transparencyBackgroundBrush;
|
return transparencyBackgroundBrush;
|
||||||
}
|
}
|
||||||
|
@ -270,6 +285,9 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Are the keys on this surface locked?
|
||||||
|
/// </summary>
|
||||||
public bool KeysLocked {
|
public bool KeysLocked {
|
||||||
get {
|
get {
|
||||||
return keysLocked;
|
return keysLocked;
|
||||||
|
@ -279,6 +297,9 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is this surface modified? This is only true if the surface has not been exported.
|
||||||
|
/// </summary>
|
||||||
public bool Modified {
|
public bool Modified {
|
||||||
get {
|
get {
|
||||||
return modified;
|
return modified;
|
||||||
|
@ -288,6 +309,9 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The DrawingMode property specifies the mode for drawing, more or less the element type.
|
||||||
|
/// </summary>
|
||||||
public DrawingModes DrawingMode {
|
public DrawingModes DrawingMode {
|
||||||
get {return drawingMode;}
|
get {return drawingMode;}
|
||||||
set {
|
set {
|
||||||
|
@ -300,6 +324,9 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Property for accessing the last save "full" path
|
||||||
|
/// </summary>
|
||||||
public string LastSaveFullPath {
|
public string LastSaveFullPath {
|
||||||
get {
|
get {
|
||||||
return lastSaveFullPath;
|
return lastSaveFullPath;
|
||||||
|
@ -309,11 +336,17 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Property for accessing the URL to which the surface was recently uploaded
|
||||||
|
/// </summary>
|
||||||
public string UploadURL {
|
public string UploadURL {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Property for accessing the capture details
|
||||||
|
/// </summary>
|
||||||
public ICaptureDetails CaptureDetails {
|
public ICaptureDetails CaptureDetails {
|
||||||
get {
|
get {
|
||||||
return captureDetails;
|
return captureDetails;
|
||||||
|
@ -323,6 +356,9 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base Surface constructor
|
||||||
|
/// </summary>
|
||||||
public Surface() : base(){
|
public Surface() : base(){
|
||||||
LOG.Debug("Creating a surface!");
|
LOG.Debug("Creating a surface!");
|
||||||
this.MouseDown += new MouseEventHandler(SurfaceMouseDown);
|
this.MouseDown += new MouseEventHandler(SurfaceMouseDown);
|
||||||
|
@ -362,11 +398,19 @@ namespace Greenshot.Drawing {
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Surface constructor with an image
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newImage"></param>
|
||||||
public Surface(Image newImage) : this() {
|
public Surface(Image newImage) : this() {
|
||||||
LOG.Debug("Got image with dimensions " + newImage.Width + "," + newImage.Height + " bpp: " + newImage.PixelFormat);
|
LOG.Debug("Got image with dimensions " + newImage.Width + "," + newImage.Height + " bpp: " + newImage.PixelFormat);
|
||||||
SetImage(newImage, true);
|
SetImage(newImage, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Surface contructor with a capture
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="capture"></param>
|
||||||
public Surface(ICapture capture) : this(capture.Image) {
|
public Surface(ICapture capture) : this(capture.Image) {
|
||||||
// Make sure the image is NOT disposed, we took the reference directly into ourselves
|
// Make sure the image is NOT disposed, we took the reference directly into ourselves
|
||||||
((Capture)capture).NullImage();
|
((Capture)capture).NullImage();
|
||||||
|
@ -378,10 +422,10 @@ namespace Greenshot.Drawing {
|
||||||
captureDetails = capture.CaptureDetails;
|
captureDetails = capture.CaptureDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// <summary>
|
||||||
* The public accessible Dispose
|
/// The public accessible Dispose
|
||||||
* Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
|
/// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
|
||||||
*/
|
/// </summary>
|
||||||
public new void Dispose() {
|
public new void Dispose() {
|
||||||
LOG.Debug("Disposing a surface!");
|
LOG.Debug("Disposing a surface!");
|
||||||
if (buffer != null) {
|
if (buffer != null) {
|
||||||
|
@ -428,31 +472,44 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns if the surface can do a undo
|
||||||
|
/// </summary>
|
||||||
public bool CanUndo {
|
public bool CanUndo {
|
||||||
get {
|
get {
|
||||||
return undoStack.Count > 0;
|
return undoStack.Count > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns if the surface can do a redo
|
||||||
|
/// </summary>
|
||||||
public bool CanRedo {
|
public bool CanRedo {
|
||||||
get {
|
get {
|
||||||
return redoStack.Count > 0;
|
return redoStack.Count > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LangKey UndoActionKey {
|
/// <summary>
|
||||||
|
/// Get the language key for the undo action
|
||||||
|
/// </summary>
|
||||||
|
public LangKey UndoActionLanguageKey {
|
||||||
get {
|
get {
|
||||||
if (CanUndo) {
|
if (CanUndo) {
|
||||||
return undoStack.Peek().ActionKey;
|
return undoStack.Peek().ActionLanguageKey;
|
||||||
} else {
|
} else {
|
||||||
return LangKey.none;
|
return LangKey.none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LangKey RedoActionKey {
|
/// <summary>
|
||||||
|
/// Get the language key for redo action
|
||||||
|
/// </summary>
|
||||||
|
public LangKey RedoActionLanguageKey {
|
||||||
get {
|
get {
|
||||||
if (CanRedo) {
|
if (CanRedo) {
|
||||||
return redoStack.Peek().ActionKey;
|
return redoStack.Peek().ActionLanguageKey;
|
||||||
} else {
|
} else {
|
||||||
return LangKey.none;
|
return LangKey.none;
|
||||||
}
|
}
|
||||||
|
@ -483,6 +540,12 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This saves the elements of this surface to a stream.
|
||||||
|
/// Is used to save a template of the complete surface
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="streamWrite"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public long SaveElementsToStream(Stream streamWrite) {
|
public long SaveElementsToStream(Stream streamWrite) {
|
||||||
long bytesWritten = 0;
|
long bytesWritten = 0;
|
||||||
try {
|
try {
|
||||||
|
@ -496,6 +559,10 @@ namespace Greenshot.Drawing {
|
||||||
return bytesWritten;
|
return bytesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This loads elements from a stream, among others this is used to load a surface.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="streamRead"></param>
|
||||||
public void LoadElementsFromStream(Stream streamRead) {
|
public void LoadElementsFromStream(Stream streamRead) {
|
||||||
try {
|
try {
|
||||||
BinaryFormatter binaryRead = new BinaryFormatter();
|
BinaryFormatter binaryRead = new BinaryFormatter();
|
||||||
|
@ -512,6 +579,11 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This is called from the DrawingMode setter, which is not very correct...
|
||||||
|
/// But here an element is created which is not yet draw, thus "undrawnElement".
|
||||||
|
/// The element is than used while drawing on the surface.
|
||||||
|
/// </summary>
|
||||||
private void CreateUndrawnElement() {
|
private void CreateUndrawnElement() {
|
||||||
if(undrawnElement != null) {
|
if(undrawnElement != null) {
|
||||||
FieldAggregator.UnbindElement(undrawnElement);
|
FieldAggregator.UnbindElement(undrawnElement);
|
||||||
|
@ -878,11 +950,18 @@ namespace Greenshot.Drawing {
|
||||||
/// <returns>true if this is possible</returns>
|
/// <returns>true if this is possible</returns>
|
||||||
public bool isCropPossible(ref Rectangle cropRectangle) {
|
public bool isCropPossible(ref Rectangle cropRectangle) {
|
||||||
cropRectangle = Helpers.GuiRectangle.GetGuiRectangle(cropRectangle.Left, cropRectangle.Top, cropRectangle.Width, cropRectangle.Height);
|
cropRectangle = Helpers.GuiRectangle.GetGuiRectangle(cropRectangle.Left, cropRectangle.Top, cropRectangle.Width, cropRectangle.Height);
|
||||||
if (cropRectangle.Left < 0) cropRectangle = new Rectangle(0, cropRectangle.Top, cropRectangle.Width + cropRectangle.Left, cropRectangle.Height);
|
if (cropRectangle.Left < 0) {
|
||||||
if (cropRectangle.Top < 0) cropRectangle = new Rectangle(cropRectangle.Left, 0, cropRectangle.Width, cropRectangle.Height + cropRectangle.Top);
|
cropRectangle = new Rectangle(0, cropRectangle.Top, cropRectangle.Width + cropRectangle.Left, cropRectangle.Height);
|
||||||
if (cropRectangle.Left + cropRectangle.Width > Width) cropRectangle = new Rectangle(cropRectangle.Left, cropRectangle.Top, Width - cropRectangle.Left, cropRectangle.Height);
|
}
|
||||||
if (cropRectangle.Top + cropRectangle.Height > Height) cropRectangle = new Rectangle(cropRectangle.Left, cropRectangle.Top, cropRectangle.Width, Height - cropRectangle.Top);
|
if (cropRectangle.Top < 0) {
|
||||||
|
cropRectangle = new Rectangle(cropRectangle.Left, 0, cropRectangle.Width, cropRectangle.Height + cropRectangle.Top);
|
||||||
|
}
|
||||||
|
if (cropRectangle.Left + cropRectangle.Width > Width) {
|
||||||
|
cropRectangle = new Rectangle(cropRectangle.Left, cropRectangle.Top, Width - cropRectangle.Left, cropRectangle.Height);
|
||||||
|
}
|
||||||
|
if (cropRectangle.Top + cropRectangle.Height > Height) {
|
||||||
|
cropRectangle = new Rectangle(cropRectangle.Left, cropRectangle.Top, cropRectangle.Width, Height - cropRectangle.Top);
|
||||||
|
}
|
||||||
if (cropRectangle.Height > 0 && cropRectangle.Width > 0) {
|
if (cropRectangle.Height > 0 && cropRectangle.Width > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -931,6 +1010,12 @@ namespace Greenshot.Drawing {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The background here is the captured image.
|
||||||
|
/// This is called from the SurfaceBackgroundChangeMemento.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="previous"></param>
|
||||||
|
/// <param name="offset"></param>
|
||||||
public void UndoBackgroundChange(Image previous, Point offset) {
|
public void UndoBackgroundChange(Image previous, Point offset) {
|
||||||
SetImage(previous, false);
|
SetImage(previous, false);
|
||||||
elements.MoveBy(offset.X, offset.Y);
|
elements.MoveBy(offset.X, offset.Y);
|
||||||
|
@ -940,6 +1025,11 @@ namespace Greenshot.Drawing {
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This event handler is called when someone presses the mouse on a surface.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
void SurfaceMouseDown(object sender, MouseEventArgs e) {
|
void SurfaceMouseDown(object sender, MouseEventArgs e) {
|
||||||
mouseStart = e.Location;
|
mouseStart = e.Location;
|
||||||
|
|
||||||
|
@ -1003,6 +1093,11 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This event handle is called when the mouse button is unpressed
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
void SurfaceMouseUp(object sender, MouseEventArgs e) {
|
void SurfaceMouseUp(object sender, MouseEventArgs e) {
|
||||||
Point currentMouse = new Point(e.X, e.Y);
|
Point currentMouse = new Point(e.X, e.Y);
|
||||||
|
|
||||||
|
@ -1059,6 +1154,11 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This event handler is called when the mouse moves over the surface
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
void SurfaceMouseMove(object sender, MouseEventArgs e) {
|
void SurfaceMouseMove(object sender, MouseEventArgs e) {
|
||||||
Point currentMouse = e.Location;
|
Point currentMouse = e.Location;
|
||||||
|
|
||||||
|
@ -1100,11 +1200,21 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This event handler is called when the surface is double clicked.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
void SurfaceDoubleClick(object sender, MouseEventArgs e) {
|
void SurfaceDoubleClick(object sender, MouseEventArgs e) {
|
||||||
selectedElements.OnDoubleClick();
|
selectedElements.OnDoubleClick();
|
||||||
selectedElements.Invalidate();
|
selectedElements.Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Privately used to get the rendered image with all the elements on it.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="renderMode"></param>
|
||||||
|
/// <returns></returns>
|
||||||
private Image GetImage(RenderMode renderMode) {
|
private Image GetImage(RenderMode renderMode) {
|
||||||
// Generate a copy of the original image with a dpi equal to the default...
|
// Generate a copy of the original image with a dpi equal to the default...
|
||||||
Bitmap clone = ImageHelper.Clone(image);
|
Bitmap clone = ImageHelper.Clone(image);
|
||||||
|
@ -1120,6 +1230,10 @@ namespace Greenshot.Drawing {
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This returns the image "result" of this surface, with all the elements rendered on it.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public Image GetImageForExport() {
|
public Image GetImageForExport() {
|
||||||
return GetImage(RenderMode.EXPORT);
|
return GetImage(RenderMode.EXPORT);
|
||||||
}
|
}
|
||||||
|
@ -1166,7 +1280,10 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a checkboard when capturing with transparency
|
/// <summary>
|
||||||
|
/// Draw a checkboard when capturing with transparency
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e">PaintEventArgs</param>
|
||||||
protected override void OnPaintBackground(PaintEventArgs e) {
|
protected override void OnPaintBackground(PaintEventArgs e) {
|
||||||
// check if we need to draw the checkerboard
|
// check if we need to draw the checkerboard
|
||||||
if (Image.IsAlphaPixelFormat(Image.PixelFormat) && transparencyBackgroundBrush != null) {
|
if (Image.IsAlphaPixelFormat(Image.PixelFormat) && transparencyBackgroundBrush != null) {
|
||||||
|
@ -1210,6 +1327,11 @@ namespace Greenshot.Drawing {
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove an element of the elements list
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="elementToRemove">Element to remove</param>
|
||||||
|
/// <param name="makeUndoable">flag specifying if the remove needs to be undoable</param>
|
||||||
public void RemoveElement(IDrawableContainer elementToRemove, bool makeUndoable) {
|
public void RemoveElement(IDrawableContainer elementToRemove, bool makeUndoable) {
|
||||||
DeselectElement(elementToRemove);
|
DeselectElement(elementToRemove);
|
||||||
elements.Remove(elementToRemove);
|
elements.Remove(elementToRemove);
|
||||||
|
@ -1226,18 +1348,31 @@ namespace Greenshot.Drawing {
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add the supplied elements to the surface
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="elementsToAdd"></param>
|
||||||
public void AddElements(DrawableContainerList elementsToAdd) {
|
public void AddElements(DrawableContainerList elementsToAdd) {
|
||||||
foreach(IDrawableContainer element in elementsToAdd) {
|
foreach(IDrawableContainer element in elementsToAdd) {
|
||||||
AddElement(element, true);
|
AddElement(element, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasSelectedElements() {
|
/// <summary>
|
||||||
|
/// Returns if this surface has selected elements
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool HasSelectedElements {
|
||||||
|
get {
|
||||||
return (selectedElements != null && selectedElements.Count > 0);
|
return (selectedElements != null && selectedElements.Count > 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove all the selected elements
|
||||||
|
/// </summary>
|
||||||
public void RemoveSelectedElements() {
|
public void RemoveSelectedElements() {
|
||||||
if (HasSelectedElements()) {
|
if (HasSelectedElements) {
|
||||||
// As RemoveElement will remove the element from the selectedElements list we need to copy the element
|
// As RemoveElement will remove the element from the selectedElements list we need to copy the element
|
||||||
// to another list.
|
// to another list.
|
||||||
List<DrawableContainer> elementsToRemove = new List<DrawableContainer>();
|
List<DrawableContainer> elementsToRemove = new List<DrawableContainer>();
|
||||||
|
@ -1256,19 +1391,30 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cut the selected elements from the surface to the clipboard
|
||||||
|
/// </summary>
|
||||||
public void CutSelectedElements() {
|
public void CutSelectedElements() {
|
||||||
if (HasSelectedElements()) {
|
if (HasSelectedElements) {
|
||||||
ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), selectedElements);
|
ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), selectedElements);
|
||||||
RemoveSelectedElements();
|
RemoveSelectedElements();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Copy the selected elements to the clipboard
|
||||||
|
/// </summary>
|
||||||
public void CopySelectedElements() {
|
public void CopySelectedElements() {
|
||||||
if (HasSelectedElements()) {
|
if (HasSelectedElements) {
|
||||||
ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), selectedElements);
|
ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), selectedElements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This method is called to confirm/cancel "confirmable" elements, like the crop-container.
|
||||||
|
/// Called when pressing enter or using the "check" in the editor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="confirm"></param>
|
||||||
public void ConfirmSelectedConfirmableElements(bool confirm){
|
public void ConfirmSelectedConfirmableElements(bool confirm){
|
||||||
// create new collection so that we can iterate safely (selectedElements might change due with confirm/cancel)
|
// create new collection so that we can iterate safely (selectedElements might change due with confirm/cancel)
|
||||||
List<IDrawableContainer> selectedDCs = new List<IDrawableContainer>(selectedElements);
|
List<IDrawableContainer> selectedDCs = new List<IDrawableContainer>(selectedElements);
|
||||||
|
@ -1285,6 +1431,9 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Paste all the elements that are on the clipboard
|
||||||
|
/// </summary>
|
||||||
public void PasteElementFromClipboard() {
|
public void PasteElementFromClipboard() {
|
||||||
List<string> formats = ClipboardHelper.GetFormats();
|
List<string> formats = ClipboardHelper.GetFormats();
|
||||||
if (formats == null || formats.Count == 0) {
|
if (formats == null || formats.Count == 0) {
|
||||||
|
@ -1326,8 +1475,11 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Duplicate all the selecteded elements
|
||||||
|
/// </summary>
|
||||||
public void DuplicateSelectedElements() {
|
public void DuplicateSelectedElements() {
|
||||||
if(LOG.IsDebugEnabled) LOG.Debug("Duplicating "+selectedElements.Count+" selected elements");
|
LOG.DebugFormat("Duplicating {0} selected elements", selectedElements.Count);
|
||||||
DrawableContainerList dcs = selectedElements.Clone();
|
DrawableContainerList dcs = selectedElements.Clone();
|
||||||
dcs.Parent = this;
|
dcs.Parent = this;
|
||||||
dcs.MoveBy(10,10);
|
dcs.MoveBy(10,10);
|
||||||
|
@ -1336,6 +1488,10 @@ namespace Greenshot.Drawing {
|
||||||
SelectElements(dcs);
|
SelectElements(dcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deselect the specified element
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="container"></param>
|
||||||
public void DeselectElement(IDrawableContainer container) {
|
public void DeselectElement(IDrawableContainer container) {
|
||||||
container.HideGrippers();
|
container.HideGrippers();
|
||||||
container.Selected = false;
|
container.Selected = false;
|
||||||
|
@ -1346,8 +1502,11 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deselect all the selected elements
|
||||||
|
/// </summary>
|
||||||
public void DeselectAllElements() {
|
public void DeselectAllElements() {
|
||||||
if (HasSelectedElements()) {
|
if (HasSelectedElements) {
|
||||||
while(selectedElements.Count > 0) {
|
while(selectedElements.Count > 0) {
|
||||||
IDrawableContainer element = selectedElements[0];
|
IDrawableContainer element = selectedElements[0];
|
||||||
element.Invalidate();
|
element.Invalidate();
|
||||||
|
@ -1362,6 +1521,10 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Select the supplied element
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="container"></param>
|
||||||
public void SelectElement(IDrawableContainer container) {
|
public void SelectElement(IDrawableContainer container) {
|
||||||
if (!selectedElements.Contains(container)) {
|
if (!selectedElements.Contains(container)) {
|
||||||
selectedElements.Add(container);
|
selectedElements.Add(container);
|
||||||
|
@ -1375,16 +1538,27 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Select all elements, this is called when Ctrl+A is pressed
|
||||||
|
/// </summary>
|
||||||
public void SelectAllElements() {
|
public void SelectAllElements() {
|
||||||
SelectElements(elements);
|
SelectElements(elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Select the supplied elements
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="elements"></param>
|
||||||
public void SelectElements(DrawableContainerList elements) {
|
public void SelectElements(DrawableContainerList elements) {
|
||||||
foreach(DrawableContainer element in elements) {
|
foreach(DrawableContainer element in elements) {
|
||||||
SelectElement(element);
|
SelectElement(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Process key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="k"></param>
|
||||||
public void ProcessCmdKey(Keys k) {
|
public void ProcessCmdKey(Keys k) {
|
||||||
if (selectedElements.Count > 0) {
|
if (selectedElements.Count > 0) {
|
||||||
bool shiftModifier = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;
|
bool shiftModifier = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;
|
||||||
|
@ -1439,6 +1613,9 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Property for accessing the elements on the surface
|
||||||
|
/// </summary>
|
||||||
public DrawableContainerList Elements {
|
public DrawableContainerList Elements {
|
||||||
get {
|
get {
|
||||||
return elements;
|
return elements;
|
||||||
|
|
|
@ -811,8 +811,8 @@ namespace Greenshot {
|
||||||
this.undoToolStripMenuItem.Enabled = canUndo;
|
this.undoToolStripMenuItem.Enabled = canUndo;
|
||||||
string undoAction = "";
|
string undoAction = "";
|
||||||
if (canUndo) {
|
if (canUndo) {
|
||||||
if (surface.UndoActionKey != LangKey.none) {
|
if (surface.UndoActionLanguageKey != LangKey.none) {
|
||||||
undoAction = Language.GetString(surface.UndoActionKey);
|
undoAction = Language.GetString(surface.UndoActionLanguageKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string undoText = Language.GetFormattedString(LangKey.editor_undo, undoAction);
|
string undoText = Language.GetFormattedString(LangKey.editor_undo, undoAction);
|
||||||
|
@ -824,8 +824,8 @@ namespace Greenshot {
|
||||||
this.redoToolStripMenuItem.Enabled = canRedo;
|
this.redoToolStripMenuItem.Enabled = canRedo;
|
||||||
string redoAction = "";
|
string redoAction = "";
|
||||||
if (canRedo) {
|
if (canRedo) {
|
||||||
if (surface.RedoActionKey != LangKey.none) {
|
if (surface.RedoActionLanguageKey != LangKey.none) {
|
||||||
redoAction = Language.GetString(surface.RedoActionKey);
|
redoAction = Language.GetString(surface.RedoActionLanguageKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string redoText = Language.GetFormattedString(LangKey.editor_redo, redoAction);
|
string redoText = Language.GetFormattedString(LangKey.editor_redo, redoAction);
|
||||||
|
@ -839,7 +839,7 @@ namespace Greenshot {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// check dependencies for the Surface
|
// check dependencies for the Surface
|
||||||
bool hasItems = surface.HasSelectedElements();
|
bool hasItems = surface.HasSelectedElements;
|
||||||
bool actionAllowedForSelection = hasItems && !controlsDisabledDueToConfirmable;
|
bool actionAllowedForSelection = hasItems && !controlsDisabledDueToConfirmable;
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
|
@ -918,7 +918,7 @@ namespace Greenshot {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void refreshFieldControls() {
|
private void refreshFieldControls() {
|
||||||
propertiesToolStrip.SuspendLayout();
|
propertiesToolStrip.SuspendLayout();
|
||||||
if(surface.HasSelectedElements() || surface.DrawingMode != DrawingModes.None) {
|
if(surface.HasSelectedElements || surface.DrawingMode != DrawingModes.None) {
|
||||||
FieldAggregator props = surface.FieldAggregator;
|
FieldAggregator props = surface.FieldAggregator;
|
||||||
btnFillColor.Visible = props.HasFieldValue(FieldType.FILL_COLOR);
|
btnFillColor.Visible = props.HasFieldValue(FieldType.FILL_COLOR);
|
||||||
btnLineColor.Visible = props.HasFieldValue(FieldType.LINE_COLOR);
|
btnLineColor.Visible = props.HasFieldValue(FieldType.LINE_COLOR);
|
||||||
|
@ -983,7 +983,7 @@ namespace Greenshot {
|
||||||
updateUndoRedoSurfaceDependencies();
|
updateUndoRedoSurfaceDependencies();
|
||||||
|
|
||||||
// en/disablearrage controls depending on hierarchy of selected elements
|
// en/disablearrage controls depending on hierarchy of selected elements
|
||||||
bool actionAllowedForSelection = surface.HasSelectedElements() && !controlsDisabledDueToConfirmable;
|
bool actionAllowedForSelection = surface.HasSelectedElements && !controlsDisabledDueToConfirmable;
|
||||||
bool push = actionAllowedForSelection && surface.CanPushSelectionDown();
|
bool push = actionAllowedForSelection && surface.CanPushSelectionDown();
|
||||||
bool pull = actionAllowedForSelection && surface.CanPullSelectionUp();
|
bool pull = actionAllowedForSelection && surface.CanPullSelectionUp();
|
||||||
this.arrangeToolStripMenuItem.Enabled = (push || pull);
|
this.arrangeToolStripMenuItem.Enabled = (push || pull);
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace Greenshot.Memento {
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LangKey ActionKey {
|
public LangKey ActionLanguageKey {
|
||||||
get {
|
get {
|
||||||
return LangKey.none;
|
return LangKey.none;
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,12 @@ namespace Greenshot.Memento {
|
||||||
public IMemento Restore() {
|
public IMemento Restore() {
|
||||||
// Before
|
// Before
|
||||||
drawableContainer.Invalidate();
|
drawableContainer.Invalidate();
|
||||||
|
// Store the selected state, as it's overwritten by the RemoveElement
|
||||||
|
bool selected = drawableContainer.Selected;
|
||||||
|
|
||||||
DeleteElementMemento oldState = new DeleteElementMemento(surface, drawableContainer);
|
DeleteElementMemento oldState = new DeleteElementMemento(surface, drawableContainer);
|
||||||
surface.RemoveElement(drawableContainer, false);
|
surface.RemoveElement(drawableContainer, false);
|
||||||
|
drawableContainer.Selected = true;
|
||||||
|
|
||||||
// After
|
// After
|
||||||
drawableContainer.Invalidate();
|
drawableContainer.Invalidate();
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace Greenshot.Memento {
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LangKey ActionKey {
|
public LangKey ActionLanguageKey {
|
||||||
get {
|
get {
|
||||||
return LangKey.none;
|
return LangKey.none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace Greenshot.Memento {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LangKey ActionKey {
|
public LangKey ActionLanguageKey {
|
||||||
get {
|
get {
|
||||||
//return LangKey.editor_deleteelement;
|
//return LangKey.editor_deleteelement;
|
||||||
return LangKey.none;
|
return LangKey.none;
|
||||||
|
@ -60,6 +60,10 @@ namespace Greenshot.Memento {
|
||||||
|
|
||||||
AddElementMemento oldState = new AddElementMemento(surface, drawableContainer);
|
AddElementMemento oldState = new AddElementMemento(surface, drawableContainer);
|
||||||
surface.AddElement(drawableContainer, false);
|
surface.AddElement(drawableContainer, false);
|
||||||
|
// The container has a selected flag which represents the state at the moment it was deleted.
|
||||||
|
if (drawableContainer.Selected) {
|
||||||
|
surface.SelectElement(drawableContainer);
|
||||||
|
}
|
||||||
|
|
||||||
// After
|
// After
|
||||||
drawableContainer.Invalidate();
|
drawableContainer.Invalidate();
|
||||||
|
|
|
@ -56,7 +56,7 @@ namespace Greenshot.Memento {
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LangKey ActionKey {
|
public LangKey ActionLanguageKey {
|
||||||
get {
|
get {
|
||||||
return LangKey.none;
|
return LangKey.none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace Greenshot.Memento {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the language key for the action which is performed
|
/// Returns the language key for the action which is performed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
LangKey ActionKey {
|
LangKey ActionLanguageKey {
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace Greenshot.Memento {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LangKey ActionKey {
|
public LangKey ActionLanguageKey {
|
||||||
get {
|
get {
|
||||||
//return LangKey.editor_crop;
|
//return LangKey.editor_crop;
|
||||||
return LangKey.none;
|
return LangKey.none;
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace Greenshot.Memento {
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LangKey ActionKey {
|
public LangKey ActionLanguageKey {
|
||||||
get {
|
get {
|
||||||
return LangKey.none;
|
return LangKey.none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,9 @@ namespace Greenshot.Plugin {
|
||||||
long SaveElementsToStream(Stream stream);
|
long SaveElementsToStream(Stream stream);
|
||||||
void LoadElementsFromStream(Stream stream);
|
void LoadElementsFromStream(Stream stream);
|
||||||
|
|
||||||
bool HasSelectedElements();
|
bool HasSelectedElements {
|
||||||
|
get;
|
||||||
|
}
|
||||||
void RemoveSelectedElements();
|
void RemoveSelectedElements();
|
||||||
void CutSelectedElements();
|
void CutSelectedElements();
|
||||||
void CopySelectedElements();
|
void CopySelectedElements();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue