using System;
using System.Collections.Generic;
using System.Linq;
namespace InABox.Core
{
// When creating a new field with properties, make sure to override LoadProperties() and SaveProperties()
public abstract class DFLayoutFieldProperties : DFLayoutObject
{
[EditorSequence(-999)]
[CodeEditor(Editable = Editable.Enabled, ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789")]
public string Code { get; set; }
[EditorSequence(-998)]
[TextBoxEditor]
public string Description { get; set; }
[EditorSequence(-997)]
[ComboLookupEditor(typeof(PropertyLookupGenerator))]
public string Property { get; set; }
[CheckBoxEditor]
[EditorSequence(4)]
public bool Required { get; set; }
[CheckBoxEditor]
[EditorSequence(5)]
public bool Secure { get; set; }
[CheckBoxEditor]
[EditorSequence(6)]
public bool Retain { get; set; }
[CheckBoxEditor]
[EditorSequence(7)]
public bool Hidden { get; set; }
[ExpressionEditor(null)]
[EditorSequence(8)]
public string Expression { get; set; }
///
/// An expression that sets the field to have a background colour of its result.
/// The result of the expression should be either a hex code like #rrggbb or #aarrggbb, or the string name of a ,
/// like 'Yellow'.
///
[ExpressionEditor(null, ToolTip = "Evalutes to either a hex code (#RRGGBB or #AARRGGBB) or a colour name (like 'Red' or 'Yellow'), which sets the background colour for this variable.")]
[EditorSequence(9)]
public string ColourExpression { get; set; }
public abstract string FormatValue(object? value);
public abstract void Serialize(DFSaveStorageEntry entry, object? value);
public abstract object? Deserialize(DFLoadStorageEntry entry);
public abstract object? GetValue(object? value);
public virtual IEnumerable GetAdditionalColumns()
{
return Enumerable.Empty();
}
public virtual IEnumerable> GetAdditionalValues(object? value)
{
return Enumerable.Empty>();
}
public abstract IEnumerable GetDisplayColumns();
public abstract IEnumerable> GetDisplayValues(object? value);
protected override void LoadProperties()
{
Description = GetProperty(nameof(Description), "");
Property = GetProperty(nameof(Property), "");
Required = GetProperty(nameof(Required), false);
Secure = GetProperty(nameof(Secure), false);
Retain = GetProperty(nameof(Retain), false);
Expression = GetProperty(nameof(Expression), "");
ColourExpression = GetProperty(nameof(ColourExpression), "");
}
protected override void SaveProperties()
{
SetProperty(nameof(Description), Description);
SetProperty(nameof(Property), Property);
SetProperty(nameof(Required), Required);
SetProperty(nameof(Secure), Secure);
SetProperty(nameof(Retain), Retain);
SetProperty(nameof(Expression), Expression);
SetProperty(nameof(ColourExpression), ColourExpression);
}
private class PropertyLookupGenerator : LookupGenerator