From 837db296b58af58fef294eb35bf367d41cf7f441 Mon Sep 17 00:00:00 2001 From: Jaex Date: Fri, 9 Sep 2016 21:14:37 +0300 Subject: [PATCH] If region capture context menu closed because of right click then don't show context menu on mouse up, that way user can close context menu with right click --- .../Shapes/ShapeManager.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs index b9ee25736..74edc67dc 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs @@ -27,6 +27,7 @@ using ShareX.ScreenCaptureLib.Properties; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; @@ -186,7 +187,8 @@ public bool NodesVisible private ToolStripSeparator tssObjectOptions, tssShapeOptions; private ToolStripMenuItem tsmiDeleteSelected, tsmiDeleteAll, tsmiBorderColor, tsmiFillColor, tsmiHighlightColor, tsmiQuickCrop; private ToolStripLabeledNumericUpDown tslnudBorderSize, tslnudCornerRadius, tslnudBlurRadius, tslnudPixelateSize; - private bool isLeftPressed, isRightPressed, isUpPressed, isDownPressed; + private bool isLeftPressed, isRightPressed, isUpPressed, isDownPressed, allowOptionsMenu; + private Stopwatch cmsCloseTimer; public ShapeManager(RegionCaptureForm form) { @@ -255,6 +257,14 @@ private void CreateContextMenu() } }; + cmsContextMenu.Closed += (sender, e) => + { + if (e.CloseReason == ToolStripDropDownCloseReason.AppClicked) + { + cmsCloseTimer = Stopwatch.StartNew(); + } + }; + #region Editor mode if (form.Mode == RegionCaptureMode.Editor) @@ -914,6 +924,8 @@ private void form_LostFocus(object sender, EventArgs e) private void form_MouseDown(object sender, MouseEventArgs e) { + allowOptionsMenu = cmsCloseTimer == null || cmsCloseTimer.ElapsedMilliseconds > 100; + if (e.Button == MouseButtons.Left) { if (!IsCreating) @@ -1245,7 +1257,10 @@ private void RunAction(RegionCaptureAction action) DeleteIntersectShape(); break; case RegionCaptureAction.OpenOptionsMenu: - OpenOptionsMenu(); + if (allowOptionsMenu) + { + OpenOptionsMenu(); + } break; case RegionCaptureAction.SwapToolType: SwapShapeType();