Пример #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();
            }
        }
Пример #2
0
        /// <summary>
        /// Fill all GreenshotControls with the values from the configuration
        /// </summary>
        protected void FillFields()
        {
            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))
                        {
                            LOG.DebugFormat("Wrong property '{0}' configured for field '{1}'", configBindable.PropertyName, field.Name);
                            continue;
                        }

                        CheckBox checkBox = controlObject as CheckBox;
                        if (checkBox != null)
                        {
                            checkBox.Checked = (bool)iniValue.Value;
                            checkBox.Enabled = !iniValue.IsFixed;
                            continue;
                        }
                        RadioButton radíoButton = controlObject as RadioButton;
                        if (radíoButton != null)
                        {
                            radíoButton.Checked = (bool)iniValue.Value;
                            radíoButton.Enabled = !iniValue.IsFixed;
                            continue;
                        }
                        GreenshotComboBox comboxBox = controlObject as GreenshotComboBox;
                        if (comboxBox != null)
                        {
                            comboxBox.Populate(iniValue.ValueType);
                            comboxBox.SetValue((Enum)iniValue.Value);
                            comboxBox.Enabled = !iniValue.IsFixed;
                            continue;
                        }
                    }
                }
            }
            OnFieldsFilled();
        }
        /// <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();
            }
        }
 /// <summary>
 /// Fill all GreenshotControls with the values from the configuration
 /// </summary>
 protected void FillFields()
 {
     foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
     {
         if (!field.FieldType.IsSubclassOf(typeof(Control)))
         {
             continue;
         }
         Object controlObject = field.GetValue(this);
         if (typeof(IGreenshotConfigBindable).IsAssignableFrom(field.FieldType))
         {
             IGreenshotConfigBindable configBindable = controlObject as IGreenshotConfigBindable;
             if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName))
             {
                 IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
                 if (section != null)
                 {
                     if (!section.Values.ContainsKey(configBindable.PropertyName))
                     {
                         LOG.WarnFormat("Wrong property '{0}' configured for field '{1}'", configBindable.PropertyName, field.Name);
                         continue;
                     }
                     if (typeof(CheckBox).IsAssignableFrom(field.FieldType))
                     {
                         CheckBox checkBox = controlObject as CheckBox;
                         checkBox.Checked = (bool)section.Values[configBindable.PropertyName].Value;
                     }
                     else if (typeof(TextBox).IsAssignableFrom(field.FieldType))
                     {
                         TextBox textBox = controlObject as TextBox;
                         textBox.Text = (string)section.Values[configBindable.PropertyName].Value;
                     }
                     else if (typeof(GreenshotComboBox).IsAssignableFrom(field.FieldType))
                     {
                         GreenshotComboBox comboxBox = controlObject as GreenshotComboBox;
                         comboxBox.Populate(section.Values[configBindable.PropertyName].ValueType);
                         comboxBox.SetValue((Enum)section.Values[configBindable.PropertyName].Value);
                     }
                 }
             }
         }
     }
 }
        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);
                        }
                    }
                }
            }
        }