Browse Source

Merge branch 'selector-parse-no-sprache' of https://github.com/jkoritzinsky/Avalonia into selector-parse-no-sprache

pull/1668/head
Jeremy Koritzinsky 8 years ago
parent
commit
df3ef49693
  1. 2
      packages.cake
  2. 4
      readme.md
  3. 4
      samples/ControlCatalog/DecoratedWindow.xaml.cs
  4. 2
      src/Avalonia.Controls/AutoCompleteBox.cs
  5. 95
      src/Avalonia.Controls/Calendar/Calendar.cs
  6. 2
      src/Avalonia.Controls/Calendar/CalendarDateRange.cs
  7. 31
      src/Avalonia.Controls/Calendar/CalendarItem.cs
  8. 2
      src/Avalonia.Controls/Calendar/DatePicker.cs
  9. 18
      src/Avalonia.Controls/Design.cs
  10. 13
      src/Avalonia.Controls/DropDownItem.cs
  11. 2
      src/Avalonia.Controls/Embedding/Offscreen/OffscreenTopLevel.cs
  12. 2
      src/Avalonia.Controls/Platform/InProcessDragSource.cs
  13. 27
      src/Avalonia.Controls/Presenters/CarouselPresenter.cs
  14. 16
      src/Avalonia.Controls/TextBox.cs
  15. 18
      src/Avalonia.Controls/Window.cs
  16. 3
      src/Avalonia.DesignerSupport/DesignWindowLoader.cs
  17. 2
      src/Avalonia.Styling/Styling/Style.cs
  18. 5
      src/Avalonia.Themes.Default/Calendar.xaml
  19. 6
      src/Avalonia.Visuals/Media/FontFamily.cs
  20. 3
      src/Markup/Avalonia.Markup/Data/MultiBinding.cs
  21. 2
      src/Windows/Avalonia.Win32/SystemDialogImpl.cs
  22. 206
      tests/Avalonia.Controls.UnitTests/CarouselTests.cs
  23. 53
      tests/Avalonia.Controls.UnitTests/TextBoxTests.cs

2
packages.cake

@ -120,6 +120,7 @@ public class Packages
var SharpDXDirect3D9Version = packageVersions["SharpDX.Direct3D9"].FirstOrDefault().Item1; var SharpDXDirect3D9Version = packageVersions["SharpDX.Direct3D9"].FirstOrDefault().Item1;
var SharpDXDXGIVersion = packageVersions["SharpDX.DXGI"].FirstOrDefault().Item1; var SharpDXDXGIVersion = packageVersions["SharpDX.DXGI"].FirstOrDefault().Item1;
var SystemMemoryVersion = packageVersions["System.Memory"].FirstOrDefault().Item1; var SystemMemoryVersion = packageVersions["System.Memory"].FirstOrDefault().Item1;
var SystemComponentModelAnnotationsVersion = packageVersions["System.ComponentModel.Annotations"].FirstOrDefault().Item1;
context.Information("Package: Serilog, version: {0}", SerilogVersion); context.Information("Package: Serilog, version: {0}", SerilogVersion);
context.Information("Package: System.Reactive, version: {0}", SystemReactiveVersion); context.Information("Package: System.Reactive, version: {0}", SystemReactiveVersion);
@ -238,6 +239,7 @@ public class Packages
new NuSpecDependency() { Id = "System.Reactive", Version = SystemReactiveVersion }, new NuSpecDependency() { Id = "System.Reactive", Version = SystemReactiveVersion },
new NuSpecDependency() { Id = "Avalonia.Remote.Protocol", Version = parameters.Version }, new NuSpecDependency() { Id = "Avalonia.Remote.Protocol", Version = parameters.Version },
new NuSpecDependency() { Id = "System.Memory", Version = SystemMemoryVersion }, new NuSpecDependency() { Id = "System.Memory", Version = SystemMemoryVersion },
new NuSpecDependency() { Id = "System.ComponentModel.Annotations", Version = SystemComponentModelAnnotationsVersion },
//.NET Core //.NET Core
new NuSpecDependency() { Id = "System.Threading.ThreadPool", TargetFramework = "netcoreapp2.0", Version = "4.3.0" }, new NuSpecDependency() { Id = "System.Threading.ThreadPool", TargetFramework = "netcoreapp2.0", Version = "4.3.0" },
new NuSpecDependency() { Id = "Microsoft.Extensions.DependencyModel", TargetFramework = "netcoreapp2.0", Version = "1.1.0" }, new NuSpecDependency() { Id = "Microsoft.Extensions.DependencyModel", TargetFramework = "netcoreapp2.0", Version = "1.1.0" },

4
readme.md

