mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 13:10:00 -07:00
Refactored default Field values, works now but still don't know why empty values are written.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@873 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
ec71396600
commit
f55107dd2f
3 changed files with 67 additions and 37 deletions
|
@ -48,20 +48,7 @@ namespace Greenshot.Editor {
|
||||||
public Font Editor_Font = null;
|
public Font Editor_Font = null;
|
||||||
|
|
||||||
[IniProperty("LastFieldValue", Description="Field values, make sure the last used settings are re-used")]
|
[IniProperty("LastFieldValue", Description="Field values, make sure the last used settings are re-used")]
|
||||||
public Dictionary<FieldType, object> LastUsedFieldValues;
|
public Dictionary<string, object> LastUsedFieldValues;
|
||||||
|
|
||||||
public void UpdateLastUsedFieldValue(IField f) {
|
|
||||||
if(f.Value != null) {
|
|
||||||
LastUsedFieldValues[f.FieldType] = f.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IField GetLastUsedValueForField(IField f) {
|
|
||||||
if(LastUsedFieldValues.ContainsKey(f.FieldType)) {
|
|
||||||
f.Value = LastUsedFieldValues[f.FieldType];
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Supply values we can't put as defaults
|
/// Supply values we can't put as defaults
|
||||||
|
@ -71,29 +58,36 @@ namespace Greenshot.Editor {
|
||||||
public override object GetDefault(string property) {
|
public override object GetDefault(string property) {
|
||||||
switch(property) {
|
switch(property) {
|
||||||
case "LastFieldValue":
|
case "LastFieldValue":
|
||||||
Dictionary<FieldType, object> fieldDefaults = new Dictionary<FieldType, object>();
|
return new Dictionary<string, object>();
|
||||||
fieldDefaults.Add(FieldType.ARROWHEADS, ArrowContainer.ArrowHeadCombination.END_POINT);
|
|
||||||
fieldDefaults.Add(FieldType.BLUR_RADIUS, 3);
|
|
||||||
fieldDefaults.Add(FieldType.BRIGHTNESS, 0.9d);
|
|
||||||
fieldDefaults.Add(FieldType.FILL_COLOR, Color.Transparent);
|
|
||||||
fieldDefaults.Add(FieldType.FLAGS, null);
|
|
||||||
fieldDefaults.Add(FieldType.FONT_BOLD, false);
|
|
||||||
fieldDefaults.Add(FieldType.FONT_FAMILY, FontFamily.GenericSansSerif.Name);
|
|
||||||
fieldDefaults.Add(FieldType.FONT_ITALIC, false);
|
|
||||||
fieldDefaults.Add(FieldType.FONT_SIZE, 11f);
|
|
||||||
fieldDefaults.Add(FieldType.HIGHLIGHT_COLOR, Color.Yellow);
|
|
||||||
fieldDefaults.Add(FieldType.LINE_COLOR, Color.Red);
|
|
||||||
fieldDefaults.Add(FieldType.LINE_THICKNESS, 1);
|
|
||||||
fieldDefaults.Add(FieldType.MAGNIFICATION_FACTOR, 2);
|
|
||||||
fieldDefaults.Add(FieldType.PIXEL_SIZE, 5);
|
|
||||||
fieldDefaults.Add(FieldType.PREVIEW_QUALITY, 1.0d);
|
|
||||||
fieldDefaults.Add(FieldType.SHADOW, false);
|
|
||||||
fieldDefaults.Add(FieldType.PREPARED_FILTER_OBFUSCATE, FilterContainer.PreparedFilter.PIXELIZE);
|
|
||||||
fieldDefaults.Add(FieldType.PREPARED_FILTER_HIGHLIGHT, FilterContainer.PreparedFilter.TEXT_HIGHTLIGHT);
|
|
||||||
return fieldDefaults;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateLastUsedFieldValue(IField f) {
|
||||||
|
string key = GetKeyForField(f);
|
||||||
|
if(f.Value != null) {
|
||||||
|
if (LastUsedFieldValues.ContainsKey(key)) {
|
||||||
|
LastUsedFieldValues[key] = f.Value;
|
||||||
|
} else {
|
||||||
|
LastUsedFieldValues.Add(key, f.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IField GetLastUsedValueForField(IField f) {
|
||||||
|
string key = GetKeyForField(f);
|
||||||
|
if(LastUsedFieldValues.ContainsKey(key)) {
|
||||||
|
f.Value = LastUsedFieldValues[key];
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetKeyForField(IField f) {
|
||||||
|
if(f.Scope == null) {
|
||||||
|
return f.FieldType.ToString();
|
||||||
|
} else {
|
||||||
|
return f.FieldType.ToString() + "-" + f.Scope;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,6 @@ namespace Greenshot.Drawing.Fields {
|
||||||
// update last used from DC field, so that scope is honored
|
// update last used from DC field, so that scope is honored
|
||||||
config.UpdateLastUsedFieldValue(dcf);
|
config.UpdateLastUsedFieldValue(dcf);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,29 @@ namespace Greenshot.Drawing.Fields {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FieldFactory {
|
public class FieldFactory {
|
||||||
private static EditorConfiguration config = IniConfig.GetIniSection<EditorConfiguration>();
|
private static EditorConfiguration config = IniConfig.GetIniSection<EditorConfiguration>();
|
||||||
|
private static Dictionary<FieldType, object> DEFAULT_VALUES;
|
||||||
|
|
||||||
|
static FieldFactory() {
|
||||||
|
DEFAULT_VALUES = new Dictionary<FieldType, object>();
|
||||||
|
DEFAULT_VALUES.Add(FieldType.ARROWHEADS, ArrowContainer.ArrowHeadCombination.END_POINT);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.BLUR_RADIUS, 3);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.BRIGHTNESS, 0.9d);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.FILL_COLOR, Color.Transparent);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.FLAGS, null);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.FONT_BOLD, false);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.FONT_FAMILY, FontFamily.GenericSansSerif.Name);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.FONT_ITALIC, false);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.FONT_SIZE, 11f);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.HIGHLIGHT_COLOR, Color.Yellow);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.LINE_COLOR, Color.Red);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.LINE_THICKNESS, 1);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.MAGNIFICATION_FACTOR, 2);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.PIXEL_SIZE, 5);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.PREVIEW_QUALITY, 1.0d);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.SHADOW, false);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.PREPARED_FILTER_OBFUSCATE, FilterContainer.PreparedFilter.PIXELIZE);
|
||||||
|
DEFAULT_VALUES.Add(FieldType.PREPARED_FILTER_HIGHLIGHT, FilterContainer.PreparedFilter.TEXT_HIGHTLIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
private FieldFactory() {}
|
private FieldFactory() {}
|
||||||
|
|
||||||
|
@ -67,6 +90,7 @@ namespace Greenshot.Drawing.Fields {
|
||||||
return CreateField(fieldType, scope, null);
|
return CreateField(fieldType, scope, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <param name="fieldType">FieldType of the field to construct</param>
|
/// <param name="fieldType">FieldType of the field to construct</param>
|
||||||
/// <param name="preferredDefaultValue">overwrites the original default value being defined in FieldType</param>
|
/// <param name="preferredDefaultValue">overwrites the original default value being defined in FieldType</param>
|
||||||
/// <returns>a new Field of the given fieldType and preferredDefaultValue, with the scope of it's value being restricted to the Type scope</returns>
|
/// <returns>a new Field of the given fieldType and preferredDefaultValue, with the scope of it's value being restricted to the Type scope</returns>
|
||||||
|
@ -81,16 +105,29 @@ namespace Greenshot.Drawing.Fields {
|
||||||
if(ret.Value == null) {
|
if(ret.Value == null) {
|
||||||
if(preferredDefaultValue != null) {
|
if(preferredDefaultValue != null) {
|
||||||
ret.Value = preferredDefaultValue;
|
ret.Value = preferredDefaultValue;
|
||||||
|
} else {
|
||||||
|
ret.Value = GetDefaultValueForField(ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static object GetDefaultValueForField(Field f) {
|
||||||
|
if(DEFAULT_VALUES.ContainsKey(f.FieldType)) {
|
||||||
|
return DEFAULT_VALUES[f.FieldType];
|
||||||
|
} else {
|
||||||
|
throw new KeyNotFoundException("No default value has been defined for "+f.FieldType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <returns>a List of all available fields with their respective default value</returns>
|
/// <returns>a List of all available fields with their respective default value</returns>
|
||||||
public static List<Field> GetDefaultFields() {
|
public static List<Field> GetDefaultFields() {
|
||||||
List<Field> ret = new List<Field>();
|
List<Field> ret = new List<Field>();
|
||||||
foreach(FieldType ft in FieldType.GetValues(typeof(FieldType))) {
|
foreach(FieldType ft in FieldType.GetValues(typeof(FieldType))) {
|
||||||
ret.Add(CreateField(ft));
|
Field f = CreateField(ft);
|
||||||
|
f.Value = GetDefaultValueForField(f);
|
||||||
|
ret.Add(f);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue