mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 00:53:51 -07:00
Some fixes which should reduce memory usage a bit, also preventing possible memory leaks.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2005 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
aefd9a17a4
commit
e654c38eb8
6 changed files with 45 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,14 +60,14 @@ namespace Greenshot.Destinations {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method will create the destination picker menu
|
||||
/// This method will create and show the destination picker menu
|
||||
/// </summary>
|
||||
/// <param name="addDynamics">Boolean if the dynamic values also need to be added</param>
|
||||
/// <param name="surface">The surface which can be exported</param>
|
||||
/// <param name="captureDetails">Details for the surface</param>
|
||||
/// <param name="destinations">The list of destinations to show</param>
|
||||
/// <returns></returns>
|
||||
public static ContextMenuStrip CreatePickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> destinations) {
|
||||
public static void ShowPickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<IDestination> subDestinations = new List<IDestination>();
|
||||
|
@ -255,8 +255,23 @@ namespace Greenshot {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// According to some information I found, the clear doesn't work correctly when the shortcutkeys are set?
|
||||
/// This helper method takes care of this.
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue