Browse Source

feat(Controls): Address rule CA1822

pull/9189/head
Giuseppe Lippolis 4 years ago
parent
commit
ee84a8c7fd
  1. 8
      src/Avalonia.Controls/Automation/Peers/ComboBoxAutomationPeer.cs
  2. 10
      src/Avalonia.Controls/Calendar/CalendarBlackoutDatesCollection.cs
  3. 10
      src/Avalonia.Controls/Calendar/SelectedDatesCollection.cs
  4. 8
      src/Avalonia.Controls/ComboBox.cs
  5. 6
      src/Avalonia.Controls/DateTimePickers/DateTimePickerPanel.cs
  6. 6
      src/Avalonia.Controls/Grid.cs
  7. 16
      src/Avalonia.Controls/GridSplitter.cs
  8. 4
      src/Avalonia.Controls/Platform/InProcessDragSource.cs
  9. 8
      src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs
  10. 4
      src/Avalonia.Controls/Primitives/AdornerLayer.cs
  11. 4
      src/Avalonia.Controls/Primitives/Popup.cs
  12. 10
      src/Avalonia.Controls/Repeater/RecyclePool.cs
  13. 4
      src/Avalonia.Controls/Repeater/RecyclingElementFactory.cs
  14. 6
      src/Avalonia.Controls/SplitView.cs
  15. 10
      src/Avalonia.Controls/TextBox.cs
  16. 4
      src/Avalonia.Controls/TopLevel.cs
  17. 6
      src/Avalonia.Controls/TreeView.cs
  18. 1
      src/Avalonia.Controls/UserControl.cs

8
src/Avalonia.Controls/Automation/Peers/ComboBoxAutomationPeer.cs

@ -18,7 +18,7 @@ namespace Avalonia.Automation.Peers
public new ComboBox Owner => (ComboBox)base.Owner;
public ExpandCollapseState ExpandCollapseState => ToState(Owner.IsDropDownOpen);
public ExpandCollapseState ExpandCollapseState => ComboBoxAutomationPeer.ToState(Owner.IsDropDownOpen);
public bool ShowsMenu => true;
public void Collapse() => Owner.IsDropDownOpen = false;
public void Expand() => Owner.IsDropDownOpen = true;
@ -66,12 +66,12 @@ namespace Avalonia.Automation.Peers
{
RaisePropertyChangedEvent(
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
ToState((bool)e.OldValue!),
ToState((bool)e.NewValue!));
ComboBoxAutomationPeer.ToState((bool)e.OldValue!),
ComboBoxAutomationPeer.ToState((bool)e.NewValue!));
}
}
private ExpandCollapseState ToState(bool value)
private static ExpandCollapseState ToState(bool value)
{
return value ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
}

10
src/Avalonia.Controls/Calendar/CalendarBlackoutDatesCollection.cs

