Browse Source

Fixed SD2-783: GDI Handle leak

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1380 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
37c2bc671d
  1. 12
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/LayoutConfiguration.cs
  2. 12
      src/Main/Base/Project/Src/Services/IconService.cs
  3. 23
      src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.cs
  4. 43
      src/Main/Core/Project/Src/Services/ResourceService/ResourceService.cs

12
src/Main/Base/Project/Src/Gui/Workbench/Layouts/LayoutConfiguration.cs

@ -90,11 +90,17 @@ namespace ICSharpCode.SharpDevelop.Gui
return PropertyService.Get("Workbench.CurrentLayout", "Default"); return PropertyService.Get("Workbench.CurrentLayout", "Default");
} }
set { set {
if (WorkbenchSingleton.InvokeRequired)
throw new InvalidOperationException("Invoke required");
if (value != CurrentLayoutName) { if (value != CurrentLayoutName) {
PropertyService.Set("Workbench.CurrentLayout", value); PropertyService.Set("Workbench.CurrentLayout", value);
WorkbenchSingleton.SafeThreadCall(WorkbenchSingleton.Workbench.WorkbenchLayout, "LoadConfiguration"); WorkbenchSingleton.Workbench.WorkbenchLayout.LoadConfiguration();
WorkbenchSingleton.SafeThreadCall(typeof(LayoutConfiguration), "OnLayoutChanged", EventArgs.Empty); OnLayoutChanged(EventArgs.Empty);
#if DEBUG
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
#endif
} }
} }
} }

12
src/Main/Base/Project/Src/Services/IconService.cs

@ -73,8 +73,9 @@ namespace ICSharpCode.Core
public static Bitmap GetBitmap(string name) public static Bitmap GetBitmap(string name)
{ {
if (ResourceService.GetBitmap(name) != null) { Bitmap bmp = ResourceService.GetBitmap(name);
return ResourceService.GetBitmap(name); if (bmp != null) {
return bmp;
} }
return ResourceService.GetBitmap("Icons.16x16.MiscFiles"); return ResourceService.GetBitmap("Icons.16x16.MiscFiles");
@ -82,8 +83,11 @@ namespace ICSharpCode.Core
public static Icon GetIcon(string name) public static Icon GetIcon(string name)
{ {
Bitmap bitmap = GetBitmap(name); Icon icon = ResourceService.GetIcon(name);
return Icon.FromHandle(bitmap.GetHicon()); if (icon != null) {
return icon;
}
return ResourceService.GetIcon("Icons.16x16.MiscFiles");
} }

23
src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.cs

@ -7,6 +7,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Drawing; using System.Drawing;
using System.ComponentModel; using System.ComponentModel;
@ -276,20 +277,26 @@ namespace ICSharpCode.SharpDevelop.Gui
foreach (IProject project in ProjectService.OpenSolution.Projects) { foreach (IProject project in ProjectService.OpenSolution.Projects) {
IProjectContent projectContent = ParserService.GetProjectContent(project); IProjectContent projectContent = ParserService.GetProjectContent(project);
if (projectContent != null) { if (projectContent != null) {
foreach (IClass c in projectContent.Classes) { AddClasses(lowerText, list, projectContent.Classes);
string className = c.Name;
if (className.Length >= text.Length) {
if (className.ToLowerInvariant().IndexOf(lowerText) >= 0) {
list.Add(c);
}
}
}
} }
} }
} }
return list; return list;
} }
void AddClasses(string lowerText, ArrayList list, IEnumerable<IClass> classes)
{
foreach (IClass c in classes) {
string className = c.Name;
if (className.Length >= lowerText.Length) {
if (className.ToLowerInvariant().IndexOf(lowerText) >= 0) {
list.Add(c);
}
}
AddClasses(lowerText, list, c.InnerClasses);
}
}
void AddItem(string text, int imageIndex, object tag, double priority) void AddItem(string text, int imageIndex, object tag, double priority)
{ {
if (visibleEntries.ContainsKey(text)) if (visibleEntries.ContainsKey(text))

43
src/Main/Core/Project/Src/Services/ResourceService/ResourceService.cs

@ -65,6 +65,9 @@ namespace ICSharpCode.Core
static Hashtable localStrings = null; static Hashtable localStrings = null;
static Hashtable localIcons = null; static Hashtable localIcons = null;
static Dictionary<string, Icon> iconCache = new Dictionary<string, Icon>();
static Dictionary<string, Bitmap> bitmapCache = new Dictionary<string, Bitmap>();
/// <summary>Strings resource managers for the current language</summary> /// <summary>Strings resource managers for the current language</summary>
static List<ResourceManager> localStringsResMgrs = new List<ResourceManager>(); static List<ResourceManager> localStringsResMgrs = new List<ResourceManager>();
/// <summary>Image resource managers for the current language</summary> /// <summary>Image resource managers for the current language</summary>
@ -182,6 +185,9 @@ namespace ICSharpCode.Core
static void LoadLanguageResources(string language) static void LoadLanguageResources(string language)
{ {
iconCache.Clear();
bitmapCache.Clear();
try { try {
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(language); Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(language);
} catch (Exception) { } catch (Exception) {
@ -400,15 +406,22 @@ namespace ICSharpCode.Core
/// </exception> /// </exception>
public static Icon GetIcon(string name) public static Icon GetIcon(string name)
{ {
object iconobj = GetImageResource(name); lock (iconCache) {
Icon ico;
if (iconobj == null) { if (iconCache.TryGetValue(name, out ico))
return null; return ico;
}
if (iconobj is Icon) { object iconobj = GetImageResource(name);
return (Icon)iconobj; if (iconobj == null) {
} else { return null;
return Icon.FromHandle(((Bitmap)iconobj).GetHicon()); }
if (iconobj is Icon) {
ico = (Icon)iconobj;
} else {
ico = Icon.FromHandle(((Bitmap)iconobj).GetHicon());
}
iconCache[name] = ico;
return ico;
} }
} }
@ -427,9 +440,15 @@ namespace ICSharpCode.Core
/// </exception> /// </exception>
public static Bitmap GetBitmap(string name) public static Bitmap GetBitmap(string name)
{ {
Bitmap b = (Bitmap)GetImageResource(name); lock (bitmapCache) {
Debug.Assert(b != null, "Resource " + name); Bitmap bmp;
return b; if (bitmapCache.TryGetValue(name, out bmp))
return bmp;
bmp = (Bitmap)GetImageResource(name);
Debug.Assert(bmp != null, "Resource " + name);
bitmapCache[name] = bmp;
return bmp;
}
} }
} }
} }

Loading…
Cancel
Save