Browse Source

Renamed IsEnabledCore -> IsEffectivelyEnabled.

I now understand how WPF's `IsEnabledCore` works, and it's not like this. Rename `IsEnabledCore` to `IsEffectivelyEnabled` so that we can add a new `IsEnabledCore` property which works like WPF's.

This also aligns with the existing `IsEffectivelyVisible` property.
pull/2529/head
Steven Kirk 7 years ago
parent
commit
e6be9b7c5a
  1. 2
      src/Avalonia.Controls/ComboBox.cs
  2. 2
      src/Avalonia.Input/FocusManager.cs
  3. 6
      src/Avalonia.Input/IInputElement.cs
  4. 42
      src/Avalonia.Input/InputElement.cs
  5. 2
      src/Avalonia.Input/InputExtensions.cs
  6. 4
      src/Avalonia.Input/Navigation/FocusExtensions.cs
  7. 2
      tests/Avalonia.Controls.UnitTests/ButtonTests.cs
  8. 2
      tests/Avalonia.Controls.UnitTests/MenuItemTests.cs

2
src/Avalonia.Controls/ComboBox.cs

@ -302,7 +302,7 @@ namespace Avalonia.Controls
} }
} }
private bool CanFocus(IControl control) => control.Focusable && control.IsEnabledCore && control.IsVisible; private bool CanFocus(IControl control) => control.Focusable && control.IsEffectivelyEnabled && control.IsVisible;
private void UpdateSelectionBoxItem(object item) private void UpdateSelectionBoxItem(object item)
{ {

2
src/Avalonia.Input/FocusManager.cs

@ -146,7 +146,7 @@ namespace Avalonia.Input
/// </summary> /// </summary>
/// <param name="e">The element.</param> /// <param name="e">The element.</param>
/// <returns>True if the element can be focused.</returns> /// <returns>True if the element can be focused.</returns>
private static bool CanFocus(IInputElement e) => e.Focusable && e.IsEnabledCore && e.IsVisible; private static bool CanFocus(IInputElement e) => e.Focusable && e.IsEffectivelyEnabled && e.IsVisible;
/// <summary> /// <summary>
/// Gets the focus scope ancestors of the specified control, traversing popups. /// Gets the focus scope ancestors of the specified control, traversing popups.

6
src/Avalonia.Input/IInputElement.cs

@ -83,14 +83,14 @@ namespace Avalonia.Input
Cursor Cursor { get; } Cursor Cursor { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether the control is effectively enabled for user interaction. /// Gets a value indicating whether this control and all its parents are enabled.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The <see cref="IsEnabled"/> property is used to toggle the enabled state for individual /// The <see cref="IsEnabled"/> property is used to toggle the enabled state for individual
/// controls. The <see cref="IsEnabledCore"/> property takes into account the /// controls. The <see cref="IsEffectivelyEnabled"/> property takes into account the
/// <see cref="IsEnabled"/> value of this control and its parent controls. /// <see cref="IsEnabled"/> value of this control and its parent controls.
/// </remarks> /// </remarks>
bool IsEnabledCore { get; } bool IsEffectivelyEnabled { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether the control is focused. /// Gets a value indicating whether the control is focused.

42
src/Avalonia.Input/InputElement.cs

@ -27,10 +27,10 @@ namespace Avalonia.Input
AvaloniaProperty.Register<InputElement, bool>(nameof(IsEnabled), true); AvaloniaProperty.Register<InputElement, bool>(nameof(IsEnabled), true);
/// <summary> /// <summary>
/// Defines the <see cref="IsEnabledCore"/> property. /// Defines the <see cref="IsEffectivelyEnabled"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<bool> IsEnabledCoreProperty = public static readonly StyledProperty<bool> IsEffectivelyEnabledProperty =
AvaloniaProperty.Register<InputElement, bool>(nameof(IsEnabledCore), true); AvaloniaProperty.Register<InputElement, bool>(nameof(IsEffectivelyEnabled), true);
/// <summary> /// <summary>
/// Gets or sets associated mouse cursor. /// Gets or sets associated mouse cursor.
@ -168,7 +168,7 @@ namespace Avalonia.Input
PointerReleasedEvent.AddClassHandler<InputElement>(x => x.OnPointerReleased); PointerReleasedEvent.AddClassHandler<InputElement>(x => x.OnPointerReleased);
PointerWheelChangedEvent.AddClassHandler<InputElement>(x => x.OnPointerWheelChanged); PointerWheelChangedEvent.AddClassHandler<InputElement>(x => x.OnPointerWheelChanged);
PseudoClass<InputElement, bool>(IsEnabledCoreProperty, x => !x, ":disabled"); PseudoClass<InputElement, bool>(IsEffectivelyEnabledProperty, x => !x, ":disabled");
PseudoClass<InputElement>(IsFocusedProperty, ":focus"); PseudoClass<InputElement>(IsFocusedProperty, ":focus");
PseudoClass<InputElement>(IsPointerOverProperty, ":pointerover"); PseudoClass<InputElement>(IsPointerOverProperty, ":pointerover");
} }
@ -349,23 +349,23 @@ namespace Avalonia.Input
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The <see cref="IsEnabled"/> property is used to toggle the enabled state for individual /// The <see cref="IsEnabled"/> property is used to toggle the enabled state for individual
/// controls. The <see cref="IsEnabledCore"/> property takes into account the /// controls. The <see cref="IsEffectivelyEnabled"/> property takes into account the
/// <see cref="IsEnabled"/> value of this control and its parent controls. /// <see cref="IsEnabled"/> value of this control and its parent controls.
/// </remarks> /// </remarks>
bool IInputElement.IsEnabledCore => IsEnabledCore; bool IInputElement.IsEffectivelyEnabled => IsEffectivelyEnabled;
/// <summary> /// <summary>
/// Gets a value indicating whether the control is effectively enabled for user interaction. /// Gets a value indicating whether the control is effectively enabled for user interaction.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The <see cref="IsEnabled"/> property is used to toggle the enabled state for individual /// The <see cref="IsEnabled"/> property is used to toggle the enabled state for individual
/// controls. The <see cref="IsEnabledCore"/> property takes into account the /// controls. The <see cref="IsEffectivelyEnabled"/> property takes into account the
/// <see cref="IsEnabled"/> value of this control and its parent controls. /// <see cref="IsEnabled"/> value of this control and its parent controls.
/// </remarks> /// </remarks>
protected bool IsEnabledCore protected bool IsEffectivelyEnabled
{ {
get { return GetValue(IsEnabledCoreProperty); } get { return GetValue(IsEffectivelyEnabledProperty); }
set { SetValue(IsEnabledCoreProperty, value); } set { SetValue(IsEffectivelyEnabledProperty, value); }
} }
public List<KeyBinding> KeyBindings { get; } = new List<KeyBinding>(); public List<KeyBinding> KeyBindings { get; } = new List<KeyBinding>();
@ -393,7 +393,7 @@ namespace Avalonia.Input
protected override void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e) protected override void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e)
{ {
base.OnAttachedToVisualTreeCore(e); base.OnAttachedToVisualTreeCore(e);
UpdateIsEnabledCore(); UpdateIsEffectivelyEnabled();
} }
/// <summary> /// <summary>
@ -488,7 +488,7 @@ namespace Avalonia.Input
private static void IsEnabledChanged(AvaloniaPropertyChangedEventArgs e) private static void IsEnabledChanged(AvaloniaPropertyChangedEventArgs e)
{ {
((InputElement)e.Sender).UpdateIsEnabledCore(); ((InputElement)e.Sender).UpdateIsEffectivelyEnabled();
} }
/// <summary> /// <summary>
@ -512,32 +512,32 @@ namespace Avalonia.Input
} }
/// <summary> /// <summary>
/// Updates the <see cref="IsEnabledCore"/> property value. /// Updates the <see cref="IsEffectivelyEnabled"/> property value.
/// </summary> /// </summary>
private void UpdateIsEnabledCore() private void UpdateIsEffectivelyEnabled()
{ {
UpdateIsEnabledCore(this.GetVisualParent<InputElement>()); UpdateIsEffectivelyEnabled(this.GetVisualParent<InputElement>());
} }
/// <summary> /// <summary>
/// Updates the <see cref="IsEnabledCore"/> property based on the parent's /// Updates the <see cref="IsEffectivelyEnabled"/> property based on the parent's
/// <see cref="IsEnabledCore"/>. /// <see cref="IsEffectivelyEnabled"/>.
/// </summary> /// </summary>
/// <param name="parent">The parent control.</param> /// <param name="parent">The parent control.</param>
private void UpdateIsEnabledCore(InputElement parent) private void UpdateIsEffectivelyEnabled(InputElement parent)
{ {
if (parent != null) if (parent != null)
{ {
IsEnabledCore = IsEnabled && parent.IsEnabledCore; IsEffectivelyEnabled = IsEnabled && parent.IsEffectivelyEnabled;
} }
else else
{ {
IsEnabledCore = IsEnabled; IsEffectivelyEnabled = IsEnabled;
} }
foreach (var child in this.GetVisualChildren().OfType<InputElement>()) foreach (var child in this.GetVisualChildren().OfType<InputElement>())
{ {
child.UpdateIsEnabledCore(this); child.UpdateIsEffectivelyEnabled(this);
} }
} }
} }

