FEATURE-863: Fixed counter to work with a flag, still the starting value is not serialized / deserialized?

This commit is contained in:
Robin 2016-11-22 07:31:11 +01:00
parent f2f37700b3
commit dc29ef0a27
6 changed files with 30 additions and 31 deletions

View file

@ -51,7 +51,6 @@ namespace Greenshot.Drawing.Fields
public static readonly IFieldType PREPARED_FILTER_OBFUSCATE = new FieldType("PREPARED_FILTER_OBFUSCATE"); public static readonly IFieldType PREPARED_FILTER_OBFUSCATE = new FieldType("PREPARED_FILTER_OBFUSCATE");
public static readonly IFieldType PREPARED_FILTER_HIGHLIGHT = new FieldType("PREPARED_FILTER_HIGHLIGHT"); public static readonly IFieldType PREPARED_FILTER_HIGHLIGHT = new FieldType("PREPARED_FILTER_HIGHLIGHT");
public static readonly IFieldType FLAGS = new FieldType("FLAGS"); public static readonly IFieldType FLAGS = new FieldType("FLAGS");
public static readonly IFieldType COUNTER_START = new FieldType("COUNTER_START");
public static IFieldType[] Values = { public static IFieldType[] Values = {
ARROWHEADS, ARROWHEADS,
@ -73,8 +72,7 @@ namespace Greenshot.Drawing.Fields
SHADOW, SHADOW,
PREPARED_FILTER_OBFUSCATE, PREPARED_FILTER_OBFUSCATE,
PREPARED_FILTER_HIGHLIGHT, PREPARED_FILTER_HIGHLIGHT,
FLAGS, FLAGS
COUNTER_START
}; };
public string Name public string Name

View file

