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)
{

2
src/Avalonia.Input/FocusManager.cs

@ -146,7 +146,7 @@ namespace Avalonia.Input
/// </summary>
/// <param name="e">The element.</param>
/// <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>
/// 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; }
/// <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>
/// <remarks>
/// 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.
/// </remarks>
bool IsEnabledCore { get; }
bool IsEffectivelyEnabled { get; }
/// <summary>
/// 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);
/// <summary>
/// Defines the <see cref="IsEnabledCore"/> property.
/// Defines the <see cref="IsEffectivelyEnabled"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsEnabledCoreProperty =
AvaloniaProperty.Register<InputElement, bool>(nameof(IsEnabledCore), true);
public static readonly StyledProperty<bool> IsEffectivelyEnabledProperty =
AvaloniaProperty.Register<InputElement, bool>(nameof(IsEffectivelyEnabled), true);
/// <summary>
/// Gets or sets associated mouse cursor.
@ -168,7 +168,7 @@ namespace Avalonia.Input
PointerReleasedEvent.AddClassHandler<InputElement>(x => x.OnPointerReleased);
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>(IsPointerOverProperty, ":pointerover");
}
@ -349,23 +349,23 @@ namespace Avalonia.Input
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
bool IInputElement.IsEnabledCore => IsEnabledCore;
bool IInputElement.IsEffectivelyEnabled => IsEffectivelyEnabled;
/// <summary>
/// Gets a value indicating whether the control is effectively enabled for user interaction.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
protected bool IsEnabledCore
protected bool IsEffectivelyEnabled
{
get { return GetValue(IsEnabledCoreProperty); }
set { SetValue(IsEnabledCoreProperty, value); }
get { return GetValue(IsEffectivelyEnabledProperty); }
set { SetValue(IsEffectivelyEnabledProperty, value); }
}
public List<KeyBinding> KeyBindings { get; } = new List<KeyBinding>();
@ -393,7 +393,7 @@ namespace Avalonia.Input
protected override void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTreeCore(e);
UpdateIsEnabledCore();
UpdateIsEffectivelyEnabled();
}
/// <summary>
@ -488,7 +488,7 @@ namespace Avalonia.Input
private static void IsEnabledChanged(AvaloniaPropertyChangedEventArgs e)
{
((InputElement)e.Sender).UpdateIsEnabledCore();
((InputElement)e.Sender).UpdateIsEffectivelyEnabled();
}
/// <summary>
@ -512,32 +512,32 @@ namespace Avalonia.Input
}
/// <summary>
/// Updates the <see cref="IsEnabledCore"/> property value.
/// Updates the <see cref="IsEffectivelyEnabled"/> property value.
/// </summary>
private void UpdateIsEnabledCore()
private void UpdateIsEffectivelyEnabled()
{
UpdateIsEnabledCore(this.GetVisualParent<InputElement>());
UpdateIsEffectivelyEnabled(this.GetVisualParent<InputElement>());
}
/// <summary>
/// Updates the <see cref="IsEnabledCore"/> property based on the parent's
/// <see cref="IsEnabledCore"/>.
/// Updates the <see cref="IsEffectivelyEnabled"/> property based on the parent's
/// <see cref="IsEffectivelyEnabled"/>.
/// </summary>
/// <param name="parent">The parent control.</param>
private void UpdateIsEnabledCore(InputElement parent)
private void UpdateIsEffectivelyEnabled(InputElement parent)
{
if (parent != null)
{
IsEnabledCore = IsEnabled && parent.IsEnabledCore;
IsEffectivelyEnabled = IsEnabled && parent.IsEffectivelyEnabled;
}
else
{
IsEnabledCore = IsEnabled;
IsEffectivelyEnabled = IsEnabled;
}
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 &&
element.IsVisible &&
element.IsHitTestVisible &&
element.IsEnabledCore &&
element.IsEffectivelyEnabled &&
element.IsAttachedToVisualTree;
}
}

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

@ -13,13 +13,13 @@ namespace Avalonia.Input.Navigation
/// </summary>
/// <param name="e">The element.</param>
/// <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>
/// Checks if descendants of the specified element can be focused.
/// </summary>
/// <param name="e">The element.</param>
/// <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 };
Assert.False(((IInputElement)target).IsEnabledCore);
Assert.False(((IInputElement)target).IsEffectivelyEnabled);
}
[Fact]

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

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

Loading…
Cancel
Save