Skip to content

Commit

Permalink
Make ExpressionObserver accept a priority for sets.
Browse files Browse the repository at this point in the history
This makes auto-expanding the treeview in DevTools work again.
  • Loading branch information
grokys committed Mar 9, 2016
1 parent 22952e4 commit 886fbb5
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/Markup/Perspex.Markup.Xaml/Data/Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public InstancedBinding Initiate(
targetProperty?.PropertyType ?? typeof(object),
Converter ?? DefaultValueConverter.Instance,
ConverterParameter,
FallbackValue);
FallbackValue,
Priority);

return new InstancedBinding(subject, Mode, Priority);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Markup/Perspex.Markup/Data/ExpressionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Reactive.Subjects;
using Perspex.Data;

namespace Perspex.Markup.Data
{
Expand Down Expand Up @@ -76,9 +77,9 @@ public WeakReference CurrentValue
}
}

public virtual bool SetValue(object value)
public virtual bool SetValue(object value, BindingPriority priority)
{
return Next?.SetValue(value) ?? false;
return Next?.SetValue(value, priority) ?? false;
}

public virtual IDisposable Subscribe(IObserver<object> observer)
Expand Down
6 changes: 4 additions & 2 deletions src/Markup/Perspex.Markup/Data/ExpressionObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Perspex.Data;
using Perspex.Markup.Data.Plugins;

namespace Perspex.Markup.Data
Expand Down Expand Up @@ -105,11 +106,12 @@ public ExpressionObserver(
/// Attempts to set the value of a property expression.
/// </summary>
/// <param name="value">The value to set.</param>
/// <param name="priority">The binding priority to use.</param>
/// <returns>
/// True if the value could be set; false if the expression does not evaluate to a
/// property.
/// </returns>
public bool SetValue(object value)
public bool SetValue(object value, BindingPriority priority = BindingPriority.LocalValue)
{
IncrementCount();

Expand All @@ -120,7 +122,7 @@ public bool SetValue(object value)

try
{
return _node?.SetValue(value) ?? false;
return _node?.SetValue(value, priority) ?? false;
}
finally
{
Expand Down
9 changes: 7 additions & 2 deletions src/Markup/Perspex.Markup/Data/ExpressionSubject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Globalization;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Perspex.Data;
using Perspex.Utilities;

namespace Perspex.Markup.Data
Expand All @@ -18,6 +19,7 @@ public class ExpressionSubject : ISubject<object>, IDescription
private readonly ExpressionObserver _inner;
private readonly Type _targetType;
private readonly object _fallbackValue;
private readonly BindingPriority _priority;

/// <summary>
/// Initializes a new instance of the <see cref="ExpressionObserver"/> class.
Expand All @@ -41,12 +43,14 @@ public ExpressionSubject(ExpressionObserver inner, Type targetType)
/// <param name="fallbackValue">
/// The value to use when the binding is unable to produce a value.
/// </param>
/// <param name="priority">The binding priority.</param>
public ExpressionSubject(
ExpressionObserver inner,
Type targetType,
IValueConverter converter,
object converterParameter = null,
object fallbackValue = null)
object fallbackValue = null,
BindingPriority priority = BindingPriority.LocalValue)
{
Contract.Requires<ArgumentNullException>(inner != null);
Contract.Requires<ArgumentNullException>(targetType != null);
Expand All @@ -57,6 +61,7 @@ public ExpressionSubject(
Converter = converter;
ConverterParameter = converterParameter;
_fallbackValue = fallbackValue;
_priority = priority;
}

/// <summary>
Expand Down Expand Up @@ -100,7 +105,7 @@ public void OnNext(object value)
converted = TypeUtilities.Default(type);
}

_inner.SetValue(converted);
_inner.SetValue(converted, _priority);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Markup/Perspex.Markup/Data/LogicalNotNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
using System;
using System.Globalization;
using System.Reactive.Linq;
using Perspex.Data;

namespace Perspex.Markup.Data
{
internal class LogicalNotNode : ExpressionNode
{
public override bool SetValue(object value)
public override bool SetValue(object value, BindingPriority priority)
{
return false;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Markup/Perspex.Markup/Data/Plugins/IPropertyAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using System;
using Perspex.Data;

namespace Perspex.Markup.Data.Plugins
{
Expand All @@ -27,9 +28,12 @@ public interface IPropertyAccessor : IDisposable
/// <param name="value">
/// The value to set. Guaranteed to be of a valid type for the property.
/// </param>
/// <param name="priority">
/// The priority with which to set the value.
/// </param>
/// <returns>
/// True if the property was set; false if the property could not be set.
/// </returns>
bool SetValue(object value);
bool SetValue(object value, BindingPriority priority);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Reactive.Linq;
using System.Reflection;
using Perspex.Data;
using Perspex.Utilities;

namespace Perspex.Markup.Data.Plugins
Expand Down Expand Up @@ -106,7 +107,7 @@ public void Dispose()
}
}

public bool SetValue(object value)
public bool SetValue(object value, BindingPriority priority)
{
if (_property.CanWrite)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Reactive.Linq;
using Perspex.Data;

namespace Perspex.Markup.Data.Plugins
{
Expand Down Expand Up @@ -95,11 +96,11 @@ public void Dispose()
_subscription = null;
}

public bool SetValue(object value)
public bool SetValue(object value, BindingPriority priority)
{
if (!_property.IsReadOnly)
{
Instance.SetValue(_property, value);
Instance.SetValue(_property, value, priority);
return true;
}

Expand Down
7 changes: 4 additions & 3 deletions src/Markup/Perspex.Markup/Data/PropertyAccessorNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using Perspex.Data;
using Perspex.Markup.Data.Plugins;

namespace Perspex.Markup.Data
Expand All @@ -26,17 +27,17 @@ public PropertyAccessorNode(string propertyName)

public Type PropertyType => _accessor?.PropertyType;

public override bool SetValue(object value)
public override bool SetValue(object value, BindingPriority priority)
{
if (Next != null)
{
return Next.SetValue(value);
return Next.SetValue(value, priority);
}
else
{
if (_accessor != null)
{
return _accessor.SetValue(value);
return _accessor.SetValue(value, priority);
}

return false;
Expand Down

0 comments on commit 886fbb5

Please sign in to comment.