mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-28 03:00:22 +12:00
Fixed undo/redo bugs
This commit is contained in:
parent
40bd40c52e
commit
69e95870de
|
@ -77,8 +77,11 @@ public void CreateCanvasMemento()
|
|||
|
||||
public void CreateShapesMemento()
|
||||
{
|
||||
ImageEditorMemento memento = GetMementoFromShapes();
|
||||
AddMemento(memento);
|
||||
if (!shapeManager.IsCurrentShapeTypeRegion && shapeManager.CurrentTool != ShapeType.ToolCrop && shapeManager.CurrentTool != ShapeType.ToolCutOut)
|
||||
{
|
||||
ImageEditorMemento memento = GetMementoFromShapes();
|
||||
AddMemento(memento);
|
||||
}
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
|
|
|
@ -90,6 +90,16 @@ internal class Resources {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrow_circle_315 {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrow_circle_315", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
|
|
|
@ -826,4 +826,7 @@ Would you like to close image editor?</value>
|
|||
<data name="ImageURL" xml:space="preserve">
|
||||
<value>Image URL</value>
|
||||
</data>
|
||||
<data name="arrow_circle_315" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrow-circle-315.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
BIN
ShareX.ScreenCaptureLib/Resources/arrow-circle-315.png
Normal file
BIN
ShareX.ScreenCaptureLib/Resources/arrow-circle-315.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 791 B |
|
@ -192,8 +192,6 @@ private set
|
|||
|
||||
public bool IsCurrentShapeTypeRegion => IsShapeTypeRegion(CurrentTool);
|
||||
|
||||
public bool IsCurrentShapeTypeTool => IsShapeTypeTool(CurrentTool);
|
||||
|
||||
public int StartingStepNumber { get; set; } = 1;
|
||||
|
||||
public bool IsCreating { get; set; }
|
||||
|
@ -629,7 +627,7 @@ private void form_KeyDown(object sender, KeyEventArgs e)
|
|||
}
|
||||
break;
|
||||
case Keys.Shift | Keys.Delete:
|
||||
DeleteAllShapes();
|
||||
DeleteAllShapes(true);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -980,11 +978,6 @@ public void StartRegionSelection()
|
|||
ClearTools();
|
||||
DeselectCurrentShape();
|
||||
|
||||
if (!IsCurrentShapeTypeRegion && !IsCurrentShapeTypeTool)
|
||||
{
|
||||
history.CreateShapesMemento();
|
||||
}
|
||||
|
||||
shape = AddShape();
|
||||
shape.OnCreating();
|
||||
}
|
||||
|
@ -1141,6 +1134,8 @@ private BaseShape AddShape()
|
|||
|
||||
private void AddShape(BaseShape shape)
|
||||
{
|
||||
history.CreateShapesMemento();
|
||||
|
||||
Shapes.Add(shape);
|
||||
CurrentShape = shape;
|
||||
}
|
||||
|
@ -1472,6 +1467,8 @@ public void DeleteShape(BaseShape shape)
|
|||
{
|
||||
if (shape != null)
|
||||
{
|
||||
history.CreateShapesMemento();
|
||||
|
||||
shape.Dispose();
|
||||
Shapes.Remove(shape);
|
||||
DeselectShape(shape);
|
||||
|
@ -1495,10 +1492,15 @@ private void DeleteIntersectShape()
|
|||
DeleteShape(GetIntersectShape());
|
||||
}
|
||||
|
||||
private void DeleteAllShapes()
|
||||
private void DeleteAllShapes(bool takeSnapshot = false)
|
||||
{
|
||||
if (Shapes.Count > 0)
|
||||
{
|
||||
if (takeSnapshot)
|
||||
{
|
||||
history.CreateShapesMemento();
|
||||
}
|
||||
|
||||
foreach (BaseShape shape in Shapes)
|
||||
{
|
||||
shape.Dispose();
|
||||
|
@ -1674,6 +1676,7 @@ public void MoveAll(PointF offset)
|
|||
public void CollapseAllHorizontal(float x, float width)
|
||||
{
|
||||
float x2 = x + width;
|
||||
|
||||
if (width <= 0) return;
|
||||
|
||||
List<BaseShape> toDelete = new List<BaseShape>();
|
||||
|
@ -1681,6 +1684,7 @@ public void CollapseAllHorizontal(float x, float width)
|
|||
foreach (BaseShape shape in Shapes)
|
||||
{
|
||||
RectangleF sr = shape.Rectangle;
|
||||
|
||||
if (sr.Left < x)
|
||||
{
|
||||
if (sr.Right <= x)
|
||||
|
@ -1727,6 +1731,7 @@ public void CollapseAllHorizontal(float x, float width)
|
|||
public void CollapseAllVertical(float y, float height)
|
||||
{
|
||||
float y2 = y + height;
|
||||
|
||||
if (height <= 0) return;
|
||||
|
||||
List<BaseShape> toDelete = new List<BaseShape>();
|
||||
|
@ -1734,6 +1739,7 @@ public void CollapseAllVertical(float y, float height)
|
|||
foreach (BaseShape shape in Shapes)
|
||||
{
|
||||
RectangleF sr = shape.Rectangle;
|
||||
|
||||
if (sr.Top < y)
|
||||
{
|
||||
if (sr.Bottom <= y)
|
||||
|
@ -1801,19 +1807,6 @@ private bool IsShapeTypeRegion(ShapeType shapeType)
|
|||
return false;
|
||||
}
|
||||
|
||||
private bool IsShapeTypeTool(ShapeType shapeType)
|
||||
{
|
||||
switch (shapeType)
|
||||
{
|
||||
case ShapeType.ToolSelect:
|
||||
case ShapeType.ToolCrop:
|
||||
case ShapeType.ToolCutOut:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void UpdateNodes()
|
||||
{
|
||||
BaseShape shape = CurrentShape;
|
||||
|
@ -1865,7 +1858,6 @@ private void DuplicateCurrrentShape(bool insertMousePosition)
|
|||
}
|
||||
|
||||
shapeCopy.OnMoved();
|
||||
history.CreateShapesMemento();
|
||||
AddShape(shapeCopy);
|
||||
SelectCurrentShape();
|
||||
}
|
||||
|
@ -1916,7 +1908,6 @@ private void PasteFromClipboard(bool insertMousePosition)
|
|||
shape.Rectangle = new RectangleF(pos.X, pos.Y, 1, 1);
|
||||
shape.Text = text.Trim();
|
||||
shape.OnCreated();
|
||||
history.CreateShapesMemento();
|
||||
AddShape(shape);
|
||||
SelectCurrentShape();
|
||||
}
|
||||
|
@ -2043,8 +2034,8 @@ public void NewImage()
|
|||
if (bmp != null)
|
||||
{
|
||||
Form.ImageFilePath = "";
|
||||
DeleteAllShapes();
|
||||
history.CreateCanvasMemento();
|
||||
DeleteAllShapes();
|
||||
UpdateMenu();
|
||||
UpdateCanvas(bmp);
|
||||
}
|
||||
|
@ -2070,8 +2061,8 @@ private void LoadImageFile(string filePath)
|
|||
if (bmp != null)
|
||||
{
|
||||
Form.ImageFilePath = filePath;
|
||||
DeleteAllShapes();
|
||||
history.CreateCanvasMemento();
|
||||
DeleteAllShapes();
|
||||
UpdateMenu();
|
||||
UpdateCanvas(bmp);
|
||||
}
|
||||
|
@ -2154,7 +2145,6 @@ private void InsertImage(Image img)
|
|||
shape.Rectangle = new RectangleF(pos.X, pos.Y, 1, 1);
|
||||
shape.SetImage(img, centerImage);
|
||||
shape.OnCreated();
|
||||
history.CreateShapesMemento();
|
||||
AddShape(shape);
|
||||
SelectCurrentShape();
|
||||
}
|
||||
|
|
|
@ -687,7 +687,7 @@ internal void CreateToolbar()
|
|||
tsddbEdit.DropDownItems.Add(tsmiUndo);
|
||||
|
||||
tsmiRedo = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_Redo);
|
||||
tsmiRedo.Image = Resources.arrow_circle;
|
||||
tsmiRedo.Image = Resources.arrow_circle_315;
|
||||
tsmiRedo.ShortcutKeyDisplayString = "Ctrl+Y";
|
||||
tsmiRedo.Click += (sender, e) => history.Redo();
|
||||
tsddbEdit.DropDownItems.Add(tsmiRedo);
|
||||
|
@ -715,7 +715,7 @@ internal void CreateToolbar()
|
|||
tsmiDeleteAll = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_DeleteAll);
|
||||
tsmiDeleteAll.Image = Resources.eraser;
|
||||
tsmiDeleteAll.ShortcutKeyDisplayString = "Shift+Del";
|
||||
tsmiDeleteAll.Click += (sender, e) => DeleteAllShapes();
|
||||
tsmiDeleteAll.Click += (sender, e) => DeleteAllShapes(true);
|
||||
tsddbEdit.DropDownItems.Add(tsmiDeleteAll);
|
||||
|
||||
tsddbEdit.DropDownItems.Add(new ToolStripSeparator());
|
||||
|
|
|
@ -1009,6 +1009,9 @@
|
|||
<ItemGroup>
|
||||
<None Include="Resources\control-pause.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\arrow-circle-315.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
Loading…
Reference in a new issue