More performance improvements

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1919 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-06-11 21:05:48 +00:00
commit 59665da813
2 changed files with 48 additions and 32 deletions

View file

@ -87,6 +87,8 @@ namespace Greenshot {
// init surface // init surface
this.surface = iSurface as Surface; this.surface = iSurface as Surface;
editorList.Add(this); editorList.Add(this);
this.SuspendLayout();
// //
// The InitializeComponent() call is required for Windows Forms designer support. // The InitializeComponent() call is required for Windows Forms designer support.
// //
@ -172,6 +174,7 @@ namespace Greenshot {
// Create the file menu, normally this is done when opening but if we don't do it now the short-cut keys are missing. // Create the file menu, normally this is done when opening but if we don't do it now the short-cut keys are missing.
// See Bugs #3526974 & #3527020 // See Bugs #3526974 & #3527020
FileMenuDropDownOpening(null, null); FileMenuDropDownOpening(null, null);
this.ResumeLayout();
} }
void AddDestinationButton(IDestination toolstripDestination) { void AddDestinationButton(IDestination toolstripDestination) {

View file

@ -12,11 +12,13 @@ using System.IO;
namespace GreenshotPlugin.Controls { namespace GreenshotPlugin.Controls {
public abstract class GreenshotForm : Form, IGreenshotLanguageBindable { public abstract class GreenshotForm : Form, IGreenshotLanguageBindable {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(GreenshotForm)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(GreenshotForm));
private static IDictionary<Type, FieldInfo[]> reflectionCache = new Dictionary<Type, FieldInfo[]>();
private IComponentChangeService m_changeService; private IComponentChangeService m_changeService;
private bool isDesignModeLanguageSet = false; private bool isDesignModeLanguageSet = false;
private bool applyLanguageManually = false; private bool applyLanguageManually = false;
private IDictionary<string, Control> designTimeControls; private IDictionary<string, Control> designTimeControls;
private IDictionary<string, ToolStripItem> designTimeToolStripItems; private IDictionary<string, ToolStripItem> designTimeToolStripItems;
[Category("Greenshot"), DefaultValue(null), Description("Specifies key of the language file to use when displaying the text.")] [Category("Greenshot"), DefaultValue(null), Description("Specifies key of the language file to use when displaying the text.")]
public string LanguageKey { public string LanguageKey {
get; get;
@ -274,41 +276,43 @@ namespace GreenshotPlugin.Controls {
/// </summary> /// </summary>
protected void ApplyLanguage() { protected void ApplyLanguage() {
string langString = null; string langString = null;
// Set title of the form this.SuspendLayout();
if (!string.IsNullOrEmpty(LanguageKey) && Language.TryGetString(LanguageKey, out langString)) { try {
this.Text = langString; // Set title of the form
} if (!string.IsNullOrEmpty(LanguageKey) && Language.TryGetString(LanguageKey, out langString)) {
// Reset the text values for all GreenshotControls this.Text = langString;
foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
if (!field.FieldType.IsSubclassOf(typeof(Control)) && !field.FieldType.IsSubclassOf(typeof(ToolStripItem))) {
LOG.DebugFormat("No Control or ToolStripItem: {0}", field.Name);
continue;
} }
Object controlObject = field.GetValue(this);
if (controlObject == null) { // Reset the text values for all GreenshotControls
LOG.DebugFormat("No value: {0}", field.Name); foreach (FieldInfo field in GetCachedFields(this.GetType())) {
continue; Object controlObject = field.GetValue(this);
} if (controlObject == null) {
Control applyToControl = controlObject as Control; LOG.DebugFormat("No value: {0}", field.Name);
if (applyToControl == null) {
ToolStripItem applyToItem = controlObject as ToolStripItem;
if (applyToItem == null) {
LOG.DebugFormat("No Control or ToolStripItem: {0}", field.Name);
continue; continue;
} }
ApplyLanguage(applyToItem); Control applyToControl = controlObject as Control;
} else { if (applyToControl == null) {
ApplyLanguage(applyToControl); ToolStripItem applyToItem = controlObject as ToolStripItem;
if (applyToItem == null) {
LOG.DebugFormat("No Control or ToolStripItem: {0}", field.Name);
continue;
}
ApplyLanguage(applyToItem);
} else {
ApplyLanguage(applyToControl);
}
} }
}
if (DesignMode) {
if (DesignMode) { foreach (Control designControl in designTimeControls.Values) {
foreach (Control designControl in designTimeControls.Values) { ApplyLanguage(designControl);
ApplyLanguage(designControl); }
} foreach (ToolStripItem designToolStripItem in designTimeToolStripItems.Values) {
foreach (ToolStripItem designToolStripItem in designTimeToolStripItems.Values) { ApplyLanguage(designToolStripItem);
ApplyLanguage(designToolStripItem); }
} }
} finally {
this.ResumeLayout();
} }
} }
@ -337,12 +341,21 @@ namespace GreenshotPlugin.Controls {
} }
} }
} }
private static FieldInfo[] GetCachedFields(Type typeToGetFieldsFor) {
FieldInfo[] fields = null;
if (!reflectionCache.TryGetValue(typeToGetFieldsFor, out fields)) {
fields = typeToGetFieldsFor.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
reflectionCache.Add(typeToGetFieldsFor, fields);
}
return fields;
}
/// <summary> /// <summary>
/// Fill all GreenshotControls with the values from the configuration /// Fill all GreenshotControls with the values from the configuration
/// </summary> /// </summary>
protected void FillFields() { protected void FillFields() {
foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { foreach (FieldInfo field in GetCachedFields(this.GetType())) {
if (!field.FieldType.IsSubclassOf(typeof(Control))) { if (!field.FieldType.IsSubclassOf(typeof(Control))) {
continue; continue;
} }
@ -384,7 +397,7 @@ namespace GreenshotPlugin.Controls {
/// </summary> /// </summary>
protected void StoreFields() { protected void StoreFields() {
bool iniDirty = false; bool iniDirty = false;
foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { foreach (FieldInfo field in GetCachedFields(this.GetType())) {
if (!field.FieldType.IsSubclassOf(typeof(Control))) { if (!field.FieldType.IsSubclassOf(typeof(Control))) {
continue; continue;
} }