@ -122,7 +122,7 @@ namespace Avalonia.Controls.Primitives
/// </remarks>
protected override void ClearItems()
{
EnsureValidThread();
CalendarBlackoutDatesCollection.EnsureValidThread();
base.ClearItems();
_owner.UpdateMonths();
@ -140,7 +140,7 @@ namespace Avalonia.Controls.Primitives
/// </remarks>
protected override void InsertItem(int index, CalendarDateRange item)
{
EnsureValidThread();
CalendarBlackoutDatesCollection.EnsureValidThread();
if (!IsValid(item))
{
@ -162,7 +162,7 @@ namespace Avalonia.Controls.Primitives
/// </remarks>
protected override void RemoveItem(int index)
{
EnsureValidThread();
CalendarBlackoutDatesCollection.EnsureValidThread();
base.RemoveItem(index);
_owner.UpdateMonths();
@ -182,7 +182,7 @@ namespace Avalonia.Controls.Primitives
/// </remarks>
protected override void SetItem(int index, CalendarDateRange item)
{
EnsureValidThread();
CalendarBlackoutDatesCollection.EnsureValidThread();
if (!IsValid(item))
{
@ -206,7 +206,7 @@ namespace Avalonia.Controls.Primitives
return true;
}
private void EnsureValidThread()
private static void EnsureValidThread()
{
Dispatcher.UIThread.VerifyAccess();
}

10
src/Avalonia.Controls/Calendar/SelectedDatesCollection.cs

@ -133,7 +133,7 @@ namespace Avalonia.Controls.Primitives
/// </remarks>
protected override void ClearItems()
{
EnsureValidThread();
SelectedDatesCollection.EnsureValidThread();
Collection<DateTime> addedItems = new Collection<DateTime>();
Collection<DateTime> removedItems = new Collection<DateTime>();
@ -170,7 +170,7 @@ namespace Avalonia.Controls.Primitives
/// </remarks>
protected override void InsertItem(int index, DateTime item)
{
EnsureValidThread();
SelectedDatesCollection.EnsureValidThread();
if (!Contains(item))
{
@ -233,7 +233,7 @@ namespace Avalonia.Controls.Primitives
/// </remarks>
protected override void RemoveItem(int index)
{
EnsureValidThread();
SelectedDatesCollection.EnsureValidThread();
if (index >= Count)
{
@ -284,7 +284,7 @@ namespace Avalonia.Controls.Primitives
/// </remarks>
protected override void SetItem(int index, DateTime item)
{
EnsureValidThread();
SelectedDatesCollection.EnsureValidThread();
if (!Contains(item))
{
@ -353,7 +353,7 @@ namespace Avalonia.Controls.Primitives
return true;
}
private void EnsureValidThread()
private static void EnsureValidThread()
{
Dispatcher.UIThread.VerifyAccess();
}

8
src/Avalonia.Controls/ComboBox.cs

@ -236,7 +236,7 @@ namespace Avalonia.Controls
else if (IsDropDownOpen && SelectedIndex < 0 && ItemCount > 0 &&
(e.Key == Key.Up || e.Key == Key.Down) && IsFocused == true)
{
var firstChild = Presenter?.Panel?.Children.FirstOrDefault(c => CanFocus(c));
var firstChild = Presenter?.Panel?.Children.FirstOrDefault(c => ComboBox.CanFocus(c));
if (firstChild != null)
{
FocusManager.Instance?.Focus(firstChild, NavigationMethod.Directional);
@ -341,7 +341,7 @@ namespace Avalonia.Controls
{
_subscriptionsOnOpen.Clear();
if (CanFocus(this))
if (ComboBox.CanFocus(this))
{
Focus();
}
@ -403,14 +403,14 @@ namespace Avalonia.Controls
container = ItemContainerGenerator.ContainerFromIndex(selectedIndex);
}
if (container != null && CanFocus(container))
if (container != null && ComboBox.CanFocus(container))
{
container.Focus();
}
}
}
private bool CanFocus(IControl control) => control.Focusable && control.IsEffectivelyEnabled && control.IsVisible;
private static bool CanFocus(IControl control) => control.Focusable && control.IsEffectivelyEnabled && control.IsVisible;
private void UpdateSelectionBoxItem(object? item)
{

6
src/Avalonia.Controls/DateTimePickers/DateTimePickerPanel.cs

@ -545,8 +545,8 @@ namespace Avalonia.Controls.Primitives
private void OnItemTapped(object? sender, TappedEventArgs e)
{
if (e.Source is IVisual source &&
GetItemFromSource(source) is ListBoxItem listBoxItem &&
if (e.Source is IVisual source &&
DateTimePickerPanel.GetItemFromSource(source) is ListBoxItem listBoxItem &&
listBoxItem.Tag is int tag)
{
SelectedValue = tag;
@ -555,7 +555,7 @@ namespace Avalonia.Controls.Primitives
}
//Helper to get ListBoxItem from pointerevent source
private ListBoxItem? GetItemFromSource(IVisual src)
private static ListBoxItem? GetItemFromSource(IVisual src)
{
var item = src;
while (item != null && !(item is ListBoxItem))

6
src/Avalonia.Controls/Grid.cs

@ -1117,7 +1117,7 @@ namespace Avalonia.Controls
else
{
// otherwise...
cellMeasureWidth = GetMeasureSizeForRange(
cellMeasureWidth = Grid.GetMeasureSizeForRange(
DefinitionsU,
PrivateCells[cell].ColumnIndex,
PrivateCells[cell].ColumnSpan);
@ -1137,7 +1137,7 @@ namespace Avalonia.Controls
}
else
{
cellMeasureHeight = GetMeasureSizeForRange(
cellMeasureHeight = Grid.GetMeasureSizeForRange(
DefinitionsV,
PrivateCells[cell].RowIndex,
PrivateCells[cell].RowSpan);
@ -1165,7 +1165,7 @@ namespace Avalonia.Controls
/// <remarks>
/// For "Auto" definitions MinWidth is used in place of PreferredSize.
/// </remarks>
private double GetMeasureSizeForRange(
private static double GetMeasureSizeForRange(
IReadOnlyList<DefinitionBase> definitions,
int start,
int count)

16
src/Avalonia.Controls/GridSplitter.cs

@ -288,13 +288,13 @@ namespace Avalonia.Controls
_resizeData.Definition1 = GetGridDefinition(_resizeData.Grid, index1, _resizeData.ResizeDirection);
_resizeData.OriginalDefinition1Length =
_resizeData.Definition1.UserSizeValueCache; // Save Size if user cancels.
_resizeData.OriginalDefinition1ActualLength = GetActualLength(_resizeData.Definition1);
_resizeData.OriginalDefinition1ActualLength = GridSplitter.GetActualLength(_resizeData.Definition1);
_resizeData.Definition2Index = index2;
_resizeData.Definition2 = GetGridDefinition(_resizeData.Grid, index2, _resizeData.ResizeDirection);
_resizeData.OriginalDefinition2Length =
_resizeData.Definition2.UserSizeValueCache; // Save Size if user cancels.
_resizeData.OriginalDefinition2ActualLength = GetActualLength(_resizeData.Definition2);
_resizeData.OriginalDefinition2ActualLength = GridSplitter.GetActualLength(_resizeData.Definition2);
// Determine how to resize the columns.
bool isStar1 = IsStar(_resizeData.Definition1);
@ -516,7 +516,7 @@ namespace Avalonia.Controls
/// <summary>
/// Retrieves the ActualWidth or ActualHeight of the definition depending on its type Column or Row.
/// </summary>
private double GetActualLength(DefinitionBase definition)
private static double GetActualLength(DefinitionBase definition)
{
var column = definition as ColumnDefinition;
@ -537,11 +537,11 @@ namespace Avalonia.Controls
/// </summary>
private void GetDeltaConstraints(out double minDelta, out double maxDelta)
{
double definition1Len = GetActualLength(_resizeData!.Definition1!);
double definition1Len = GridSplitter.GetActualLength(_resizeData!.Definition1!);
double definition1Min = _resizeData.Definition1!.UserMinSizeValueCache;
double definition1Max = _resizeData.Definition1.UserMaxSizeValueCache;
double definition2Len = GetActualLength(_resizeData.Definition2!);
double definition2Len = GridSplitter.GetActualLength(_resizeData.Definition2!);
double definition2Min = _resizeData.Definition2!.UserMinSizeValueCache;
double definition2Max = _resizeData.Definition2.UserMaxSizeValueCache;
@ -590,7 +590,7 @@ namespace Avalonia.Controls
}
else if (IsStar(definition))
{
SetDefinitionLength(definition, new GridLength(GetActualLength(definition), GridUnitType.Star));
SetDefinitionLength(definition, new GridLength(GridSplitter.GetActualLength(definition), GridUnitType.Star));
}
}
}
@ -629,8 +629,8 @@ namespace Avalonia.Controls
if (definition1 != null && definition2 != null)
{
double actualLength1 = GetActualLength(definition1);
double actualLength2 = GetActualLength(definition2);
double actualLength1 = GridSplitter.GetActualLength(definition1);
double actualLength2 = GridSplitter.GetActualLength(definition2);
double pixelLength = 1 / _resizeData.Scaling;
double epsilon = pixelLength + LayoutHelper.LayoutEpsilon;

4
src/Avalonia.Controls/Platform/InProcessDragSource.cs

@ -64,12 +64,12 @@ namespace Avalonia.Platform
var tl = root.GetSelfAndVisualAncestors().OfType<TopLevel>().FirstOrDefault();
tl?.PlatformImpl?.Input?.Invoke(rawEvent);
var effect = GetPreferredEffect(rawEvent.Effects & _allowedEffects, modifiers);
var effect = InProcessDragSource.GetPreferredEffect(rawEvent.Effects & _allowedEffects, modifiers);
UpdateCursor(root, effect);
return effect;
}
private DragDropEffects GetPreferredEffect(DragDropEffects effect, RawInputModifiers modifiers)
private static DragDropEffects GetPreferredEffect(DragDropEffects effect, RawInputModifiers modifiers)
{
if (effect == DragDropEffects.Copy || effect == DragDropEffects.Move || effect == DragDropEffects.Link || effect == DragDropEffects.None)
return effect; // No need to check for the modifiers.

8
src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

@ -295,7 +295,7 @@ namespace Avalonia.Controls.Presenters
// arrange then that change wasn't just due to scrolling (as scrolling doesn't adjust
// relative positions within Child).
if (_anchorElement != null &&
TranslateBounds(_anchorElement, Child!, out var updatedBounds) &&
ScrollContentPresenter.TranslateBounds(_anchorElement, Child!, out var updatedBounds) &&
updatedBounds.Position != _anchorElementBounds.Position)
{
var offset = updatedBounds.Position - _anchorElementBounds.Position;
@ -588,7 +588,7 @@ namespace Avalonia.Controls.Presenters
private bool GetViewportBounds(IControl element, out Rect bounds)
{
if (TranslateBounds(element, Child!, out var childBounds))
if (ScrollContentPresenter.TranslateBounds(element, Child!, out var childBounds))
{
// We want the bounds relative to the new Offset, regardless of whether the child
// control has actually been arranged to this offset yet, so translate first to the
@ -605,7 +605,7 @@ namespace Avalonia.Controls.Presenters
private Rect TranslateBounds(IControl control, IControl to)
{
if (TranslateBounds(control, to, out var bounds))
if (ScrollContentPresenter.TranslateBounds(control, to, out var bounds))
{
return bounds;
}
@ -613,7 +613,7 @@ namespace Avalonia.Controls.Presenters
throw new InvalidOperationException("The control's bounds could not be translated to the requested control.");
}
private bool TranslateBounds(IControl control, IControl to, out Rect bounds)
private static bool TranslateBounds(IControl control, IControl to, out Rect bounds)
{
if (!control.IsVisible)
{

4
src/Avalonia.Controls/Primitives/AdornerLayer.cs

@ -211,7 +211,7 @@ namespace Avalonia.Controls.Primitives
{
child.RenderTransform = new MatrixTransform(info.Bounds.Value.Transform);
child.RenderTransformOrigin = new RelativePoint(new Point(0, 0), RelativeUnit.Absolute);
UpdateClip(child, info.Bounds.Value, isClipEnabled);
AdornerLayer.UpdateClip(child, info.Bounds.Value, isClipEnabled);
child.Arrange(info.Bounds.Value.Bounds);
}
else
@ -232,7 +232,7 @@ namespace Avalonia.Controls.Primitives
layer?.UpdateAdornedElement(adorner, adorned);
}
private void UpdateClip(IControl control, TransformedBounds bounds, bool isEnabled)
private static void UpdateClip(IControl control, TransformedBounds bounds, bool isEnabled)
{
if (!isEnabled)
{

4
src/Avalonia.Controls/Primitives/Popup.cs

@ -475,7 +475,7 @@ namespace Avalonia.Controls.Primitives
_openState = new PopupOpenState(placementTarget, topLevel, popupHost, cleanupPopup);
WindowManagerAddShadowHintChanged(popupHost, WindowManagerAddShadowHint);
Popup.WindowManagerAddShadowHintChanged(popupHost, WindowManagerAddShadowHint);
popupHost.Show();
@ -639,7 +639,7 @@ namespace Avalonia.Controls.Primitives
return Disposable.Create((unsubscribe, target, handler), state => state.unsubscribe(state.target, state.handler));
}
private void WindowManagerAddShadowHintChanged(IPopupHost host, bool hint)
private static void WindowManagerAddShadowHintChanged(IPopupHost host, bool hint)
{
if(host is PopupRoot pr && pr.PlatformImpl is not null)
{

10
src/Avalonia.Controls/Repeater/RecyclePool.cs

@ -32,7 +32,7 @@ namespace Avalonia.Controls
public void PutElement(IControl element, string key, IControl? owner)
{
var ownerAsPanel = EnsureOwnerIsPanelOrNull(owner);
var ownerAsPanel = RecyclePool.EnsureOwnerIsPanelOrNull(owner);
var elementInfo = new ElementInfo(element, ownerAsPanel);
if (!_elements.TryGetValue(key, out var pool))
@ -56,7 +56,7 @@ namespace Avalonia.Controls
var elementInfo = elements.FirstOrDefault(x => x.Owner == owner) ?? elements.LastOrDefault();
elements.Remove(elementInfo!);
var ownerAsPanel = EnsureOwnerIsPanelOrNull(owner);
var ownerAsPanel = RecyclePool.EnsureOwnerIsPanelOrNull(owner);
if (elementInfo!.Owner != null && elementInfo.Owner != ownerAsPanel)
{
// Element is still under its parent. remove it from its parent.
@ -80,10 +80,10 @@ namespace Avalonia.Controls
return null;
}
internal string GetReuseKey(IControl element) => ((Control)element).GetValue(ReuseKeyProperty);
internal void SetReuseKey(IControl element, string value) => ((Control)element).SetValue(ReuseKeyProperty, value);
internal static string GetReuseKey(IControl element) => ((Control)element).GetValue(ReuseKeyProperty);
internal static void SetReuseKey(IControl element, string value) => ((Control)element).SetValue(ReuseKeyProperty, value);
private IPanel? EnsureOwnerIsPanelOrNull(IControl? owner)
private static IPanel? EnsureOwnerIsPanelOrNull(IControl? owner)
{
if (owner is IPanel panel)
{

4
src/Avalonia.Controls/Repeater/RecyclingElementFactory.cs

@ -72,7 +72,7 @@ namespace Avalonia.Controls
element = dataTemplate.Build(args.Data)!;
// Associate ReuseKey with element
RecyclePool.SetReuseKey(element, templateKey);
Avalonia.Controls.RecyclePool.SetReuseKey(element, templateKey);
}
return element;
@ -81,7 +81,7 @@ namespace Avalonia.Controls
protected override void RecycleElementCore(ElementFactoryRecycleArgs args)
{
var element = args.Element!;
var key = RecyclePool.GetReuseKey(element);
var key = Avalonia.Controls.RecyclePool.GetReuseKey(element);
RecyclePool.PutElement(element, key, args.Parent);
}

6
src/Avalonia.Controls/SplitView.cs

@ -431,7 +431,7 @@ namespace Avalonia.Controls
}
}
private string GetPseudoClass(SplitViewDisplayMode mode)
private static string GetPseudoClass(SplitViewDisplayMode mode)
{
return mode switch
{
@ -463,8 +463,8 @@ namespace Avalonia.Controls
private void OnDisplayModeChanged(AvaloniaPropertyChangedEventArgs e)
{
var oldState = GetPseudoClass(e.GetOldValue<SplitViewDisplayMode>());
var newState = GetPseudoClass(e.GetNewValue<SplitViewDisplayMode>());
var oldState = SplitView.GetPseudoClass(e.GetOldValue<SplitViewDisplayMode>());
var newState = SplitView.GetPseudoClass(e.GetNewValue<SplitViewDisplayMode>());
PseudoClasses.Remove($":{oldState}");
PseudoClasses.Add($":{newState}");

10
src/Avalonia.Controls/TextBox.cs

@ -397,9 +397,9 @@ namespace Avalonia.Controls
var selectionStart = SelectionStart;
var selectionEnd = SelectionEnd;
CaretIndex = CoerceCaretIndex(caretIndex, value);
SelectionStart = CoerceCaretIndex(selectionStart, value);
SelectionEnd = CoerceCaretIndex(selectionEnd, value);
CaretIndex = TextBox.CoerceCaretIndex(caretIndex, value);
SelectionStart = TextBox.CoerceCaretIndex(selectionStart, value);
SelectionEnd = TextBox.CoerceCaretIndex(selectionEnd, value);
var textChanged = SetAndRaise(TextProperty, ref _text, value);
@ -1380,9 +1380,9 @@ namespace Avalonia.Controls
}
}
private int CoerceCaretIndex(int value) => CoerceCaretIndex(value, Text);
private int CoerceCaretIndex(int value) => TextBox.CoerceCaretIndex(value, Text);
private int CoerceCaretIndex(int value, string? text)
private static int CoerceCaretIndex(int value, string? text)
{
if (text == null)
{

4
src/Avalonia.Controls/TopLevel.cs

@ -429,7 +429,7 @@ namespace Avalonia.Controls
LayoutHelper.InvalidateSelfAndChildrenMeasure(this);
}
private bool TransparencyLevelsMatch (WindowTransparencyLevel requested, WindowTransparencyLevel received)
private static bool TransparencyLevelsMatch (WindowTransparencyLevel requested, WindowTransparencyLevel received)
{
if(requested == received)
{
@ -449,7 +449,7 @@ namespace Avalonia.Controls
{
if(transparencyLevel == WindowTransparencyLevel.None ||
TransparencyLevelHint == WindowTransparencyLevel.None ||
!TransparencyLevelsMatch(TransparencyLevelHint, transparencyLevel))
!TopLevel.TransparencyLevelsMatch(TransparencyLevelHint, transparencyLevel))
{
_transparencyFallbackBorder.Background = TransparencyBackgroundFallback;
}

6
src/Avalonia.Controls/TreeView.cs

@ -284,7 +284,7 @@ namespace Avalonia.Controls
foreach (IControl container in ItemContainerGenerator.Index!.Containers)
{
MarkContainerSelected(container, false);
TreeView.MarkContainerSelected(container, false);
}
if (SelectedItems.Count > 0)
@ -339,7 +339,7 @@ namespace Avalonia.Controls
{
var container = ItemContainerGenerator.Index!.ContainerFromItem(item)!;
MarkContainerSelected(container, selected);
TreeView.MarkContainerSelected(container, selected);
}
private void SelectedItemsAdded(IList items)
@ -826,7 +826,7 @@ namespace Avalonia.Controls
/// </summary>
/// <param name="container">The container.</param>
/// <param name="selected">Whether the control is selected</param>
private void MarkContainerSelected(IControl container, bool selected)
private static void MarkContainerSelected(IControl container, bool selected)
{
if (container == null)
{

1
src/Avalonia.Controls/UserControl.cs

@ -1,4 +1,3 @@
using System;
using Avalonia.Styling;
namespace Avalonia.Controls

Loading…
Cancel
Save