mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-01 12:41:24 +12:00
Added delete selected and delete all to context menu
This commit is contained in:
parent
ee11959beb
commit
5b3b7636e9
|
@ -36,9 +36,22 @@ public class ShapeManager
|
|||
{
|
||||
public List<BaseShape> Shapes { get; private set; } = new List<BaseShape>();
|
||||
|
||||
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<BaseShape> CurrentShapeChanged;
|
||||
public event Action<ShapeType> 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<ShapeType>())
|
||||
|
@ -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<ToolStripMenuItem>().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)
|
||||
|
|
Loading…
Reference in a new issue