2
src/Avalonia.Input/InputExtensions.cs

@ -45,7 +45,7 @@ namespace Avalonia.Input
return element != null && return element != null &&
element.IsVisible && element.IsVisible &&
element.IsHitTestVisible && element.IsHitTestVisible &&
element.IsEnabledCore && element.IsEffectivelyEnabled &&
element.IsAttachedToVisualTree; element.IsAttachedToVisualTree;
} }
} }

4
src/Avalonia.Input/Navigation/FocusExtensions.cs

@ -13,13 +13,13 @@ namespace Avalonia.Input.Navigation
/// </summary> /// </summary>
/// <param name="e">The element.</param> /// <param name="e">The element.</param>
/// <returns>True if the element can be focused.</returns> /// <returns>True if the element can be focused.</returns>
public static bool CanFocus(this IInputElement e) => e.Focusable && e.IsEnabledCore && e.IsVisible; public static bool CanFocus(this IInputElement e) => e.Focusable && e.IsEffectivelyEnabled && e.IsVisible;
/// <summary> /// <summary>
/// Checks if descendants of the specified element can be focused. /// Checks if descendants of the specified element can be focused.
/// </summary> /// </summary>
/// <param name="e">The element.</param> /// <param name="e">The element.</param>
/// <returns>True if descendants of the element can be focused.</returns> /// <returns>True if descendants of the element can be focused.</returns>
public static bool CanFocusDescendants(this IInputElement e) => e.IsEnabledCore && e.IsVisible; public static bool CanFocusDescendants(this IInputElement e) => e.IsEffectivelyEnabled && e.IsVisible;
} }
} }

2
tests/Avalonia.Controls.UnitTests/ButtonTests.cs

@ -43,7 +43,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot { Child = target }; var root = new TestRoot { Child = target };
Assert.False(((IInputElement)target).IsEnabledCore); Assert.False(((IInputElement)target).IsEffectivelyEnabled);
} }
[Fact] [Fact]

2
tests/Avalonia.Controls.UnitTests/MenuItemTests.cs

@ -71,7 +71,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot { Child = target }; var root = new TestRoot { Child = target };
Assert.False(((IInputElement)target).IsEnabledCore); Assert.False(((IInputElement)target).IsEffectivelyEnabled);
} }
private class TestCommand : ICommand private class TestCommand : ICommand

Loading…
Cancel
Save