refactoring: added IField

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@703 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
JKlingen 2010-07-25 16:52:51 +00:00
commit 0dffa6054b
15 changed files with 209 additions and 191 deletions

View file

@ -286,22 +286,18 @@ namespace Greenshot.Configuration {
} }
} }
public void UpdateLastUsedFieldValue(Field f) { public void UpdateLastUsedFieldValue(IField f) {
if(f.Value != null) { if(f.Value != null) {
string key = GetKeyForField(f); string key = GetKeyForField(f);
LastUsedFieldValues[key] = f.Value; LastUsedFieldValues[key] = f.Value;
} }
} }
public Field GetLastUsedValueForField(Field f, object preferredDefaultValue) { public IField GetLastUsedValueForField(IField f) {
string key = GetKeyForField(f); string key = GetKeyForField(f);
if(LastUsedFieldValues.ContainsKey(key)) { if(LastUsedFieldValues.ContainsKey(key)) {
f.Value = LastUsedFieldValues[key]; f.Value = LastUsedFieldValues[key];
} else if(preferredDefaultValue != null) { }
f.Value = preferredDefaultValue;
}else {
f.Value = f.FieldType.DefaultValue;
}
return f; return f;
} }
@ -309,11 +305,11 @@ namespace Greenshot.Configuration {
/// <returns></returns> /// <returns></returns>
/// <param name="f"></param> /// <param name="f"></param>
/// <returns>the key under which last used value for the Field can be stored/retrieved</returns> /// <returns>the key under which last used value for the Field can be stored/retrieved</returns>
private string GetKeyForField(Field f) { private string GetKeyForField(IField f) {
if(f.Scope == null) { if(f.Scope == null) {
return f.FieldType.Name; return f.FieldType.ToString();
} else { } else {
return f.FieldType.Name + "-" + f.Scope; return f.FieldType.ToString() + "-" + f.Scope;
} }
} }
} }

View file