@ -49,19 +49,9 @@ namespace Greenshot.Drawing {
Init(); Init();
} }
private void UpdateCounterOnFieldChanged(object sender, FieldChangedEventArgs fieldChangedEventArgs)
{
if (Equals(fieldChangedEventArgs.Field.FieldType, FieldType.COUNTER_START))
{
Parent.CounterStart = (int)fieldChangedEventArgs.Field.Value;
}
}
private void Init() private void Init()
{ {
CreateDefaultAdorners(); CreateDefaultAdorners();
FieldChanged -= UpdateCounterOnFieldChanged;
FieldChanged += UpdateCounterOnFieldChanged;
} }
#region Number serializing #region Number serializing
@ -113,10 +103,6 @@ namespace Greenshot.Drawing {
} }
((Surface) Parent)?.RemoveStepLabel(this); ((Surface) Parent)?.RemoveStepLabel(this);
base.SwitchParent(newParent); base.SwitchParent(newParent);
if (Parent != null)
{
Parent.CounterStart = GetFieldValueAsInt(FieldType.COUNTER_START);
}
if (newParent != null) { if (newParent != null) {
((Surface)Parent)?.AddStepLabel(this); ((Surface)Parent)?.AddStepLabel(this);
} }
@ -150,7 +136,7 @@ namespace Greenshot.Drawing {
protected override void InitializeFields() { protected override void InitializeFields() {
AddField(GetType(), FieldType.FILL_COLOR, Color.DarkRed); AddField(GetType(), FieldType.FILL_COLOR, Color.DarkRed);
AddField(GetType(), FieldType.LINE_COLOR, Color.White); AddField(GetType(), FieldType.LINE_COLOR, Color.White);
AddField(GetType(), FieldType.COUNTER_START, 1); AddField(GetType(), FieldType.FLAGS, FieldFlag.COUNTER);
} }
/// <summary> /// <summary>

View file

@ -33,6 +33,7 @@ using GreenshotPlugin.Interfaces.Drawing;
using log4net; using log4net;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Drawing.Imaging; using System.Drawing.Imaging;
@ -46,7 +47,7 @@ namespace Greenshot.Drawing
/// <summary> /// <summary>
/// Description of Surface. /// Description of Surface.
/// </summary> /// </summary>
public sealed class Surface : Control, ISurface public sealed class Surface : Control, ISurface, INotifyPropertyChanged
{ {
private static readonly ILog LOG = LogManager.GetLogger(typeof(Surface)); private static readonly ILog LOG = LogManager.GetLogger(typeof(Surface));
public static int Count; public static int Count;
@ -55,6 +56,11 @@ namespace Greenshot.Drawing
// Property to identify the Surface ID // Property to identify the Surface ID
private Guid _uniqueId = Guid.NewGuid(); private Guid _uniqueId = Guid.NewGuid();
/// <summary>
/// This value is used to start counting the step labels
/// </summary>
private int _counterStart = 1;
/// <summary> /// <summary>
/// The GUID of the surface /// The GUID of the surface
/// </summary> /// </summary>
@ -73,6 +79,20 @@ namespace Greenshot.Drawing
/// <summary> /// <summary>
/// Event handlers (do not serialize!) /// Event handlers (do not serialize!)
/// </summary> /// </summary>
[NonSerialized]
private PropertyChangedEventHandler _propertyChanged;
public event PropertyChangedEventHandler PropertyChanged
{
add
{
_propertyChanged += value;
}
remove
{
_propertyChanged -= value;
}
}
[NonSerialized] [NonSerialized]
private SurfaceElementEventHandler _movingElementChanged; private SurfaceElementEventHandler _movingElementChanged;
public event SurfaceElementEventHandler MovingElementChanged public event SurfaceElementEventHandler MovingElementChanged
@ -228,11 +248,6 @@ namespace Greenshot.Drawing
/// </summary> /// </summary>
private readonly List<StepLabelContainer> _stepLabels = new List<StepLabelContainer>(); private readonly List<StepLabelContainer> _stepLabels = new List<StepLabelContainer>();
/// <summary>
/// This value is used to start counting the step labels
/// </summary>
private int _counterStart = 1;
public void AddStepLabel(StepLabelContainer stepLabel) public void AddStepLabel(StepLabelContainer stepLabel)
{ {
if (!_stepLabels.Contains(stepLabel)) if (!_stepLabels.Contains(stepLabel))
@ -254,9 +269,10 @@ namespace Greenshot.Drawing
get { return _counterStart; } get { return _counterStart; }
set set
{ {
if (_counterStart != value) if (_propertyChanged != null && _counterStart != value)
{ {
_counterStart = value; _counterStart = value;
_propertyChanged(this, new PropertyChangedEventArgs("CounterStart"));
Invalidate(); Invalidate();
} }
} }

View file

@ -1033,7 +1033,7 @@ namespace Greenshot {
new BidirectionalBinding(previewQualityUpDown, "Value", _surface.FieldAggregator.GetField(FieldType.PREVIEW_QUALITY), "Value", DecimalDoublePercentageConverter.GetInstance(), NotNullValidator.GetInstance()); new BidirectionalBinding(previewQualityUpDown, "Value", _surface.FieldAggregator.GetField(FieldType.PREVIEW_QUALITY), "Value", DecimalDoublePercentageConverter.GetInstance(), NotNullValidator.GetInstance());
new BidirectionalBinding(obfuscateModeButton, "SelectedTag", _surface.FieldAggregator.GetField(FieldType.PREPARED_FILTER_OBFUSCATE), "Value"); new BidirectionalBinding(obfuscateModeButton, "SelectedTag", _surface.FieldAggregator.GetField(FieldType.PREPARED_FILTER_OBFUSCATE), "Value");
new BidirectionalBinding(highlightModeButton, "SelectedTag", _surface.FieldAggregator.GetField(FieldType.PREPARED_FILTER_HIGHLIGHT), "Value"); new BidirectionalBinding(highlightModeButton, "SelectedTag", _surface.FieldAggregator.GetField(FieldType.PREPARED_FILTER_HIGHLIGHT), "Value");
new BidirectionalBinding(counterUpDown, "Value", _surface.FieldAggregator.GetField(FieldType.COUNTER_START), "Value", DecimalIntConverter.GetInstance(), NotNullValidator.GetInstance()); new BidirectionalBinding(counterUpDown, "Value", _surface, "CounterStart", DecimalIntConverter.GetInstance(), NotNullValidator.GetInstance());
} }
/// <summary> /// <summary>
@ -1059,7 +1059,8 @@ namespace Greenshot {
textHorizontalAlignmentButton.Visible = props.HasFieldValue(FieldType.TEXT_HORIZONTAL_ALIGNMENT); textHorizontalAlignmentButton.Visible = props.HasFieldValue(FieldType.TEXT_HORIZONTAL_ALIGNMENT);
textVerticalAlignmentButton.Visible = props.HasFieldValue(FieldType.TEXT_VERTICAL_ALIGNMENT); textVerticalAlignmentButton.Visible = props.HasFieldValue(FieldType.TEXT_VERTICAL_ALIGNMENT);
shadowButton.Visible = props.HasFieldValue(FieldType.SHADOW); shadowButton.Visible = props.HasFieldValue(FieldType.SHADOW);
counterLabel.Visible = counterUpDown.Visible = props.HasFieldValue(FieldType.COUNTER_START); counterLabel.Visible = counterUpDown.Visible = props.HasFieldValue(FieldType.FLAGS)
&& ((FieldFlag)props.GetFieldValue(FieldType.FLAGS) & FieldFlag.COUNTER) == FieldFlag.COUNTER;
btnConfirm.Visible = btnCancel.Visible = props.HasFieldValue(FieldType.FLAGS) btnConfirm.Visible = btnCancel.Visible = props.HasFieldValue(FieldType.FLAGS)
&& ((FieldFlag)props.GetFieldValue(FieldType.FLAGS) & FieldFlag.CONFIRMABLE) == FieldFlag.CONFIRMABLE; && ((FieldFlag)props.GetFieldValue(FieldType.FLAGS) & FieldFlag.CONFIRMABLE) == FieldFlag.CONFIRMABLE;

View file

@ -236,9 +236,6 @@
<DependentUpon>GreenshotResources.cs</DependentUpon> <DependentUpon>GreenshotResources.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Interfaces\Drawing\Filters\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>

View file

@ -28,7 +28,8 @@ namespace GreenshotPlugin.Interfaces.Drawing
public enum FieldFlag public enum FieldFlag
{ {
NONE = 0, NONE = 0,
CONFIRMABLE = 1 CONFIRMABLE = 1,
COUNTER = 2
} }
public interface IFieldType public interface IFieldType
{ {