diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs b/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs index 3a5501aa8..5bb8e6ed3 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/ShapeManager.cs @@ -36,9 +36,22 @@ public class ShapeManager { public List Shapes { get; private set; } = new List(); - public BaseShape CurrentShape { get; private set; } + private BaseShape currentShape; - private ShapeType currentShapeType = ShapeType.RegionRectangle; + public BaseShape CurrentShape + { + get + { + return currentShape; + } + private set + { + currentShape = value; + OnCurrentShapeChanged(currentShape); + } + } + + private ShapeType currentShapeType; public ShapeType CurrentShapeType { @@ -49,9 +62,9 @@ public ShapeType CurrentShapeType private set { currentShapeType = value; - config.CurrentShapeType = CurrentShapeType; + config.CurrentShapeType = currentShapeType; DeselectArea(); - OnCurrentShapeTypeChanged(CurrentShapeType); + OnCurrentShapeTypeChanged(currentShapeType); } } @@ -149,6 +162,7 @@ public bool IsResizing public bool IncludeControls { get; set; } public int MinimumSize { get; set; } = 3; + public event Action CurrentShapeChanged; public event Action CurrentShapeTypeChanged; private RectangleRegionForm surface; @@ -170,6 +184,7 @@ public ShapeManager(RectangleRegionForm surface) CreateContextMenu(); + CurrentShape = null; //CurrentShapeType = config.CurrentShapeType; CurrentShapeType = ShapeType.RegionRectangle; } @@ -198,6 +213,17 @@ private void CreateContextMenu() tsmiCloseMenu.Click += (sender, e) => cmsContextMenu.Close(); cmsContextMenu.Items.Add(tsmiCloseMenu); + ToolStripSeparator tssObjectOptions = new ToolStripSeparator(); + cmsContextMenu.Items.Add(tssObjectOptions); + + ToolStripMenuItem tsmiDeleteSelected = new ToolStripMenuItem("Delete selected object"); + tsmiDeleteSelected.Click += (sender, e) => RemoveCurrentArea(); + cmsContextMenu.Items.Add(tsmiDeleteSelected); + + ToolStripMenuItem tsmiDeleteAll = new ToolStripMenuItem("Delete all objects"); + tsmiDeleteAll.Click += (sender, e) => ClearAll(); + cmsContextMenu.Items.Add(tsmiDeleteAll); + cmsContextMenu.Items.Add(new ToolStripSeparator()); foreach (ShapeType shapeType in Helpers.GetEnums()) @@ -417,6 +443,12 @@ private void CreateContextMenu() tsmiShowFPS.Click += (sender, e) => config.ShowFPS = tsmiShowFPS.Checked; tsmiOptions.DropDownItems.Add(tsmiShowFPS); + CurrentShapeChanged += shape => + { + tssObjectOptions.Visible = tsmiDeleteAll.Visible = Shapes.Count > 0; + tsmiDeleteSelected.Visible = shape != null; + }; + CurrentShapeTypeChanged += shapeType => { foreach (ToolStripMenuItem tsmi in cmsContextMenu.Items.OfType().Where(x => x.Tag is ShapeType)) @@ -945,6 +977,12 @@ private void RemoveCurrentArea() } } + private void ClearAll() + { + Shapes.Clear(); + DeselectArea(); + } + private bool IsAreaValid(Rectangle rect) { return !rect.IsEmpty && rect.Width >= MinimumSize && rect.Height >= MinimumSize; @@ -1006,6 +1044,14 @@ public Rectangle CombineAreas() return Rectangle.Empty; } + private void OnCurrentShapeChanged(BaseShape shape) + { + if (CurrentShapeChanged != null) + { + CurrentShapeChanged(shape); + } + } + private void OnCurrentShapeTypeChanged(ShapeType shapeType) { if (CurrentShapeTypeChanged != null)