Browse Source

Use PlatformHotkeyConfiguration.Instance instead of locator

pull/11564/head
Max Katz 3 years ago
parent
commit
596f876868
  1. 6
      src/Avalonia.Controls.DataGrid/Utils/KeyboardHelper.cs
  2. 2
      src/Avalonia.Controls/ContextMenu.cs
  3. 2
      src/Avalonia.Controls/Control.cs
  4. 2
      src/Avalonia.Controls/Flyouts/PopupFlyoutBase.cs
  5. 4
      src/Avalonia.Controls/ListBox.cs
  6. 2
      src/Avalonia.Controls/MaskedTextBox.cs
  7. 2
      src/Avalonia.Controls/SelectableTextBlock.cs
  8. 11
      src/Avalonia.Controls/TextBox.cs
  9. 2
      src/Avalonia.Controls/TopLevel.cs
  10. 4
      src/Avalonia.Controls/TreeView.cs
  11. 4
      src/Avalonia.Native/AvaloniaNativePlatform.cs
  12. 24
      tests/Avalonia.Controls.UnitTests/ListBoxTests_Multiple.cs
  13. 14
      tests/Avalonia.Controls.UnitTests/ListBoxTests_Single.cs
  14. 8
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs
  15. 6
      tests/Avalonia.Controls.UnitTests/TreeViewTests.cs

6
src/Avalonia.Controls.DataGrid/Utils/KeyboardHelper.cs

@ -24,9 +24,9 @@ namespace Avalonia.Controls.Utils
} }
public static KeyModifiers GetPlatformCtrlOrCmdKeyModifier() public static KeyModifiers GetPlatformCtrlOrCmdKeyModifier()
{ {
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>(); var keymap = PlatformHotkeyConfiguration.Instance;
return keymap?.CommandModifiers ?? KeyModifiers.Control; return keymap.CommandModifiers;
} }
} }
} }

2
src/Avalonia.Controls/ContextMenu.cs