@ -18,7 +18,7 @@ Avalonia is a WPF-inspired cross-platform XAML-based UI framework providing a fl
## Getting Started ## Getting Started
Avalonia [Visual Studio Extension](https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaforVisualStudio) contains project and control templates that will help you get started. After installing it, open "New Project" dialog in Visual Studio, choose "Avalonia" in "Visual C#" section, select "Avalonia .NET Core Application" and press OK (<a href="http://avaloniaui.net/tutorial/images/add-dialogs.png">screenshot</a>). Now you can write code and markup that will work on multiple platforms! Avalonia [Visual Studio Extension](https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaforVisualStudio) contains project and control templates that will help you get started. After installing it, open "New Project" dialog in Visual Studio, choose "Avalonia" in "Visual C#" section, select "Avalonia .NET Core Application" and press OK (<a href="http://avaloniaui.net/docs/quickstart/images/new-project-dialog.png">screenshot</a>). Now you can write code and markup that will work on multiple platforms!
Avalonia is delivered via <b>NuGet</b> package manager. You can find the packages here: ([stable(ish)](https://www.nuget.org/packages/Avalonia/), [nightly](https://github.com/AvaloniaUI/Avalonia/wiki/Using-nightly-build-feed)) Avalonia is delivered via <b>NuGet</b> package manager. You can find the packages here: ([stable(ish)](https://www.nuget.org/packages/Avalonia/), [nightly](https://github.com/AvaloniaUI/Avalonia/wiki/Using-nightly-build-feed))
@ -52,7 +52,7 @@ Please read the [contribution guidelines](http://avaloniaui.net/contributing/con
### Contributors ### Contributors
This project exists thanks to all the people who contribute. [[Contribute](http://avaloniaui.net/contributing/contributing)]. This project exists thanks to all the people who contribute. [[Contribute](http://avaloniaui.net/contributing/contributing)].
<a href="graphs/contributors"><img src="https://opencollective.com/Avalonia/contributors.svg?width=890&button=false" /></a> <a href="https://github.com/AvaloniaUI/Avalonia/graphs/contributors"><img src="https://opencollective.com/Avalonia/contributors.svg?width=890&button=false" /></a>
### Backers ### Backers

4
samples/ControlCatalog/DecoratedWindow.xaml.cs

@ -20,7 +20,7 @@ namespace ControlCatalog
ctl.Cursor = new Cursor(cursor); ctl.Cursor = new Cursor(cursor);
ctl.PointerPressed += delegate ctl.PointerPressed += delegate
{ {
PlatformImpl.BeginResizeDrag(edge); PlatformImpl?.BeginResizeDrag(edge);
}; };
} }
@ -29,7 +29,7 @@ namespace ControlCatalog
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
this.FindControl<Control>("TitleBar").PointerPressed += delegate this.FindControl<Control>("TitleBar").PointerPressed += delegate
{ {
PlatformImpl.BeginMoveDrag(); PlatformImpl?.BeginMoveDrag();
}; };
SetupSide("Left", StandardCursorType.LeftSide, WindowEdge.West); SetupSide("Left", StandardCursorType.LeftSide, WindowEdge.West);
SetupSide("Right", StandardCursorType.RightSide, WindowEdge.East); SetupSide("Right", StandardCursorType.RightSide, WindowEdge.East);

2
src/Avalonia.Controls/AutoCompleteBox.cs

@ -2150,7 +2150,7 @@ namespace Avalonia.Controls
} }
// Update the view // Update the view
if (e.Action == NotifyCollectionChangedAction.Remove || e.Action == NotifyCollectionChangedAction.Replace) if ((e.Action == NotifyCollectionChangedAction.Remove || e.Action == NotifyCollectionChangedAction.Replace) && e.OldItems != null)
{ {
for (int index = 0; index < e.OldItems.Count; index++) for (int index = 0; index < e.OldItems.Count; index++)
{ {

95
src/Avalonia.Controls/Calendar/Calendar.cs

@ -769,7 +769,7 @@ namespace Avalonia.Controls
} }
private static void UpdateDisplayDate(Calendar c, DateTime addedDate, DateTime removedDate) private static void UpdateDisplayDate(Calendar c, DateTime addedDate, DateTime removedDate)
{ {
Debug.Assert(c != null, "c should not be null!"); Contract.Requires<ArgumentNullException>(c != null);
// If DisplayDate < DisplayDateStart, DisplayDate = DisplayDateStart // If DisplayDate < DisplayDateStart, DisplayDate = DisplayDateStart
if (DateTime.Compare(addedDate, c.DisplayDateRangeStart) < 0) if (DateTime.Compare(addedDate, c.DisplayDateRangeStart) < 0)
@ -1016,8 +1016,6 @@ namespace Avalonia.Controls
internal CalendarDayButton FindDayButtonFromDay(DateTime day) internal CalendarDayButton FindDayButtonFromDay(DateTime day)
{ {
CalendarDayButton b;
DateTime? d;
CalendarItem monthControl = MonthControl; CalendarItem monthControl = MonthControl;
// REMOVE_RTM: should be updated if we support MultiCalendar // REMOVE_RTM: should be updated if we support MultiCalendar
@ -1028,14 +1026,16 @@ namespace Avalonia.Controls
{ {
for (int childIndex = ColumnsPerMonth; childIndex < count; childIndex++) for (int childIndex = ColumnsPerMonth; childIndex < count; childIndex++)
{ {
b = monthControl.MonthView.Children[childIndex] as CalendarDayButton; if (monthControl.MonthView.Children[childIndex] is CalendarDayButton b)
d = b.DataContext as DateTime?;
if (d.HasValue)
{ {
if (DateTimeHelper.CompareDays(d.Value, day) == 0) var d = b.DataContext as DateTime?;
if (d.HasValue)
{ {
return b; if (DateTimeHelper.CompareDays(d.Value, day) == 0)
{
return b;
}
} }
} }
} }
@ -1044,20 +1044,6 @@ namespace Avalonia.Controls
return null; return null;
} }
private void Calendar_SizeChanged(object sender, EventArgs e)
{
Debug.Assert(sender is Calendar, "The sender should be a Calendar!");
var size = Bounds.Size;
RectangleGeometry rg = new RectangleGeometry();
rg.Rect = new Rect(0, 0, size.Width, size.Height);
if (Root != null)
{
Root.Clip = rg;
}
}
private void OnSelectedMonthChanged(DateTime? selectedMonth) private void OnSelectedMonthChanged(DateTime? selectedMonth)
{ {
if (selectedMonth.HasValue) if (selectedMonth.HasValue)
@ -1090,7 +1076,6 @@ namespace Avalonia.Controls
internal void ResetStates() internal void ResetStates()
{ {
CalendarDayButton d;
CalendarItem monthControl = MonthControl; CalendarItem monthControl = MonthControl;
int count = RowsPerMonth * ColumnsPerMonth; int count = RowsPerMonth * ColumnsPerMonth;
if (monthControl != null) if (monthControl != null)
@ -1099,7 +1084,7 @@ namespace Avalonia.Controls
{ {
for (int childIndex = ColumnsPerMonth; childIndex < count; childIndex++) for (int childIndex = ColumnsPerMonth; childIndex < count; childIndex++)
{ {
d = monthControl.MonthView.Children[childIndex] as CalendarDayButton; var d = (CalendarDayButton)monthControl.MonthView.Children[childIndex];
d.IgnoreMouseOverState(); d.IgnoreMouseOverState();
} }
} }
@ -1190,8 +1175,6 @@ namespace Avalonia.Controls
if (HoverEnd != null && HoverStart != null) if (HoverEnd != null && HoverStart != null)
{ {
int startIndex, endIndex, i; int startIndex, endIndex, i;
CalendarDayButton b;
DateTime? d;
CalendarItem monthControl = MonthControl; CalendarItem monthControl = MonthControl;
// This assumes a contiguous set of dates: // This assumes a contiguous set of dates:
@ -1201,18 +1184,20 @@ namespace Avalonia.Controls
for (i = startIndex; i <= endIndex; i++) for (i = startIndex; i <= endIndex; i++)
{ {
b = monthControl.MonthView.Children[i] as CalendarDayButton; if (monthControl.MonthView.Children[i] is CalendarDayButton b)
b.IsSelected = true;
d = b.DataContext as DateTime?;
if (d.HasValue && DateTimeHelper.CompareDays(HoverEnd.Value, d.Value) == 0)
{ {
if (FocusButton != null) b.IsSelected = true;
var d = b.DataContext as DateTime?;
if (d.HasValue && DateTimeHelper.CompareDays(HoverEnd.Value, d.Value) == 0)
{ {
FocusButton.IsCurrent = false; if (FocusButton != null)
{
FocusButton.IsCurrent = false;
}
b.IsCurrent = HasFocusInternal;
FocusButton = b;
} }
b.IsCurrent = HasFocusInternal;
FocusButton = b;
} }
} }
} }
@ -1228,8 +1213,6 @@ namespace Avalonia.Controls
if (HoverEnd != null && HoverStart != null) if (HoverEnd != null && HoverStart != null)
{ {
CalendarItem monthControl = MonthControl; CalendarItem monthControl = MonthControl;
CalendarDayButton b;
DateTime? d;
if (HoverEndIndex != null && HoverStartIndex != null) if (HoverEndIndex != null && HoverStartIndex != null)
{ {
@ -1240,15 +1223,17 @@ namespace Avalonia.Controls
{ {
for (i = startIndex; i <= endIndex; i++) for (i = startIndex; i <= endIndex; i++)
{ {
b = monthControl.MonthView.Children[i] as CalendarDayButton; if (monthControl.MonthView.Children[i] is CalendarDayButton b)
d = b.DataContext as DateTime?;
if (d.HasValue)
{ {
if (!SelectedDates.Contains(d.Value)) var d = b.DataContext as DateTime?;
if (d.HasValue)
{ {
b.IsSelected = false; if (!SelectedDates.Contains(d.Value))
} {
b.IsSelected = false;
}
}
} }
} }
} }
@ -1257,7 +1242,7 @@ namespace Avalonia.Controls
// It is SingleRange // It is SingleRange
for (i = startIndex; i <= endIndex; i++) for (i = startIndex; i <= endIndex; i++)
{ {
(monthControl.MonthView.Children[i] as CalendarDayButton).IsSelected = false; ((CalendarDayButton)monthControl.MonthView.Children[i]).IsSelected = false;
} }
} }
} }
@ -1628,16 +1613,15 @@ namespace Avalonia.Controls
e.Handled = true; e.Handled = true;
} }
} }
internal void Calendar_KeyDown(object sender, KeyEventArgs e)
{
Calendar c = sender as Calendar;
Debug.Assert(c != null, "c should not be null!");
if (!e.Handled && c.IsEnabled) internal void Calendar_KeyDown(KeyEventArgs e)
{
if (!e.Handled && IsEnabled)
{ {
e.Handled = ProcessCalendarKey(e); e.Handled = ProcessCalendarKey(e);
} }
} }
internal bool ProcessCalendarKey(KeyEventArgs e) internal bool ProcessCalendarKey(KeyEventArgs e)
{ {
if (DisplayMode == CalendarMode.Month) if (DisplayMode == CalendarMode.Month)
@ -1976,7 +1960,7 @@ namespace Avalonia.Controls
} }
} }
} }
private void Calendar_KeyUp(object sender, KeyEventArgs e) private void Calendar_KeyUp(KeyEventArgs e)
{ {
if (!e.Handled && (e.Key == Key.LeftShift || e.Key == Key.RightShift)) if (!e.Handled && (e.Key == Key.LeftShift || e.Key == Key.RightShift))
{ {
@ -2083,6 +2067,9 @@ namespace Avalonia.Controls
DisplayDateProperty.Changed.AddClassHandler<Calendar>(x => x.OnDisplayDateChanged); DisplayDateProperty.Changed.AddClassHandler<Calendar>(x => x.OnDisplayDateChanged);
DisplayDateStartProperty.Changed.AddClassHandler<Calendar>(x => x.OnDisplayDateStartChanged); DisplayDateStartProperty.Changed.AddClassHandler<Calendar>(x => x.OnDisplayDateStartChanged);
DisplayDateEndProperty.Changed.AddClassHandler<Calendar>(x => x.OnDisplayDateEndChanged); DisplayDateEndProperty.Changed.AddClassHandler<Calendar>(x => x.OnDisplayDateEndChanged);
KeyDownEvent.AddClassHandler<Calendar>(x => x.Calendar_KeyDown);
KeyUpEvent.AddClassHandler<Calendar>(x => x.Calendar_KeyUp);
} }
/// <summary> /// <summary>
@ -2122,10 +2109,6 @@ namespace Avalonia.Controls
month.Owner = this; month.Owner = this;
} }
} }
LayoutUpdated += Calendar_SizeChanged;
KeyDown += Calendar_KeyDown;
KeyUp += Calendar_KeyUp;
} }
} }

