diff --git a/Greenshot/Configuration/AppConfig.cs b/Greenshot/Configuration/AppConfig.cs index f89338a03..3394a4758 100644 --- a/Greenshot/Configuration/AppConfig.cs +++ b/Greenshot/Configuration/AppConfig.cs @@ -286,22 +286,18 @@ namespace Greenshot.Configuration { } } - public void UpdateLastUsedFieldValue(Field f) { + public void UpdateLastUsedFieldValue(IField f) { if(f.Value != null) { string key = GetKeyForField(f); LastUsedFieldValues[key] = f.Value; } } - public Field GetLastUsedValueForField(Field f, object preferredDefaultValue) { + public IField GetLastUsedValueForField(IField f) { string key = GetKeyForField(f); if(LastUsedFieldValues.ContainsKey(key)) { f.Value = LastUsedFieldValues[key]; - } else if(preferredDefaultValue != null) { - f.Value = preferredDefaultValue; - }else { - f.Value = f.FieldType.DefaultValue; - } + } return f; } @@ -309,11 +305,11 @@ namespace Greenshot.Configuration { /// /// /// the key under which last used value for the Field can be stored/retrieved - private string GetKeyForField(Field f) { + private string GetKeyForField(IField f) { if(f.Scope == null) { - return f.FieldType.Name; + return f.FieldType.ToString(); } else { - return f.FieldType.Name + "-" + f.Scope; + return f.FieldType.ToString() + "-" + f.Scope; } } } diff --git a/Greenshot/Drawing/CropContainer.cs b/Greenshot/Drawing/CropContainer.cs index 84c61db56..21ea7f398 100644 --- a/Greenshot/Drawing/CropContainer.cs +++ b/Greenshot/Drawing/CropContainer.cs @@ -33,7 +33,7 @@ namespace Greenshot.Drawing { /// public class CropContainer : DrawableContainer { 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) { diff --git a/Greenshot/Drawing/Fields/AbstractFieldHolder.cs b/Greenshot/Drawing/Fields/AbstractFieldHolder.cs index dd5cac654..1c2f0a78f 100644 --- a/Greenshot/Drawing/Fields/AbstractFieldHolder.cs +++ b/Greenshot/Drawing/Fields/AbstractFieldHolder.cs @@ -48,8 +48,8 @@ namespace Greenshot.Drawing.Fields { // we keep to Coolections of our fields, dictionary for quick access, list for serialization // this allows us to use default serialization [NonSerialized] - private Dictionary fieldsByType = new Dictionary(); - private List fields = new List(); + private Dictionary fieldsByType = new Dictionary(); + private List fields = new List(); @@ -58,7 +58,7 @@ namespace Greenshot.Drawing.Fields { [OnDeserializedAttribute()] private void OnDeserialized(StreamingContext context) { - fieldsByType = new Dictionary(); + fieldsByType = new Dictionary(); // listen to changing properties foreach(Field field in fields) { 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(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)); }; } - public void RemoveField(Field field) { + public void RemoveField(IField field) { fields.Remove(field); fieldsByType.Remove(field.FieldType); field.PropertyChanged -= delegate { if(fieldChanged != null) fieldChanged(this, new FieldChangedEventArgs(field)); }; } - public List GetFields() { + public List GetFields() { return fields; } - public Field GetField(FieldType fieldType) { + public IField GetField(FieldType fieldType) { try { return fieldsByType[fieldType]; } catch(KeyNotFoundException e) { diff --git a/Greenshot/Drawing/Fields/AbstractFieldHolderWithChildren.cs b/Greenshot/Drawing/Fields/AbstractFieldHolderWithChildren.cs index 8254ed35e..4a2a1ff4f 100644 --- a/Greenshot/Drawing/Fields/AbstractFieldHolderWithChildren.cs +++ b/Greenshot/Drawing/Fields/AbstractFieldHolderWithChildren.cs @@ -72,8 +72,8 @@ namespace Greenshot.Drawing.Fields { if(childrenChanged != null) childrenChanged(this, EventArgs.Empty); } - public new List GetFields() { - List ret = new List(); + public new List GetFields() { + List ret = new List(); ret.AddRange(base.GetFields()); foreach(IFieldHolder fh in Children) { ret.AddRange(fh.GetFields()); @@ -81,8 +81,8 @@ namespace Greenshot.Drawing.Fields { return ret; } - public new Field GetField(FieldType fieldType) { - Field ret = null; + public new IField GetField(FieldType fieldType) { + IField ret = null; if(base.HasField(fieldType)) { ret = base.GetField(fieldType); } else { @@ -113,12 +113,12 @@ namespace Greenshot.Drawing.Fields { } public new bool HasFieldValue(FieldType fieldType) { - Field f = GetField(fieldType); + IField f = GetField(fieldType); return f != null && f.HasValue; } public new void SetFieldValue(FieldType fieldType, object value) { - Field f = GetField(fieldType); + IField f = GetField(fieldType); if(f != null) f.Value = value; } diff --git a/Greenshot/Drawing/Fields/Field.cs b/Greenshot/Drawing/Fields/Field.cs index 1b05b9143..121d4d0ff 100644 --- a/Greenshot/Drawing/Fields/Field.cs +++ b/Greenshot/Drawing/Fields/Field.cs @@ -27,7 +27,7 @@ namespace Greenshot.Drawing.Fields { /// line thickness of a rectangle. /// [Serializable] - public class Field : INotifyPropertyChanged { + public class Field : IField { [field:NonSerialized] public event PropertyChangedEventHandler PropertyChanged; @@ -39,8 +39,17 @@ namespace Greenshot.Drawing.Fields { if(PropertyChanged!=null) PropertyChanged(this, new PropertyChangedEventArgs("Value")); } } } - public FieldType FieldType; - public string Scope; + private FieldType fieldType; + public FieldType FieldType { + get { return fieldType; } + set { fieldType = value; } + } + + private string scope; + public string Scope { + get { return scope; } + set { scope = value; } + } /// /// 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)) /// public Field(FieldType fieldType, Type scope) { - FieldType = fieldType; - Scope = scope.FullName; + this.fieldType = fieldType; + this.scope = scope.FullName; } public Field(FieldType fieldType, string scope) { - FieldType = fieldType; - Scope = scope; + this.fieldType = fieldType; + this.scope = scope; } public Field(FieldType fieldType) { - FieldType = fieldType; + this.fieldType = fieldType; } /// /// Returns true if this field holds a value other than null. @@ -76,7 +85,7 @@ namespace Greenshot.Drawing.Fields { /// /// public Field Clone() { - Field ret = new Field(FieldType, Scope); + Field ret = new Field(fieldType, scope); ret.Value = Value; return ret; } @@ -84,9 +93,9 @@ namespace Greenshot.Drawing.Fields { public override int GetHashCode() { int hashCode = 0; unchecked { - hashCode += 1000000009 * FieldType.GetHashCode(); - if (Scope != null) - hashCode += 1000000021 * Scope.GetHashCode(); + hashCode += 1000000009 * fieldType.GetHashCode(); + if (scope != null) + hashCode += 1000000021 * scope.GetHashCode(); } return hashCode; } @@ -96,27 +105,12 @@ namespace Greenshot.Drawing.Fields { if (other == null) { 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() { - 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); } } - - /// - /// EventHandler to be used when a field value changes - /// - public delegate void FieldChangedEventHandler(object sender, FieldChangedEventArgs e); - - /// - /// EventArgs to be used with FieldChangedEventHandler - /// - public class FieldChangedEventArgs : EventArgs { - public readonly Field Field; - public FieldChangedEventArgs(Field field) { - this.Field = field; - } - } } diff --git a/Greenshot/Drawing/Fields/FieldAggregator.cs b/Greenshot/Drawing/Fields/FieldAggregator.cs index 5bd8e8a7e..b2b5264ca 100644 --- a/Greenshot/Drawing/Fields/FieldAggregator.cs +++ b/Greenshot/Drawing/Fields/FieldAggregator.cs @@ -59,7 +59,7 @@ namespace Greenshot.Drawing.Fields { } - public override void AddField(Field field) { + public override void AddField(IField field) { base.AddField(field); field.PropertyChanged += new PropertyChangedEventHandler(OwnPropertyChanged); } @@ -142,24 +142,24 @@ namespace Greenshot.Drawing.Fields { status = Status.IDLE; } - private List FindCommonFields() { - List ret = null; + private List FindCommonFields() { + List ret = null; if(boundContainers.Count > 0) { // take all fields from the least selected container... ret = boundContainers[boundContainers.Count-1].GetFields(); for(int i=0;i fieldsToRemove = new List(); - foreach(Field f in ret) { + List fieldsToRemove = new List(); + foreach(IField f in ret) { // ... throw out those that do not apply to one of the other containers if(!dc.HasField(f.FieldType)) fieldsToRemove.Add(f); } - foreach(Field f in fieldsToRemove) { + foreach(IField f in fieldsToRemove) { ret.Remove(f); } } } - if(ret == null) ret = new List(); + if(ret == null) ret = new List(); return ret; } @@ -171,7 +171,7 @@ namespace Greenshot.Drawing.Fields { if(f.Scope == null || dc.GetType().FullName.Equals(f.Scope)) { if(LOG.IsDebugEnabled) LOG.Debug("Updating field: "+f.FieldType+": "+f.Value); if(dc.HasField(f.FieldType)) { - Field dcf = dc.GetField(f.FieldType); + IField dcf = dc.GetField(f.FieldType); dcf.Value = f.Value; // update last used from DC field, so that scope is honored AppConfig.GetInstance().UpdateLastUsedFieldValue(dcf); diff --git a/Greenshot/Drawing/Fields/FieldFactory.cs b/Greenshot/Drawing/Fields/FieldFactory.cs index 92e195382..cc5c9c7bd 100644 --- a/Greenshot/Drawing/Fields/FieldFactory.cs +++ b/Greenshot/Drawing/Fields/FieldFactory.cs @@ -31,6 +31,30 @@ namespace Greenshot.Drawing.Fields { /// public class FieldFactory { + private static Dictionary DEFAULT_VALUES; + + static FieldFactory() { + DEFAULT_VALUES = new Dictionary(); + 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() {} /// FieldType of the field to construct @@ -73,16 +97,29 @@ namespace Greenshot.Drawing.Fields { } else { 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; } + 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); + } + } + + /// a List of all available fields with their respective default value public static List GetDefaultFields() { List ret = new List(); - foreach(FieldType ft in FieldType.Values) { + foreach(FieldType ft in FieldType.GetValues(typeof(FieldType))) { Field f = CreateField(ft); - f.Value = ft.DefaultValue; + f.Value = GetDefaultValueForField(f); ret.Add(f); } return ret; diff --git a/Greenshot/Drawing/Fields/FieldType.cs b/Greenshot/Drawing/Fields/FieldType.cs deleted file mode 100644 index d0c404532..000000000 --- a/Greenshot/Drawing/Fields/FieldType.cs +++ /dev/null @@ -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 . - */ -using System; -using System.Drawing; - -namespace Greenshot.Drawing.Fields { - /// - /// Defines all FieldTypes + their default value. - /// (The additional value is why this is not an enum) - /// - [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); - } - - } - - -} diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index 5350b4ad9..6ddbd1d4b 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -728,7 +728,7 @@ namespace Greenshot { fontItalicButton.Visible = props.HasFieldValue(FieldType.FONT_ITALIC); shadowButton.Visible = props.HasFieldValue(FieldType.SHADOW); 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); highlightModeButton.Visible = props.HasFieldValue(FieldType.PREPARED_FILTER_HIGHLIGHT); @@ -747,7 +747,7 @@ namespace Greenshot { FieldAggregator props = surface.FieldAggregator; // if a confirmable element is selected, we must disable most of the controls // 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 if(!controlsDisabledDueToConfirmable) { ToolStripItemEndisabler.Disable(menuStrip1); diff --git a/Greenshot/Greenshot.csproj b/Greenshot/Greenshot.csproj index b213d8376..e330c9dd2 100644 --- a/Greenshot/Greenshot.csproj +++ b/Greenshot/Greenshot.csproj @@ -98,8 +98,6 @@ - - diff --git a/Greenshot/Test/Drawing/Properties/SerializationTest.cs b/Greenshot/Test/Drawing/Properties/SerializationTest.cs index e15ff3646..940afcf12 100644 --- a/Greenshot/Test/Drawing/Properties/SerializationTest.cs +++ b/Greenshot/Test/Drawing/Properties/SerializationTest.cs @@ -87,8 +87,8 @@ namespace Greenshot.Test.Drawing.Properties ObfuscateContainer clone = (ObfuscateContainer)Objects.DeepClone(oc); Assert.AreEqual(oc.Children.GetType(), clone.Children.GetType()); - System.Collections.Generic.List ocFields = oc.GetFields(); - System.Collections.Generic.List cloneFields = clone.GetFields(); + System.Collections.Generic.List ocFields = oc.GetFields(); + System.Collections.Generic.List cloneFields = clone.GetFields(); Assert.AreEqual(ocFields, cloneFields); } diff --git a/GreenshotCore/Drawing/Fields/FieldType.cs b/GreenshotCore/Drawing/Fields/FieldType.cs new file mode 100644 index 000000000..7ce4aa5bc --- /dev/null +++ b/GreenshotCore/Drawing/Fields/FieldType.cs @@ -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 . + */ +using System; +using System.Drawing; + +namespace Greenshot.Drawing.Fields { + /// + /// Defines all FieldTypes + their default value. + /// (The additional value is why this is not an enum) + /// + [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 + } + +} diff --git a/GreenshotCore/Drawing/Fields/IField.cs b/GreenshotCore/Drawing/Fields/IField.cs new file mode 100644 index 000000000..104e0f794 --- /dev/null +++ b/GreenshotCore/Drawing/Fields/IField.cs @@ -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 . + */ +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; } + } + + /// + /// EventHandler to be used when a field value changes + /// + public delegate void FieldChangedEventHandler(object sender, FieldChangedEventArgs e); + + /// + /// EventArgs to be used with FieldChangedEventHandler + /// + public class FieldChangedEventArgs : EventArgs { + public readonly IField Field; + public FieldChangedEventArgs(IField field) { + this.Field = field; + } + } +} diff --git a/Greenshot/Drawing/Fields/IFieldHolder.cs b/GreenshotCore/Drawing/Fields/IFieldHolder.cs similarity index 93% rename from Greenshot/Drawing/Fields/IFieldHolder.cs rename to GreenshotCore/Drawing/Fields/IFieldHolder.cs index 4a2050b93..d875e3697 100644 --- a/Greenshot/Drawing/Fields/IFieldHolder.cs +++ b/GreenshotCore/Drawing/Fields/IFieldHolder.cs @@ -32,10 +32,10 @@ namespace Greenshot.Drawing.Fields { event FieldChangedEventHandler FieldChanged; - void AddField(Field field); - void RemoveField(Field field); - List GetFields(); - Field GetField(FieldType fieldType); + void AddField(IField field); + void RemoveField(IField field); + List GetFields(); + IField GetField(FieldType fieldType); bool HasField(FieldType fieldType); void SetFieldValue(FieldType fieldType, object value); } diff --git a/GreenshotCore/GreenshotCore.csproj b/GreenshotCore/GreenshotCore.csproj index c1ddc2506..96cdbc548 100644 --- a/GreenshotCore/GreenshotCore.csproj +++ b/GreenshotCore/GreenshotCore.csproj @@ -44,8 +44,13 @@ + + + + +