@ -33,7 +33,7 @@ namespace Greenshot.Drawing {
/// </summary> /// </summary>
public class CropContainer : DrawableContainer { public class CropContainer : DrawableContainer {
public CropContainer(Surface parent) : base(parent) { public CropContainer(Surface parent) : base(parent) {
AddField(FieldFactory.CreateFieldWithValue(FieldType.FLAGS, FieldType.Flag.CONFIRMABLE)); AddField(FieldFactory.CreateFieldWithValue(FieldType.FLAGS, FieldFlag.CONFIRMABLE));
} }
public override void Draw(Graphics g, RenderMode rm) { public override void Draw(Graphics g, RenderMode rm) {

View file

@ -48,8 +48,8 @@ namespace Greenshot.Drawing.Fields {
// we keep to Coolections of our fields, dictionary for quick access, list for serialization // we keep to Coolections of our fields, dictionary for quick access, list for serialization
// this allows us to use default serialization // this allows us to use default serialization
[NonSerialized] [NonSerialized]
private Dictionary<FieldType, Field> fieldsByType = new Dictionary<FieldType, Field>(); private Dictionary<FieldType, IField> fieldsByType = new Dictionary<FieldType, IField>();
private List<Field> fields = new List<Field>(); private List<IField> fields = new List<IField>();
@ -58,7 +58,7 @@ namespace Greenshot.Drawing.Fields {
[OnDeserializedAttribute()] [OnDeserializedAttribute()]
private void OnDeserialized(StreamingContext context) { private void OnDeserialized(StreamingContext context) {
fieldsByType = new Dictionary<FieldType, Field>(); fieldsByType = new Dictionary<FieldType, IField>();
// listen to changing properties // listen to changing properties
foreach(Field field in fields) { foreach(Field field in fields) {
field.PropertyChanged += delegate { if(fieldChanged != null) fieldChanged(this, new FieldChangedEventArgs(field)); }; field.PropertyChanged += delegate { if(fieldChanged != null) fieldChanged(this, new FieldChangedEventArgs(field)); };
@ -66,7 +66,7 @@ namespace Greenshot.Drawing.Fields {
} }
} }
public virtual void AddField(Field field) { public virtual void AddField(IField field) {
if(fieldsByType != null && fieldsByType.ContainsKey(field.FieldType)) { if(fieldsByType != null && fieldsByType.ContainsKey(field.FieldType)) {
if(LOG.IsDebugEnabled) LOG.Debug("A field with of type '"+field.FieldType+"' already exists in this "+GetType()+", will overwrite."); if(LOG.IsDebugEnabled) LOG.Debug("A field with of type '"+field.FieldType+"' already exists in this "+GetType()+", will overwrite.");
} }
@ -76,18 +76,18 @@ namespace Greenshot.Drawing.Fields {
field.PropertyChanged += delegate { if(fieldChanged != null) fieldChanged(this, new FieldChangedEventArgs(field)); }; field.PropertyChanged += delegate { if(fieldChanged != null) fieldChanged(this, new FieldChangedEventArgs(field)); };
} }
public void RemoveField(Field field) { public void RemoveField(IField field) {
fields.Remove(field); fields.Remove(field);
fieldsByType.Remove(field.FieldType); fieldsByType.Remove(field.FieldType);
field.PropertyChanged -= delegate { if(fieldChanged != null) fieldChanged(this, new FieldChangedEventArgs(field)); }; field.PropertyChanged -= delegate { if(fieldChanged != null) fieldChanged(this, new FieldChangedEventArgs(field)); };
} }
public List<Field> GetFields() { public List<IField> GetFields() {
return fields; return fields;
} }
public Field GetField(FieldType fieldType) { public IField GetField(FieldType fieldType) {
try { try {
return fieldsByType[fieldType]; return fieldsByType[fieldType];
} catch(KeyNotFoundException e) { } catch(KeyNotFoundException e) {

View file

@ -72,8 +72,8 @@ namespace Greenshot.Drawing.Fields {
if(childrenChanged != null) childrenChanged(this, EventArgs.Empty); if(childrenChanged != null) childrenChanged(this, EventArgs.Empty);
} }
public new List<Field> GetFields() { public new List<IField> GetFields() {
List<Field> ret = new List<Field>(); List<IField> ret = new List<IField>();
ret.AddRange(base.GetFields()); ret.AddRange(base.GetFields());
foreach(IFieldHolder fh in Children) { foreach(IFieldHolder fh in Children) {
ret.AddRange(fh.GetFields()); ret.AddRange(fh.GetFields());
@ -81,8 +81,8 @@ namespace Greenshot.Drawing.Fields {
return ret; return ret;
} }
public new Field GetField(FieldType fieldType) { public new IField GetField(FieldType fieldType) {
Field ret = null; IField ret = null;
if(base.HasField(fieldType)) { if(base.HasField(fieldType)) {
ret = base.GetField(fieldType); ret = base.GetField(fieldType);
} else { } else {
@ -113,12 +113,12 @@ namespace Greenshot.Drawing.Fields {
} }
public new bool HasFieldValue(FieldType fieldType) { public new bool HasFieldValue(FieldType fieldType) {
Field f = GetField(fieldType); IField f = GetField(fieldType);
return f != null && f.HasValue; return f != null && f.HasValue;
} }
public new void SetFieldValue(FieldType fieldType, object value) { public new void SetFieldValue(FieldType fieldType, object value) {
Field f = GetField(fieldType); IField f = GetField(fieldType);
if(f != null) f.Value = value; if(f != null) f.Value = value;
} }

View file

@ -27,7 +27,7 @@ namespace Greenshot.Drawing.Fields {
/// line thickness of a rectangle. /// line thickness of a rectangle.
/// </summary> /// </summary>
[Serializable] [Serializable]
public class Field : INotifyPropertyChanged { public class Field : IField {
[field:NonSerialized] [field:NonSerialized]
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
@ -39,8 +39,17 @@ namespace Greenshot.Drawing.Fields {
if(PropertyChanged!=null) PropertyChanged(this, new PropertyChangedEventArgs("Value")); } if(PropertyChanged!=null) PropertyChanged(this, new PropertyChangedEventArgs("Value")); }
} }
} }
public FieldType FieldType; private FieldType fieldType;
public string Scope; public FieldType FieldType {
get { return fieldType; }
set { fieldType = value; }
}
private string scope;
public string Scope {
get { return scope; }
set { scope = value; }
}
/// <summary> /// <summary>
/// Constructs a new Field instance, usually you should be using FieldFactory /// Constructs a new Field instance, usually you should be using FieldFactory
@ -54,15 +63,15 @@ namespace Greenshot.Drawing.Fields {
/// should not be reused for FieldHolders of another Type (e.g. typeof(EllipseContainer)) /// should not be reused for FieldHolders of another Type (e.g. typeof(EllipseContainer))
/// </param> /// </param>
public Field(FieldType fieldType, Type scope) { public Field(FieldType fieldType, Type scope) {
FieldType = fieldType; this.fieldType = fieldType;
Scope = scope.FullName; this.scope = scope.FullName;
} }
public Field(FieldType fieldType, string scope) { public Field(FieldType fieldType, string scope) {
FieldType = fieldType; this.fieldType = fieldType;
Scope = scope; this.scope = scope;
} }
public Field(FieldType fieldType) { public Field(FieldType fieldType) {
FieldType = fieldType; this.fieldType = fieldType;
} }
/// <summary> /// <summary>
/// Returns true if this field holds a value other than null. /// Returns true if this field holds a value other than null.
@ -76,7 +85,7 @@ namespace Greenshot.Drawing.Fields {
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public Field Clone() { public Field Clone() {
Field ret = new Field(FieldType, Scope); Field ret = new Field(fieldType, scope);
ret.Value = Value; ret.Value = Value;
return ret; return ret;
} }
@ -84,9 +93,9 @@ namespace Greenshot.Drawing.Fields {
public override int GetHashCode() { public override int GetHashCode() {
int hashCode = 0; int hashCode = 0;
unchecked { unchecked {
hashCode += 1000000009 * FieldType.GetHashCode(); hashCode += 1000000009 * fieldType.GetHashCode();
if (Scope != null) if (scope != null)
hashCode += 1000000021 * Scope.GetHashCode(); hashCode += 1000000021 * scope.GetHashCode();
} }
return hashCode; return hashCode;
} }
@ -96,27 +105,12 @@ namespace Greenshot.Drawing.Fields {
if (other == null) { if (other == null) {
return false; return false;
} }
return this.FieldType == other.FieldType && object.Equals(this.Scope, other.Scope); return this.fieldType == other.fieldType && object.Equals(this.scope, other.scope);
} }
public override string ToString() { public override string ToString() {
return string.Format("[Field FieldType={1} Value={0} Scope={2}]", this.myValue, this.FieldType, this.Scope); return string.Format("[Field FieldType={1} Value={0} Scope={2}]", this.myValue, this.fieldType, this.scope);
} }
} }
/// <summary>
/// EventHandler to be used when a field value changes
/// </summary>
public delegate void FieldChangedEventHandler(object sender, FieldChangedEventArgs e);
/// <summary>
/// EventArgs to be used with FieldChangedEventHandler
/// </summary>
public class FieldChangedEventArgs : EventArgs {
public readonly Field Field;
public FieldChangedEventArgs(Field field) {
this.Field = field;
}
}
} }

View file

@ -59,7 +59,7 @@ namespace Greenshot.Drawing.Fields {
} }
public override void AddField(Field field) { public override void AddField(IField field) {
base.AddField(field); base.AddField(field);
field.PropertyChanged += new PropertyChangedEventHandler(OwnPropertyChanged); field.PropertyChanged += new PropertyChangedEventHandler(OwnPropertyChanged);
} }
@ -142,24 +142,24 @@ namespace Greenshot.Drawing.Fields {
status = Status.IDLE; status = Status.IDLE;
} }
private List<Field> FindCommonFields() { private List<IField> FindCommonFields() {
List<Field> ret = null; List<IField> ret = null;
if(boundContainers.Count > 0) { if(boundContainers.Count > 0) {
// take all fields from the least selected container... // take all fields from the least selected container...
ret = boundContainers[boundContainers.Count-1].GetFields(); ret = boundContainers[boundContainers.Count-1].GetFields();
for(int i=0;i<boundContainers.Count-1; i++) { for(int i=0;i<boundContainers.Count-1; i++) {
DrawableContainer dc = boundContainers[i]; DrawableContainer dc = boundContainers[i];
List<Field> fieldsToRemove = new List<Field>(); List<IField> fieldsToRemove = new List<IField>();
foreach(Field f in ret) { foreach(IField f in ret) {
// ... throw out those that do not apply to one of the other containers // ... throw out those that do not apply to one of the other containers
if(!dc.HasField(f.FieldType)) fieldsToRemove.Add(f); if(!dc.HasField(f.FieldType)) fieldsToRemove.Add(f);
} }
foreach(Field f in fieldsToRemove) { foreach(IField f in fieldsToRemove) {
ret.Remove(f); ret.Remove(f);
} }
} }
} }
if(ret == null) ret = new List<Field>(); if(ret == null) ret = new List<IField>();
return ret; return ret;
} }
@ -171,7 +171,7 @@ namespace Greenshot.Drawing.Fields {
if(f.Scope == null || dc.GetType().FullName.Equals(f.Scope)) { if(f.Scope == null || dc.GetType().FullName.Equals(f.Scope)) {
if(LOG.IsDebugEnabled) LOG.Debug("Updating field: "+f.FieldType+": "+f.Value); if(LOG.IsDebugEnabled) LOG.Debug("Updating field: "+f.FieldType+": "+f.Value);
if(dc.HasField(f.FieldType)) { if(dc.HasField(f.FieldType)) {
Field dcf = dc.GetField(f.FieldType); IField dcf = dc.GetField(f.FieldType);
dcf.Value = f.Value; dcf.Value = f.Value;
// update last used from DC field, so that scope is honored // update last used from DC field, so that scope is honored
AppConfig.GetInstance().UpdateLastUsedFieldValue(dcf); AppConfig.GetInstance().UpdateLastUsedFieldValue(dcf);

View file

@ -31,6 +31,30 @@ namespace Greenshot.Drawing.Fields {
/// </summary> /// </summary>
public class FieldFactory { public class FieldFactory {
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() {}
/// <param name="fieldType">FieldType of the field to construct</param> /// <param name="fieldType">FieldType of the field to construct</param>
@ -73,16 +97,29 @@ namespace Greenshot.Drawing.Fields {
} else { } else {
ret = new Field(fieldType); ret = new Field(fieldType);
} }
AppConfig.GetInstance().GetLastUsedValueForField(ret, preferredDefaultValue); AppConfig.GetInstance().GetLastUsedValueForField(ret);
if(ret.Value == null) {
if(preferredDefaultValue != null) 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.Values) { foreach(FieldType ft in FieldType.GetValues(typeof(FieldType))) {
Field f = CreateField(ft); Field f = CreateField(ft);
f.Value = ft.DefaultValue; f.Value = GetDefaultValueForField(f);
ret.Add(f); ret.Add(f);
} }
return ret; return ret;

View file

@ -1,117 +0,0 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
namespace Greenshot.Drawing.Fields {
/// <summary>
/// Defines all FieldTypes + their default value.
/// (The additional value is why this is not an enum)
/// </summary>
[Serializable]
public class FieldType {
public static readonly FieldType ARROWHEADS = new FieldType("ARROWHEADS", Greenshot.Drawing.ArrowContainer.ArrowHeadCombination.END_POINT);
public static readonly FieldType BLUR_RADIUS = new FieldType("BLUR_RADIUS", 3);
public static readonly FieldType BRIGHTNESS = new FieldType("BRIGHTNESS", 0.9d);
public static readonly FieldType FILL_COLOR = new FieldType("FILL_COLOR", Color.Transparent);
public static readonly FieldType FONT_BOLD = new FieldType("FONT_BOLD", false);
public static readonly FieldType FONT_FAMILY = new FieldType("FONT_FAMILY", FontFamily.GenericSansSerif.Name);
public static readonly FieldType FONT_ITALIC = new FieldType("FONT_ITALIC", false);
public static readonly FieldType FONT_SIZE = new FieldType("FONT_SIZE", 11f);
public static readonly FieldType HIGHLIGHT_COLOR = new FieldType("HIGHLIGHT_COLOR", Color.Yellow);
public static readonly FieldType LINE_COLOR = new FieldType("LINE_COLOR", Color.Red);
public static readonly FieldType LINE_THICKNESS = new FieldType("LINE_THICKNESS", 1);
public static readonly FieldType MAGNIFICATION_FACTOR = new FieldType("MAGNIFICATION_FACTOR", 2);
public static readonly FieldType PIXEL_SIZE = new FieldType("PIXEL_SIZE", 5);
public static readonly FieldType PREVIEW_QUALITY = new FieldType("PREVIEW_QUALITY", 1.0d);
public static readonly FieldType SHADOW = new FieldType("SHADOW", false);
public static readonly FieldType PREPARED_FILTER_OBFUSCATE = new FieldType("PREPARED_FILTER_OBFUSCATE", FilterContainer.PreparedFilter.PIXELIZE);
public static readonly FieldType PREPARED_FILTER_HIGHLIGHT = new FieldType("PREPARED_FILTER_HIGHLIGHT", FilterContainer.PreparedFilter.TEXT_HIGHTLIGHT);
public static readonly FieldType FLAGS = new FieldType("FLAGS", null);
public static FieldType[] Values = new FieldType[]{
ARROWHEADS,
BLUR_RADIUS,
BRIGHTNESS,
FILL_COLOR,
FONT_BOLD,
FONT_FAMILY,
FONT_ITALIC,
FONT_SIZE,
HIGHLIGHT_COLOR,
LINE_COLOR,
LINE_THICKNESS,
MAGNIFICATION_FACTOR,
PIXEL_SIZE,
PREVIEW_QUALITY,
SHADOW,
PREPARED_FILTER_OBFUSCATE,
PREPARED_FILTER_HIGHLIGHT,
FLAGS
};
[Flags]
public enum Flag {
NONE = 0,
CONFIRMABLE = 1
}
public object DefaultValue;
public string Name;
private FieldType(string name, object defaultValue) {
Name = name;
DefaultValue=defaultValue;
}
public override string ToString() {
return this.Name;
}
public override int GetHashCode()
{
int hashCode = 0;
unchecked {
if (Name != null)
hashCode += 1000000009 * Name.GetHashCode();
}
return hashCode;
}
public override bool Equals(object obj)
{
FieldType other = obj as FieldType;
if (other == null)
return false;
return object.Equals(this.Name,other.Name);
}
public static bool operator ==(FieldType a, FieldType b) {
return object.Equals(a,b);
}
public static bool operator !=(FieldType a, FieldType b) {
return !object.Equals(a,b);
}
}
}

View file

@ -728,7 +728,7 @@ namespace Greenshot {
fontItalicButton.Visible = props.HasFieldValue(FieldType.FONT_ITALIC); fontItalicButton.Visible = props.HasFieldValue(FieldType.FONT_ITALIC);
shadowButton.Visible = props.HasFieldValue(FieldType.SHADOW); shadowButton.Visible = props.HasFieldValue(FieldType.SHADOW);
btnConfirm.Visible = btnCancel.Visible = props.HasFieldValue(FieldType.FLAGS) btnConfirm.Visible = btnCancel.Visible = props.HasFieldValue(FieldType.FLAGS)
&& ((FieldType.Flag)props.GetFieldValue(FieldType.FLAGS)&FieldType.Flag.CONFIRMABLE) == FieldType.Flag.CONFIRMABLE; && ((FieldFlag)props.GetFieldValue(FieldType.FLAGS)&FieldFlag.CONFIRMABLE) == FieldFlag.CONFIRMABLE;
obfuscateModeButton.Visible = props.HasFieldValue(FieldType.PREPARED_FILTER_OBFUSCATE); obfuscateModeButton.Visible = props.HasFieldValue(FieldType.PREPARED_FILTER_OBFUSCATE);
highlightModeButton.Visible = props.HasFieldValue(FieldType.PREPARED_FILTER_HIGHLIGHT); highlightModeButton.Visible = props.HasFieldValue(FieldType.PREPARED_FILTER_HIGHLIGHT);
@ -747,7 +747,7 @@ namespace Greenshot {
FieldAggregator props = surface.FieldAggregator; FieldAggregator props = surface.FieldAggregator;
// if a confirmable element is selected, we must disable most of the controls // if a confirmable element is selected, we must disable most of the controls
// since we demand confirmation or cancel for confirmable element // since we demand confirmation or cancel for confirmable element
if (props.HasFieldValue(FieldType.FLAGS) && ((FieldType.Flag)props.GetFieldValue(FieldType.FLAGS) & FieldType.Flag.CONFIRMABLE) == FieldType.Flag.CONFIRMABLE) { if (props.HasFieldValue(FieldType.FLAGS) && ((FieldFlag)props.GetFieldValue(FieldType.FLAGS) & FieldFlag.CONFIRMABLE) == FieldFlag.CONFIRMABLE) {
// disable most controls // disable most controls
if(!controlsDisabledDueToConfirmable) { if(!controlsDisabledDueToConfirmable) {
ToolStripItemEndisabler.Disable(menuStrip1); ToolStripItemEndisabler.Disable(menuStrip1);

View file

@ -98,8 +98,6 @@
<Compile Include="Drawing\Fields\AbstractFieldHolder.cs" /> <Compile Include="Drawing\Fields\AbstractFieldHolder.cs" />
<Compile Include="Drawing\Fields\Field.cs" /> <Compile Include="Drawing\Fields\Field.cs" />
<Compile Include="Drawing\Fields\FieldFactory.cs" /> <Compile Include="Drawing\Fields\FieldFactory.cs" />
<Compile Include="Drawing\Fields\FieldType.cs" />
<Compile Include="Drawing\Fields\IFieldHolder.cs" />
<Compile Include="Drawing\Fields\FieldAggregator.cs" /> <Compile Include="Drawing\Fields\FieldAggregator.cs" />
<Compile Include="Drawing\MetafileContainer.cs" /> <Compile Include="Drawing\MetafileContainer.cs" />
<Compile Include="Drawing\ObfuscateContainer.cs" /> <Compile Include="Drawing\ObfuscateContainer.cs" />

View file

@ -87,8 +87,8 @@ namespace Greenshot.Test.Drawing.Properties
ObfuscateContainer clone = (ObfuscateContainer)Objects.DeepClone(oc); ObfuscateContainer clone = (ObfuscateContainer)Objects.DeepClone(oc);
Assert.AreEqual(oc.Children.GetType(), clone.Children.GetType()); Assert.AreEqual(oc.Children.GetType(), clone.Children.GetType());
System.Collections.Generic.List<Field> ocFields = oc.GetFields(); System.Collections.Generic.List<IField> ocFields = oc.GetFields();
System.Collections.Generic.List<Field> cloneFields = clone.GetFields(); System.Collections.Generic.List<IField> cloneFields = clone.GetFields();
Assert.AreEqual(ocFields, cloneFields); Assert.AreEqual(ocFields, cloneFields);
} }

View file

@ -0,0 +1,57 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
namespace Greenshot.Drawing.Fields {
/// <summary>
/// Defines all FieldTypes + their default value.
/// (The additional value is why this is not an enum)
/// </summary>
[Serializable]
public enum FieldType {
ARROWHEADS,
BLUR_RADIUS,
BRIGHTNESS,
FILL_COLOR,
FONT_BOLD,
FONT_FAMILY,
FONT_ITALIC,
FONT_SIZE,
HIGHLIGHT_COLOR,
LINE_COLOR,
LINE_THICKNESS,
MAGNIFICATION_FACTOR,
PIXEL_SIZE,
PREVIEW_QUALITY,
SHADOW,
PREPARED_FILTER_OBFUSCATE,
PREPARED_FILTER_HIGHLIGHT,
FLAGS
}
[Flags]
public enum FieldFlag {
NONE = 0,
CONFIRMABLE = 1
}
}

View file

@ -0,0 +1,48 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.ComponentModel;
namespace Greenshot.Drawing.Fields {
public interface IField : INotifyPropertyChanged
{
object Value { get; set; }
FieldType FieldType { get; set; }
string Scope { get; set; }
bool HasValue { get; }
}
/// <summary>
/// EventHandler to be used when a field value changes
/// </summary>
public delegate void FieldChangedEventHandler(object sender, FieldChangedEventArgs e);
/// <summary>
/// EventArgs to be used with FieldChangedEventHandler
/// </summary>
public class FieldChangedEventArgs : EventArgs {
public readonly IField Field;
public FieldChangedEventArgs(IField field) {
this.Field = field;
}
}
}

View file

@ -32,10 +32,10 @@ namespace Greenshot.Drawing.Fields {
event FieldChangedEventHandler FieldChanged; event FieldChangedEventHandler FieldChanged;
void AddField(Field field); void AddField(IField field);
void RemoveField(Field field); void RemoveField(IField field);
List<Field> GetFields(); List<IField> GetFields();
Field GetField(FieldType fieldType); IField GetField(FieldType fieldType);
bool HasField(FieldType fieldType); bool HasField(FieldType fieldType);
void SetFieldValue(FieldType fieldType, object value); void SetFieldValue(FieldType fieldType, object value);
} }

View file

@ -44,8 +44,13 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Drawing" />
<Folder Include="Drawing\Fields" />
<Folder Include="Lib" /> <Folder Include="Lib" />
<Folder Include="UnmanagedHelpers" /> <Folder Include="UnmanagedHelpers" />
<Compile Include="Drawing\Fields\FieldType.cs" />
<Compile Include="Drawing\Fields\IField.cs" />
<Compile Include="Drawing\Fields\IFieldHolder.cs" />
<Compile Include="UnmanagedHelpers\GDI32.cs" /> <Compile Include="UnmanagedHelpers\GDI32.cs" />
<Compile Include="UnmanagedHelpers\User32.cs" /> <Compile Include="UnmanagedHelpers\User32.cs" />
<Compile Include="UnmanagedHelpers\Win32Errors.cs" /> <Compile Include="UnmanagedHelpers\Win32Errors.cs" />