@ -405,7 +405,7 @@ namespace Avalonia.Controls
{ {
if (IsOpen) if (IsOpen)
{ {
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>(); var keymap = PlatformHotkeyConfiguration.Instance;
if (keymap?.OpenContextMenu.Any(k => k.Matches(e)) == true if (keymap?.OpenContextMenu.Any(k => k.Matches(e)) == true
&& !CancelClosing()) && !CancelClosing())

2
src/Avalonia.Controls/Control.cs

@ -480,7 +480,7 @@ namespace Avalonia.Controls
if (e.Source == this if (e.Source == this
&& !e.Handled) && !e.Handled)
{ {
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>()?.OpenContextMenu; var keymap = PlatformHotkeyConfiguration.Instance?.OpenContextMenu;
if (keymap is null) if (keymap is null)
{ {

2
src/Avalonia.Controls/Flyouts/PopupFlyoutBase.cs

@ -392,7 +392,7 @@ namespace Avalonia.Controls.Primitives
&& IsOpen && IsOpen
&& Target?.ContextFlyout == this) && Target?.ContextFlyout == this)
{ {
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>(); var keymap = PlatformHotkeyConfiguration.Instance;
if (keymap?.OpenContextMenu.Any(k => k.Matches(e)) == true) if (keymap?.OpenContextMenu.Any(k => k.Matches(e)) == true)
{ {

4
src/Avalonia.Controls/ListBox.cs

@ -127,7 +127,7 @@ namespace Avalonia.Controls
protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyDown(KeyEventArgs e)
{ {
var hotkeys = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>(); var hotkeys = PlatformHotkeyConfiguration.Instance;
var ctrl = hotkeys is not null && e.KeyModifiers.HasAllFlags(hotkeys.CommandModifiers); var ctrl = hotkeys is not null && e.KeyModifiers.HasAllFlags(hotkeys.CommandModifiers);
if (!ctrl && if (!ctrl &&
@ -165,7 +165,7 @@ namespace Avalonia.Controls
internal bool UpdateSelectionFromPointerEvent(Control source, PointerEventArgs e) internal bool UpdateSelectionFromPointerEvent(Control source, PointerEventArgs e)
{ {
var hotkeys = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>(); var hotkeys = PlatformHotkeyConfiguration.Instance;
var toggle = hotkeys is not null && e.KeyModifiers.HasAllFlags(hotkeys.CommandModifiers); var toggle = hotkeys is not null && e.KeyModifiers.HasAllFlags(hotkeys.CommandModifiers);
return UpdateSelectionFromEventSource( return UpdateSelectionFromEventSource(

2
src/Avalonia.Controls/MaskedTextBox.cs

@ -204,7 +204,7 @@ namespace Avalonia.Controls
return; return;
} }
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>(); var keymap = PlatformHotkeyConfiguration.Instance;
bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e)); bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e));

2
src/Avalonia.Controls/SelectableTextBlock.cs

@ -198,7 +198,7 @@ namespace Avalonia.Controls
var handled = false; var handled = false;
var modifiers = e.KeyModifiers; var modifiers = e.KeyModifiers;
var keymap = AvaloniaLocator.Current.GetRequiredService<PlatformHotkeyConfiguration>(); var keymap = PlatformHotkeyConfiguration.Instance!;
bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e)); bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e));

11
src/Avalonia.Controls/TextBox.cs

@ -32,20 +32,17 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets a platform-specific <see cref="KeyGesture"/> for the Cut action /// Gets a platform-specific <see cref="KeyGesture"/> for the Cut action
/// </summary> /// </summary>
public static KeyGesture? CutGesture { get; } = AvaloniaLocator.Current public static KeyGesture? CutGesture { get; } = PlatformHotkeyConfiguration.Instance?.Cut.FirstOrDefault();
.GetService<PlatformHotkeyConfiguration>()?.Cut.FirstOrDefault();
/// <summary> /// <summary>
/// Gets a platform-specific <see cref="KeyGesture"/> for the Copy action /// Gets a platform-specific <see cref="KeyGesture"/> for the Copy action
/// </summary> /// </summary>
public static KeyGesture? CopyGesture { get; } = AvaloniaLocator.Current public static KeyGesture? CopyGesture { get; } = PlatformHotkeyConfiguration.Instance?.Copy.FirstOrDefault();
.GetService<PlatformHotkeyConfiguration>()?.Copy.FirstOrDefault();
/// <summary> /// <summary>
/// Gets a platform-specific <see cref="KeyGesture"/> for the Paste action /// Gets a platform-specific <see cref="KeyGesture"/> for the Paste action
/// </summary> /// </summary>
public static KeyGesture? PasteGesture { get; } = AvaloniaLocator.Current public static KeyGesture? PasteGesture { get; } = PlatformHotkeyConfiguration.Instance?.Paste.FirstOrDefault();
.GetService<PlatformHotkeyConfiguration>()?.Paste.FirstOrDefault();
/// <summary> /// <summary>
/// Defines the <see cref="AcceptsReturn"/> property /// Defines the <see cref="AcceptsReturn"/> property
@ -1103,7 +1100,7 @@ namespace Avalonia.Controls
var handled = false; var handled = false;
var modifiers = e.KeyModifiers; var modifiers = e.KeyModifiers;
var keymap = AvaloniaLocator.Current.GetRequiredService<PlatformHotkeyConfiguration>(); var keymap = PlatformHotkeyConfiguration.Instance!;
bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e)); bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e));
bool DetectSelection() => e.KeyModifiers.HasAllFlags(keymap.SelectionModifiers); bool DetectSelection() => e.KeyModifiers.HasAllFlags(keymap.SelectionModifiers);

2
src/Avalonia.Controls/TopLevel.cs

@ -250,7 +250,7 @@ namespace Avalonia.Controls
if (e is RawKeyEventArgs rawKeyEventArgs && rawKeyEventArgs.Type == RawKeyEventType.KeyDown) if (e is RawKeyEventArgs rawKeyEventArgs && rawKeyEventArgs.Type == RawKeyEventType.KeyDown)
{ {
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>()?.Back; var keymap = PlatformHotkeyConfiguration.Instance?.Back;
if (keymap != null) if (keymap != null)
{ {

4
src/Avalonia.Controls/TreeView.cs

@ -571,7 +571,7 @@ namespace Avalonia.Controls
if (!e.Handled) if (!e.Handled)
{ {
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>(); var keymap = PlatformHotkeyConfiguration.Instance;
bool Match(List<KeyGesture>? gestures) => gestures?.Any(g => g.Matches(e)) ?? false; bool Match(List<KeyGesture>? gestures) => gestures?.Any(g => g.Matches(e)) ?? false;
if (this.SelectionMode == SelectionMode.Multiple && Match(keymap?.SelectAll)) if (this.SelectionMode == SelectionMode.Multiple && Match(keymap?.SelectAll))
@ -656,7 +656,7 @@ namespace Avalonia.Controls
e.Source, e.Source,
true, true,
e.KeyModifiers.HasAllFlags(KeyModifiers.Shift), e.KeyModifiers.HasAllFlags(KeyModifiers.Shift),
e.KeyModifiers.HasAllFlags(AvaloniaLocator.Current.GetRequiredService<PlatformHotkeyConfiguration>().CommandModifiers), e.KeyModifiers.HasAllFlags(PlatformHotkeyConfiguration.Instance!.CommandModifiers),
point.Properties.IsRightButtonPressed); point.Properties.IsRightButtonPressed);
} }
} }

4
src/Avalonia.Native/AvaloniaNativePlatform.cs

@ -113,8 +113,8 @@ namespace Avalonia.Native
.Bind<IPlatformDragSource>().ToConstant(new AvaloniaNativeDragSource(_factory)) .Bind<IPlatformDragSource>().ToConstant(new AvaloniaNativeDragSource(_factory))
.Bind<IPlatformLifetimeEventsImpl>().ToConstant(applicationPlatform) .Bind<IPlatformLifetimeEventsImpl>().ToConstant(applicationPlatform)
.Bind<INativeApplicationCommands>().ToConstant(new MacOSNativeMenuCommands(_factory.CreateApplicationCommands())); .Bind<INativeApplicationCommands>().ToConstant(new MacOSNativeMenuCommands(_factory.CreateApplicationCommands()));
var hotkeys = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>(); var hotkeys = PlatformHotkeyConfiguration.Instance;
if (hotkeys is not null) if (hotkeys is not null)
{ {
hotkeys.MoveCursorToTheStartOfLine.Add(new KeyGesture(Key.Left, hotkeys.CommandModifiers)); hotkeys.MoveCursorToTheStartOfLine.Add(new KeyGesture(Key.Left, hotkeys.CommandModifiers));

24
tests/Avalonia.Controls.UnitTests/ListBoxTests_Multiple.cs

@ -34,7 +34,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
_helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift); _helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift);
Assert.Equal(new[] { "Foo", "Bar", "Baz" }, target.SelectedItems); Assert.Equal(new[] { "Foo", "Bar", "Baz" }, target.SelectedItems);
@ -60,7 +60,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
SelectionChangedEventArgs receivedArgs = null; SelectionChangedEventArgs receivedArgs = null;
@ -118,7 +118,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
_helper.Click(target.Presenter.Panel.Children[1]); _helper.Click(target.Presenter.Panel.Children[1]);
_helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control); _helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control);
_helper.Click(target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control); _helper.Click(target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control);
@ -152,7 +152,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
_helper.Click(target.Presenter.Panel.Children[1]); _helper.Click(target.Presenter.Panel.Children[1]);
_helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control); _helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control);
@ -183,7 +183,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
_helper.Click(target.Presenter.Panel.Children[3]); _helper.Click(target.Presenter.Panel.Children[3]);
_helper.Click(target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control); _helper.Click(target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control);
@ -211,7 +211,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
_helper.Click(target.Presenter.Panel.Children[3]); _helper.Click(target.Presenter.Panel.Children[3]);
_helper.Click(target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift); _helper.Click(target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift);
@ -239,7 +239,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
_helper.Click(target.Presenter.Panel.Children[0]); _helper.Click(target.Presenter.Panel.Children[0]);
_helper.Click(target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift); _helper.Click(target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift);
@ -266,7 +266,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
SelectionChangedEventArgs receivedArgs = null; SelectionChangedEventArgs receivedArgs = null;
@ -319,7 +319,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
_helper.Click(target.Presenter.Panel.Children[0]); _helper.Click(target.Presenter.Panel.Children[0]);
Assert.Equal(new[] { "Foo" }, target.SelectedItems); Assert.Equal(new[] { "Foo" }, target.SelectedItems);
@ -414,7 +414,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
_helper.Click(target.Presenter.Panel.Children[0]); _helper.Click(target.Presenter.Panel.Children[0]);
_helper.Click(target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Shift); _helper.Click(target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Shift);
@ -444,7 +444,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
_helper.Click(target.Presenter.Panel.Children[0]); _helper.Click(target.Presenter.Panel.Children[0]);
_helper.Click(target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Shift); _helper.Click(target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Shift);
@ -471,7 +471,7 @@ namespace Avalonia.Controls.UnitTests
var root = new TestRoot(target); var root = new TestRoot(target);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
_helper.Click(target.Presenter.Panel.Children[0]); _helper.Click(target.Presenter.Panel.Children[0]);
_helper.Click(target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Control); _helper.Click(target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Control);

