|
@@ -19,12 +19,16 @@ namespace Avalonia.Controls
|
|
|
[TemplatePart("PART_MinuteDownButton", typeof(RepeatButton))]
|
|
|
[TemplatePart("PART_MinuteSelector", typeof(DateTimePickerPanel), IsRequired = true)]
|
|
|
[TemplatePart("PART_MinuteUpButton", typeof(RepeatButton))]
|
|
|
+ [TemplatePart("PART_SecondDownButton", typeof(RepeatButton))]
|
|
|
+ [TemplatePart("PART_SecondHost", typeof(Panel), IsRequired = true)]
|
|
|
+ [TemplatePart("PART_SecondSelector", typeof(DateTimePickerPanel), IsRequired = true)]
|
|
|
+ [TemplatePart("PART_SecondUpButton", typeof(RepeatButton))]
|
|
|
[TemplatePart("PART_PeriodDownButton", typeof(RepeatButton))]
|
|
|
[TemplatePart("PART_PeriodHost", typeof(Panel), IsRequired = true)]
|
|
|
[TemplatePart("PART_PeriodSelector", typeof(DateTimePickerPanel), IsRequired = true)]
|
|
|
[TemplatePart("PART_PeriodUpButton", typeof(RepeatButton))]
|
|
|
[TemplatePart("PART_PickerContainer", typeof(Grid), IsRequired = true)]
|
|
|
- [TemplatePart("PART_SecondSpacer", typeof(Rectangle), IsRequired = true)]
|
|
|
+ [TemplatePart("PART_ThirdSpacer", typeof(Rectangle), IsRequired = true)]
|
|
|
public class TimePickerPresenter : PickerPresenterBase
|
|
|
{
|
|
|
/// <summary>
|
|
@@ -32,12 +36,24 @@ namespace Avalonia.Controls
|
|
|
/// </summary>
|
|
|
public static readonly StyledProperty<int> MinuteIncrementProperty =
|
|
|
TimePicker.MinuteIncrementProperty.AddOwner<TimePickerPresenter>();
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Defines the <see cref="SecondIncrement"/> property
|
|
|
+ /// </summary>
|
|
|
+ public static readonly StyledProperty<int> SecondIncrementProperty =
|
|
|
+ TimePicker.SecondIncrementProperty.AddOwner<TimePickerPresenter>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// Defines the <see cref="ClockIdentifier"/> property
|
|
|
/// </summary>
|
|
|
public static readonly StyledProperty<string> ClockIdentifierProperty =
|
|
|
TimePicker.ClockIdentifierProperty.AddOwner<TimePickerPresenter>();
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Defines the <see cref="UseSeconds"/> property
|
|
|
+ /// </summary>
|
|
|
+ public static readonly StyledProperty<bool> UseSecondsProperty =
|
|
|
+ TimePicker.UseSecondsProperty.AddOwner<TimePickerPresenter>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// Defines the <see cref="Time"/> property
|
|
@@ -60,15 +76,20 @@ namespace Avalonia.Controls
|
|
|
private Button? _acceptButton;
|
|
|
private Button? _dismissButton;
|
|
|
private Rectangle? _spacer2;
|
|
|
+ private Rectangle? _spacer3;
|
|
|
+ private Panel? _secondHost;
|
|
|
private Panel? _periodHost;
|
|
|
private DateTimePickerPanel? _hourSelector;
|
|
|
private DateTimePickerPanel? _minuteSelector;
|
|
|
+ private DateTimePickerPanel? _secondSelector;
|
|
|
private DateTimePickerPanel? _periodSelector;
|
|
|
private Button? _hourUpButton;
|
|
|
private Button? _minuteUpButton;
|
|
|
+ private Button? _secondUpButton;
|
|
|
private Button? _periodUpButton;
|
|
|
private Button? _hourDownButton;
|
|
|
private Button? _minuteDownButton;
|
|
|
+ private Button? _secondDownButton;
|
|
|
private Button? _periodDownButton;
|
|
|
|
|
|
/// <summary>
|
|
@@ -79,6 +100,15 @@ namespace Avalonia.Controls
|
|
|
get => GetValue(MinuteIncrementProperty);
|
|
|
set => SetValue(MinuteIncrementProperty, value);
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Gets or sets the second increment in the selector
|
|
|
+ /// </summary>
|
|
|
+ public int SecondIncrement
|
|
|
+ {
|
|
|
+ get => GetValue(SecondIncrementProperty);
|
|
|
+ set => SetValue(SecondIncrementProperty, value);
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets or sets the current clock identifier, either 12HourClock or 24HourClock
|
|
@@ -88,6 +118,15 @@ namespace Avalonia.Controls
|
|
|
get => GetValue(ClockIdentifierProperty);
|
|
|
set => SetValue(ClockIdentifierProperty, value);
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Gets or sets the current clock identifier, either 12HourClock or 24HourClock
|
|
|
+ /// </summary>
|
|
|
+ public bool UseSeconds
|
|
|
+ {
|
|
|
+ get => GetValue(UseSecondsProperty);
|
|
|
+ set => SetValue(UseSecondsProperty, value);
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets or sets the current time
|
|
@@ -104,12 +143,15 @@ namespace Avalonia.Controls
|
|
|
|
|
|
_pickerContainer = e.NameScope.Get<Grid>("PART_PickerContainer");
|
|
|
_periodHost = e.NameScope.Get<Panel>("PART_PeriodHost");
|
|
|
+ _secondHost = e.NameScope.Get<Panel>("PART_SecondHost");
|
|
|
|
|
|
_hourSelector = e.NameScope.Get<DateTimePickerPanel>("PART_HourSelector");
|
|
|
_minuteSelector = e.NameScope.Get<DateTimePickerPanel>("PART_MinuteSelector");
|
|
|
+ _secondSelector = e.NameScope.Get<DateTimePickerPanel>("PART_SecondSelector");
|
|
|
_periodSelector = e.NameScope.Get<DateTimePickerPanel>("PART_PeriodSelector");
|
|
|
-
|
|
|
+
|
|
|
_spacer2 = e.NameScope.Get<Rectangle>("PART_SecondSpacer");
|
|
|
+ _spacer3 = e.NameScope.Get<Rectangle>("PART_ThirdSpacer");
|
|
|
|
|
|
_acceptButton = e.NameScope.Get<Button>("PART_AcceptButton");
|
|
|
_acceptButton.Click += OnAcceptButtonClicked;
|
|
@@ -127,6 +169,13 @@ namespace Avalonia.Controls
|
|
|
_minuteDownButton = e.NameScope.Find<RepeatButton>("PART_MinuteDownButton");
|
|
|
if (_minuteDownButton != null)
|
|
|
_minuteDownButton.Click += OnSelectorButtonClick;
|
|
|
+
|
|
|
+ _secondUpButton = e.NameScope.Find<RepeatButton>("PART_SecondUpButton");
|
|
|
+ if (_secondUpButton != null)
|
|
|
+ _secondUpButton.Click += OnSelectorButtonClick;
|
|
|
+ _secondDownButton = e.NameScope.Find<RepeatButton>("PART_SecondDownButton");
|
|
|
+ if (_secondDownButton != null)
|
|
|
+ _secondDownButton.Click += OnSelectorButtonClick;
|
|
|
|
|
|
_periodUpButton = e.NameScope.Find<RepeatButton>("PART_PeriodUpButton");
|
|
|
if (_periodUpButton != null)
|
|
@@ -146,7 +195,11 @@ namespace Avalonia.Controls
|
|
|
{
|
|
|
base.OnPropertyChanged(change);
|
|
|
|
|
|
- if (change.Property == MinuteIncrementProperty || change.Property == ClockIdentifierProperty || change.Property == TimeProperty)
|
|
|
+ if (change.Property == MinuteIncrementProperty ||
|
|
|
+ change.Property == SecondIncrementProperty ||
|
|
|
+ change.Property == ClockIdentifierProperty ||
|
|
|
+ change.Property == UseSecondsProperty ||
|
|
|
+ change.Property == TimeProperty)
|
|
|
{
|
|
|
InitPicker();
|
|
|
}
|
|
@@ -180,6 +233,7 @@ namespace Avalonia.Controls
|
|
|
{
|
|
|
var hr = _hourSelector!.SelectedValue;
|
|
|
var min = _minuteSelector!.SelectedValue;
|
|
|
+ var sec = _secondSelector!.SelectedValue;
|
|
|
var per = _periodSelector!.SelectedValue;
|
|
|
|
|
|
if (ClockIdentifier == "12HourClock")
|
|
@@ -187,7 +241,7 @@ namespace Avalonia.Controls
|
|
|
hr = per == 1 ? (hr == 12) ? 12 : hr + 12 : per == 0 && hr == 12 ? 0 : hr;
|
|
|
}
|
|
|
|
|
|
- SetCurrentValue(TimeProperty, new TimeSpan(hr, min, 0));
|
|
|
+ SetCurrentValue(TimeProperty, new TimeSpan(hr, min, sec));
|
|
|
|
|
|
base.OnConfirmed();
|
|
|
}
|
|
@@ -210,6 +264,12 @@ namespace Avalonia.Controls
|
|
|
_minuteSelector.Increment = MinuteIncrement;
|
|
|
_minuteSelector.SelectedValue = Time.Minutes;
|
|
|
_minuteSelector.ItemFormat = "mm";
|
|
|
+
|
|
|
+ _secondSelector!.MaximumValue = 59;
|
|
|
+ _secondSelector.MinimumValue = 0;
|
|
|
+ _secondSelector.Increment = SecondIncrement;
|
|
|
+ _secondSelector.SelectedValue = Time.Seconds;
|
|
|
+ _secondSelector.ItemFormat = "ss";
|
|
|
|
|
|
_periodSelector!.MaximumValue = 1;
|
|
|
_periodSelector.MinimumValue = 0;
|
|
@@ -223,14 +283,24 @@ namespace Avalonia.Controls
|
|
|
{
|
|
|
bool use24HourClock = ClockIdentifier == "24HourClock";
|
|
|
|
|
|
- var columnsD = use24HourClock ? "*, Auto, *" : "*, Auto, *, Auto, *";
|
|
|
+ var columnsD = "*, Auto, *";
|
|
|
+ if (UseSeconds) columnsD += ", Auto *";
|
|
|
+ if (!use24HourClock) columnsD += ", Auto *";
|
|
|
+
|
|
|
_pickerContainer!.ColumnDefinitions = new ColumnDefinitions(columnsD);
|
|
|
|
|
|
- _spacer2!.IsVisible = !use24HourClock;
|
|
|
- _periodHost!.IsVisible = !use24HourClock;
|
|
|
+ _spacer2!.IsVisible = UseSeconds;
|
|
|
+ _secondHost!.IsVisible = UseSeconds;
|
|
|
|
|
|
- Grid.SetColumn(_spacer2, use24HourClock ? 0 : 3);
|
|
|
- Grid.SetColumn(_periodHost, use24HourClock ? 0 : 4);
|
|
|
+ _spacer3!.IsVisible = !use24HourClock;
|
|
|
+ _periodHost!.IsVisible = !use24HourClock;
|
|
|
+
|
|
|
+ var amPmColumn = (UseSeconds) ? 6 : 4;
|
|
|
+
|
|
|
+ Grid.SetColumn(_spacer2, UseSeconds ? 3 : 0);
|
|
|
+ Grid.SetColumn(_secondHost, UseSeconds ? 4 : 0);
|
|
|
+ Grid.SetColumn(_spacer3, use24HourClock ? 0 : amPmColumn-1);
|
|
|
+ Grid.SetColumn(_periodHost, use24HourClock ? 0 : amPmColumn);
|
|
|
}
|
|
|
|
|
|
private void OnDismissButtonClicked(object? sender, RoutedEventArgs e)
|
|
@@ -253,6 +323,10 @@ namespace Avalonia.Controls
|
|
|
_minuteSelector!.ScrollUp();
|
|
|
else if (sender == _minuteDownButton)
|
|
|
_minuteSelector!.ScrollDown();
|
|
|
+ else if (sender == _secondUpButton)
|
|
|
+ _secondSelector!.ScrollUp();
|
|
|
+ else if (sender == _secondDownButton)
|
|
|
+ _secondSelector!.ScrollDown();
|
|
|
else if (sender == _periodUpButton)
|
|
|
_periodSelector!.ScrollUp();
|
|
|
else if (sender == _periodDownButton)
|