mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-03 02:36:50 +13:00
Added delete selected and delete all to context menu
This commit is contained in:
parent
ee11959beb
commit
5b3b7636e9
1 changed files with 50 additions and 4 deletions
|
@ -36,9 +36,22 @@ public class ShapeManager
|
||||||
{
|
{
|
||||||
public List<BaseShape> Shapes { get; private set; } = new List<BaseShape>();
|
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
|
public ShapeType CurrentShapeType
|
||||||
{
|
{
|
||||||
|
@ -49,9 +62,9 @@ public ShapeType CurrentShapeType
|
||||||
private set
|
private set
|
||||||
{
|
{
|
||||||
currentShapeType = value;
|
currentShapeType = value;
|
||||||
config.CurrentShapeType = CurrentShapeType;
|
config.CurrentShapeType = currentShapeType;
|
||||||
DeselectArea();
|
DeselectArea();
|
||||||
OnCurrentShapeTypeChanged(CurrentShapeType);
|
OnCurrentShapeTypeChanged(currentShapeType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,6 +162,7 @@ public bool IsResizing
|
||||||
public bool IncludeControls { get; set; }
|
public bool IncludeControls { get; set; }
|
||||||
public int MinimumSize { get; set; } = 3;
|
public int MinimumSize { get; set; } = 3;
|
||||||
|
|
||||||
|
public event Action<BaseShape> CurrentShapeChanged;
|
||||||
public event Action<ShapeType> CurrentShapeTypeChanged;
|
public event Action<ShapeType> CurrentShapeTypeChanged;
|
||||||
|
|
||||||
private RectangleRegionForm surface;
|
private RectangleRegionForm surface;
|
||||||
|
@ -170,6 +184,7 @@ public ShapeManager(RectangleRegionForm surface)
|
||||||
|
|
||||||
CreateContextMenu();
|
CreateContextMenu();
|
||||||
|
|
||||||
|
CurrentShape = null;
|
||||||
//CurrentShapeType = config.CurrentShapeType;
|
//CurrentShapeType = config.CurrentShapeType;
|
||||||
CurrentShapeType = ShapeType.RegionRectangle;
|
CurrentShapeType = ShapeType.RegionRectangle;
|
||||||
}
|
}
|
||||||
|
@ -198,6 +213,17 @@ private void CreateContextMenu()
|
||||||
tsmiCloseMenu.Click += (sender, e) => cmsContextMenu.Close();
|
tsmiCloseMenu.Click += (sender, e) => cmsContextMenu.Close();
|
||||||
cmsContextMenu.Items.Add(tsmiCloseMenu);
|
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());
|
cmsContextMenu.Items.Add(new ToolStripSeparator());
|
||||||
|
|
||||||
foreach (ShapeType shapeType in Helpers.GetEnums<ShapeType>())
|
foreach (ShapeType shapeType in Helpers.GetEnums<ShapeType>())
|
||||||
|
@ -417,6 +443,12 @@ private void CreateContextMenu()
|
||||||
tsmiShowFPS.Click += (sender, e) => config.ShowFPS = tsmiShowFPS.Checked;
|
tsmiShowFPS.Click += (sender, e) => config.ShowFPS = tsmiShowFPS.Checked;
|
||||||
tsmiOptions.DropDownItems.Add(tsmiShowFPS);
|
tsmiOptions.DropDownItems.Add(tsmiShowFPS);
|
||||||
|
|
||||||
|
CurrentShapeChanged += shape =>
|
||||||
|
{
|
||||||
|
tssObjectOptions.Visible = tsmiDeleteAll.Visible = Shapes.Count > 0;
|
||||||
|
tsmiDeleteSelected.Visible = shape != null;
|
||||||
|
};
|
||||||
|
|
||||||
CurrentShapeTypeChanged += shapeType =>
|
CurrentShapeTypeChanged += shapeType =>
|
||||||
{
|
{
|
||||||
foreach (ToolStripMenuItem tsmi in cmsContextMenu.Items.OfType<ToolStripMenuItem>().Where(x => x.Tag is 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)
|
private bool IsAreaValid(Rectangle rect)
|
||||||
{
|
{
|
||||||
return !rect.IsEmpty && rect.Width >= MinimumSize && rect.Height >= MinimumSize;
|
return !rect.IsEmpty && rect.Width >= MinimumSize && rect.Height >= MinimumSize;
|
||||||
|
@ -1006,6 +1044,14 @@ public Rectangle CombineAreas()
|
||||||
return Rectangle.Empty;
|
return Rectangle.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnCurrentShapeChanged(BaseShape shape)
|
||||||
|
{
|
||||||
|
if (CurrentShapeChanged != null)
|
||||||
|
{
|
||||||
|
CurrentShapeChanged(shape);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnCurrentShapeTypeChanged(ShapeType shapeType)
|
private void OnCurrentShapeTypeChanged(ShapeType shapeType)
|
||||||
{
|
{
|
||||||
if (CurrentShapeTypeChanged != null)
|
if (CurrentShapeTypeChanged != null)
|
||||||
|
|
Loading…
Reference in a new issue