Added GreenshotComboBox, this binds to a ini configuration (enum) and fills the values depending on the type of the enum, including translations!

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1769 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-04-11 09:17:06 +00:00
commit 4e13e13f47
5 changed files with 129 additions and 18 deletions

View file

@ -52,7 +52,7 @@ namespace GreenshotPlugin.Controls {
if (!string.IsNullOrEmpty(LanguageKey)) {
this.Text = language.GetString(LanguageKey);
}
// 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))) {
continue;
@ -71,6 +71,21 @@ namespace GreenshotPlugin.Controls {
LOG.WarnFormat("Greenshot control without language key: {0}", field.Name);
}
}
// Repopulate the combox boxes
if (typeof(IGreenshotConfigBindable).IsAssignableFrom(field.FieldType)) {
if (typeof(GreenshotComboBox).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) {
GreenshotComboBox comboxBox = controlObject as GreenshotComboBox;
// Only update the language, so get the actual value and than repopulate
object currentValue = comboxBox.GetSelectedEnum(language, section.Values[configBindable.PropertyName].ValueType);
comboxBox.Populate(language, section.Values[configBindable.PropertyName].ValueType, currentValue);
}
}
}
}
}
}
@ -99,6 +114,9 @@ namespace GreenshotPlugin.Controls {
} 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(language, section.Values[configBindable.PropertyName].ValueType, (Enum)section.Values[configBindable.PropertyName].Value);
}
}
}
@ -136,6 +154,9 @@ namespace GreenshotPlugin.Controls {
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(language, section.Values[configBindable.PropertyName].ValueType);
}
}
}