diff --git a/Xamarin.PropertyEditing.Mac.Standalone/Main.storyboard b/Xamarin.PropertyEditing.Mac.Standalone/Main.storyboard index cac80b0..a8b8ff6 100644 --- a/Xamarin.PropertyEditing.Mac.Standalone/Main.storyboard +++ b/Xamarin.PropertyEditing.Mac.Standalone/Main.storyboard @@ -672,7 +672,7 @@ - + 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 EditorViewModel => (PredefinedValuesViewModel)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); + } } } } diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs b/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs index c963108..943afc6 100644 --- a/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs +++ b/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs @@ -166,11 +166,11 @@ namespace Xamarin.PropertyEditing.Mac propertyFilter.ConstraintTo(this, (pf, c) => pf.Left == c.Left + 12), propertyArrangeModeLabel.ConstraintTo(this, (pl, c) => pl.Top == c.Top + 5), - propertyArrangeModeLabel.ConstraintTo(propertyArrangeMode, (pl, pa) => pl.Left == pa.Left - 73), + propertyArrangeModeLabel.ConstraintTo(propertyArrangeMode, (pl, pa) => pl.Left == pa.Left - 71), propertyArrangeMode.ConstraintTo(this, (pa, c) => pa.Top == c.Top + 3), - propertyArrangeMode.ConstraintTo(this, (pa, c) => pa.Left == c.Left + 312), - propertyArrangeMode.ConstraintTo(this, (pa, c) => pa.Width == 154), + propertyArrangeMode.ConstraintTo(this, (pa, c) => pa.Left == c.Left + 310), + propertyArrangeMode.ConstraintTo(this, (pa, c) => pa.Width == c.Width - 320), tableContainer.ConstraintTo(this, (t, c) => t.Top == c.Top + 30), tableContainer.ConstraintTo(this, (t, c) => t.Width == c.Width - 20), diff --git a/Xamarin.PropertyEditing/ViewModels/PredefinedValuesViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PredefinedValuesViewModel.cs index a6c0998..d24177f 100644 --- a/Xamarin.PropertyEditing/ViewModels/PredefinedValuesViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/PredefinedValuesViewModel.cs @@ -48,6 +48,8 @@ namespace Xamarin.PropertyEditing.ViewModels } } + public bool IsConstrainedToPredefined => this.predefinedValues.IsConstrainedToPredefined; + // TODO: Combination (flags) values protected override TValue ValidateValue (TValue validationValue)