// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Reactive.Disposables;
using Avalonia.Data;
namespace Avalonia
{
///
/// Stores bindings for a priority level in a .
///
///
///
/// Each priority level in a has a current ,
/// a list of and a . When there are no
/// bindings present, or all bindings return then
/// Value will equal DirectValue.
///
///
/// When there are bindings present, then the latest added binding that doesn't return
/// UnsetValue will take precedence. The active binding is returned by the
/// property (which refers to the active binding's
/// property rather than the index in
/// Bindings).
///
///
/// If DirectValue is set while a binding is active, then it will replace the
/// current value until the active binding fires again.
///
///
internal class PriorityLevel
{
private object _directValue;
private int _nextIndex;
///
/// Initializes a new instance of the class.
///
/// The owner.
/// The priority.
public PriorityLevel(
PriorityValue owner,
int priority)
{
Contract.Requires(owner != null);
Owner = owner;
Priority = priority;
Value = _directValue = AvaloniaProperty.UnsetValue;
ActiveBindingIndex = -1;
Bindings = new LinkedList();
}
///
/// Gets the owner of the level.
///
public PriorityValue Owner { get; }
///
/// Gets the priority of this level.
///
public int Priority { get; }
///
/// Gets or sets the direct value for this priority level.
///
public object DirectValue
{
get
{
return _directValue;
}
set
{
Value = _directValue = value;
Owner.LevelValueChanged(this);
}
}
///
/// Gets the current binding for the priority level.
///
public object Value { get; private set; }
///
/// Gets the value of the active binding, or -1
/// if no binding is active.
///
public int ActiveBindingIndex { get; private set; }
///
/// Gets the bindings for the priority level.
///
public LinkedList Bindings { get; }
///
/// Adds a binding.
///
/// The binding to add.
/// A disposable used to remove the binding.
public IDisposable Add(IObservable