Ejemplo n.º 1
0
        /// <summary>
        /// Store all GreenshotControl values to the configuration
        /// </summary>
        protected void StoreFields()
        {
            bool iniDirty = false;

            foreach (FieldInfo field in GetCachedFields(GetType()))
            {
                Object controlObject = field.GetValue(this);
                if (controlObject == null)
                {
                    continue;
                }
                IGreenshotConfigBindable configBindable = controlObject as IGreenshotConfigBindable;
                if (configBindable == null)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName))
                {
                    IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
                    if (section != null)
                    {
                        IniValue iniValue = null;
                        if (!section.Values.TryGetValue(configBindable.PropertyName, out iniValue))
                        {
                            continue;
                        }
                        CheckBox checkBox = controlObject as CheckBox;
                        if (checkBox != null)
                        {
                            iniValue.Value = checkBox.Checked;
                            iniDirty       = true;
                            continue;
                        }
                        RadioButton radioButton = controlObject as RadioButton;
                        if (radioButton != null)
                        {
                            iniValue.Value = radioButton.Checked;
                            iniDirty       = true;
                            continue;
                        }
                        GreenshotComboBox comboxBox = controlObject as GreenshotComboBox;
                        if (comboxBox != null)
                        {
                            iniValue.Value = comboxBox.GetSelectedEnum();
                            iniDirty       = true;
                            continue;
                        }
                    }
                }
            }
            if (iniDirty)
            {
                //IniConfig.Save();
            }
        }
        /// <summary>
        /// Store all GreenshotControl values to the configuration
        /// </summary>
        protected void StoreFields()
        {
            bool iniDirty = false;

            foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (!field.FieldType.IsSubclassOf(typeof(Control)))
                {
                    continue;
                }
                if (!typeof(IGreenshotConfigBindable).IsAssignableFrom(field.FieldType))
                {
                    continue;
                }
                Object controlObject = field.GetValue(this);
                IGreenshotConfigBindable configBindable = controlObject as IGreenshotConfigBindable;

                if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName))
                {
                    IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
                    if (section != null)
                    {
                        if (typeof(CheckBox).IsAssignableFrom(field.FieldType))
                        {
                            CheckBox checkBox = controlObject as CheckBox;
                            section.Values[configBindable.PropertyName].Value = checkBox.Checked;
                            iniDirty = true;
                        }
                        else if (typeof(TextBox).IsAssignableFrom(field.FieldType))
                        {
                            TextBox textBox = controlObject as TextBox;
                            section.Values[configBindable.PropertyName].Value = textBox.Text;
                            iniDirty = true;
                        }
                        else if (typeof(GreenshotComboBox).IsAssignableFrom(field.FieldType))
                        {
                            GreenshotComboBox comboxBox = controlObject as GreenshotComboBox;
                            section.Values[configBindable.PropertyName].Value = comboxBox.GetSelectedEnum();
                        }
                    }
                }
            }
            if (iniDirty)
            {
                IniConfig.Save();
            }
        }
        protected void ApplyLanguage(Control applyTo)
        {
            IGreenshotLanguageBindable languageBindable = applyTo as IGreenshotLanguageBindable;

            if (languageBindable == null)
            {
                // check if it's a menu!
                if (applyTo is ToolStrip)
                {
                    ToolStrip toolStrip = applyTo as ToolStrip;
                    foreach (ToolStripItem item in toolStrip.Items)
                    {
                        ApplyLanguage(item);
                    }
                }
                return;
            }

            string languageKey = languageBindable.LanguageKey;

            // Apply language text to the control
            ApplyLanguage(applyTo, languageKey);
            // Repopulate the combox boxes
            if (typeof(IGreenshotConfigBindable).IsAssignableFrom(applyTo.GetType()))
            {
                if (typeof(GreenshotComboBox).IsAssignableFrom(applyTo.GetType()))
                {
                    IGreenshotConfigBindable configBindable = applyTo as IGreenshotConfigBindable;
                    if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName))
                    {
                        IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
                        if (section != null)
                        {
                            GreenshotComboBox comboxBox = applyTo as GreenshotComboBox;
                            // Only update the language, so get the actual value and than repopulate
                            Enum currentValue = (Enum)comboxBox.GetSelectedEnum();
                            comboxBox.Populate(section.Values[configBindable.PropertyName].ValueType);
                            comboxBox.SetValue(currentValue);
                        }
                    }
                }
            }
        }