From 620ffa1bc24db2e31abc2e8fbc19ded1c3f78e58 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Fri, 16 Feb 2018 17:48:08 +0000 Subject: [PATCH] right-click delete a link --- EduNetworkBuilder/NetworkBuilder.cs | 48 ++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index a565074..a798eb7 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -932,6 +932,27 @@ namespace EduNetworkBuilder } } + private void pbNetworkView_RightMouseUponLink(NetworkLink LinkReleasedOn, MouseEventArgs e) + { + if (LinkReleasedOn == null) return; + if (pbNetworkView.ContextMenuStrip == null) + { + pbNetworkView.ContextMenuStrip = new ContextMenuStrip(); + } + pbNetworkView.ContextMenuStrip.Items.Clear(); + + int index=0; + + //We need to make sure the item is not critical before we delete it. + pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("_Delete")); + pbNetworkView.ContextMenuStrip.Items[index].Tag = LinkReleasedOn; + pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_RemoveNetLink_Click; + + pbNetworkView.ContextMenuStrip.Visible = true; + pbNetworkView.ContextMenuStrip.Show(Cursor.Position); + + } + private void pbNetworkView_Hide_Click(object sender, EventArgs e) { if (ItemClickedOn != null) @@ -1064,6 +1085,21 @@ namespace EduNetworkBuilder } + private void pbNetworkView_RemoveNetLink_Click(object sender, EventArgs e) + { + ToolStripItem thing = (ToolStripItem)sender; + if (thing.Tag != null) + { + NetworkLink NL = (NetworkLink)thing.Tag; + myNetwork.RemoveComponent(NL); + } + myNetwork.TestForCompletion(true); + pbNetworkView.Update(); + UpdateVisuals(); + + } + + private void pbNetworkView_DHCPRequest_Click(object sender, EventArgs e) { ItemClickedOn.DHCPRequestFromHere(); @@ -1245,6 +1281,15 @@ namespace EduNetworkBuilder TimeSpan duration; duration = DateTime.Now - LastClick; + if(ReleasedOnLink != null && e.Button == MouseButtons.Right) + { + //Right-click on a line. Make a special context menu for that. + // delete + // edit + pbNetworkView_RightMouseUponLink(ReleasedOnLink, e); + return; //We do not do the rest of this... + } + //Track size of area for the click/drag int sx; int sy; @@ -1418,7 +1463,8 @@ namespace EduNetworkBuilder ClickedImageLocation = e.Location; //See if we have clicked on something ItemClickedOn = myNetwork.ItemAtPosition(location); - MouseIsDown = true; + if(e.Button == MouseButtons.Left) + MouseIsDown = true; LastMouseDown = DateTime.UtcNow; //Make a duplicate of the old background image. LastBackgroundImage = new Bitmap(pbNetworkView.BackgroundImage);