Browse Source

Merge branch 'master' into fixes/Samples/ControlCatalog

pull/8717/head
Max Katz 4 years ago
committed by GitHub
parent
commit
1b36323354
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/Avalonia.Controls/AutoCompleteBox.cs
  2. 77
      src/Avalonia.Controls/Calendar/Calendar.cs
  3. 71
      src/Avalonia.Controls/Calendar/CalendarItem.cs
  4. 2
      src/Avalonia.Controls/Calendar/SelectedDatesCollection.cs

11
src/Avalonia.Controls/AutoCompleteBox.cs

@ -392,6 +392,8 @@ namespace Avalonia.Controls
private AutoCompleteSelector<object>? _itemSelector; private AutoCompleteSelector<object>? _itemSelector;
private AutoCompleteSelector<string?>? _textSelector; private AutoCompleteSelector<string?>? _textSelector;
private readonly EventHandler _populateDropDownHandler;
public static readonly RoutedEvent<SelectionChangedEventArgs> SelectionChangedEvent = public static readonly RoutedEvent<SelectionChangedEventArgs> SelectionChangedEvent =
RoutedEvent.Register<SelectionChangedEventArgs>(nameof(SelectionChanged), RoutingStrategies.Bubble, typeof(AutoCompleteBox)); RoutedEvent.Register<SelectionChangedEventArgs>(nameof(SelectionChanged), RoutingStrategies.Bubble, typeof(AutoCompleteBox));
@ -668,6 +670,7 @@ namespace Avalonia.Controls
if (newValue == TimeSpan.Zero) if (newValue == TimeSpan.Zero)
{ {
_delayTimer.Tick -= _populateDropDownHandler;
_delayTimer = null; _delayTimer = null;
} }
} }
@ -678,7 +681,7 @@ namespace Avalonia.Controls
if (_delayTimer == null) if (_delayTimer == null)
{ {
_delayTimer = new DispatcherTimer(); _delayTimer = new DispatcherTimer();
_delayTimer.Tick += PopulateDropDown; _delayTimer.Tick += _populateDropDownHandler;
} }
// Set the new tick interval // Set the new tick interval
@ -864,6 +867,7 @@ namespace Avalonia.Controls
/// </summary> /// </summary>
public AutoCompleteBox() public AutoCompleteBox()
{ {
_populateDropDownHandler = PopulateDropDown;
ClearView(); ClearView();
} }
@ -1771,10 +1775,7 @@ namespace Avalonia.Controls
/// <param name="e">The event arguments.</param> /// <param name="e">The event arguments.</param>
private void PopulateDropDown(object? sender, EventArgs e) private void PopulateDropDown(object? sender, EventArgs e)
{ {
if (_delayTimer != null) _delayTimer?.Stop();
{
_delayTimer.Stop();
}
// Update the prefix/search text. // Update the prefix/search text.
SearchText = Text; SearchText = Text;

77
src/Avalonia.Controls/Calendar/Calendar.cs

@ -224,7 +224,7 @@ namespace Avalonia.Controls
/// </para> /// </para>
/// </remarks> /// </remarks>
[TemplatePart(PART_ElementMonth, typeof(CalendarItem))] [TemplatePart(PART_ElementMonth, typeof(CalendarItem))]
[TemplatePart(PART_ElementRoot, typeof(Panel))] [TemplatePart(PART_ElementRoot, typeof(Panel))]
public class Calendar : TemplatedControl public class Calendar : TemplatedControl
{ {
internal const int RowsPerMonth = 7; internal const int RowsPerMonth = 7;
@ -338,14 +338,11 @@ namespace Avalonia.Controls
/// <param name="e">The DependencyPropertyChangedEventArgs.</param> /// <param name="e">The DependencyPropertyChangedEventArgs.</param>
private void OnIsTodayHighlightedChanged(AvaloniaPropertyChangedEventArgs e) private void OnIsTodayHighlightedChanged(AvaloniaPropertyChangedEventArgs e)
{ {
if (DisplayDate != null) int i = DateTimeHelper.CompareYearMonth(DisplayDateInternal, DateTime.Today);
{
int i = DateTimeHelper.CompareYearMonth(DisplayDateInternal, DateTime.Today);
if (i > -2 && i < 2) if (i > -2 && i < 2)
{ {
UpdateMonths(); UpdateMonths();
}
} }
} }
@ -655,7 +652,7 @@ namespace Avalonia.Controls
SelectedDatesChanged?.Invoke(this, e); SelectedDatesChanged?.Invoke(this, e);
} }
} }
internal Collection<DateTime> RemovedItems { get; set; } internal Collection<DateTime> RemovedItems { get; set; }
internal DateTime? LastSelectedDateInternal { get; set; } internal DateTime? LastSelectedDateInternal { get; set; }
internal DateTime? LastSelectedDate internal DateTime? LastSelectedDate
@ -914,7 +911,7 @@ namespace Avalonia.Controls
o => o.DisplayDateEnd, o => o.DisplayDateEnd,
(o, v) => o.DisplayDateEnd = v, (o, v) => o.DisplayDateEnd = v,
defaultBindingMode: BindingMode.TwoWay); defaultBindingMode: BindingMode.TwoWay);
/// <summary> /// <summary>
/// Gets or sets the last date to be displayed. /// Gets or sets the last date to be displayed.
/// </summary> /// </summary>
@ -1242,7 +1239,7 @@ namespace Avalonia.Controls
{ {
b.IsSelected = false; b.IsSelected = false;
} }
} }
} }
} }
} }
@ -1278,7 +1275,7 @@ namespace Avalonia.Controls
internal void OnPreviousClick() internal void OnPreviousClick()
{ {
if (DisplayMode == CalendarMode.Month && DisplayDate != null) if (DisplayMode == CalendarMode.Month)
{ {
DateTime? d = DateTimeHelper.AddMonths(DateTimeHelper.DiscardDayTime(DisplayDate), -1); DateTime? d = DateTimeHelper.AddMonths(DateTimeHelper.DiscardDayTime(DisplayDate), -1);
if (d.HasValue) if (d.HasValue)
@ -1326,7 +1323,7 @@ namespace Avalonia.Controls
} }
internal void OnNextClick() internal void OnNextClick()
{ {
if (DisplayMode == CalendarMode.Month && DisplayDate != null) if (DisplayMode == CalendarMode.Month)
{ {
DateTime? d = DateTimeHelper.AddMonths(DateTimeHelper.DiscardDayTime(DisplayDate), 1); DateTime? d = DateTimeHelper.AddMonths(DateTimeHelper.DiscardDayTime(DisplayDate), 1);
if (d.HasValue) if (d.HasValue)
@ -1645,7 +1642,7 @@ namespace Avalonia.Controls
{ {
if (DisplayMode == CalendarMode.Month) if (DisplayMode == CalendarMode.Month)
{ {
if (LastSelectedDate.HasValue && DisplayDateInternal != null) if (LastSelectedDate.HasValue)
{ {
// If a blackout day is inactive, when clicked on it, the // If a blackout day is inactive, when clicked on it, the
// previous inactive day which is not a blackout day can get // previous inactive day which is not a blackout day can get
@ -1897,24 +1894,21 @@ namespace Avalonia.Controls
{ {
case CalendarMode.Month: case CalendarMode.Month:
{ {
if (DisplayDate != null) DateTime? selectedDate = new DateTime(DisplayDateInternal.Year, DisplayDateInternal.Month, 1);
{
DateTime? selectedDate = new DateTime(DisplayDateInternal.Year, DisplayDateInternal.Month, 1);
if (DateTimeHelper.CompareYearMonth(DateTime.MaxValue, selectedDate.Value) > 0) if (DateTimeHelper.CompareYearMonth(DateTime.MaxValue, selectedDate.Value) > 0)
{ {
// since DisplayDate is not equal to // since DisplayDate is not equal to
// DateTime.MaxValue we are sure selectedDate is\ // DateTime.MaxValue we are sure selectedDate is\
// not null // not null
selectedDate = DateTimeHelper.AddMonths(selectedDate.Value, 1)!.Value; selectedDate = DateTimeHelper.AddMonths(selectedDate.Value, 1)!.Value;
selectedDate = DateTimeHelper.AddDays(selectedDate.Value, -1)!.Value; selectedDate = DateTimeHelper.AddDays(selectedDate.Value, -1)!.Value;
}
else
{
selectedDate = DateTime.MaxValue;
}
ProcessSelection(shift, selectedDate, null);
} }
else
{
selectedDate = DateTime.MaxValue;
}
ProcessSelection(shift, selectedDate, null);
break; break;
} }
case CalendarMode.Year: case CalendarMode.Year:
@ -2026,7 +2020,6 @@ namespace Avalonia.Controls
focusDate = DisplayDate; focusDate = DisplayDate;
LastSelectedDate = DisplayDate; LastSelectedDate = DisplayDate;
} }
Debug.Assert(focusDate != null, "focusDate should not be null!");
FocusButton = FindDayButtonFromDay(focusDate); FocusButton = FindDayButtonFromDay(focusDate);
if (FocusButton != null) if (FocusButton != null)
@ -2091,17 +2084,17 @@ namespace Avalonia.Controls
static Calendar() static Calendar()
{ {
IsEnabledProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnIsEnabledChanged(e)); IsEnabledProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnIsEnabledChanged(e));
FirstDayOfWeekProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnFirstDayOfWeekChanged(e)); FirstDayOfWeekProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnFirstDayOfWeekChanged(e));
IsTodayHighlightedProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnIsTodayHighlightedChanged(e)); IsTodayHighlightedProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnIsTodayHighlightedChanged(e));
DisplayModeProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnDisplayModePropertyChanged(e)); DisplayModeProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnDisplayModePropertyChanged(e));
SelectionModeProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnSelectionModeChanged(e)); SelectionModeProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnSelectionModeChanged(e));
SelectedDateProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnSelectedDateChanged(e)); SelectedDateProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnSelectedDateChanged(e));
DisplayDateProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnDisplayDateChanged(e)); DisplayDateProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnDisplayDateChanged(e));
DisplayDateStartProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnDisplayDateStartChanged(e)); DisplayDateStartProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnDisplayDateStartChanged(e));
DisplayDateEndProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnDisplayDateEndChanged(e)); DisplayDateEndProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnDisplayDateEndChanged(e));
KeyDownEvent.AddClassHandler<Calendar>((x,e) => x.Calendar_KeyDown(e)); KeyDownEvent.AddClassHandler<Calendar>((x, e) => x.Calendar_KeyDown(e));
KeyUpEvent.AddClassHandler<Calendar>((x,e) => x.Calendar_KeyUp(e)); KeyUpEvent.AddClassHandler<Calendar>((x, e) => x.Calendar_KeyUp(e));
} }
/// <summary> /// <summary>

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