2
src/Avalonia.Controls/Calendar/CalendarDateRange.cs

@ -66,7 +66,7 @@ namespace Avalonia.Controls
/// <returns>Inherited code: Requires comment 2.</returns> /// <returns>Inherited code: Requires comment 2.</returns>
internal bool ContainsAny(CalendarDateRange range) internal bool ContainsAny(CalendarDateRange range)
{ {
Debug.Assert(range != null, "range should not be null!"); Contract.Requires<ArgumentNullException>(range != null);
int start = DateTime.Compare(Start, range.Start); int start = DateTime.Compare(Start, range.Start);

31
src/Avalonia.Controls/Calendar/CalendarItem.cs

@ -517,7 +517,7 @@ namespace Avalonia.Controls.Primitives
for (int childIndex = Calendar.ColumnsPerMonth; childIndex < count; childIndex++) for (int childIndex = Calendar.ColumnsPerMonth; childIndex < count; childIndex++)
{ {
CalendarDayButton childButton = MonthView.Children[childIndex] as CalendarDayButton; CalendarDayButton childButton = MonthView.Children[childIndex] as CalendarDayButton;
Debug.Assert(childButton != null, "childButton should not be null!"); Contract.Requires<ArgumentNullException>(childButton != null);
childButton.Index = childIndex; childButton.Index = childIndex;
SetButtonState(childButton, dateToAdd); SetButtonState(childButton, dateToAdd);
@ -554,7 +554,7 @@ namespace Avalonia.Controls.Primitives
for (int i = childIndex; i < count; i++) for (int i = childIndex; i < count; i++)
{ {
childButton = MonthView.Children[i] as CalendarDayButton; childButton = MonthView.Children[i] as CalendarDayButton;
Debug.Assert(childButton != null, "childButton should not be null!"); Contract.Requires<ArgumentNullException>(childButton != null);
// button needs a content to occupy the necessary space // button needs a content to occupy the necessary space
// for the content presenter // for the content presenter
childButton.Content = i.ToString(DateTimeHelper.GetCurrentDateFormat()); childButton.Content = i.ToString(DateTimeHelper.GetCurrentDateFormat());
@ -650,7 +650,7 @@ namespace Avalonia.Controls.Primitives
foreach (object child in YearView.Children) foreach (object child in YearView.Children)
{ {
CalendarButton childButton = child as CalendarButton; CalendarButton childButton = child as CalendarButton;
Debug.Assert(childButton != null, "childButton should not be null!"); Contract.Requires<ArgumentNullException>(childButton != null);
// There should be no time component. Time is 12:00 AM // There should be no time component. Time is 12:00 AM
DateTime day = new DateTime(_currentMonth.Year, count + 1, 1); DateTime day = new DateTime(_currentMonth.Year, count + 1, 1);
childButton.DataContext = day; childButton.DataContext = day;
@ -746,7 +746,7 @@ namespace Avalonia.Controls.Primitives
foreach (object child in YearView.Children) foreach (object child in YearView.Children)
{ {
CalendarButton childButton = child as CalendarButton; CalendarButton childButton = child as CalendarButton;
Debug.Assert(childButton != null, "childButton should not be null!"); Contract.Requires<ArgumentNullException>(childButton != null);
year = decade + count; year = decade + count;
if (year <= DateTime.MaxValue.Year && year >= DateTime.MinValue.Year) if (year <= DateTime.MaxValue.Year && year >= DateTime.MinValue.Year)
@ -826,7 +826,7 @@ namespace Avalonia.Controls.Primitives
{ {
Owner.Focus(); Owner.Focus();
} }
Button b = sender as Button; Button b = (Button)sender;
DateTime d; DateTime d;
if (b.IsEnabled) if (b.IsEnabled)
@ -863,7 +863,7 @@ namespace Avalonia.Controls.Primitives
Owner.Focus(); Owner.Focus();
} }
Button b = sender as Button; Button b = (Button)sender;
if (b.IsEnabled) if (b.IsEnabled)
{ {
Owner.OnPreviousClick(); Owner.OnPreviousClick();
@ -878,7 +878,7 @@ namespace Avalonia.Controls.Primitives
{ {
Owner.Focus(); Owner.Focus();
} }
Button b = sender as Button; Button b = (Button)sender;
if (b.IsEnabled) if (b.IsEnabled)
{ {
@ -891,8 +891,7 @@ namespace Avalonia.Controls.Primitives
{ {
if (Owner != null) if (Owner != null)
{ {
CalendarDayButton b = sender as CalendarDayButton; if (_isMouseLeftButtonDown && sender is CalendarDayButton b && b.IsEnabled && !b.IsBlackout)
if (_isMouseLeftButtonDown && b != null && b.IsEnabled && !b.IsBlackout)
{ {
// Update the states of all buttons to be selected starting // Update the states of all buttons to be selected starting
// from HoverStart to b // from HoverStart to b
@ -918,7 +917,7 @@ namespace Avalonia.Controls.Primitives
Debug.Assert(b.DataContext != null, "The DataContext should not be null!"); Debug.Assert(b.DataContext != null, "The DataContext should not be null!");
Owner.UnHighlightDays(); Owner.UnHighlightDays();
Owner.HoverEndIndex = b.Index; Owner.HoverEndIndex = b.Index;
Owner.HoverEnd = (DateTime)b.DataContext; Owner.HoverEnd = (DateTime?)b.DataContext;
// Update the States of the buttons // Update the States of the buttons
Owner.HighlightDays(); Owner.HighlightDays();
return; return;
@ -931,7 +930,7 @@ namespace Avalonia.Controls.Primitives
{ {
if (_isMouseLeftButtonDown) if (_isMouseLeftButtonDown)
{ {
CalendarDayButton b = sender as CalendarDayButton; CalendarDayButton b = (CalendarDayButton)sender;
// The button is in Pressed state. Change the state to normal. // The button is in Pressed state. Change the state to normal.
if (e.Device.Captured == b) if (e.Device.Captured == b)
e.Device.Capture(null); e.Device.Capture(null);
@ -973,7 +972,7 @@ namespace Avalonia.Controls.Primitives
if (b.IsEnabled && !b.IsBlackout) if (b.IsEnabled && !b.IsBlackout)
{ {
DateTime selectedDate = (DateTime)b.DataContext; DateTime selectedDate = (DateTime)b.DataContext;
Debug.Assert(selectedDate != null, "selectedDate should not be null!"); Contract.Requires<ArgumentNullException>(selectedDate != null);
_isMouseLeftButtonDown = true; _isMouseLeftButtonDown = true;
// null check is added for unit tests // null check is added for unit tests
if (e != null) if (e != null)
@ -1149,7 +1148,7 @@ namespace Avalonia.Controls.Primitives
if (_isControlPressed && Owner.SelectionMode == CalendarSelectionMode.MultipleRange) if (_isControlPressed && Owner.SelectionMode == CalendarSelectionMode.MultipleRange)
{ {
CalendarDayButton b = sender as CalendarDayButton; CalendarDayButton b = sender as CalendarDayButton;
Debug.Assert(b != null, "The sender should be a non-null CalendarDayButton!"); Contract.Requires<ArgumentNullException>(b != null);
if (b.IsSelected) if (b.IsSelected)
{ {
@ -1169,7 +1168,7 @@ namespace Avalonia.Controls.Primitives
private void Month_CalendarButtonMouseDown(object sender, PointerPressedEventArgs e) private void Month_CalendarButtonMouseDown(object sender, PointerPressedEventArgs e)
{ {
CalendarButton b = sender as CalendarButton; CalendarButton b = sender as CalendarButton;
Debug.Assert(b != null, "The sender should be a non-null CalendarDayButton!"); Contract.Requires<ArgumentNullException>(b != null);
_isMouseLeftButtonDownYearView = true; _isMouseLeftButtonDownYearView = true;
@ -1208,7 +1207,7 @@ namespace Avalonia.Controls.Primitives
if (_isMouseLeftButtonDownYearView) if (_isMouseLeftButtonDownYearView)
{ {
CalendarButton b = sender as CalendarButton; CalendarButton b = sender as CalendarButton;
Debug.Assert(b != null, "The sender should be a non-null CalendarDayButton!"); Contract.Requires<ArgumentNullException>(b != null);
UpdateYearViewSelection(b); UpdateYearViewSelection(b);
} }
} }
@ -1217,7 +1216,7 @@ namespace Avalonia.Controls.Primitives
{ {
if (_isMouseLeftButtonDownYearView) if (_isMouseLeftButtonDownYearView)
{ {
CalendarButton b = sender as CalendarButton; CalendarButton b = (CalendarButton)sender;
// The button is in Pressed state. Change the state to normal. // The button is in Pressed state. Change the state to normal.
if (e.Device.Captured == b) if (e.Device.Captured == b)
e.Device.Capture(null); e.Device.Capture(null);

2
src/Avalonia.Controls/Calendar/DatePicker.cs

@ -842,7 +842,7 @@ namespace Avalonia.Controls
private void Calendar_KeyDown(object sender, KeyEventArgs e) private void Calendar_KeyDown(object sender, KeyEventArgs e)
{ {
Calendar c = sender as Calendar; Calendar c = sender as Calendar;
Debug.Assert(c != null, "The Calendar should not be null!"); Contract.Requires<ArgumentNullException>(c != null);
if (!e.Handled && (e.Key == Key.Enter || e.Key == Key.Space || e.Key == Key.Escape) && c.DisplayMode == CalendarMode.Month) if (!e.Handled && (e.Key == Key.Enter || e.Key == Key.Space || e.Key == Key.Escape) && c.DisplayMode == CalendarMode.Month)
{ {

18
src/Avalonia.Controls/Design.cs

@ -1,5 +1,6 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Avalonia.Styling;
namespace Avalonia.Controls namespace Avalonia.Controls
{ {
@ -45,23 +46,18 @@ namespace Avalonia.Controls
{ {
return control.GetValue(DataContextProperty); return control.GetValue(DataContextProperty);
} }
static readonly ConditionalWeakTable<object, Control> Substitutes = new ConditionalWeakTable<object, Control>();
public static readonly AttachedProperty<Control> PreviewWithProperty = AvaloniaProperty public static readonly AttachedProperty<Control> PreviewWithProperty = AvaloniaProperty
.RegisterAttached<AvaloniaObject, Control>("PreviewWith", typeof (Design)); .RegisterAttached<Style, Control>("PreviewWith", typeof (Design));
public static void SetPreviewWith(object target, Control control) public static void SetPreviewWith(Style target, Control control)
{ {
Substitutes.Remove(target); target.SetValue(PreviewWithProperty, control);
Substitutes.Add(target, control);
} }
public static Control GetPreviewWith(object target) public static Control GetPreviewWith(Style target)
{ {
Control rv; return target.GetValue(PreviewWithProperty);
Substitutes.TryGetValue(target, out rv);
return rv;
} }
public static void ApplyDesignModeProperties(Control target, Control source) public static void ApplyDesignModeProperties(Control target, Control source)

13
src/Avalonia.Controls/DropDownItem.cs

@ -22,14 +22,13 @@ namespace Avalonia.Controls
static DropDownItem() static DropDownItem()
{ {
FocusableProperty.OverrideDefaultValue<DropDownItem>(true); FocusableProperty.OverrideDefaultValue<DropDownItem>(true);
IsFocusedProperty.Changed.Subscribe(x => }
{
var sender = x.Sender as IControl;
if (sender != null) public DropDownItem()
{ {
((IPseudoClasses)sender.Classes).Set(":selected", (bool)x.NewValue); this.GetObservable(DropDownItem.IsFocusedProperty).Subscribe(focused =>
} {
PseudoClasses.Set(":selected", focused);
}); });
} }

2
src/Avalonia.Controls/Embedding/Offscreen/OffscreenTopLevel.cs

@ -57,7 +57,7 @@ namespace Avalonia.Controls.Embedding.Offscreen
Type IStyleable.StyleKey => typeof(EmbeddableControlRoot); Type IStyleable.StyleKey => typeof(EmbeddableControlRoot);
public void Dispose() public void Dispose()
{ {
PlatformImpl.Dispose(); PlatformImpl?.Dispose();
} }
} }
} }

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

@ -62,7 +62,7 @@ namespace Avalonia.Platform
RawDragEvent rawEvent = new RawDragEvent(_dragDrop, type, root, pt, _draggedData, _allowedEffects); RawDragEvent rawEvent = new RawDragEvent(_dragDrop, type, root, pt, _draggedData, _allowedEffects);
var tl = root.GetSelfAndVisualAncestors().OfType<TopLevel>().FirstOrDefault(); var tl = root.GetSelfAndVisualAncestors().OfType<TopLevel>().FirstOrDefault();
tl.PlatformImpl.Input(rawEvent); tl.PlatformImpl?.Input(rawEvent);
var effect = GetPreferredEffect(rawEvent.Effects & _allowedEffects, modifiers); var effect = GetPreferredEffect(rawEvent.Effects & _allowedEffects, modifiers);
UpdateCursor(root, effect); UpdateCursor(root, effect);

27
src/Avalonia.Controls/Presenters/CarouselPresenter.cs

@ -106,7 +106,6 @@ namespace Avalonia.Controls.Presenters
/// <inheritdoc/> /// <inheritdoc/>
protected override void ItemsChanged(NotifyCollectionChangedEventArgs e) protected override void ItemsChanged(NotifyCollectionChangedEventArgs e)
{ {
// TODO: Handle items changing.
switch (e.Action) switch (e.Action)
{ {
case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Remove:
@ -115,9 +114,35 @@ namespace Avalonia.Controls.Presenters
var generator = ItemContainerGenerator; var generator = ItemContainerGenerator;
var containers = generator.RemoveRange(e.OldStartingIndex, e.OldItems.Count); var containers = generator.RemoveRange(e.OldStartingIndex, e.OldItems.Count);
Panel.Children.RemoveAll(containers.Select(x => x.ContainerControl)); Panel.Children.RemoveAll(containers.Select(x => x.ContainerControl));
MoveToPage(-1, SelectedIndex);
} }
break; break;
case NotifyCollectionChangedAction.Reset:
{
var generator = ItemContainerGenerator;
var containers = generator.Containers.ToList();
generator.Clear();
Panel.Children.RemoveAll(containers.Select(x => x.ContainerControl));
var newIndex = SelectedIndex;
if(SelectedIndex < 0)
{
if(Items != null && Items.Count() > 0)
{
newIndex = 0;
}
else
{
newIndex = -1;
}
}
MoveToPage(-1, newIndex);
}
break;
} }
} }

16
src/Avalonia.Controls/TextBox.cs

@ -68,6 +68,10 @@ namespace Avalonia.Controls
public static readonly StyledProperty<bool> UseFloatingWatermarkProperty = public static readonly StyledProperty<bool> UseFloatingWatermarkProperty =
AvaloniaProperty.Register<TextBox, bool>(nameof(UseFloatingWatermark)); AvaloniaProperty.Register<TextBox, bool>(nameof(UseFloatingWatermark));
public static readonly DirectProperty<TextBox, string> NewLineProperty =
AvaloniaProperty.RegisterDirect<TextBox, string>(nameof(NewLine),
textbox => textbox.NewLine, (textbox, newline) => textbox.NewLine = newline);
struct UndoRedoState : IEquatable<UndoRedoState> struct UndoRedoState : IEquatable<UndoRedoState>
{ {
public string Text { get; } public string Text { get; }
@ -90,6 +94,7 @@ namespace Avalonia.Controls
private UndoRedoHelper<UndoRedoState> _undoRedoHelper; private UndoRedoHelper<UndoRedoState> _undoRedoHelper;
private bool _isUndoingRedoing; private bool _isUndoingRedoing;
private bool _ignoreTextChanges; private bool _ignoreTextChanges;
private string _newLine = Environment.NewLine;
private static readonly string[] invalidCharacters = new String[1] { "\u007f" }; private static readonly string[] invalidCharacters = new String[1] { "\u007f" };
static TextBox() static TextBox()
@ -241,6 +246,15 @@ namespace Avalonia.Controls
set { SetValue(TextWrappingProperty, value); } set { SetValue(TextWrappingProperty, value); }
} }
/// <summary>
/// Gets or sets which characters are inserted when Enter is pressed. Default: <see cref="Environment.NewLine"/>
/// </summary>
public string NewLine
{
get { return _newLine; }
set { SetAndRaise(NewLineProperty, ref _newLine, value); }
}
protected override void OnTemplateApplied(TemplateAppliedEventArgs e) protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
{ {
_presenter = e.NameScope.Get<TextPresenter>("PART_TextPresenter"); _presenter = e.NameScope.Get<TextPresenter>("PART_TextPresenter");
@ -498,7 +512,7 @@ namespace Avalonia.Controls
case Key.Enter: case Key.Enter:
if (AcceptsReturn) if (AcceptsReturn)
{ {
HandleTextInput("\r\n"); HandleTextInput(NewLine);
handled = true; handled = true;
} }

18
src/Avalonia.Controls/Window.cs

@ -145,11 +145,9 @@ namespace Avalonia.Controls
: base(impl) : base(impl)
{ {
impl.Closing = HandleClosing; impl.Closing = HandleClosing;
impl.WindowStateChanged = HandleWindowStateChanged;
_maxPlatformClientSize = PlatformImpl?.MaxClientSize ?? default(Size); _maxPlatformClientSize = PlatformImpl?.MaxClientSize ?? default(Size);
Screens = new Screens(PlatformImpl?.Screen); Screens = new Screens(PlatformImpl?.Screen);
if (PlatformImpl != null)
PlatformImpl.WindowStateChanged = s => WindowState = s;
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -318,6 +316,20 @@ namespace Avalonia.Controls
return args.Cancel; return args.Cancel;
} }
protected virtual void HandleWindowStateChanged(WindowState state)
{
WindowState = state;
if (state == WindowState.Minimized)
{
Renderer.Stop();
}
else
{
Renderer.Start();
}
}
/// <summary> /// <summary>
/// Hides the window but does not close it. /// Hides the window but does not close it.
/// </summary> /// </summary>

3
src/Avalonia.DesignerSupport/DesignWindowLoader.cs

@ -36,8 +36,7 @@ namespace Avalonia.DesignerSupport
var styles = loaded as Styles; var styles = loaded as Styles;
if (styles != null) if (styles != null)
{ {
var substitute = Design.GetPreviewWith(styles) ?? var substitute = styles.OfType<Style>().Select(Design.GetPreviewWith).FirstOrDefault(s => s != null);
styles.Select(Design.GetPreviewWith).FirstOrDefault(s => s != null);
if (substitute != null) if (substitute != null)
{ {
substitute.Styles.AddRange(styles); substitute.Styles.AddRange(styles);

2
src/Avalonia.Styling/Styling/Style.cs

@ -15,7 +15,7 @@ namespace Avalonia.Styling
/// <summary> /// <summary>
/// Defines a style. /// Defines a style.
/// </summary> /// </summary>
public class Style : IStyle, ISetStyleParent public class Style : AvaloniaObject, IStyle, ISetStyleParent
{ {
private static Dictionary<IStyleable, List<IDisposable>> _applied = private static Dictionary<IStyleable, List<IDisposable>> _applied =
new Dictionary<IStyleable, List<IDisposable>>(); new Dictionary<IStyleable, List<IDisposable>>();

5
src/Avalonia.Themes.Default/Calendar.xaml

@ -15,9 +15,10 @@
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<StackPanel Name="Root" <StackPanel Name="Root"
HorizontalAlignment="Center"> HorizontalAlignment="Center"
ClipToBounds="True">
<CalendarItem Name="CalendarItem" <CalendarItem Name="CalendarItem"
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"

6
src/Avalonia.Visuals/Media/FontFamily.cs

@ -77,10 +77,10 @@ namespace Avalonia.Media
/// <summary> /// <summary>
/// Implicit conversion of string to FontFamily /// Implicit conversion of string to FontFamily
/// </summary> /// </summary>
/// <param name="fontFamily"></param> /// <param name="s"></param>
public static implicit operator FontFamily(string fontFamily) public static implicit operator FontFamily(string s)
{ {
return new FontFamily(fontFamily); return Parse(s);
} }
/// <summary> /// <summary>

3
src/Markup/Avalonia.Markup/Data/MultiBinding.cs

@ -10,6 +10,7 @@ using System.Reactive.Subjects;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Data.Converters; using Avalonia.Data.Converters;
using Avalonia.Metadata; using Avalonia.Metadata;
using JetBrains.Annotations;
namespace Avalonia.Data namespace Avalonia.Data
{ {
@ -65,7 +66,7 @@ namespace Avalonia.Data
var children = Bindings.Select(x => x.Initiate(target, null)); var children = Bindings.Select(x => x.Initiate(target, null));
var input = children.Select(x => x.Subject).CombineLatest().Select(x => ConvertValue(x, targetType)); var input = children.Select(x => x.Subject).CombineLatest().Select(x => ConvertValue(x, targetType));
var mode = Mode == BindingMode.Default ? var mode = Mode == BindingMode.Default ?
targetProperty.GetMetadata(target.GetType()).DefaultBindingMode : Mode; targetProperty?.GetMetadata(target.GetType()).DefaultBindingMode : Mode;
switch (mode) switch (mode)
{ {

2
src/Windows/Avalonia.Win32/SystemDialogImpl.cs

@ -54,7 +54,7 @@ namespace Avalonia.Win32
var fileBuffer = new char[256]; var fileBuffer = new char[256];
dialog.InitialFileName?.CopyTo(0, fileBuffer, 0, dialog.InitialFileName.Length); dialog.InitialFileName?.CopyTo(0, fileBuffer, 0, dialog.InitialFileName.Length);
string userSelectedExt = null; string userSelectedExt = string.Empty;
var title = ToChars(dialog.Title); var title = ToChars(dialog.Title);

206
tests/Avalonia.Controls.UnitTests/CarouselTests.cs

@ -1,11 +1,13 @@
// Copyright (c) The Avalonia Project. All rights reserved. // 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. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Avalonia.Controls.Presenters; using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates; using Avalonia.Controls.Templates;
using Avalonia.LogicalTree; using Avalonia.LogicalTree;
using Avalonia.VisualTree;
using Xunit; using Xunit;
namespace Avalonia.Controls.UnitTests namespace Avalonia.Controls.UnitTests
@ -50,7 +52,7 @@ namespace Avalonia.Controls.UnitTests
Assert.Single(target.GetLogicalChildren()); Assert.Single(target.GetLogicalChildren());
var child = target.GetLogicalChildren().Single(); var child = target.GetLogicalChildren().Single();
Assert.IsType<TextBlock>(child); Assert.IsType<TextBlock>(child);
Assert.Equal("Foo", ((TextBlock)child).Text); Assert.Equal("Foo", ((TextBlock)child).Text);
} }
@ -93,6 +95,208 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(2, target.ItemContainerGenerator.Containers.Count()); Assert.Equal(2, target.ItemContainerGenerator.Containers.Count());
} }
[Fact]
public void Selected_Item_Changes_To_First_Item_When_Items_Property_Changes()
{
var items = new ObservableCollection<string>
{
"Foo",
"Bar",
"FooBar"
};
var target = new Carousel
{
Template = new FuncControlTemplate<Carousel>(CreateTemplate),
Items = items,
IsVirtualized = false
};
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
Assert.Single(target.GetLogicalChildren());
var child = target.GetLogicalChildren().Single();
Assert.IsType<TextBlock>(child);
Assert.Equal("Foo", ((TextBlock)child).Text);
var newItems = items.ToList();
newItems.RemoveAt(0);
target.Items = newItems;
child = target.GetLogicalChildren().Single();
Assert.IsType<TextBlock>(child);
Assert.Equal("Bar", ((TextBlock)child).Text);
}
[Fact]
public void Selected_Item_Changes_To_First_Item_When_Items_Property_Changes_And_Virtualized()
{
var items = new ObservableCollection<string>
{
"Foo",
"Bar",
"FooBar"
};
var target = new Carousel
{
Template = new FuncControlTemplate<Carousel>(CreateTemplate),
Items = items
};
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
Assert.Single(target.GetLogicalChildren());
var child = target.GetLogicalChildren().Single();
Assert.IsType<TextBlock>(child);
Assert.Equal("Foo", ((TextBlock)child).Text);
var newItems = items.ToList();
newItems.RemoveAt(0);
target.Items = newItems;
child = target.GetLogicalChildren().Single();
Assert.IsType<TextBlock>(child);
Assert.Equal("Bar", ((TextBlock)child).Text);
}
[Fact]
public void Selected_Index_Changes_To_When_Items_Assigned_Null()
{
var items = new ObservableCollection<string>
{
"Foo",
"Bar",
"FooBar"
};
var target = new Carousel
{
Template = new FuncControlTemplate<Carousel>(CreateTemplate),
Items = items,
IsVirtualized = false
};
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
Assert.Single(target.GetLogicalChildren());
var child = target.GetLogicalChildren().Single();
Assert.IsType<TextBlock>(child);
Assert.Equal("Foo", ((TextBlock)child).Text);
target.Items = null;
var numChildren = target.GetLogicalChildren().Count();
Assert.Equal(0, numChildren);
Assert.Equal(-1, target.SelectedIndex);
}
[Fact]
public void Selected_Index_Is_Maintained_Carousel_Created_With_Non_Zero_SelectedIndex()
{
var items = new ObservableCollection<string>
{
"Foo",
"Bar",
"FooBar"
};
var target = new Carousel
{
Template = new FuncControlTemplate<Carousel>(CreateTemplate),
Items = items,
IsVirtualized = false,
SelectedIndex = 2
};
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
Assert.Equal("FooBar", target.SelectedItem);
var child = target.GetVisualDescendants().LastOrDefault();
Assert.IsType<TextBlock>(child);
Assert.Equal("FooBar", ((TextBlock)child).Text);
}
[Fact]
public void Selected_Item_Changes_To_Next_First_Item_When_Item_Removed_From_Beggining_Of_List()
{
var items = new ObservableCollection<string>
{
"Foo",
"Bar",
"FooBar"
};
var target = new Carousel
{
Template = new FuncControlTemplate<Carousel>(CreateTemplate),
Items = items,
IsVirtualized = false
};
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
Assert.Single(target.GetLogicalChildren());
var child = target.GetLogicalChildren().Single();
Assert.IsType<TextBlock>(child);
Assert.Equal("Foo", ((TextBlock)child).Text);
items.RemoveAt(0);
child = target.GetLogicalChildren().Single();
Assert.IsType<TextBlock>(child);
Assert.Equal("Bar", ((TextBlock)child).Text);
}
[Fact]
public void Selected_Item_Changes_To_NextAvailable_Item_If_SelectedItem_Is_Removed_From_Middle()
{
var items = new ObservableCollection<string>
{
"Foo",
"Bar",
"FooBar"
};
var target = new Carousel
{
Template = new FuncControlTemplate<Carousel>(CreateTemplate),
Items = items,
IsVirtualized = false
};
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
target.SelectedIndex = 1;
items.RemoveAt(1);
Assert.Equal(1, target.SelectedIndex);
Assert.Equal("FooBar", target.SelectedItem);
}
private Control CreateTemplate(Carousel control) private Control CreateTemplate(Carousel control)
{ {
return new CarouselPresenter return new CarouselPresenter

53
tests/Avalonia.Controls.UnitTests/TextBoxTests.cs

@ -247,6 +247,59 @@ namespace Avalonia.Controls.UnitTests
} }
} }
[Fact]
public void Press_Enter_Does_Not_Accept_Return()
{
using (UnitTestApplication.Start(Services))
{
var target = new TextBox
{
Template = CreateTemplate(),
AcceptsReturn = false,
Text = "1234"
};
RaiseKeyEvent(target, Key.Enter, 0);
Assert.Equal("1234", target.Text);
}
}
[Fact]
public void Press_Enter_Add_Default_Newline()
{
using (UnitTestApplication.Start(Services))
{
var target = new TextBox
{
Template = CreateTemplate(),
AcceptsReturn = true
};
RaiseKeyEvent(target, Key.Enter, 0);
Assert.Equal(Environment.NewLine, target.Text);
}
}
[Fact]
public void Press_Enter_Add_Custom_Newline()
{
using (UnitTestApplication.Start(Services))
{
var target = new TextBox
{
Template = CreateTemplate(),
AcceptsReturn = true,
NewLine = "Test"
};
RaiseKeyEvent(target, Key.Enter, 0);
Assert.Equal("Test", target.Text);
}
}
[Theory] [Theory]
[InlineData(new object[] { false, TextWrapping.NoWrap, ScrollBarVisibility.Hidden })] [InlineData(new object[] { false, TextWrapping.NoWrap, ScrollBarVisibility.Hidden })]
[InlineData(new object[] { false, TextWrapping.Wrap, ScrollBarVisibility.Hidden })] [InlineData(new object[] { false, TextWrapping.Wrap, ScrollBarVisibility.Hidden })]

Loading…
Cancel
Save