Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominique Louis <dominique@cnlilyzhou.fareast.corp.microsoft.com>2019-02-12 20:15:30 +0300
committerDominique Louis <dominique@cnlilyzhou.fareast.corp.microsoft.com>2019-02-12 20:15:30 +0300
commit76ec52eb7768db3de80ee05951670b717bec3d5b (patch)
tree407dbe72f385abe8501f1ac2963d5d0d7fc48ddc
parentdbb0df8f4aec9363a0efeb7b2c1a873776174c70 (diff)
Use NSDataPicker. Remove CustomnDatePicker.dominique-UseNativeNSDataPicker
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/CustomDatePicker.cs101
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs50
-rw-r--r--Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj1
3 files changed, 24 insertions, 128 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CustomDatePicker.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CustomDatePicker.cs
deleted file mode 100644
index 284ed2f..0000000
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/CustomDatePicker.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-using System;
-using AppKit;
-using CoreGraphics;
-
-namespace Xamarin.PropertyEditing.Mac
-{
- internal class CustomDatePicker : NSView
- {
- public event EventHandler Activated;
-
- private const int stepperSpace = 2;
- private const int stepperWidth = 11;
- private const int stepperLeftSeparation = -10;
-
- private const int stepperTopHeight = 9;
- private const int stepperBotHeight = 10;
-
- private NSDatePicker datePicker;
- public NSDatePicker DatePicker => this.datePicker;
-
- private readonly SpinnerButton incrementButton;
- private readonly SpinnerButton decrementButton;
-
- private readonly IHostResourceProvider hostResources;
-
- public DateTime DateTime
- {
- get => this.datePicker.DateValue.ToDateTime ();
- set => this.datePicker.DateValue = value.ToNSDate ();
- }
-
- public NSFont Font
- {
- get => this.datePicker.Font;
- set => this.datePicker.Font = value;
- }
-
- public bool Enabled
- {
- get => this.datePicker.Enabled;
- set
- {
- this.datePicker.Enabled = value;
- this.incrementButton.Enabled = value;
- this.decrementButton.Enabled = value;
- }
- }
-
- public CustomDatePicker (IHostResourceProvider hostResources)
- {
- this.hostResources = hostResources;
- TranslatesAutoresizingMaskIntoConstraints = false;
-
- this.datePicker = new NSDatePicker {
- DatePickerStyle = NSDatePickerStyle.TextFieldAndStepper,
- ControlSize = NSControlSize.Mini,
- DatePickerElements = NSDatePickerElementFlags.HourMinuteSecond | NSDatePickerElementFlags.YearMonthDateDay,
- TranslatesAutoresizingMaskIntoConstraints = false
- };
-
- //HACK: DatePicker doesn't allow modify the current spinners of the control
- //to fix this we overlap our current spinners leaving the current functionality of the native control
- this.incrementButton = new SpinnerButton (this.hostResources, isUp: true) {
- TranslatesAutoresizingMaskIntoConstraints = false,
- AcceptsUserInteraction = false
- };
- this.decrementButton = new SpinnerButton (this.hostResources, isUp: false) {
- TranslatesAutoresizingMaskIntoConstraints = false,
- AcceptsUserInteraction = false
- };
-
- this.datePicker.Activated += NumericEditor_Activated;
-
- AddSubview (this.datePicker);
- AddSubview (this.incrementButton);
- AddSubview (this.decrementButton);
-
- AddConstraints (new[] {
- NSLayoutConstraint.Create (this.datePicker, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight - 3),
-
- NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.datePicker, NSLayoutAttribute.Top, 1f, 0f),
- NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.datePicker, NSLayoutAttribute.Right, 1f, stepperLeftSeparation),
- NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, stepperWidth),
- NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, stepperTopHeight),
-
- NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.datePicker, NSLayoutAttribute.Top, 1f, stepperTopHeight),
- NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.datePicker, NSLayoutAttribute.Right, 1f, stepperLeftSeparation),
- NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, stepperWidth),
- NSLayoutConstraint.Create (this.decrementButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, stepperBotHeight),
- });
- }
-
- private void NumericEditor_Activated (object sender, EventArgs e) => Activated?.Invoke (this, EventArgs.Empty);
-
- protected override void Dispose (bool disposing)
- {
- this.datePicker.Activated -= NumericEditor_Activated;
- base.Dispose (disposing);
- }
- }
-}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs
index 6b33414..3e59ee0 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections;
using AppKit;
using CoreGraphics;
@@ -9,43 +9,41 @@ using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
internal class DateTimeEditorControl : PropertyEditorControl<PropertyViewModel<DateTime>>
- {
- private const int HeightMargin = 1;
- private readonly CustomDatePicker editor;
+ {
+ private readonly NSDatePicker datePicker;
public DateTimeEditorControl (IHostResourceProvider hostResources)
- : base (hostResources)
- {
- this.editor = new CustomDatePicker (hostResources) {
+ : base (hostResources)
+ {
+ this.datePicker = new NSDatePicker {
+ ControlSize = NSControlSize.Small,
+ DatePickerElements = NSDatePickerElementFlags.HourMinuteSecond | NSDatePickerElementFlags.YearMonthDateDay,
+ DatePickerStyle = NSDatePickerStyle.TextFieldAndStepper,
Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize),
- };
+ TranslatesAutoresizingMaskIntoConstraints = false
+ };
// update the value on keypress
- this.editor.Activated += Editor_Activated;
+ this.datePicker.Activated += Editor_Activated;
- AddSubview (this.editor);
+ AddSubview (this.datePicker);
AddConstraints (new[] {
- NSLayoutConstraint.Create (this.editor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f),
- NSLayoutConstraint.Create (this.editor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0),
- NSLayoutConstraint.Create (this.editor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 140),
- NSLayoutConstraint.Create (this.editor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 20),
+ NSLayoutConstraint.Create (this.datePicker, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f),
+ NSLayoutConstraint.Create (this.datePicker, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 1f),
+ NSLayoutConstraint.Create (this.datePicker, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -34f),
+ NSLayoutConstraint.Create (this.datePicker, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 20),
});
}
- private void Editor_Activated (object sender, EventArgs e) => ViewModel.Value = this.editor.DateTime;
-
- public override NSView FirstKeyView => this.editor.DatePicker;
- public override NSView LastKeyView => this.editor.DatePicker;
+ private void Editor_Activated (object sender, EventArgs e) => ViewModel.Value = this.datePicker.DateValue.ToDateTime ();
- public override nint GetHeight (EditorViewModel vm)
- {
- return DefaultControlHeight - HeightMargin;
- }
+ public override NSView FirstKeyView => this.datePicker;
+ public override NSView LastKeyView => this.datePicker;
protected override void UpdateValue ()
{
- this.editor.DateTime = ViewModel.Value;
+ this.datePicker.DateValue = ViewModel.Value.ToNSDate ();
}
protected override void HandleErrorsChanged (object sender, System.ComponentModel.DataErrorsChangedEventArgs e)
@@ -65,17 +63,17 @@ namespace Xamarin.PropertyEditing.Mac
protected override void SetEnabled ()
{
- this.editor.Enabled = ViewModel.Property.CanWrite;
+ this.datePicker.Enabled = ViewModel.Property.CanWrite;
}
protected override void UpdateAccessibilityValues ()
{
- this.editor.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityDateTime, ViewModel.Property.Name);
+ this.datePicker.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityDateTime, ViewModel.Property.Name);
}
protected override void Dispose (bool disposing)
{
- this.editor.Activated -= Editor_Activated;
+ this.datePicker.Activated -= Editor_Activated;
base.Dispose (disposing);
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj
index 431398f..6c8d9c6 100644
--- a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj
+++ b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj
@@ -147,7 +147,6 @@
<Compile Include="Controls\Custom\FocusableComboBox.cs" />
<Compile Include="Controls\DateTimeEditorControl.cs" />
<Compile Include="Controls\DateExtensions.cs" />
- <Compile Include="Controls\Custom\CustomDatePicker.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controls\" />