ae7c3a3fff
- OperationMode now designed and implemented in a way that allows serialization - Modes are now defined using an enumeration with with attributes decorated values - MainWindow.xaml.cs's event handlers now only listen for changes to certain properties - Property naming conventions fixed - AvaloniaProperties are now public + static + readonly
45 lines
1.7 KiB
C#
45 lines
1.7 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
|
|
using BFR.Helpers;
|
|
using BFR.Operations.Attributes;
|
|
|
|
namespace BFR.Operations
|
|
{
|
|
public class ReplaceOperationMode : OperationMode<ReplaceMode>
|
|
{
|
|
public bool IsPattern => Index == ReplaceMode.Pattern;
|
|
public bool IsCharacters => Index == ReplaceMode.Characters;
|
|
public bool IsFromNToN => Index == ReplaceMode.FromNToN;
|
|
public bool IsFirstN => Index == ReplaceMode.FirstN;
|
|
public bool IsLastN => Index == ReplaceMode.LastN;
|
|
|
|
public readonly static ReplaceOperationMode[] Modes = All();
|
|
|
|
protected ReplaceOperationMode(ReplaceMode index, string name, string description) :
|
|
base(index, name, description) { }
|
|
|
|
protected static ReplaceOperationMode[] All() => ((IEnumerable<ReplaceMode>)Enum.GetValues(typeof(ReplaceMode))).Select(x =>
|
|
new ReplaceOperationMode(
|
|
x,
|
|
x.GetAttribute<DisplayNameAttribute>().DisplayName,
|
|
x.GetAttribute<DescriptionAttribute>().Description
|
|
)).ToArray();
|
|
}
|
|
|
|
public enum ReplaceMode
|
|
{
|
|
[DisplayName(nameof(Pattern)), Description("Replaces the specified pattern.")]
|
|
Pattern,
|
|
[DisplayName(nameof(Characters)), Description("Replaces each of the specified characters.")]
|
|
Characters,
|
|
[DisplayName("From N to N"), Description("Replaces everything in the specified range (zero-based indeces).")]
|
|
FromNToN,
|
|
[DisplayName("First N"), Description("Replaces the first N characters.")]
|
|
FirstN,
|
|
[DisplayName("Last N"), Description("Replaces the last N characters.")]
|
|
LastN,
|
|
}
|
|
}
|