mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 09:03:44 -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) {
|
foreach (string inspectorCaption in inspectorCaptions.Keys) {
|
||||||
destinations.Add(new EmailDestination(inspectorCaption, inspectorCaptions[inspectorCaption]));
|
destinations.Add(new EmailDestination(inspectorCaption, inspectorCaptions[inspectorCaption]));
|
||||||
}
|
}
|
||||||
ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
|
PickerDestination.ShowPickerMenu(false, surface, captureDetails, destinations);
|
||||||
PickerDestination.ShowMenuAtCursor(menu);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,14 +60,14 @@ namespace Greenshot.Destinations {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method will create the destination picker menu
|
/// This method will create and show the destination picker menu
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="addDynamics">Boolean if the dynamic values also need to be added</param>
|
/// <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="surface">The surface which can be exported</param>
|
||||||
/// <param name="captureDetails">Details for the surface</param>
|
/// <param name="captureDetails">Details for the surface</param>
|
||||||
/// <param name="destinations">The list of destinations to show</param>
|
/// <param name="destinations">The list of destinations to show</param>
|
||||||
/// <returns></returns>
|
/// <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();
|
ContextMenuStrip menu = new ContextMenuStrip();
|
||||||
menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
|
menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
|
||||||
LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason);
|
LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason);
|
||||||
|
@ -138,14 +138,14 @@ namespace Greenshot.Destinations {
|
||||||
};
|
};
|
||||||
menu.Items.Add(closeItem);
|
menu.Items.Add(closeItem);
|
||||||
|
|
||||||
return menu;
|
ShowMenuAtCursor(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// 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>
|
/// </summary>
|
||||||
/// <param name="menu"></param>
|
/// <param name="menu"></param>
|
||||||
public static void ShowMenuAtCursor(ContextMenuStrip menu) {
|
private static void ShowMenuAtCursor(ContextMenuStrip menu) {
|
||||||
// find a suitable location
|
// find a suitable location
|
||||||
Point location = Cursor.Position;
|
Point location = Cursor.Position;
|
||||||
Rectangle menuRectangle = new Rectangle(location, menu.Size);
|
Rectangle menuRectangle = new Rectangle(location, menu.Size);
|
||||||
|
@ -160,6 +160,17 @@ namespace Greenshot.Destinations {
|
||||||
User32.SetForegroundWindow(MainForm.instance.notifyIcon.ContextMenuStrip.Handle);
|
User32.SetForegroundWindow(MainForm.instance.notifyIcon.ContextMenuStrip.Handle);
|
||||||
menu.Show(location);
|
menu.Show(location);
|
||||||
menu.Focus();
|
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>
|
/// <summary>
|
||||||
|
@ -181,8 +192,7 @@ namespace Greenshot.Destinations {
|
||||||
destinations.Add(destination);
|
destinations.Add(destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextMenuStrip menu = CreatePickerMenu(true, surface, captureDetails, destinations);
|
ShowPickerMenu(true, surface, captureDetails, destinations);
|
||||||
ShowMenuAtCursor(menu);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,8 +131,7 @@ namespace Greenshot.Destinations {
|
||||||
foreach (string presentation in presentations) {
|
foreach (string presentation in presentations) {
|
||||||
destinations.Add(new PowerpointDestination(presentation));
|
destinations.Add(new PowerpointDestination(presentation));
|
||||||
}
|
}
|
||||||
ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
|
PickerDestination.ShowPickerMenu(false, surface, captureDetails, destinations);
|
||||||
PickerDestination.ShowMenuAtCursor(menu);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,8 +139,7 @@ namespace Greenshot.Destinations {
|
||||||
foreach (string document in documents) {
|
foreach (string document in documents) {
|
||||||
destinations.Add(new WordDestination(document));
|
destinations.Add(new WordDestination(document));
|
||||||
}
|
}
|
||||||
ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
|
PickerDestination.ShowPickerMenu(false, surface, captureDetails, destinations);
|
||||||
PickerDestination.ShowMenuAtCursor(menu);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -498,6 +498,15 @@ namespace Greenshot.Drawing {
|
||||||
AddContextMenuItems(menu, surface);
|
AddContextMenuItems(menu, surface);
|
||||||
if (menu.Items.Count > 0) {
|
if (menu.Items.Count > 0) {
|
||||||
menu.Show(surface, e.Location);
|
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
|
// Generate the entries for the drop down
|
||||||
destinationButton.DropDownOpening += delegate(object sender, EventArgs e) {
|
destinationButton.DropDownOpening += delegate(object sender, EventArgs e) {
|
||||||
destinationButton.DropDownItems.Clear();
|
ClearItems(destinationButton.DropDownItems);
|
||||||
destinationButton.DropDownItems.Add(defaultItem);
|
destinationButton.DropDownItems.Add(defaultItem);
|
||||||
|
|
||||||
List<IDestination> subDestinations = new List<IDestination>();
|
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) {
|
void FileMenuDropDownOpening(object sender, EventArgs eventArgs) {
|
||||||
this.fileStripMenuItem.DropDownItems.Clear();
|
ClearItems(this.fileStripMenuItem.DropDownItems);
|
||||||
//this.fileStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
//this.fileStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
// this.saveToolStripMenuItem,
|
// this.saveToolStripMenuItem,
|
||||||
// this.saveAsToolStripMenuItem,
|
// this.saveAsToolStripMenuItem,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue