From 9f2974cf6b575e1b5803a82730c96841a92a8ed6 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Wed, 28 Feb 2018 12:18:04 -0600 Subject: [PATCH] Able to right-click and delete shapes --- EduNetworkBuilder/Network.cs | 7 +++++++ EduNetworkBuilder/NetworkBuilder.cs | 30 +++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index 10ab1c3..ec66c80 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -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; } diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index 50fcb21..eefe609 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -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;