@ -4,7 +4,6 @@
// All other rights reserved. // All other rights reserved.
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using Avalonia.Collections.Pooled; using Avalonia.Collections.Pooled;
@ -353,7 +352,6 @@ namespace Avalonia.Controls.Primitives
{ {
if (Owner != null) if (Owner != null)
{ {
Debug.Assert(Owner.DisplayDate != null, "The Owner Calendar's DisplayDate should not be null!");
_currentMonth = Owner.DisplayDateInternal; _currentMonth = Owner.DisplayDateInternal;
} }
else else
@ -361,17 +359,14 @@ namespace Avalonia.Controls.Primitives
_currentMonth = DateTime.Today; _currentMonth = DateTime.Today;
} }
if (_currentMonth != null) SetMonthModeHeaderButton();
{ SetMonthModePreviousButton(_currentMonth);
SetMonthModeHeaderButton(); SetMonthModeNextButton(_currentMonth);
SetMonthModePreviousButton(_currentMonth);
SetMonthModeNextButton(_currentMonth);
if (MonthView != null) if (MonthView != null)
{ {
SetDayTitles(); SetDayTitles();
SetCalendarDayButtons(_currentMonth); SetCalendarDayButtons(_currentMonth);
}
} }
} }
private void SetMonthModeHeaderButton() private void SetMonthModeHeaderButton()
@ -592,7 +587,6 @@ namespace Avalonia.Controls.Primitives
{ {
if (Owner != null) if (Owner != null)
{ {
Debug.Assert(Owner.SelectedMonth != null, "The Owner Calendar's SelectedMonth should not be null!");
_currentMonth = (DateTime)Owner.SelectedMonth; _currentMonth = (DateTime)Owner.SelectedMonth;
} }
else else
@ -600,16 +594,13 @@ namespace Avalonia.Controls.Primitives
_currentMonth = DateTime.Today; _currentMonth = DateTime.Today;
} }
if (_currentMonth != null) SetYearModeHeaderButton();
{ SetYearModePreviousButton();
SetYearModeHeaderButton(); SetYearModeNextButton();
SetYearModePreviousButton();
SetYearModeNextButton();
if (YearView != null) if (YearView != null)
{ {
SetMonthButtonsForYearMode(); SetMonthButtonsForYearMode();
}
} }
} }
private void SetYearModeHeaderButton() private void SetYearModeHeaderButton()
@ -660,7 +651,6 @@ namespace Avalonia.Controls.Primitives
childButton.IsCalendarButtonFocused = false; childButton.IsCalendarButtonFocused = false;
} }
Debug.Assert(Owner.DisplayDateInternal != null, "The Owner Calendar's DisplayDateInternal should not be null!");
childButton.IsSelected = (DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateInternal) == 0); childButton.IsSelected = (DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateInternal) == 0);
if (DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateRangeStart) < 0 || DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateRangeEnd) > 0) if (DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateRangeStart) < 0 || DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateRangeEnd) > 0)
@ -685,7 +675,6 @@ namespace Avalonia.Controls.Primitives
if (Owner != null) if (Owner != null)
{ {
Debug.Assert(Owner.SelectedYear != null, "The owning Calendar's selected year should not be null!");
selectedYear = Owner.SelectedYear; selectedYear = Owner.SelectedYear;
_currentMonth = (DateTime)Owner.SelectedMonth; _currentMonth = (DateTime)Owner.SelectedMonth;
} }
@ -695,19 +684,16 @@ namespace Avalonia.Controls.Primitives
selectedYear = DateTime.Today; selectedYear = DateTime.Today;
} }
if (_currentMonth != null) int decade = DateTimeHelper.DecadeOfDate(selectedYear);
{ int decadeEnd = DateTimeHelper.EndOfDecade(selectedYear);
int decade = DateTimeHelper.DecadeOfDate(selectedYear);
int decadeEnd = DateTimeHelper.EndOfDecade(selectedYear);
SetDecadeModeHeaderButton(decade, decadeEnd); SetDecadeModeHeaderButton(decade, decadeEnd);
SetDecadeModePreviousButton(decade); SetDecadeModePreviousButton(decade);
SetDecadeModeNextButton(decadeEnd); SetDecadeModeNextButton(decadeEnd);
if (YearView != null) if (YearView != null)
{ {
SetYearButtons(decade, decadeEnd); SetYearButtons(decade, decadeEnd);
}
} }
} }
internal void UpdateYearViewSelection(CalendarButton calendarButton) internal void UpdateYearViewSelection(CalendarButton calendarButton)
@ -822,22 +808,15 @@ namespace Avalonia.Controls.Primitives
{ {
if (Owner.DisplayMode == CalendarMode.Month) if (Owner.DisplayMode == CalendarMode.Month)
{ {
if (Owner.DisplayDate != null) d = Owner.DisplayDateInternal;
{ Owner.SelectedMonth = new DateTime(d.Year, d.Month, 1);
d = Owner.DisplayDateInternal;
Owner.SelectedMonth = new DateTime(d.Year, d.Month, 1);
}
Owner.DisplayMode = CalendarMode.Year; Owner.DisplayMode = CalendarMode.Year;
} }
else else
{ {
Debug.Assert(Owner.DisplayMode == CalendarMode.Year, "The Owner Calendar's DisplayMode should be Year!"); Debug.Assert(Owner.DisplayMode == CalendarMode.Year, "The Owner Calendar's DisplayMode should be Year!");
d = Owner.SelectedMonth;
if (Owner.SelectedMonth != null) Owner.SelectedYear = new DateTime(d.Year, d.Month, 1);
{
d = Owner.SelectedMonth;
Owner.SelectedYear = new DateTime(d.Year, d.Month, 1);
}
Owner.DisplayMode = CalendarMode.Decade; Owner.DisplayMode = CalendarMode.Decade;
} }
} }

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

@ -297,7 +297,7 @@ namespace Avalonia.Controls.Primitives
} }
else else
{ {
if (item != null && DateTime.Compare(this[index], item) != 0 && Calendar.IsValidDateSelection(_owner, item)) if (DateTime.Compare(this[index], item) != 0 && Calendar.IsValidDateSelection(_owner, item))
{ {
removedItems.Add(this[index]); removedItems.Add(this[index]);
base.SetItem(index, item); base.SetItem(index, item);

Loading…
Cancel
Save