Tweaks to Resize Arrange By correctly and use NSPopUpButton instead of NSComboBox for constrained predefined values.

This commit is contained in:
Dominique Louis 2017-11-22 19:38:06 +00:00
Родитель 870cbce82b
Коммит 8008d53094
4 изменённых файлов: 86 добавлений и 22 удалений

Просмотреть файл

@ -672,7 +672,7 @@
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="XfG-lQ-9wD" customClass="ViewController" sceneMemberID="viewController">
<view key="view" id="m2S-Jp-Qdl">
<view key="view" id="m2S-Jp-Qdl" wantsLayer="YES">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>

Просмотреть файл

@ -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);
}
}
}
}

Просмотреть файл

@ -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),

Просмотреть файл

@ -48,6 +48,8 @@ namespace Xamarin.PropertyEditing.ViewModels
}
}
public bool IsConstrainedToPredefined => this.predefinedValues.IsConstrainedToPredefined;
// TODO: Combination (flags) values
protected override TValue ValidateValue (TValue validationValue)