From 91afd92d3ce2ec0984c8b14717cf7536cfa12526 Mon Sep 17 00:00:00 2001 From: CartBlanche Date: Mon, 16 Dec 2019 10:41:45 +0000 Subject: [PATCH] [Mac] Use the NSView.Tag property to set which control is the 1st one to receive focus. --- .../Controls/BasePointEditorControl.cs | 1 + .../Controls/BaseRectangleEditorControl.cs | 1 + .../Controls/BooleanEditorControl.cs | 2 +- Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs | 1 + Xamarin.PropertyEditing.Mac/Controls/CharEditorControl.cs | 1 + .../Controls/CollectionInlineEditorControl.cs | 3 ++- .../Controls/CombinablePropertyEditor.cs | 1 + .../Controls/Custom/NumericSpinEditor.cs | 6 ++++++ .../Controls/Custom/PropertyButton.cs | 3 ++- .../Controls/DateTimeEditorControl.cs | 1 + .../Controls/FilePathEditorControl.cs | 1 + .../Controls/NumericEditorControl.cs | 4 +++- Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs | 1 + .../Controls/PredefinedValuesEditor.cs | 2 ++ Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs | 4 +++- Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs | 1 + .../Controls/TimeSpanEditorControl.cs | 1 + Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs | 1 + 18 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs index 60f044073..195509cdb 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs @@ -28,6 +28,7 @@ protected BasePointEditorControl (IHostResourceProvider hostResources) XEditor = new NumericSpinEditor (hostResources) { BackgroundColor = NSColor.Clear, + Tag = 1, Value = 0.0f }; XEditor.ValueChanged += OnInputUpdated; diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs index e1289bb18..8017dac4a 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs @@ -33,6 +33,7 @@ protected BaseRectangleEditorControl (IHostResourceProvider hostResources) }; XEditor = new NumericSpinEditor (hostResources) { BackgroundColor = NSColor.Clear, + Tag = 1, Value = 0.0f }; XEditor.ValueChanged += OnInputUpdated; diff --git a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs index 2f3142ca2..403064113 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs @@ -11,7 +11,7 @@ internal class BooleanEditorControl public BooleanEditorControl (IHostResourceProvider hostResource) : base (hostResource) { - BooleanEditor = new FocusableBooleanButton (); + BooleanEditor = new FocusableBooleanButton () { Tag = 1 }; // update the value on 'enter' BooleanEditor.Activated += (sender, e) => { diff --git a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs index fc9ecc624..d5f89c97a 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs @@ -56,6 +56,7 @@ public BrushEditorControl (IHostResourceProvider hostResources) this.popUpButton = new ColorPopUpButton { ControlSize = NSControlSize.Small, Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), + Tag = 1, TranslatesAutoresizingMaskIntoConstraints = false, }; diff --git a/Xamarin.PropertyEditing.Mac/Controls/CharEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/CharEditorControl.cs index f68457dd7..448e1eece 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CharEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CharEditorControl.cs @@ -9,6 +9,7 @@ internal class CharEditorControl public CharEditorControl (IHostResourceProvider hostResources) : base (hostResources) { + Entry.Tag = 1; } protected override EntryPropertyEditorDelegate CreateDelegate (PropertyViewModel viewModel) diff --git a/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs index f2f43b5d7..eed58a0a7 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs @@ -21,7 +21,8 @@ public CollectionInlineEditorControl (IHostResourceProvider hostResources) Title = Properties.Resources.CollectionEditButton, BezelStyle = NSBezelStyle.Rounded, AccessibilityEnabled = true, - AccessibilityHelp = Properties.Resources.AccessibilityCollectionHelp + AccessibilityHelp = Properties.Resources.AccessibilityCollectionHelp, + Tag = 1, }; this.openCollection.Activated += (o, e) => { diff --git a/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs index 30f6e1d70..0637494c8 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs @@ -82,6 +82,7 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel) } checkbox.Title = choice.Name; + checkbox.Tag = i == 0 ? 1 : -1; this.combinableList[checkbox] = choice; top += subrowHeight; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs index 0240805ef..763916f62 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs @@ -171,6 +171,12 @@ public override string AccessibilityTitle { set { this.numericEditor.AccessibilityTitle = value; } } + public new nint Tag + { + get { return this.numericEditor.Tag; } + set { this.numericEditor.Tag = value; } + } + public virtual void Reset () { } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs index 41e2e4880..18147353d 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs @@ -172,7 +172,8 @@ private void FocusClickedRow () private void MakeFocusableKeyViewFirstResponder (NSView[] subViews) { foreach (NSView item in subViews) { - if (item.CanBecomeKeyView) { + if (item.CanBecomeKeyView + && item.Tag == 1) { Window?.MakeFirstResponder (item); break; } else { diff --git a/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs index 1a6ac5c47..ad00352d0 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs @@ -16,6 +16,7 @@ public DateTimeEditorControl (IHostResourceProvider hostResources) DatePickerElements = NSDatePickerElementFlags.HourMinuteSecond | NSDatePickerElementFlags.YearMonthDateDay, DatePickerStyle = NSDatePickerStyle.TextFieldAndStepper, Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), + Tag = 1, TranslatesAutoresizingMaskIntoConstraints = false }; diff --git a/Xamarin.PropertyEditing.Mac/Controls/FilePathEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/FilePathEditorControl.cs index ac32b3ac5..9bd5f81da 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/FilePathEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/FilePathEditorControl.cs @@ -14,6 +14,7 @@ public FilePathEditorControl (IHostResourceProvider hostResource) : base (hostResource) { this.currentTextField.ToolTip = this.currentTextField.PlaceholderString = string.Format (Properties.Resources.ChooseFileOrDirectory, Properties.Resources.File); + this.currentTextField.Tag = 1; this.panel.CanChooseFiles = true; this.panel.CanChooseDirectories = false; this.revealPathButton.ToolTip = string.Format (Properties.Resources.RevealFileOrDirectory, Properties.Resources.File); diff --git a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs index c726aeb13..90e2a5588 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs @@ -16,7 +16,9 @@ public NumericEditorControl (IHostResourceProvider hostResources) { base.TranslatesAutoresizingMaskIntoConstraints = false; - NumericEditor = new NumericSpinEditor (hostResources); + NumericEditor = new NumericSpinEditor (hostResources) { + Tag = 1 + }; NumericEditor.ValueChanged += OnValueChanged; var t = typeof (T); diff --git a/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs index 2df3c0146..6680ff4d8 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs @@ -22,6 +22,7 @@ public ObjectEditorControl (IHostResourceProvider hostResources) this.createObject = new FocusableButton { Title = Properties.Resources.New, BezelStyle = NSBezelStyle.Rounded, + Tag = 1, }; this.createObject.Activated += OnNewPressed; AddSubview (this.createObject); diff --git a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs index 2073645c9..ee34c15b7 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs @@ -108,6 +108,7 @@ private void RequirePopup() }, ControlSize = NSControlSize.Small, Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), + Tag = 1, TranslatesAutoresizingMaskIntoConstraints = false, StringValue = String.Empty, }; @@ -154,6 +155,7 @@ private void RequireComboBox() }, ControlSize = NSControlSize.Small, Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), + Tag = 1, TranslatesAutoresizingMaskIntoConstraints = false, StringValue = String.Empty, }; diff --git a/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs index 126d7e842..2e362419f 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs @@ -15,7 +15,9 @@ public RatioEditorControl (IHostResourceProvider hostResources) { base.TranslatesAutoresizingMaskIntoConstraints = false; - this.ratioEditor = new RatioEditor (hostResources); + this.ratioEditor = new RatioEditor (hostResources) { + Tag = 1, + }; this.ratioEditor.SetFormatter (null); // update the value on keypress diff --git a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs index e4a3f7183..0869c6e86 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs @@ -15,6 +15,7 @@ public StringEditorControl (IHostResourceProvider hostResources) : base (hostResources) { this.lastKeyView = Entry; + Entry.Tag = 1; } public override NSView LastKeyView => this.lastKeyView; diff --git a/Xamarin.PropertyEditing.Mac/Controls/TimeSpanEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/TimeSpanEditorControl.cs index 222af8172..933689595 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/TimeSpanEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/TimeSpanEditorControl.cs @@ -9,6 +9,7 @@ internal class TimeSpanEditorControl public TimeSpanEditorControl (IHostResourceProvider hostResources) : base (hostResources) { + Entry.Tag = 1; } protected override EntryPropertyEditorDelegate CreateDelegate (PropertyViewModel viewModel) diff --git a/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs index 01fa7d05c..28d3d26af 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs @@ -21,6 +21,7 @@ public TypeEditorControl (IHostResourceProvider hostResources) this.selectType = new FocusableButton { BezelStyle = NSBezelStyle.Rounded, + Tag = 1, Title = Properties.Resources.Select, }; this.selectType.Activated += OnSelectPressed;