Able to right-click and delete shapes

This commit is contained in:
Tim Young 2018-02-28 12:18:04 -06:00
parent e3fe80ea42
commit 9f2974cf6b
2 changed files with 33 additions and 4 deletions

View File

@ -1139,12 +1139,19 @@ namespace EduNetworkBuilder
Shapes.Add(what);
}
public void RemoveShape(NetShape What)
{
Shapes.Remove(What);
}
public NetShape ShapeAtPoint(Point location)
{
foreach(NetShape shape in Shapes)
{
if (shape.CornersAreClickedOn(location))
return shape;
if (shape.CenterIsClickedOn(location))
return shape;
}
return null;
}

View File

@ -831,7 +831,14 @@ namespace EduNetworkBuilder
if (ReleasedOn != null) PoweredOff = ReleasedOn.PowerOff;
pbNetworkView.ContextMenuStrip.Items.Clear();
if(ItemsSelected.Count > 0)
if(myNetwork.InShapeEditMode && ShapeForEditing != null)
{
//context menu for shape
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("_Delete"));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_DeleteShape_Click;
}
if (ItemsSelected.Count > 0)
{
//We do not want to do the normal menu...
LockedOut = false;
@ -995,7 +1002,7 @@ namespace EduNetworkBuilder
(pbNetworkView.ContextMenuStrip.Items[MenuIndex] as ToolStripMenuItem).DropDownItems.Add(NB.Translate("NB_Orange"), null, pbNetworkView_Color_Click);
(pbNetworkView.ContextMenuStrip.Items[MenuIndex] as ToolStripMenuItem).DropDownItems.Add(NB.Translate("NB_Cyan"), null, pbNetworkView_Color_Click);
}
if (ReleasedOn == null && ItemsSelected.Count == 0)
if ((!myNetwork.InShapeEditMode && ReleasedOn == null && ItemsSelected.Count == 0) || (myNetwork.InShapeEditMode && ShapeForEditing == null))
{
pbNetworkView.ContextMenuStrip.Visible = false;
}
@ -1283,6 +1290,17 @@ namespace EduNetworkBuilder
}
}
private void pbNetworkView_DeleteShape_Click(object sender, EventArgs e)
{
if(ShapeForEditing != null)
{
myNetwork.RemoveShape(ShapeForEditing);
ShapeForEditing = null;
UpdateForm();
}
}
private void pbNetworkView_Delete_Click(object sender, EventArgs e)
{
if(ItemsSelected.Count ==0)
@ -1402,7 +1420,7 @@ namespace EduNetworkBuilder
Point ClickLocation = myNetwork.clickedPos(e.Location);
NetworkDevice ReleasedOn = myNetwork.ItemAtPosition(ClickLocation);
NetworkLink ReleasedOnLink = null;
if(ReleasedOn == null)
if(ReleasedOn == null && !myNetwork.InShapeEditMode)
ReleasedOnLink = myNetwork.LinkAtPosition(ClickLocation);
LastBackgroundImage = null;
@ -1660,7 +1678,7 @@ namespace EduNetworkBuilder
{
ItemClickedOn = null;
ShapeForEditing = myNetwork.ShapeAtPoint(location);
if(ShapeForEditing != null)
if(ShapeForEditing != null && e.Button == MouseButtons.Left)
{
//we set the drag-point for the opposite corner
ClickedLocation = ShapeForEditing.OppositePoint(location);
@ -1670,6 +1688,10 @@ namespace EduNetworkBuilder
cbLineColor.Text = ShapeForEditing.LineColor.Name;
btnUpdateShape(); //Change the shape to what we are editing
}
else if(ShapeForEditing != null && e.Button == MouseButtons.Right)
{
//Right-clicking the shape. Context menu to come at button release!
}
}
if(e.Button == MouseButtons.Left)
MouseIsDown = true;