diff options
author | Dominique Louis <savagesoftware@gmail.com> | 2017-11-23 14:54:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-23 14:54:54 +0300 |
commit | 21d6f4b39ad775915ccd36285c15304bb59bfc32 (patch) | |
tree | 584e6a79900b00ae4b69a9422f8cfde7dfaa9807 /Xamarin.PropertyEditing.Mac/Controls | |
parent | 870cbce82b2fd8f0ee1e5189af4b20bf4ebc8b2e (diff) | |
parent | 8008d53094d6458d4887147f9033a39cb43db864 (diff) |
Merge pull request #81 from xamarin/dominique-UITweaks
Fixes to UI based on feedback
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls')
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs | 98 |
1 files changed, 80 insertions, 18 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs index 3ec93c0..98b7e5f 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs @@ -19,35 +19,51 @@ namespace Xamarin.PropertyEditing.Mac { base.TranslatesAutoresizingMaskIntoConstraints = false; - this.comboBox = new NSComboBox () { + this.comboBox = new NSComboBox { TranslatesAutoresizingMaskIntoConstraints = false, BackgroundColor = NSColor.Clear, StringValue = String.Empty, Cell = { - ControlSize = NSControlSize.Regular + ControlSize = NSControlSize.Small }, Editable = false, }; + this.popUpButton = new NSPopUpButton { + TranslatesAutoresizingMaskIntoConstraints = false, + StringValue = String.Empty, + Cell = { + ControlSize = NSControlSize.Small + }, + }; + this.comboBox.SelectionChanged += (sender, e) => { EditorViewModel.ValueName = comboBox.SelectedValue.ToString (); }; - AddSubview (this.comboBox); + popupButtonList = new NSMenu (); + popUpButton.Menu = popupButtonList; - this.DoConstraints (new[] { - comboBox.ConstraintTo (this, (cb, c) => cb.Width == c.Width - 28), - comboBox.ConstraintTo (this, (cb, c) => cb.Left == c.Left + 3), - }); + popUpButton.Activated += (o, e) => { + EditorViewModel.ValueName = (o as NSPopUpButton).Title; + }; UpdateTheme (); } - public override NSView FirstKeyView => this.comboBox; - public override NSView LastKeyView => this.comboBox; + public override NSView FirstKeyView => firstKeyView; + public override NSView LastKeyView => lastKeyView; protected PredefinedValuesViewModel<T> EditorViewModel => (PredefinedValuesViewModel<T>)ViewModel; + readonly NSComboBox comboBox; + readonly NSPopUpButton popUpButton; + NSMenu popupButtonList; + + bool dataPopulated; + NSView firstKeyView; + NSView lastKeyView; + protected override void HandleErrorsChanged (object sender, DataErrorsChangedEventArgs e) { UpdateErrorsDisplayed (ViewModel.GetErrors (e.PropertyName)); @@ -55,7 +71,11 @@ namespace Xamarin.PropertyEditing.Mac protected override void SetEnabled () { - this.comboBox.Editable = ViewModel.Property.CanWrite; + if (EditorViewModel.IsConstrainedToPredefined) { + this.popUpButton.Enabled = ViewModel.Property.CanWrite; + } else { + this.comboBox.Enabled = ViewModel.Property.CanWrite; + } } protected override void UpdateErrorsDisplayed (IEnumerable errors) @@ -70,9 +90,44 @@ namespace Xamarin.PropertyEditing.Mac protected override void OnViewModelChanged (PropertyViewModel oldModel) { - this.comboBox.RemoveAll (); - foreach (string item in EditorViewModel.PossibleValues) { - this.comboBox.Add (new NSString (item)); + if (!dataPopulated) { + if (EditorViewModel.IsConstrainedToPredefined) { + this.popupButtonList.RemoveAllItems (); + foreach (string item in EditorViewModel.PossibleValues) { + popupButtonList.AddItem (new NSMenuItem (item)); + } + + AddSubview (this.popUpButton); + + this.DoConstraints (new[] { + popUpButton.ConstraintTo (this, (pub, c) => pub.Width == c.Width - 26), + popUpButton.ConstraintTo (this, (pub, c) => pub.Left == c.Left + 3), + popUpButton.ConstraintTo (this, (pub, c) => pub.Top == c.Top + 6), + }); + + firstKeyView = this.popUpButton; + lastKeyView = this.popUpButton; + } else { + this.comboBox.RemoveAll (); + + // Once the VM is loaded we need a one time population + foreach (var item in EditorViewModel.PossibleValues) { + this.comboBox.Add (new NSString (item)); + } + + AddSubview (this.comboBox); + + this.DoConstraints (new[] { + comboBox.ConstraintTo (this, (cb, c) => cb.Width == c.Width - 28), + comboBox.ConstraintTo (this, (cb, c) => cb.Left == c.Left + 3), + comboBox.ConstraintTo (this, (cb, c) => cb.Top == c.Top + 4), + }); + + firstKeyView = this.comboBox; + lastKeyView = this.comboBox; + } + + dataPopulated = true; } base.OnViewModelChanged (oldModel); @@ -80,15 +135,22 @@ namespace Xamarin.PropertyEditing.Mac protected override void UpdateValue () { - this.comboBox.StringValue = EditorViewModel.ValueName ?? String.Empty; + if (EditorViewModel.IsConstrainedToPredefined) { + this.popUpButton.Title = EditorViewModel.ValueName ?? String.Empty; + } else { + this.comboBox.StringValue = EditorViewModel.ValueName ?? String.Empty; + } } - private readonly NSComboBox comboBox; - protected override void UpdateAccessibilityValues () { - comboBox.AccessibilityEnabled = comboBox.Enabled; - comboBox.AccessibilityTitle = Strings.AccessibilityCombobox (ViewModel.Property.Name); + if (EditorViewModel.IsConstrainedToPredefined) { + popUpButton.AccessibilityEnabled = popUpButton.Enabled; + popUpButton.AccessibilityTitle = Strings.AccessibilityCombobox (ViewModel.Property.Name); + } else { + comboBox.AccessibilityEnabled = comboBox.Enabled; + comboBox.AccessibilityTitle = Strings.AccessibilityCombobox (ViewModel.Property.Name); + } } } } |