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

View file

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

View file

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