mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
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:
parent
b574f82685
commit
0dffa6054b
15 changed files with 209 additions and 191 deletions
|
@ -286,21 +286,17 @@ 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 {
|
|||
/// <returns></returns>
|
||||
/// <param name="f"></param>
|
||||
/// <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) {
|
||||
return f.FieldType.Name;
|
||||
return f.FieldType.ToString();
|
||||
} else {
|
||||
return f.FieldType.Name + "-" + f.Scope;
|
||||
return f.FieldType.ToString() + "-" + f.Scope;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace Greenshot.Drawing {
|
|||
/// </summary>
|
||||
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) {
|
||||
|
|
|
@ -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<FieldType, Field> fieldsByType = new Dictionary<FieldType, Field>();
|
||||
private List<Field> fields = new List<Field>();
|
||||
private Dictionary<FieldType, IField> fieldsByType = new Dictionary<FieldType, IField>();
|
||||
private List<IField> fields = new List<IField>();
|
||||
|
||||
|
||||
|
||||
|
@ -58,7 +58,7 @@ namespace Greenshot.Drawing.Fields {
|
|||
|
||||
[OnDeserializedAttribute()]
|
||||
private void OnDeserialized(StreamingContext context) {
|
||||
fieldsByType = new Dictionary<FieldType, Field>();
|
||||
fieldsByType = new Dictionary<FieldType, IField>();
|
||||
// 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<Field> GetFields() {
|
||||
public List<IField> GetFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
public Field GetField(FieldType fieldType) {
|
||||
public IField GetField(FieldType fieldType) {
|
||||
try {
|
||||
return fieldsByType[fieldType];
|
||||
} catch(KeyNotFoundException e) {
|
||||
|
|
|
@ -72,8 +72,8 @@ namespace Greenshot.Drawing.Fields {
|
|||
if(childrenChanged != null) childrenChanged(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public new List<Field> GetFields() {
|
||||
List<Field> ret = new List<Field>();
|
||||
public new List<IField> GetFields() {
|
||||
List<IField> ret = new List<IField>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace Greenshot.Drawing.Fields {
|
|||
/// line thickness of a rectangle.
|
||||
/// </summary>
|
||||
[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; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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))
|
||||
/// </param>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns true if this field holds a value other than null.
|
||||
|
@ -76,7 +85,7 @@ namespace Greenshot.Drawing.Fields {
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Field> FindCommonFields() {
|
||||
List<Field> ret = null;
|
||||
private List<IField> FindCommonFields() {
|
||||
List<IField> 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<boundContainers.Count-1; i++) {
|
||||
DrawableContainer dc = boundContainers[i];
|
||||
List<Field> fieldsToRemove = new List<Field>();
|
||||
foreach(Field f in ret) {
|
||||
List<IField> fieldsToRemove = new List<IField>();
|
||||
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<Field>();
|
||||
if(ret == null) ret = new List<IField>();
|
||||
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);
|
||||
|
|
|
@ -31,6 +31,30 @@ namespace Greenshot.Drawing.Fields {
|
|||
/// </summary>
|
||||
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() {}
|
||||
|
||||
/// <param name="fieldType">FieldType of the field to construct</param>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <returns>a List of all available fields with their respective default value</returns>
|
||||
public static List<Field> GetDefaultFields() {
|
||||
List<Field> ret = new List<Field>();
|
||||
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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -98,8 +98,6 @@
|
|||
<Compile Include="Drawing\Fields\AbstractFieldHolder.cs" />
|
||||
<Compile Include="Drawing\Fields\Field.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\MetafileContainer.cs" />
|
||||
<Compile Include="Drawing\ObfuscateContainer.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<Field> ocFields = oc.GetFields();
|
||||
System.Collections.Generic.List<Field> cloneFields = clone.GetFields();
|
||||
System.Collections.Generic.List<IField> ocFields = oc.GetFields();
|
||||
System.Collections.Generic.List<IField> cloneFields = clone.GetFields();
|
||||
Assert.AreEqual(ocFields, cloneFields);
|
||||
}
|
||||
|
||||
|
|
57
GreenshotCore/Drawing/Fields/FieldType.cs
Normal file
57
GreenshotCore/Drawing/Fields/FieldType.cs
Normal 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
|
||||
}
|
||||
|
||||
}
|
48
GreenshotCore/Drawing/Fields/IField.cs
Normal file
48
GreenshotCore/Drawing/Fields/IField.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,10 +32,10 @@ namespace Greenshot.Drawing.Fields {
|
|||
|
||||
event FieldChangedEventHandler FieldChanged;
|
||||
|
||||
void AddField(Field field);
|
||||
void RemoveField(Field field);
|
||||
List<Field> GetFields();
|
||||
Field GetField(FieldType fieldType);
|
||||
void AddField(IField field);
|
||||
void RemoveField(IField field);
|
||||
List<IField> GetFields();
|
||||
IField GetField(FieldType fieldType);
|
||||
bool HasField(FieldType fieldType);
|
||||
void SetFieldValue(FieldType fieldType, object value);
|
||||
}
|
|
@ -44,8 +44,13 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Drawing" />
|
||||
<Folder Include="Drawing\Fields" />
|
||||
<Folder Include="Lib" />
|
||||
<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\User32.cs" />
|
||||
<Compile Include="UnmanagedHelpers\Win32Errors.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue