Browse Source

Merge branch 'master' into refactor/pixelsize

pull/1889/head
Jumar Macato 7 years ago
committed by GitHub
parent
commit
2521353a77
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
  2. 48
      src/Gtk/Avalonia.Gtk3/KeyTransform.cs
  3. 42
      tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

20
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@ -62,7 +62,7 @@ namespace Avalonia.Controls.Primitives
AvaloniaProperty.RegisterDirect<SelectingItemsControl, object>(
nameof(SelectedItem),
o => o.SelectedItem,
(o, v) => o.SelectedItem = v,
(o, v) => o.SelectedItem = v,
defaultBindingMode: BindingMode.TwoWay);
/// <summary>
@ -88,7 +88,7 @@ namespace Avalonia.Controls.Primitives
/// </summary>
public static readonly RoutedEvent<RoutedEventArgs> IsSelectedChangedEvent =
RoutedEvent.Register<SelectingItemsControl, RoutedEventArgs>(
"IsSelectedChanged",
"IsSelectedChanged",
RoutingStrategies.Bubble);
/// <summary>
@ -96,7 +96,7 @@ namespace Avalonia.Controls.Primitives
/// </summary>
public static readonly RoutedEvent<SelectionChangedEventArgs> SelectionChangedEvent =
RoutedEvent.Register<SelectingItemsControl, SelectionChangedEventArgs>(
"SelectionChanged",
"SelectionChanged",
RoutingStrategies.Bubble);
private static readonly IList Empty = new object[0];
@ -521,7 +521,7 @@ namespace Avalonia.Controls.Primitives
else if (multi && range)
{
SynchronizeItems(
SelectedItems,
SelectedItems,
GetRange(Items, SelectedIndex, index));
}
else
@ -583,7 +583,7 @@ namespace Avalonia.Controls.Primitives
}
/// <summary>
/// Updates the selection based on an event that may have originated in a container that
/// Updates the selection based on an event that may have originated in a container that
/// belongs to the control.
/// </summary>
/// <param name="eventSource">The control that raised the event.</param>
@ -595,7 +595,7 @@ namespace Avalonia.Controls.Primitives
/// false.
/// </returns>
protected bool UpdateSelectionFromEventSource(
IInteractive eventSource,
IInteractive eventSource,
bool select = true,
bool rangeModifier = false,
bool toggleModifier = false)
@ -807,12 +807,10 @@ namespace Avalonia.Controls.Primitives
SelectedIndex = -1;
}
}
else
foreach (var item in e.OldItems)
{
foreach (var item in e.OldItems)
{
MarkItemSelected(item, false);
}
MarkItemSelected(item, false);
}
removed = e.OldItems;

48
src/Gtk/Avalonia.Gtk3/KeyTransform.cs

@ -14,6 +14,7 @@ namespace Avalonia.Gtk.Common
{ GdkKey.Linefeed, Key.LineFeed },
{ GdkKey.Clear, Key.Clear },
{ GdkKey.Return, Key.Return },
{ GdkKey.KP_Enter, Key.Return },
{ GdkKey.Pause, Key.Pause },
{ GdkKey.Caps_Lock, Key.CapsLock },
//{ GdkKey.?, Key.HangulMode }
@ -27,7 +28,9 @@ namespace Avalonia.Gtk.Common
//{ GdkKey.?, Key.ImeModeChange }
{ GdkKey.space, Key.Space },
{ GdkKey.Prior, Key.Prior },
{ GdkKey.KP_Prior, Key.Prior },
{ GdkKey.Page_Down, Key.PageDown },
{ GdkKey.KP_Page_Down, Key.PageDown },
{ GdkKey.End, Key.End },
{ GdkKey.KP_End, Key.End },
{ GdkKey.Home, Key.Home },
@ -45,19 +48,20 @@ namespace Avalonia.Gtk.Common
{ GdkKey.Execute, Key.Execute },
//{ GdkKey.?, Key.Snapshot }
{ GdkKey.Insert, Key.Insert },
{ GdkKey.KP_Insert, Key.Insert },
{ GdkKey.Delete, Key.Delete },
{ GdkKey.KP_Delete, Key.Delete },
{ GdkKey.Help, Key.Help },
//{ GdkKey.?, Key.D0 }
//{ GdkKey.?, Key.D1 }
//{ GdkKey.?, Key.D2 }
//{ GdkKey.?, Key.D3 }
//{ GdkKey.?, Key.D4 }
//{ GdkKey.?, Key.D5 }
//{ GdkKey.?, Key.D6 }
//{ GdkKey.?, Key.D7 }
//{ GdkKey.?, Key.D8 }
//{ GdkKey.?, Key.D9 }
{ GdkKey.Key_0, Key.D0 },
{ GdkKey.Key_1, Key.D1 },
{ GdkKey.Key_2, Key.D2 },
{ GdkKey.Key_3, Key.D3 },
{ GdkKey.Key_4, Key.D4 },
{ GdkKey.Key_5, Key.D5 },
{ GdkKey.Key_6, Key.D6 },
{ GdkKey.Key_7, Key.D7 },
{ GdkKey.Key_8, Key.D8 },
{ GdkKey.Key_9, Key.D9 },
{ GdkKey.A, Key.A },
{ GdkKey.B, Key.B },
{ GdkKey.C, Key.C },
@ -112,7 +116,7 @@ namespace Avalonia.Gtk.Common
{ GdkKey.z, Key.Z },
//{ GdkKey.?, Key.LWin }
//{ GdkKey.?, Key.RWin }
//{ GdkKey.?, Key.Apps }
{ GdkKey.Menu, Key.Apps },
//{ GdkKey.?, Key.Sleep }
{ GdkKey.KP_0, Key.NumPad0 },
{ GdkKey.KP_1, Key.NumPad1 },
@ -125,11 +129,12 @@ namespace Avalonia.Gtk.Common
{ GdkKey.KP_8, Key.NumPad8 },
{ GdkKey.KP_9, Key.NumPad9 },
{ GdkKey.multiply, Key.Multiply },
//{ GdkKey.?, Key.Add }
{ GdkKey.KP_Multiply, Key.Multiply },
{ GdkKey.KP_Add, Key.Add },
//{ GdkKey.?, Key.Separator }
//{ GdkKey.?, Key.Subtract }
//{ GdkKey.?, Key.Decimal }
//{ GdkKey.?, Key.Divide }
{ GdkKey.KP_Subtract, Key.Subtract },
{ GdkKey.KP_Decimal, Key.Decimal },
{ GdkKey.KP_Divide, Key.Divide },
{ GdkKey.F1, Key.F1 },
{ GdkKey.F2, Key.F2 },
{ GdkKey.F3, Key.F3 },
@ -182,17 +187,18 @@ namespace Avalonia.Gtk.Common
//{ GdkKey.?, Key.LaunchApplication2 }
{ GdkKey.semicolon, Key.OemSemicolon },
{ GdkKey.plus, Key.OemPlus },
{ GdkKey.equal, Key.OemPlus },
{ GdkKey.comma, Key.OemComma },
{ GdkKey.minus, Key.OemMinus },
{ GdkKey.period, Key.OemPeriod },
{ GdkKey.slash, Key.Oem2 }
//{ GdkKey.?, Key.OemTilde }
{ GdkKey.slash, Key.Oem2 },
{ GdkKey.grave, Key.OemTilde },
//{ GdkKey.?, Key.AbntC1 }
//{ GdkKey.?, Key.AbntC2 }
//{ GdkKey.?, Key.Oem4 }
//{ GdkKey.?, Key.OemPipe }
//{ GdkKey.?, Key.OemCloseBrackets }
//{ GdkKey.?, Key.Oem7 }
{ GdkKey.bracketleft, Key.OemOpenBrackets },
{ GdkKey.backslash, Key.OemPipe },
{ GdkKey.bracketright, Key.OemCloseBrackets },
{ GdkKey.apostrophe, Key.OemQuotes },
//{ GdkKey.?, Key.Oem8 }
//{ GdkKey.?, Key.Oem102 }
//{ GdkKey.?, Key.ImeProcessed }

42
tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

@ -1,13 +1,11 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Avalonia.Collections;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.LogicalTree;
using Avalonia.Styling;
using Avalonia.UnitTests;
@ -196,6 +194,44 @@ namespace Avalonia.Controls.UnitTests
target.Presenter.Panel.Children.Cast<ListBoxItem>().Select(x => (string)x.Content));
}
[Fact]
public void Toggle_Selection_Should_Update_Containers()
{
var items = Enumerable.Range(0, 10).Select(x => $"Item {x}").ToArray();
var target = new ListBox
{
Template = ListBoxTemplate(),
Items = items,
SelectionMode = SelectionMode.Toggle,
ItemTemplate = new FuncDataTemplate<string>(x => new TextBlock { Height = 10 })
};
Prepare(target);
var lbItems = target.GetLogicalChildren().OfType<ListBoxItem>().ToArray();
var item = lbItems[0];
Assert.Equal(false, item.IsSelected);
RaisePressedEvent(target, item, MouseButton.Left);
Assert.Equal(true, item.IsSelected);
RaisePressedEvent(target, item, MouseButton.Left);
Assert.Equal(false, item.IsSelected);
}
private void RaisePressedEvent(ListBox listBox, ListBoxItem item, MouseButton mouseButton)
{
listBox.RaiseEvent(new PointerPressedEventArgs
{
Source = item,
RoutedEvent = InputElement.PointerPressedEvent,
MouseButton = mouseButton
});
}
[Fact]
public void ListBox_After_Scroll_IndexOutOfRangeException_Shouldnt_Be_Thrown()

Loading…
Cancel
Save