using System;
namespace InABox.Core
{
public enum Editable
{
Enabled,
Disabled,
Hidden,
///
/// Disabled when using a DynamicGrid with DirectEdit option set, but enabled in editor
///
DisabledOnDirectEdit
}
///
/// Set whether or not this property is editable, overriding any on this property or any sub-properties.
///
///
/// What this actually does is that when is loading a property, it checks to find the outer-most parent property
/// of that property with an , or if the property has one of its own. If so, it overrides the
/// property of that property's , combining using the function.
///
public class EditableAttribute: Attribute
{
public Editable Editable { get; set; }
public EditableAttribute(Editable editable)
{
Editable = editable;
}
}
public static class EditableUtils
{
public static bool IsEditable(this Editable editable)
{
return editable == Editable.Enabled || editable == Editable.DisabledOnDirectEdit;
}
public static bool IsDirectEditable(this Editable editable)
{
return editable == Editable.Enabled;
}
public static bool ColumnVisible(this Editable editable)
{
return editable != Editable.Hidden;
}
public static bool EditorVisible(this Editable editable)
{
return editable != Editable.Hidden;
}
///
/// Combine (restrictively) two editable enums.
///
///
///
///
public static Editable Combine(this Editable editable, Editable other)
{
switch (editable)
{
case Editable.Enabled:
return other;
case Editable.DisabledOnDirectEdit:
if (other == Editable.Disabled || other == Editable.Hidden)
return other;
return editable;
case Editable.Disabled:
if (other == Editable.Hidden)
return other;
return editable;
case Editable.Hidden:
default:
return editable;
}
}
}
}