From a4b2cb39a58f574a6d9e8a0cc7531e0d27d10dff Mon Sep 17 00:00:00 2001 From: Dominique Louis Date: Mon, 10 Dec 2018 13:32:54 +0000 Subject: [Mac] Initial InputMode implementation. --- .../Controls/BrushEditorControl.cs | 5 +- .../Controls/Custom/NumericSpinEditor.cs | 159 ++++++++++----------- .../Controls/Custom/RatioEditor.cs | 6 +- .../Controls/NumericEditorControl.cs | 87 +++++++++-- .../Controls/StringEditorControl.cs | 91 ++++++++++-- 5 files changed, 232 insertions(+), 116 deletions(-) (limited to 'Xamarin.PropertyEditing.Mac/Controls') diff --git a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs index c2f50b7..91cc77e 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs @@ -61,9 +61,8 @@ namespace Xamarin.PropertyEditing.Mac }; this.popUpButton = new ColorPopUpButton { - TranslatesAutoresizingMaskIntoConstraints = false, - ControlSize = NSControlSize.Small, Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize), + TranslatesAutoresizingMaskIntoConstraints = false, }; this.popupButtonList = new NSMenu (); @@ -74,7 +73,7 @@ namespace Xamarin.PropertyEditing.Mac this.AddConstraints (new[] { NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0f), NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -33f), - NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight + 1), + NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3), }); UpdateTheme (); diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs index f1c3c7c..a3c68fd 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs @@ -17,20 +17,21 @@ namespace Xamarin.PropertyEditing.Mac const int stepperWidth = 11; const int stepperTopHeight = 9; const int stepperBotHeight = 10; + const int inputModeWidth = 60; - NumericTextField numericEditor; + private NumericTextField numericEditor; public NumericTextField NumericEditor { - get { return numericEditor; } + get { return this.numericEditor; } } - UpSpinnerButton incrementButton; + private UpSpinnerButton incrementButton; public UpSpinnerButton IncrementButton { - get { return incrementButton; } + get { return this.incrementButton; } } - DownSpinnerButton decrementButton; + private DownSpinnerButton decrementButton; public DownSpinnerButton DecrementButton { - get { return decrementButton; } + get { return this.decrementButton; } } protected bool editing; @@ -47,124 +48,118 @@ namespace Xamarin.PropertyEditing.Mac } public string PlaceholderString { - get { return ((NSTextFieldCell)numericEditor.Cell).PlaceholderString; } - set { ((NSTextFieldCell)numericEditor.Cell).PlaceholderString = value; } + get { return ((NSTextFieldCell)this.numericEditor.Cell).PlaceholderString; } + set { ((NSTextFieldCell)this.numericEditor.Cell).PlaceholderString = value; } } public override CGSize IntrinsicContentSize { get { - var baseSize = numericEditor.IntrinsicContentSize; + var baseSize = this.numericEditor.IntrinsicContentSize; return new CGSize (baseSize.Width + 20, baseSize.Height); } } public NSColor BackgroundColor { - get { return numericEditor.BackgroundColor; } - set { numericEditor.BackgroundColor = value; } + get { return this.numericEditor.BackgroundColor; } + set { this.numericEditor.BackgroundColor = value; } } public override nfloat BaselineOffsetFromBottom { - get { return numericEditor.BaselineOffsetFromBottom; } + get { return this.numericEditor.BaselineOffsetFromBottom; } } public int Digits { - get { return (int)formatter.MaximumFractionDigits; } - set { formatter.MaximumFractionDigits = value; } + get { return (int)this.formatter.MaximumFractionDigits; } + set { this.formatter.MaximumFractionDigits = value; } } public double Value { - get { return numericEditor.DoubleValue; } + get { return this.numericEditor.DoubleValue; } set { SetValue (value); } } public string StringValue { - get { return numericEditor.StringValue; } + get { return this.numericEditor.StringValue; } set { SetValue (value); } } public double MinimumValue { - get { return formatter.Minimum.DoubleValue; } - set { - formatter.Minimum = new NSNumber (value); - } + get { return this.formatter.Minimum.DoubleValue; } + set { this.formatter.Minimum = new NSNumber (value); } } public double MaximumValue { - get { return formatter.Maximum.DoubleValue; } - set { - formatter.Maximum = new NSNumber (value); - } + get { return this.formatter.Maximum.DoubleValue; } + set { this.formatter.Maximum = new NSNumber (value); } } - double incrementValue = 1.0f; + private double incrementValue = 1.0f; public double IncrementValue { - get { return incrementValue; } - set { incrementValue = value; } + get { return this.incrementValue; } + set { this.incrementValue = value; } } public string FocusedFormat { - get { return numericEditor?.FocusedFormat; } - set { numericEditor.FocusedFormat = value; } + get { return this.numericEditor?.FocusedFormat; } + set { this.numericEditor.FocusedFormat = value; } } public string DisplayFormat { - get { return numericEditor?.DisplayFormat; } - set { numericEditor.DisplayFormat = value; } + get { return this.numericEditor?.DisplayFormat; } + set { this.numericEditor.DisplayFormat = value; } } public bool Enabled { - get { return numericEditor.Enabled; } + get { return this.numericEditor.Enabled; } set { - numericEditor.Enabled = value; - incrementButton.Enabled = value; - decrementButton.Enabled = value; + this.numericEditor.Enabled = value; + this.incrementButton.Enabled = value; + this.decrementButton.Enabled = value; } } - NSNumberFormatter formatter; + private NSNumberFormatter formatter; public NSNumberFormatter Formatter { - get { return formatter; } + get { return this.formatter; } set { - formatter = value; - numericEditor.Formatter = formatter; + this.formatter = value; + this.numericEditor.Formatter = this.formatter; } } public bool IsIndeterminate { - get { return !string.IsNullOrEmpty (numericEditor.StringValue); } + get { return !string.IsNullOrEmpty (this.numericEditor.StringValue); } set { if (value) - numericEditor.StringValue = string.Empty; + this.numericEditor.StringValue = string.Empty; } } public bool Editable { - get { return numericEditor.Editable; } + get { return this.numericEditor.Editable; } set { - numericEditor.Editable = value; - incrementButton.Enabled = value; - decrementButton.Enabled = value; + this.numericEditor.Editable = value; + this.incrementButton.Enabled = value; + this.decrementButton.Enabled = value; } } public NSNumberFormatterStyle NumberStyle { - get { return formatter.NumberStyle; } - set { formatter.NumberStyle = value; } + get { return this.formatter.NumberStyle; } + set { this.formatter.NumberStyle = value; } } - public bool AllowRatios - { - get { return numericEditor.AllowRatios; } - set { numericEditor.AllowRatios = value; } + public bool AllowRatios { + get { return this.numericEditor.AllowRatios; } + set { this.numericEditor.AllowRatios = value; } } - public bool AllowNegativeValues - { - get { return numericEditor.AllowNegativeValues; } - set { numericEditor.AllowNegativeValues = value; } + public bool AllowNegativeValues { + get { return this.numericEditor.AllowNegativeValues; } + set { this.numericEditor.AllowNegativeValues = value; } } public virtual void Reset () @@ -184,7 +179,7 @@ namespace Xamarin.PropertyEditing.Mac TranslatesAutoresizingMaskIntoConstraints = false }; - formatter = new NSNumberFormatter { + this.formatter = new NSNumberFormatter { FormatterBehavior = NSNumberFormatterBehavior.Version_10_4, Locale = NSLocale.CurrentLocale, MaximumFractionDigits = 15, @@ -193,30 +188,30 @@ namespace Xamarin.PropertyEditing.Mac NumberStyle = NSNumberFormatterStyle.Decimal, UsesGroupingSeparator = false }; - if (DisplayFormat != null) formatter.PositiveFormat = DisplayFormat; + if (DisplayFormat != null) this.formatter.PositiveFormat = DisplayFormat; - numericEditor = new NumericTextField { + this.numericEditor = new NumericTextField { Alignment = NSTextAlignment.Right, TranslatesAutoresizingMaskIntoConstraints = false, Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize), ControlSize = controlSize, - Formatter = formatter + Formatter = this.formatter }; - incrementButton.OnMouseLeftDown += (sender, e) => { IncrementNumericValue (); }; - decrementButton.OnMouseLeftDown += (sender, e) => { DecrementNumericValue (); }; + this.incrementButton.OnMouseLeftDown += (sender, e) => { IncrementNumericValue (); }; + this.decrementButton.OnMouseLeftDown += (sender, e) => { DecrementNumericValue (); }; - numericEditor.KeyArrowUp += (sender, e) => { IncrementNumericValue (e); }; - numericEditor.KeyArrowDown += (sender, e) => { DecrementNumericValue (e); }; + this.numericEditor.KeyArrowUp += (sender, e) => { IncrementNumericValue (e); }; + this.numericEditor.KeyArrowDown += (sender, e) => { DecrementNumericValue (e); }; - numericEditor.ValidatedEditingEnded += OnEditingEnded; + this.numericEditor.ValidatedEditingEnded += OnEditingEnded; - AddSubview (numericEditor); - AddSubview (incrementButton); - AddSubview (decrementButton); + AddSubview (this.numericEditor); + AddSubview (this.incrementButton); + AddSubview (this.decrementButton); this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.numericEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -(stepperWidth + stepperSpace + 1)), + NSLayoutConstraint.Create (this.numericEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -(stepperWidth + stepperSpace + 1)), NSLayoutConstraint.Create (this.numericEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight - 3), NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.numericEditor, NSLayoutAttribute.Top, 1f, 0f), @@ -249,24 +244,24 @@ namespace Xamarin.PropertyEditing.Mac protected void UpdateTheme () { - this.Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance; + Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance; } virtual protected void OnEditingEnded (object sender, EventArgs e) { - if (!editing) { - editing = true; + if (!this.editing) { + this.editing = true; SetValue (numericEditor.StringValue); EditingEnded?.Invoke (this, EventArgs.Empty); NotifyingValueChanged (EventArgs.Empty); - editing = false; + this.editing = false; } } void SetValue (string value) { - if (numericEditor.StringValue != value) { - numericEditor.StringValue = value; + if (this.numericEditor.StringValue != value) { + this.numericEditor.StringValue = value; } } @@ -282,26 +277,26 @@ namespace Xamarin.PropertyEditing.Mac public void IncrementNumericValue (bool shiftPressed = false) { - if (!editing) { - editing = true; - SetIncrementOrDecrementValue (shiftPressed ? 10 * incrementValue : incrementValue); - editing = false; + if (!this.editing) { + this.editing = true; + SetIncrementOrDecrementValue (shiftPressed ? 10 * this.incrementValue : this.incrementValue); + this.editing = false; } } public void DecrementNumericValue (bool shiftPressed = false) { if (!editing) { - editing = true; - SetIncrementOrDecrementValue (-(shiftPressed ? 10 * incrementValue : incrementValue)); - editing = false; + this.editing = true; + SetIncrementOrDecrementValue (-(shiftPressed ? 10 * this.incrementValue : this.incrementValue)); + this.editing = false; } } virtual protected void SetIncrementOrDecrementValue (double incDevValue) { // Constrain our value to our Min/Max before we set it - var newValue = Clamp (numericEditor.DoubleValue + incDevValue); + var newValue = Clamp (this.numericEditor.DoubleValue + incDevValue); SetValue (newValue); NotifyingValueChanged (EventArgs.Empty); diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/RatioEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/RatioEditor.cs index 507eee3..8ba4df5 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/RatioEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/RatioEditor.cs @@ -21,10 +21,10 @@ namespace Xamarin.PropertyEditing.Mac protected override void OnEditingEnded (object sender, EventArgs e) { - if (!editing) { - editing = true; + if (!this.editing) { + this.editing = true; NotifyingValueChanged (new RatioEventArgs (0, 0, 0)); - editing = false; + this.editing = false; } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs index 84a5206..ee6e826 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs @@ -1,5 +1,7 @@ using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; using AppKit; using Foundation; using Xamarin.PropertyEditing.Mac.Resources; @@ -19,8 +21,8 @@ namespace Xamarin.PropertyEditing.Mac var t = typeof (T); if (t.Name == PropertyViewModel.NullableName) { - underlyingType = Nullable.GetUnderlyingType (t); - t = underlyingType; + this.underlyingType = Nullable.GetUnderlyingType (t); + t = this.underlyingType; } TypeCode code = Type.GetTypeCode (t); switch (code) { @@ -38,25 +40,23 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (NumericEditor); + this.numericEditorWidthConstraint = NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -32f); + this.AddConstraints (new[] { NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), - NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -32f), + this.numericEditorWidthConstraint, }); } protected NumericSpinEditor NumericEditor { get; set; } protected NSNumberFormatter Formatter { - get { - return NumericEditor.Formatter; - } - set { - NumericEditor.Formatter = value; - } + get { return NumericEditor.Formatter; } + set { NumericEditor.Formatter = value; } } public override NSView FirstKeyView => NumericEditor; - public override NSView LastKeyView => NumericEditor.DecrementButton; + public override NSView LastKeyView => NumericEditor; protected NSNumberFormatterStyle NumberStyle { get { @@ -68,6 +68,11 @@ namespace Xamarin.PropertyEditing.Mac private Type underlyingType; + internal NSPopUpButton inputModePopup; + private IReadOnlyList viewModelInputModes; + + private NSLayoutConstraint numericEditorWidthConstraint; + protected override void UpdateErrorsDisplayed (IEnumerable errors) { if (ViewModel.HasErrors) { @@ -86,22 +91,31 @@ namespace Xamarin.PropertyEditing.Mac protected override void SetEnabled () { NumericEditor.Editable = ViewModel.Property.CanWrite; + if (this.inputModePopup != null) + this.inputModePopup.Enabled = ViewModel.Property.CanWrite; } protected virtual void OnValueChanged (object sender, EventArgs e) { var t = typeof (T); - if (underlyingType != null) - t = underlyingType; + if (this.underlyingType != null) + t = this.underlyingType; ViewModel.Value = (T)Convert.ChangeType (NumericEditor.Value, t); } protected override void UpdateValue() { - if (underlyingType != null) { + if (this.underlyingType != null) { NumericEditor.StringValue = ViewModel.Value == null ? string.Empty : ViewModel.Value.ToString (); + NumericEditor.Enabled = ((ViewModel.InputMode != null) && !ViewModel.InputMode.IsSingleValue) || (this.inputModePopup == null); + + if (this.inputModePopup != null) + this.inputModePopup.SelectItem ((ViewModel.InputMode == null) ? string.Empty : ViewModel.InputMode.Identifier); } else { NumericEditor.Value = (double)Convert.ChangeType (ViewModel.Value, typeof (double)); + + if (this.inputModePopup != null) + this.inputModePopup.SelectItem (-1); } } @@ -109,6 +123,53 @@ namespace Xamarin.PropertyEditing.Mac { NumericEditor.AccessibilityEnabled = NumericEditor.Enabled; NumericEditor.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityNumeric, ViewModel.Property.Name); + + if (this.inputModePopup != null) { + this.inputModePopup.AccessibilityEnabled = NumericEditor.Enabled; + this.inputModePopup.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityInpueModeEditor, ViewModel.Property.Name); + } + } + + protected override void OnViewModelChanged (PropertyViewModel oldModel) + { + if (ViewModel.HasInputModes) { + if (this.inputModePopup == null) { + this.inputModePopup = new NSPopUpButton { + Menu = new NSMenu (), + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + this.inputModePopup.Activated += (o, e) => { + var popupButton = o as NSPopUpButton; + ViewModel.InputMode = this.viewModelInputModes.FirstOrDefault (im => im.Identifier == popupButton.Title); + }; + + AddSubview (this.inputModePopup); + + this.AddConstraints (new[] { + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -33f), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 80f), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3 ), + }); + } + + this.inputModePopup.Menu.RemoveAllItems (); + this.viewModelInputModes = ViewModel.InputModes; + foreach (InputMode item in this.viewModelInputModes) { + this.inputModePopup.Menu.AddItem (new NSMenuItem (item.Identifier)); + } + + this.numericEditorWidthConstraint.Constant = -117f; // Shorten the stringEditor if we have Inputmodes Showing. + } else { + this.numericEditorWidthConstraint.Constant = -34f; // Lengthen the stringEditor if we have Inputmodes Hidden. + } + + // If we are reusing the control we'll have to hid the inputMode if this doesn't have InputMode. + if (this.inputModePopup != null) + this.inputModePopup.Hidden = !ViewModel.HasInputModes; + + base.OnViewModelChanged (oldModel); } } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs index da659cf..3992972 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs @@ -1,8 +1,11 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using AppKit; using CoreGraphics; +using Foundation; using Xamarin.PropertyEditing.Mac.Resources; using Xamarin.PropertyEditing.ViewModels; @@ -10,9 +13,19 @@ namespace Xamarin.PropertyEditing.Mac { internal class StringEditorControl : PropertyEditorControl> { + private NSTextField stringEditor { get; set; } + + private NSLayoutConstraint stringEditorWidthConstraint; + + public override NSView FirstKeyView => this.stringEditor; + public override NSView LastKeyView => this.stringEditor; + + internal NSPopUpButton inputModePopup; + private IReadOnlyList viewModelInputModes; + public StringEditorControl () { - StringEditor = new NSTextField { + this.stringEditor = new NSTextField { BackgroundColor = NSColor.Clear, ControlSize = NSControlSize.Small, Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize), @@ -21,28 +34,28 @@ namespace Xamarin.PropertyEditing.Mac }; // update the value on keypress - StringEditor.Changed += (sender, e) => { - ViewModel.Value = StringEditor.StringValue; + this.stringEditor.Changed += (sender, e) => { + ViewModel.Value = this.stringEditor.StringValue; }; - AddSubview (StringEditor); + AddSubview (this.stringEditor); + + this.stringEditorWidthConstraint = NSLayoutConstraint.Create (this.stringEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -117f); this.AddConstraints (new[] { - NSLayoutConstraint.Create (StringEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), - NSLayoutConstraint.Create (StringEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -34f), - NSLayoutConstraint.Create (StringEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3), + NSLayoutConstraint.Create (this.stringEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), + this.stringEditorWidthConstraint, + NSLayoutConstraint.Create (this.stringEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3), }); UpdateTheme (); } - internal NSTextField StringEditor { get; set; } - - public override NSView FirstKeyView => StringEditor; - public override NSView LastKeyView => StringEditor; - protected override void UpdateValue () { - StringEditor.StringValue = ViewModel.Value ?? string.Empty; + this.stringEditor.StringValue = ViewModel.Value ?? string.Empty; + this.stringEditor.Enabled = ((ViewModel.InputMode != null) && !ViewModel.InputMode.IsSingleValue) || (this.inputModePopup == null); + if (this.inputModePopup != null) + this.inputModePopup.SelectItem ((ViewModel.InputMode == null) ? string.Empty : ViewModel.InputMode.Identifier); } protected override void HandleErrorsChanged (object sender, System.ComponentModel.DataErrorsChangedEventArgs e) @@ -50,6 +63,48 @@ namespace Xamarin.PropertyEditing.Mac UpdateErrorsDisplayed (ViewModel.GetErrors (ViewModel.Property.Name)); } + protected override void OnViewModelChanged (PropertyViewModel oldModel) + { + if (ViewModel.HasInputModes) { + if (this.inputModePopup == null) { + this.inputModePopup = new NSPopUpButton { + Menu = new NSMenu (), + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + this.inputModePopup.Activated += (o, e) => { + var popupButton = o as NSPopUpButton; + ViewModel.InputMode = this.viewModelInputModes.FirstOrDefault (im => im.Identifier == popupButton.Title); + }; + + AddSubview (this.inputModePopup); + + this.AddConstraints (new[] { + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -33f), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, 80f), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight - 3 ), + }); + } + + this.inputModePopup.Menu.RemoveAllItems (); + this.viewModelInputModes = ViewModel.InputModes; + foreach (InputMode item in this.viewModelInputModes) { + this.inputModePopup.Menu.AddItem (new NSMenuItem (item.Identifier)); + } + + this.stringEditorWidthConstraint.Constant = -117f; // Shorten the stringEditor if we have Inputmodes Showing. + } else { + this.stringEditorWidthConstraint.Constant = -34f; // Lengthen the stringEditor if we have Inputmodes Hidden. + } + + // If we are reusing the control we'll have to hid the inputMode if this doesn't have InputMode. + if (this.inputModePopup != null) + this.inputModePopup.Hidden = !ViewModel.HasInputModes; + + base.OnViewModelChanged (oldModel); + } + protected override void UpdateErrorsDisplayed (IEnumerable errors) { if (ViewModel.HasErrors) { @@ -62,12 +117,18 @@ namespace Xamarin.PropertyEditing.Mac protected override void SetEnabled () { - StringEditor.Editable = ViewModel.Property.CanWrite; + this.stringEditor.Editable = ViewModel.Property.CanWrite; + if (this.inputModePopup != null) + this.inputModePopup.Enabled = ViewModel.Property.CanWrite; } protected override void UpdateAccessibilityValues () { - StringEditor.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityString, ViewModel.Property.Name); + this.stringEditor.AccessibilityEnabled = this.stringEditor.Editable; + this.stringEditor.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityString, ViewModel.Property.Name); + if (this.inputModePopup != null) { + this.inputModePopup.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityInpueModeEditor, ViewModel.Property.Name); + } } } } -- cgit v1.2.3