diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index 079649aa4..54fbdf142 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -87,6 +87,8 @@ namespace Greenshot { // init surface this.surface = iSurface as Surface; editorList.Add(this); + + this.SuspendLayout(); // // 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. // See Bugs #3526974 & #3527020 FileMenuDropDownOpening(null, null); + this.ResumeLayout(); } void AddDestinationButton(IDestination toolstripDestination) { diff --git a/GreenshotPlugin/Controls/GreenshotForm.cs b/GreenshotPlugin/Controls/GreenshotForm.cs index a3c3bce91..16d9834d5 100644 --- a/GreenshotPlugin/Controls/GreenshotForm.cs +++ b/GreenshotPlugin/Controls/GreenshotForm.cs @@ -12,11 +12,13 @@ using System.IO; namespace GreenshotPlugin.Controls { public abstract class GreenshotForm : Form, IGreenshotLanguageBindable { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(GreenshotForm)); + private static IDictionary reflectionCache = new Dictionary(); private IComponentChangeService m_changeService; private bool isDesignModeLanguageSet = false; private bool applyLanguageManually = false; private IDictionary designTimeControls; private IDictionary designTimeToolStripItems; + [Category("Greenshot"), DefaultValue(null), Description("Specifies key of the language file to use when displaying the text.")] public string LanguageKey { get; @@ -274,41 +276,43 @@ namespace GreenshotPlugin.Controls { /// protected void ApplyLanguage() { string langString = null; - // Set title of the form - if (!string.IsNullOrEmpty(LanguageKey) && Language.TryGetString(LanguageKey, out langString)) { - this.Text = langString; - } - // Reset the text values for all GreenshotControls - 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; + this.SuspendLayout(); + try { + // Set title of the form + if (!string.IsNullOrEmpty(LanguageKey) && Language.TryGetString(LanguageKey, out langString)) { + this.Text = langString; } - Object controlObject = field.GetValue(this); - if (controlObject == null) { - LOG.DebugFormat("No value: {0}", field.Name); - continue; - } - Control applyToControl = controlObject as Control; - if (applyToControl == null) { - ToolStripItem applyToItem = controlObject as ToolStripItem; - if (applyToItem == null) { - LOG.DebugFormat("No Control or ToolStripItem: {0}", field.Name); + + // Reset the text values for all GreenshotControls + foreach (FieldInfo field in GetCachedFields(this.GetType())) { + Object controlObject = field.GetValue(this); + if (controlObject == null) { + LOG.DebugFormat("No value: {0}", field.Name); continue; } - ApplyLanguage(applyToItem); - } else { - ApplyLanguage(applyToControl); + Control applyToControl = controlObject as Control; + if (applyToControl == null) { + 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) { - foreach (Control designControl in designTimeControls.Values) { - ApplyLanguage(designControl); - } - foreach (ToolStripItem designToolStripItem in designTimeToolStripItems.Values) { - ApplyLanguage(designToolStripItem); + + if (DesignMode) { + foreach (Control designControl in designTimeControls.Values) { + ApplyLanguage(designControl); + } + foreach (ToolStripItem designToolStripItem in designTimeToolStripItems.Values) { + 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; + } /// /// Fill all GreenshotControls with the values from the configuration /// 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))) { continue; } @@ -384,7 +397,7 @@ namespace GreenshotPlugin.Controls { /// protected void StoreFields() { 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))) { continue; }