diff --git a/Greenshot/Destinations/EmailDestination.cs b/Greenshot/Destinations/EmailDestination.cs index 0c0ae530e..15fefa2e8 100644 --- a/Greenshot/Destinations/EmailDestination.cs +++ b/Greenshot/Destinations/EmailDestination.cs @@ -218,8 +218,7 @@ namespace Greenshot.Destinations { foreach (string inspectorCaption in inspectorCaptions.Keys) { destinations.Add(new EmailDestination(inspectorCaption, inspectorCaptions[inspectorCaption])); } - ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations); - PickerDestination.ShowMenuAtCursor(menu); + PickerDestination.ShowPickerMenu(false, surface, captureDetails, destinations); return false; } } diff --git a/Greenshot/Destinations/PickerDestination.cs b/Greenshot/Destinations/PickerDestination.cs index 0e7262e25..d207fa5c4 100644 --- a/Greenshot/Destinations/PickerDestination.cs +++ b/Greenshot/Destinations/PickerDestination.cs @@ -60,14 +60,14 @@ namespace Greenshot.Destinations { } /// - /// This method will create the destination picker menu + /// This method will create and show the destination picker menu /// /// Boolean if the dynamic values also need to be added /// The surface which can be exported /// Details for the surface /// The list of destinations to show /// - public static ContextMenuStrip CreatePickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable destinations) { + public static void ShowPickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable destinations) { ContextMenuStrip menu = new ContextMenuStrip(); menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) { LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason); @@ -138,14 +138,14 @@ namespace Greenshot.Destinations { }; menu.Items.Add(closeItem); - return menu; + ShowMenuAtCursor(menu); } /// /// This method will show the supplied context menu at the mouse cursor, also makes sure it has focus and it's not visible in the taskbar. /// /// - public static void ShowMenuAtCursor(ContextMenuStrip menu) { + private static void ShowMenuAtCursor(ContextMenuStrip menu) { // find a suitable location Point location = Cursor.Position; Rectangle menuRectangle = new Rectangle(location, menu.Size); @@ -160,6 +160,17 @@ namespace Greenshot.Destinations { User32.SetForegroundWindow(MainForm.instance.notifyIcon.ContextMenuStrip.Handle); menu.Show(location); menu.Focus(); + + // Wait for the menu to close, so we can dispose it. + while (true) { + if (menu.Visible) { + Application.DoEvents(); + System.Threading.Thread.Sleep(100); + } else { + menu.Dispose(); + break; + } + } } /// @@ -181,8 +192,7 @@ namespace Greenshot.Destinations { destinations.Add(destination); } - ContextMenuStrip menu = CreatePickerMenu(true, surface, captureDetails, destinations); - ShowMenuAtCursor(menu); + ShowPickerMenu(true, surface, captureDetails, destinations); return true; } } diff --git a/Greenshot/Destinations/PowerpointDestination.cs b/Greenshot/Destinations/PowerpointDestination.cs index cd0d842c3..95a7aea47 100644 --- a/Greenshot/Destinations/PowerpointDestination.cs +++ b/Greenshot/Destinations/PowerpointDestination.cs @@ -131,8 +131,7 @@ namespace Greenshot.Destinations { foreach (string presentation in presentations) { destinations.Add(new PowerpointDestination(presentation)); } - ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations); - PickerDestination.ShowMenuAtCursor(menu); + PickerDestination.ShowPickerMenu(false, surface, captureDetails, destinations); return false; } } diff --git a/Greenshot/Destinations/WordDestination.cs b/Greenshot/Destinations/WordDestination.cs index 7b6b50aba..31851f11f 100644 --- a/Greenshot/Destinations/WordDestination.cs +++ b/Greenshot/Destinations/WordDestination.cs @@ -139,8 +139,7 @@ namespace Greenshot.Destinations { foreach (string document in documents) { destinations.Add(new WordDestination(document)); } - ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations); - PickerDestination.ShowMenuAtCursor(menu); + PickerDestination.ShowPickerMenu(false, surface, captureDetails, destinations); return false; } } diff --git a/Greenshot/Drawing/DrawableContainerList.cs b/Greenshot/Drawing/DrawableContainerList.cs index 294ba5e33..e3e03876f 100644 --- a/Greenshot/Drawing/DrawableContainerList.cs +++ b/Greenshot/Drawing/DrawableContainerList.cs @@ -498,6 +498,15 @@ namespace Greenshot.Drawing { AddContextMenuItems(menu, surface); if (menu.Items.Count > 0) { menu.Show(surface, e.Location); + while (true) { + if (menu.Visible) { + Application.DoEvents(); + System.Threading.Thread.Sleep(100); + } else { + menu.Dispose(); + break; + } + } } } } diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index 01644cb2a..b9839f759 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -220,7 +220,7 @@ namespace Greenshot { // Generate the entries for the drop down destinationButton.DropDownOpening += delegate(object sender, EventArgs e) { - destinationButton.DropDownItems.Clear(); + ClearItems(destinationButton.DropDownItems); destinationButton.DropDownItems.Add(defaultItem); List subDestinations = new List(); @@ -255,8 +255,23 @@ namespace Greenshot { } } + /// + /// According to some information I found, the clear doesn't work correctly when the shortcutkeys are set? + /// This helper method takes care of this. + /// + /// + private void ClearItems(ToolStripItemCollection items) { + foreach(var item in items) { + ToolStripMenuItem menuItem = item as ToolStripMenuItem; + if (menuItem != null && menuItem.ShortcutKeys != Keys.None) { + menuItem.ShortcutKeys = Keys.None; + } + } + items.Clear(); + } + void FileMenuDropDownOpening(object sender, EventArgs eventArgs) { - this.fileStripMenuItem.DropDownItems.Clear(); + ClearItems(this.fileStripMenuItem.DropDownItems); //this.fileStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { // this.saveToolStripMenuItem, // this.saveAsToolStripMenuItem,