From dc29ef0a2732d89380cf4eb2694604dc64cc5ec6 Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 22 Nov 2016 07:31:11 +0100 Subject: [PATCH] FEATURE-863: Fixed counter to work with a flag, still the starting value is not serialized / deserialized? --- Greenshot/Drawing/Fields/FieldType.cs | 4 +-- Greenshot/Drawing/StepLabelContainer.cs | 16 +---------- Greenshot/Drawing/Surface.cs | 30 +++++++++++++++----- Greenshot/Forms/ImageEditorForm.cs | 5 ++-- GreenshotPlugin/GreenshotPlugin.csproj | 3 -- GreenshotPlugin/Interfaces/Drawing/IField.cs | 3 +- 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/Greenshot/Drawing/Fields/FieldType.cs b/Greenshot/Drawing/Fields/FieldType.cs index f73518dd3..d99af3759 100644 --- a/Greenshot/Drawing/Fields/FieldType.cs +++ b/Greenshot/Drawing/Fields/FieldType.cs @@ -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 diff --git a/Greenshot/Drawing/StepLabelContainer.cs b/Greenshot/Drawing/StepLabelContainer.cs index fb5ae1e42..8775e8d43 100644 --- a/Greenshot/Drawing/StepLabelContainer.cs +++ b/Greenshot/Drawing/StepLabelContainer.cs @@ -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); } /// diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs index 33965bc7a..d12ae30bf 100644 --- a/Greenshot/Drawing/Surface.cs +++ b/Greenshot/Drawing/Surface.cs @@ -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 /// /// Description of Surface. /// - 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(); + /// + /// This value is used to start counting the step labels + /// + private int _counterStart = 1; + /// /// The GUID of the surface /// @@ -73,6 +79,20 @@ namespace Greenshot.Drawing /// /// Event handlers (do not serialize!) /// + [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 /// private readonly List _stepLabels = new List(); - /// - /// This value is used to start counting the step labels - /// - 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(); } } diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index bdd316a04..133112824 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -1033,7 +1033,7 @@ namespace Greenshot { 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(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()); } /// @@ -1059,7 +1059,8 @@ namespace Greenshot { textHorizontalAlignmentButton.Visible = props.HasFieldValue(FieldType.TEXT_HORIZONTAL_ALIGNMENT); textVerticalAlignmentButton.Visible = props.HasFieldValue(FieldType.TEXT_VERTICAL_ALIGNMENT); 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) && ((FieldFlag)props.GetFieldValue(FieldType.FLAGS) & FieldFlag.CONFIRMABLE) == FieldFlag.CONFIRMABLE; diff --git a/GreenshotPlugin/GreenshotPlugin.csproj b/GreenshotPlugin/GreenshotPlugin.csproj index a854cd79f..1c3ab8ce7 100644 --- a/GreenshotPlugin/GreenshotPlugin.csproj +++ b/GreenshotPlugin/GreenshotPlugin.csproj @@ -236,9 +236,6 @@ GreenshotResources.cs - - - diff --git a/GreenshotPlugin/Interfaces/Drawing/IField.cs b/GreenshotPlugin/Interfaces/Drawing/IField.cs index 5a8f0a673..1dcd46061 100644 --- a/GreenshotPlugin/Interfaces/Drawing/IField.cs +++ b/GreenshotPlugin/Interfaces/Drawing/IField.cs @@ -28,7 +28,8 @@ namespace GreenshotPlugin.Interfaces.Drawing public enum FieldFlag { NONE = 0, - CONFIRMABLE = 1 + CONFIRMABLE = 1, + COUNTER = 2 } public interface IFieldType {