14
tests/Avalonia.Controls.UnitTests/ListBoxTests_Single.cs

@ -49,7 +49,7 @@ namespace Avalonia.Controls.UnitTests
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
ItemsSource = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
ApplyTemplate(target); ApplyTemplate(target);
target.Presenter.Panel.Children[0].RaiseEvent(new GotFocusEventArgs target.Presenter.Panel.Children[0].RaiseEvent(new GotFocusEventArgs
@ -79,7 +79,7 @@ namespace Avalonia.Controls.UnitTests
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
ItemsSource = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
ApplyTemplate(target); ApplyTemplate(target);
_mouse.Click(target.Presenter.Panel.Children[0]); _mouse.Click(target.Presenter.Panel.Children[0]);
@ -97,7 +97,7 @@ namespace Avalonia.Controls.UnitTests
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
ItemsSource = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
ApplyTemplate(target); ApplyTemplate(target);
target.SelectedIndex = 0; target.SelectedIndex = 0;
@ -118,7 +118,7 @@ namespace Avalonia.Controls.UnitTests
ItemsSource = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Single | SelectionMode.Toggle, SelectionMode = SelectionMode.Single | SelectionMode.Toggle,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
ApplyTemplate(target); ApplyTemplate(target);
_mouse.Click(target.Presenter.Panel.Children[0]); _mouse.Click(target.Presenter.Panel.Children[0]);
@ -139,7 +139,7 @@ namespace Avalonia.Controls.UnitTests
SelectionMode = SelectionMode.Toggle, SelectionMode = SelectionMode.Toggle,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
ApplyTemplate(target); ApplyTemplate(target);
target.SelectedIndex = 0; target.SelectedIndex = 0;
@ -160,7 +160,7 @@ namespace Avalonia.Controls.UnitTests
ItemsSource = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Toggle | SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.Toggle | SelectionMode.AlwaysSelected,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
ApplyTemplate(target); ApplyTemplate(target);
target.SelectedIndex = 0; target.SelectedIndex = 0;
@ -181,7 +181,7 @@ namespace Avalonia.Controls.UnitTests
ItemsSource = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Single | SelectionMode.Toggle, SelectionMode = SelectionMode.Single | SelectionMode.Toggle,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
ApplyTemplate(target); ApplyTemplate(target);
target.SelectedIndex = 1; target.SelectedIndex = 1;

8
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

@ -1234,7 +1234,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
ItemsSource = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
Prepare(target); Prepare(target);
var container = target.ContainerFromIndex(1)!; var container = target.ContainerFromIndex(1)!;
@ -1258,7 +1258,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
ItemsSource = items, ItemsSource = items,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
Prepare(target); Prepare(target);
_helper.Down(target.Presenter.Panel.Children[1]); _helper.Down(target.Presenter.Panel.Children[1]);
@ -1355,7 +1355,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
ItemsSource = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
Prepare(target); Prepare(target);
_helper.Down((Interactive)target.Presenter.Panel.Children[3]); _helper.Down((Interactive)target.Presenter.Panel.Children[3]);
@ -1373,7 +1373,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
Template = Template(), Template = Template(),
ItemsSource = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
Prepare(target); Prepare(target);
_helper.Down((Interactive)target.Presenter.Panel.Children[3]); _helper.Down((Interactive)target.Presenter.Panel.Children[3]);

6
tests/Avalonia.Controls.UnitTests/TreeViewTests.cs

@ -1045,7 +1045,7 @@ namespace Avalonia.Controls.UnitTests
var data = CreateTestTreeData(); var data = CreateTestTreeData();
var target = CreateTarget(data: data, multiSelect: true); var target = CreateTarget(data: data, multiSelect: true);
var rootNode = data[0]; var rootNode = data[0];
var keymap = AvaloniaLocator.Current.GetRequiredService<PlatformHotkeyConfiguration>(); var keymap = PlatformHotkeyConfiguration.Instance!;
var selectAllGesture = keymap.SelectAll.First(); var selectAllGesture = keymap.SelectAll.First();
var keyEvent = new KeyEventArgs var keyEvent = new KeyEventArgs
@ -1075,7 +1075,7 @@ namespace Avalonia.Controls.UnitTests
ClickContainer(fromContainer, KeyModifiers.None); ClickContainer(fromContainer, KeyModifiers.None);
ClickContainer(toContainer, KeyModifiers.Shift); ClickContainer(toContainer, KeyModifiers.Shift);
var keymap = AvaloniaLocator.Current.GetRequiredService<PlatformHotkeyConfiguration>(); var keymap = PlatformHotkeyConfiguration.Instance!;
var selectAllGesture = keymap.SelectAll.First(); var selectAllGesture = keymap.SelectAll.First();
var keyEvent = new KeyEventArgs var keyEvent = new KeyEventArgs
@ -1105,7 +1105,7 @@ namespace Avalonia.Controls.UnitTests
ClickContainer(fromContainer, KeyModifiers.None); ClickContainer(fromContainer, KeyModifiers.None);
ClickContainer(toContainer, KeyModifiers.Shift); ClickContainer(toContainer, KeyModifiers.Shift);
var keymap = AvaloniaLocator.Current.GetRequiredService<PlatformHotkeyConfiguration>(); var keymap = PlatformHotkeyConfiguration.Instance!;
var selectAllGesture = keymap.SelectAll.First(); var selectAllGesture = keymap.SelectAll.First();
var keyEvent = new KeyEventArgs var keyEvent = new KeyEventArgs

Loading…
Cancel
Save