diff options
author | Eric Maupin <ermaup@microsoft.com> | 2019-09-25 21:34:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-25 21:34:43 +0300 |
commit | 2f6533b51fd9613de962927b3b1c0db2438e154b (patch) | |
tree | 0efa409e72b9e3913633de8509f4a8b65425a5c6 /Xamarin.PropertyEditing.Mac | |
parent | 45ff1775a2c50bdad3e398f0b86ec910f1adfd62 (diff) | |
parent | dbbd3917935045104e224e23e815f2e1da880591 (diff) |
Merge pull request #632 from xamarin/ermau-fix-966530
Fix 966530
Diffstat (limited to 'Xamarin.PropertyEditing.Mac')
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs | 12 | ||||
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs | 205 |
2 files changed, 124 insertions, 93 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs index 989cad7..c621392 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs @@ -55,11 +55,11 @@ namespace Xamarin.PropertyEditing.Mac ToolTip = Properties.Resources.Default; OnMouseEntered += (sender, e) => { - ToggleFocusImage (true); + UpdateImage (true); }; OnMouseExited += (sender, e) => { - ToggleFocusImage (); + UpdateImage (); }; OnMouseLeftDown += (sender, e) => { @@ -78,7 +78,7 @@ namespace Xamarin.PropertyEditing.Mac private void AppearanceChanged () { - ToggleFocusImage (); + UpdateImage (); } private readonly IHostResourceProvider hostResources; @@ -170,7 +170,7 @@ namespace Xamarin.PropertyEditing.Mac } } - private void ToggleFocusImage (bool focused = false) + private void UpdateImage (bool focused = false) { if (this.viewModel != null) { @@ -216,7 +216,7 @@ namespace Xamarin.PropertyEditing.Mac case ValueSource.Default: ToolTip = Properties.Resources.Default; - return; + break; case ValueSource.Local: ToolTip = Properties.Resources.Local; @@ -240,7 +240,7 @@ namespace Xamarin.PropertyEditing.Mac break; } - ToggleFocusImage (); + UpdateImage (); } private void OnPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e) diff --git a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs index d7abd38..8e74659 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs @@ -15,59 +15,15 @@ namespace Xamarin.PropertyEditing.Mac : base (hostResources) { base.TranslatesAutoresizingMaskIntoConstraints = false; - - this.comboBox = new FocusableComboBox { - AllowsExpansionToolTips = true, - BackgroundColor = NSColor.Clear, - Cell = { - LineBreakMode = NSLineBreakMode.TruncatingTail, - UsesSingleLineMode = true, - }, - ControlSize = NSControlSize.Small, - Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), - TranslatesAutoresizingMaskIntoConstraints = false, - StringValue = String.Empty, - }; - - this.comboBox.SelectionChanged += (sender, e) => { - ViewModel.ValueName = this.comboBox.SelectedValue.ToString (); - }; - - this.popUpButton = new FocusablePopUpButton { - AllowsExpansionToolTips = true, - Cell = { - LineBreakMode = NSLineBreakMode.TruncatingTail, - UsesSingleLineMode = true, - }, - ControlSize = NSControlSize.Small, - Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), - TranslatesAutoresizingMaskIntoConstraints = false, - StringValue = String.Empty, - }; - - popupButtonList = new NSMenu (); - this.popUpButton.Menu = popupButtonList; - - this.popUpButton.Activated += (o, e) => { - ViewModel.ValueName = (o as NSPopUpButton).Title; - }; } public override NSView FirstKeyView => this.firstKeyView; public override NSView LastKeyView => this.lastKeyView; - private readonly NSComboBox comboBox; - private readonly NSPopUpButton popUpButton; - private NSMenu popupButtonList; - - private bool dataPopulated; - private NSView firstKeyView; - private NSView lastKeyView; - protected override void SetEnabled () { if (ViewModel.IsConstrainedToPredefined) { - this.popUpButton.Enabled = ViewModel.Property.CanWrite; + this.popupButton.Enabled = ViewModel.Property.CanWrite; } else { this.comboBox.Enabled = ViewModel.Property.CanWrite; } @@ -75,58 +31,32 @@ namespace Xamarin.PropertyEditing.Mac protected override void OnViewModelChanged (PropertyViewModel oldModel) { - base.OnViewModelChanged (oldModel); - if (ViewModel == null) return; - if (!this.dataPopulated) { - if (ViewModel.IsConstrainedToPredefined) { - this.popupButtonList.RemoveAllItems (); - foreach (var item in ViewModel.PossibleValues) { - this.popupButtonList.AddItem (new NSMenuItem (item)); - } - - AddSubview (this.popUpButton); - - this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), - NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), - NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), - }); - - this.firstKeyView = this.popUpButton; - this.lastKeyView = this.popUpButton; - } else { - this.comboBox.RemoveAll (); - - // Once the VM is loaded we need a one time population - foreach (var item in ViewModel.PossibleValues) { - this.comboBox.Add (new NSString (item)); - } - - AddSubview (this.comboBox); - - this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), - NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), - NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), - }); - - this.firstKeyView = this.comboBox; - this.lastKeyView = this.comboBox; + if (ViewModel.IsConstrainedToPredefined) { + RequirePopup (); + + this.popupButtonList.RemoveAllItems (); + foreach (var item in ViewModel.PossibleValues) { + this.popupButtonList.AddItem (new NSMenuItem (item)); } + } else { + RequireComboBox (); - this.dataPopulated = true; + this.comboBox.RemoveAll (); + foreach (var item in ViewModel.PossibleValues) { + this.comboBox.Add (new NSString (item)); + } } - SetEnabled (); + base.OnViewModelChanged (oldModel); } protected override void UpdateValue () { if (ViewModel.IsConstrainedToPredefined) { - this.popUpButton.Title = ViewModel.ValueName ?? String.Empty; + this.popupButton.Title = ViewModel.ValueName ?? String.Empty; } else { this.comboBox.StringValue = ViewModel.ValueName ?? String.Empty; } @@ -135,12 +65,113 @@ namespace Xamarin.PropertyEditing.Mac protected override void UpdateAccessibilityValues () { if (ViewModel.IsConstrainedToPredefined) { - this.popUpButton.AccessibilityEnabled = this.popUpButton.Enabled; - this.popUpButton.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityCombobox, ViewModel.Property.Name); + this.popupButton.AccessibilityEnabled = this.popupButton.Enabled; + this.popupButton.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityCombobox, ViewModel.Property.Name); } else { this.comboBox.AccessibilityEnabled = this.comboBox.Enabled; this.comboBox.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityCombobox, ViewModel.Property.Name); } } + + private NSComboBox comboBox; + private NSPopUpButton popupButton; + private NSMenu popupButtonList; + + private NSView firstKeyView; + private NSView lastKeyView; + + private void RemovePopup() + { + if (this.popupButton == null) + return; + + this.popupButton.RemoveFromSuperview (); + this.popupButton.Dispose (); + this.popupButton = null; + + this.popupButtonList.Dispose (); + this.popupButtonList = null; + } + + private void RequirePopup() + { + if (this.popupButton != null) + return; + + RemoveComboBox (); + + this.popupButton = new FocusablePopUpButton { + AllowsExpansionToolTips = true, + Cell = { + LineBreakMode = NSLineBreakMode.TruncatingTail, + UsesSingleLineMode = true, + }, + ControlSize = NSControlSize.Small, + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), + TranslatesAutoresizingMaskIntoConstraints = false, + StringValue = String.Empty, + }; + + this.popupButtonList = new NSMenu (); + this.popupButton.Menu = this.popupButtonList; + this.popupButton.Activated += (o, e) => ViewModel.ValueName = (o as NSPopUpButton).Title; + + AddSubview (this.popupButton); + + AddConstraints (new[] { + NSLayoutConstraint.Create (this.popupButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.popupButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), + NSLayoutConstraint.Create (this.popupButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), + }); + + this.firstKeyView = this.popupButton; + this.lastKeyView = this.popupButton; + } + + private void RemoveComboBox() + { + if (this.comboBox == null) + return; + + this.comboBox.RemoveFromSuperview (); + this.comboBox.Dispose (); + this.comboBox = null; + } + + private void RequireComboBox() + { + if (this.comboBox != null) + return; + + RemovePopup (); + + this.comboBox = new FocusableComboBox { + AllowsExpansionToolTips = true, + BackgroundColor = NSColor.Clear, + Cell = { + LineBreakMode = NSLineBreakMode.TruncatingTail, + UsesSingleLineMode = true, + }, + ControlSize = NSControlSize.Small, + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), + TranslatesAutoresizingMaskIntoConstraints = false, + StringValue = String.Empty, + }; + + this.comboBox.SelectionChanged += (sender, e) => { + ViewModel.ValueName = this.comboBox.SelectedValue.ToString (); + }; + + AddSubview (this.comboBox); + + AddConstraints (new[] { + NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), + NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), + }); + + this.firstKeyView = this.comboBox; + this.lastKeyView = this.comboBox; + } } } |