From bcd495d5f17539a18037551d2d8b6191b65aac33 Mon Sep 17 00:00:00 2001 From: Dominique Louis Date: Fri, 10 May 2019 17:31:12 +0100 Subject: [PATCH 1/2] [Mac] Initial Variations Implementation --- .../Controls/BasePathEditorControl.cs | 10 +- .../Controls/BasePointEditorControl.cs | 24 +- .../Controls/BaseRectangleEditorControl.cs | 59 ++-- .../Controls/BooleanEditorControl.cs | 8 +- .../Controls/BrushEditorControl.cs | 6 +- .../Controls/CollectionInlineEditorControl.cs | 2 +- .../Controls/CombinablePropertyEditor.cs | 11 +- .../Controls/Custom/BasePopOverControl.cs | 2 +- .../Custom/BasePopOverViewModelControl.cs | 3 + .../Controls/Custom/CommandButton.cs | 124 +++++++- .../Controls/Custom/DrawingExtensions.cs | 28 ++ .../Controls/Custom/NumericSpinEditor.cs | 12 +- .../Controls/Custom/PropertyButton.cs | 93 +++--- .../Controls/Custom/UnfocusableButton.cs | 12 +- .../Controls/Custom/UnfocusableTextField.cs | 5 + .../Controls/Custom/VariationButton.cs | 60 ++++ .../Controls/CustomExpressionView.cs | 4 +- .../Controls/DateTimeEditorControl.cs | 5 +- .../Controls/EditorContainer.cs | 271 +++++++++++++++++- .../Controls/EntryPropertyEditor.cs | 5 +- .../Controls/ErrorMessageView.cs | 2 +- .../Controls/FilePathEditorControl.cs | 6 +- .../Controls/GroupEditorControl.cs | 2 + .../Controls/NumericEditorControl.cs | 16 +- .../Controls/ObjectEditorControl.cs | 4 +- .../Controls/PanelHeaderEditorControl.cs | 2 +- .../Controls/PointEditorControl.cs | 5 - .../Controls/PredefinedValuesEditor.cs | 8 +- .../Controls/PropertyContainer.cs | 29 +- .../Controls/PropertyEditorControl.cs | 22 +- .../Controls/RatioEditorControl.cs | 16 +- .../Controls/RectangleEditorControl.cs | 5 - .../RequestResource/RequestResourceView.cs | 3 - .../Controls/SizeEditorControl.cs | 5 - .../Controls/StringEditorControl.cs | 6 +- .../Controls/ThicknessEditorControl.cs | 5 - .../Controls/TypeEditorControl.cs | 2 +- .../Controls/Variations/CreateVariantView.cs | 124 ++++++++ .../Variations/CreateVariantWindow.cs | 94 ++++++ .../pe-variation-add-button-active-mac-10.png | Bin 0 -> 134 bytes ...-variation-add-button-active-mac-10@2x.png | Bin 0 -> 204 bytes ...ariation-add-button-active-mac-10~dark.png | Bin 0 -> 134 bytes ...ation-add-button-active-mac-10~dark@2x.png | Bin 0 -> 204 bytes .../pe-variation-add-button-mac-10.png | Bin 0 -> 91 bytes .../pe-variation-add-button-mac-10@2x.png | Bin 0 -> 96 bytes .../pe-variation-add-button-mac-10~dark.png | Bin 0 -> 91 bytes ...pe-variation-add-button-mac-10~dark@2x.png | Bin 0 -> 96 bytes ...-variation-delete-button-active-mac-10.png | Bin 0 -> 135 bytes ...riation-delete-button-active-mac-10@2x.png | Bin 0 -> 220 bytes ...ation-delete-button-active-mac-10~dark.png | Bin 0 -> 135 bytes ...on-delete-button-active-mac-10~dark@2x.png | Bin 0 -> 222 bytes .../pe-variation-delete-button-mac-10.png | Bin 0 -> 208 bytes .../pe-variation-delete-button-mac-10@2x.png | Bin 0 -> 257 bytes ...pe-variation-delete-button-mac-10~dark.png | Bin 0 -> 181 bytes ...variation-delete-button-mac-10~dark@2x.png | Bin 0 -> 246 bytes .../Resources/pe-variations-editor-32.png | Bin 0 -> 282 bytes .../Resources/pe-variations-editor-32@2x.png | Bin 0 -> 407 bytes .../pe-variations-editor-32~dark.png | Bin 0 -> 273 bytes .../pe-variations-editor-32~dark@2x.png | Bin 0 -> 389 bytes .../PropertyEditorPanel.cs | 2 +- .../Xamarin.PropertyEditing.Mac.csproj | 3 + .../MockControls/MockSampleControl.cs | 86 +++++- .../Properties/Resources.Designer.cs | 18 ++ .../Properties/Resources.resx | 12 + 64 files changed, 1022 insertions(+), 199 deletions(-) create mode 100644 Xamarin.PropertyEditing.Mac/Controls/Custom/VariationButton.cs create mode 100644 Xamarin.PropertyEditing.Mac/Controls/Variations/CreateVariantView.cs create mode 100644 Xamarin.PropertyEditing.Mac/Controls/Variations/CreateVariantWindow.cs create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-active-mac-10.png create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-active-mac-10@2x.png create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-active-mac-10~dark.png create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-active-mac-10~dark@2x.png create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-mac-10.png create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-mac-10@2x.png create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-mac-10~dark.png create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-mac-10~dark@2x.png create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-active-mac-10.png create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-active-mac-10@2x.png create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-active-mac-10~dark.png create mode 100644 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-active-mac-10~dark@2x.png create mode 100755 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-mac-10.png create mode 100755 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-mac-10@2x.png create mode 100755 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-mac-10~dark.png create mode 100755 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-mac-10~dark@2x.png create mode 100755 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variations-editor-32.png create mode 100755 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variations-editor-32@2x.png create mode 100755 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variations-editor-32~dark.png create mode 100755 Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variations-editor-32~dark@2x.png diff --git a/Xamarin.PropertyEditing.Mac/Controls/BasePathEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BasePathEditorControl.cs index 923281ec1..23575c04c 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BasePathEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BasePathEditorControl.cs @@ -26,7 +26,10 @@ internal abstract class BasePathEditorControl : PropertyEditorControl : PropertyEditorControl XEditor; public override NSView LastKeyView => YEditor.DecrementButton; + protected override nint BaseHeight => 36; + protected BasePointEditorControl (IHostResourceProvider hostResources) : base (hostResources) { @@ -46,23 +48,21 @@ protected BasePointEditorControl (IHostResourceProvider hostResources) AddSubview (YLabel); AddSubview (YEditor); - const float editorHeight = 18; - this.AddConstraints (new[] { - NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f), + nfloat labelHeight = NSFont.SystemFontSizeForControlSize (NSControlSize.Small); + AddConstraints (new[] { + NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset + 1), + NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight), + + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, -1f), NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f), - NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight), - - NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Bottom, 1f, -4f), - NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight), - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f), + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, YLabel, NSLayoutAttribute.Top, 1f, -1f), NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f), - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight), NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight), + NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight), NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, XEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0), NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, YEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0), @@ -73,8 +73,8 @@ protected BasePointEditorControl (IHostResourceProvider hostResources) protected override void SetEnabled () { - XEditor.Enabled = ViewModel.Property.CanWrite; - YEditor.Enabled = ViewModel.Property.CanWrite; + XEditor.Enabled = + YEditor.Enabled = ViewModel.IsInputEnabled; } protected override void UpdateAccessibilityValues () diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs index 005ef8974..e1289bb18 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs @@ -22,6 +22,8 @@ internal abstract class BaseRectangleEditorControl : PropertyEditorControl XEditor; public override NSView LastKeyView => HeightEditor.DecrementButton; + protected override nint BaseHeight => 68; + protected BaseRectangleEditorControl (IHostResourceProvider hostResources) : base (hostResources) { @@ -74,44 +76,41 @@ protected BaseRectangleEditorControl (IHostResourceProvider hostResources) AddSubview (HeightLabel); AddSubview (HeightEditor); - this.AddConstraints (new[] { - NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f), - NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), - NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f), - NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), - - NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Bottom, 1f, -4f), - NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), - - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f), - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f), - NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), - - NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), + nfloat labelHeight = NSFont.SystemFontSizeForControlSize (NSControlSize.Small); + AddConstraints (new[] { + NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset + 1), + NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight), - NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 33f), + NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, WidthLabel, NSLayoutAttribute.Top, 1f, -1f), NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, HeightEditor, NSLayoutAttribute.Left, 1f, -10f), - NSLayoutConstraint.Create (WidthEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), - - NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Bottom, 1f, -4f), - NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), - NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, HeightLabel, NSLayoutAttribute.Top, 1f, -1f), NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Width, 1f, 0f), - NSLayoutConstraint.Create (HeightEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, WidthLabel, NSLayoutAttribute.Top, 1f, 0f), - NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), + NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight), + NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, WidthEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0), + NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, HeightEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0), + + NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight), + + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, -1f), + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, WidthEditor, NSLayoutAttribute.Left, 1f, 0f), + NSLayoutConstraint.Create (XEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, YEditor, NSLayoutAttribute.Left, 1f, -10f), + + NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XLabel, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, labelHeight), + + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, HeightEditor, NSLayoutAttribute.Right, 1f, 0), + NSLayoutConstraint.Create (YEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, XEditor, NSLayoutAttribute.Width, 1f, 0f), NSLayoutConstraint.Create (XLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, XEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0), NSLayoutConstraint.Create (YLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, YEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0), - NSLayoutConstraint.Create (WidthLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, WidthEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0), - NSLayoutConstraint.Create (HeightLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, HeightEditor.Subviews[0], NSLayoutAttribute.CenterX, 1f, 0), }); AppearanceChanged (); @@ -124,10 +123,10 @@ protected virtual void OnInputUpdated (object sender, EventArgs e) protected override void SetEnabled () { - XEditor.Enabled = ViewModel.Property.CanWrite; - YEditor.Enabled = ViewModel.Property.CanWrite; - WidthEditor.Enabled = ViewModel.Property.CanWrite; - HeightEditor.Enabled = ViewModel.Property.CanWrite; + XEditor.Enabled = + YEditor.Enabled = + WidthEditor.Enabled = + HeightEditor.Enabled = ViewModel.IsInputEnabled; } protected override void UpdateAccessibilityValues () diff --git a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs index 1212fef56..2f3142ca2 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs @@ -8,8 +8,6 @@ namespace Xamarin.PropertyEditing.Mac internal class BooleanEditorControl : PropertyEditorControl> { - const string setBezelColorSelector = "setBezelColor:"; - public BooleanEditorControl (IHostResourceProvider hostResource) : base (hostResource) { @@ -29,8 +27,8 @@ public BooleanEditorControl (IHostResourceProvider hostResource) AddSubview (BooleanEditor); - this.AddConstraints (new[] { - NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + AddConstraints (new[] { + NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, -4f), NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f), }); } @@ -60,7 +58,7 @@ protected override void UpdateValue () protected override void SetEnabled () { - BooleanEditor.Enabled = ViewModel.Property.CanWrite; + BooleanEditor.Enabled = ViewModel.IsInputEnabled; } protected override void UpdateAccessibilityValues () diff --git a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs index c0e6344b6..fc9ecc624 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs @@ -64,7 +64,7 @@ public BrushEditorControl (IHostResourceProvider hostResources) AddSubview (this.popUpButton); - this.AddConstraints (new[] { + AddConstraints (new[] { NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 16), NSLayoutConstraint.Create (this.popUpButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0), @@ -84,7 +84,7 @@ public BrushEditorControl (IHostResourceProvider hostResources) protected override void SetEnabled () { - this.popUpButton.Enabled = this.ViewModel?.Property.CanWrite ?? false; + this.popUpButton.Enabled = ViewModel?.IsInputEnabled ?? false; } string GetTitle () @@ -109,7 +109,7 @@ string GetTitle () protected override void UpdateValue () { this.brushTabViewController.ViewModel = ViewModel; - this.popUpButton.Popover = (ViewModel?.Property.CanWrite ?? false) ? this.popover : null; + this.popUpButton.Popover = (ViewModel?.IsInputEnabled ?? false) ? this.popover : null; if (ViewModel.Solid != null) { var title = GetTitle (); diff --git a/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs index 37e2df220..f2f43b5d7 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs @@ -51,7 +51,7 @@ public CollectionInlineEditorControl (IHostResourceProvider hostResources) protected override void SetEnabled () { base.SetEnabled (); - this.openCollection.Enabled = ViewModel?.Property.CanWrite ?? false; + this.openCollection.Enabled = ViewModel?.IsInputEnabled ?? false; } protected override void UpdateAccessibilityValues () diff --git a/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs index 5122f2416..30f6e1d70 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs @@ -30,13 +30,18 @@ public CombinablePropertyEditor (IHostResourceProvider hostResources) public override nint GetHeight (EditorViewModel vm) { var realVm = (CombinablePropertyViewModel)vm; - return subrowHeight * realVm.Choices.Count + 6; + nint baseHeight = subrowHeight * realVm.Choices.Count + 6; + if (realVm != null && realVm.IsVariant) { + return (baseHeight * 2); + } + + return baseHeight; } protected override void SetEnabled () { foreach (var item in this.combinableList) { - item.Key.Enabled = ViewModel.Property.CanWrite; + item.Key.Enabled = ViewModel.IsInputEnabled; } } @@ -66,7 +71,7 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel) AddSubview (checkbox); - this.AddConstraints (new[] { + AddConstraints (new[] { NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, top), NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs index e4bea5ee0..5af248776 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs @@ -39,7 +39,7 @@ public BasePopOverControl (IHostResourceProvider hostResources, string title, st AddSubview (this.viewTitle); - this.AddConstraints (new[] { + AddConstraints (new[] { NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 5f), NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 5f), NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, DefaultIconButtonSize), diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs index 0f1846a15..abfaf9cbe 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using AppKit; using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac @@ -9,6 +10,8 @@ internal class BasePopOverViewModelControl : BasePopOverControl { internal PropertyViewModel ViewModel { get; } + public AutoClosePopOver PopOver { get; internal set; } + public BasePopOverViewModelControl (IHostResourceProvider hostResources, PropertyViewModel viewModel, string title, string imageNamed) : base (hostResources, title, imageNamed) { diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs index 4fde65f5d..07f1522f1 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandButton.cs @@ -8,6 +8,14 @@ internal class CommandButton : NSButton { private ICommand command; + public event EventHandler OnMouseEntered; + public event EventHandler OnMouseExited; + public event EventHandler OnMouseLeftDown; + public event EventHandler OnMouseRightDown; + + private NSTrackingArea trackingArea; + private bool commandFired; + public ICommand Command { get { return this.command; } @@ -24,16 +32,122 @@ public ICommand Command public CommandButton () { - Activated += (object sender, EventArgs e) => { - var button = (CommandButton)sender; - button.command?.Execute (null); - }; + Activated += ExecuteCommand; + } + + private void ExecuteCommand (object sender, EventArgs e) + { + if (Enabled && !this.commandFired) { + this.command?.Execute (null); + return; + } + this.commandFired = false; + } + + #region Overridden Methods + + public override void MouseDown (NSEvent theEvent) + { + if (Enabled) { + switch (theEvent.Type) { + case NSEventType.LeftMouseDown: + NotifyMouseLeftDown (); + break; + + case NSEventType.RightMouseDown: + NotifyMouseRightDown (); + break; + } + base.MouseDown (theEvent); + } + } + + public override void MouseEntered (NSEvent theEvent) + { + if (Enabled) { + NotifyMouseEntered (); + base.MouseEntered (theEvent); + } + } + + public override void MouseExited (NSEvent theEvent) + { + if (Enabled) { + NotifyMouseExited (); + base.MouseExited (theEvent); + } + } + + public override void UpdateTrackingAreas () + { + base.UpdateTrackingAreas (); + + // Add tracking so our MouseEntered and MouseExited get called. + if (this.trackingArea == null) { + NSTrackingAreaOptions options = NSTrackingAreaOptions.MouseEnteredAndExited | NSTrackingAreaOptions.ActiveAlways; + + this.trackingArea = new NSTrackingArea (Bounds, options, this, null); + + AddTrackingArea (this.trackingArea); + } } + #endregion + + #region Local Methods private void CanExecuteChanged (object sender, EventArgs e) { if (sender is ICommand cmd) - this.Enabled = cmd.CanExecute (null); + Enabled = cmd.CanExecute (null); + } + + private void NotifyMouseEntered () + { + OnMouseEntered?.Invoke (this, EventArgs.Empty); + } + + private void NotifyMouseExited () + { + OnMouseExited?.Invoke (this, EventArgs.Empty); + } + + private void NotifyMouseLeftDown () + { + ExecuteCommand (this, EventArgs.Empty); + OnMouseLeftDown?.Invoke (this, EventArgs.Empty); + this.commandFired = true; + } + + private void NotifyMouseRightDown () + { + OnMouseRightDown?.Invoke (this, EventArgs.Empty); + } + #endregion + } + + internal class FocusableCommandButton : CommandButton + { + public override bool CanBecomeKeyView { get { return Enabled; } } + + public FocusableCommandButton () + { + AllowsExpansionToolTips = true; + AllowsMixedState = true; + Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; + Cell.UsesSingleLineMode = true; + ControlSize = NSControlSize.Small; + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)); + Title = string.Empty; + TranslatesAutoresizingMaskIntoConstraints = false; + } + + public override bool BecomeFirstResponder () + { + var willBecomeFirstResponder = base.BecomeFirstResponder (); + if (willBecomeFirstResponder) { + ScrollRectToVisible (Bounds); + } + return willBecomeFirstResponder; } } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs index c8dbbef82..ec82d1d93 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/DrawingExtensions.cs @@ -116,5 +116,33 @@ public static CommonColor UpdateCMYK ( k: k ?? color.K, alpha: alpha ?? color.A); } + + public static CGPath ToCGPath (this NSBezierPath nsPath) + { + var cgPath = new CGPath (); + for (var i = 0; i < nsPath.ElementCount; i++) { + NSBezierPathElement type = nsPath.ElementAt (i, out CGPoint[] points); + + switch (type) { + case NSBezierPathElement.ClosePath: + cgPath.CloseSubpath (); + break; + + case NSBezierPathElement.CurveTo: + cgPath.AddCurveToPoint (points[0], points[1], points[2]); + break; + + case NSBezierPathElement.LineTo: + cgPath.AddLineToPoint (points[0]); + break; + + case NSBezierPathElement.MoveTo: + cgPath.MoveToPoint (points[0]); + break; + } + } + + return cgPath; + } } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs index e7ddd5dba..0240805ef 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/NumericSpinEditor.cs @@ -206,10 +206,10 @@ public NumericSpinEditor (IHostResourceProvider hostResources) this.numericEditor = new NumericTextField { Alignment = NSTextAlignment.Right, - TranslatesAutoresizingMaskIntoConstraints = false, - Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), ControlSize = NSControlSize.Small, - Formatter = this.formatter + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), + Formatter = this.formatter, + TranslatesAutoresizingMaskIntoConstraints = false, }; this.incrementButton.OnMouseLeftDown += (sender, e) => { IncrementNumericValue (); }; @@ -224,9 +224,9 @@ public NumericSpinEditor (IHostResourceProvider hostResources) AddSubview (this.incrementButton); AddSubview (this.decrementButton); - this.AddConstraints (new[] { + AddConstraints (new[] { NSLayoutConstraint.Create (this.numericEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0), - NSLayoutConstraint.Create (this.numericEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), + NSLayoutConstraint.Create (this.numericEditor, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 0), NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.numericEditor, NSLayoutAttribute.Top, 1f, 0f), NSLayoutConstraint.Create (this.incrementButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.numericEditor, NSLayoutAttribute.Right, 1f, StepperSpace), @@ -305,7 +305,7 @@ public double Clamp (double value) private const int StepperSpace = 2; private const int StepperWidth = 11; private const int StepperTopHeight = 9; - private const int StepperBotHeight = 10; + private const int StepperBotHeight = 9; private readonly IHostResourceProvider hostResources; } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs index 0070f6c67..41e2e4880 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Threading.Tasks; using AppKit; using CoreGraphics; using Xamarin.PropertyEditing.ViewModels; @@ -20,16 +21,25 @@ internal PropertyViewModel ViewModel set { if (this.viewModel != null) { this.viewModel.PropertyChanged -= OnPropertyChanged; + if (this.viewModel.SupportsBindings) this.viewModel.CreateBindingRequested -= OnBindingRequested; + + if (this.viewModel.HasVariations) + this.viewModel.CreateVariantRequested -= OnCreateVariantRequested; } this.viewModel = value; if (this.viewModel != null) { this.viewModel.PropertyChanged += OnPropertyChanged; + if (this.viewModel.SupportsBindings) this.viewModel.CreateBindingRequested += OnBindingRequested; + + if (this.viewModel.HasVariations) + this.viewModel.CreateVariantRequested += OnCreateVariantRequested; + ValueSourceChanged (this.viewModel.ValueSource); AccessibilityTitle = string.Format (Properties.Resources.AccessibilityPropertiesButton, ViewModel.Property.Name); @@ -94,7 +104,7 @@ private void PopUpContextMenu () AttributedTitle = new Foundation.NSAttributedString ( Properties.Resources.CustomExpressionEllipsis, new CoreText.CTStringAttributes { - Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1), + Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), }) }; @@ -111,7 +121,7 @@ private void PopUpContextMenu () AttributedTitle = new Foundation.NSAttributedString ( Properties.Resources.ResourceEllipsis, new CoreText.CTStringAttributes { - Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1), + Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), }) }; @@ -126,7 +136,7 @@ private void PopUpContextMenu () AttributedTitle = new Foundation.NSAttributedString ( Properties.Resources.CreateDataBindingMenuItem, new CoreText.CTStringAttributes { - Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1), + Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), }) }); } @@ -138,7 +148,7 @@ private void PopUpContextMenu () AttributedTitle = new Foundation.NSAttributedString ( Properties.Resources.Reset, new CoreText.CTStringAttributes { - Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1), + Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), }) }); } @@ -154,8 +164,8 @@ private void PopUpContextMenu () private void FocusClickedRow () { - if (Superview != null) { - MakeFocusableKeyViewFirstResponder (Superview.Subviews); + if (Superview is EditorContainer ec) { + MakeFocusableKeyViewFirstResponder (ec.EditorView.NativeView.Subviews); } } @@ -163,7 +173,7 @@ private void MakeFocusableKeyViewFirstResponder (NSView[] subViews) { foreach (NSView item in subViews) { if (item.CanBecomeKeyView) { - Window.MakeFirstResponder (item); + Window?.MakeFirstResponder (item); break; } else { MakeFocusableKeyViewFirstResponder (item.Subviews); @@ -176,34 +186,34 @@ private void UpdateImage (bool focused = false) if (this.viewModel != null) { switch (this.viewModel.ValueSource) { - case ValueSource.Binding: - Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-bound-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-bound-mac-10"); - break; - - case ValueSource.Default: - Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-default-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-default-mac-10"); - break; - - case ValueSource.Local: - Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-local-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-local-mac-10"); - break; - - case ValueSource.Inherited: - Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-inherited-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-inherited-mac-10"); - break; - - case ValueSource.Resource: - Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-inherited-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-inherited-mac-10"); - break; - - case ValueSource.Unset: - Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-default-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-default-mac-10"); - break; - - default: - // To Handle ValueSource.DefaultStyle, ValueSource.Style etc. - Image = null; - break; + case ValueSource.Binding: + Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-bound-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-bound-mac-10"); + break; + + case ValueSource.Default: + Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-default-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-default-mac-10"); + break; + + case ValueSource.Local: + Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-local-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-local-mac-10"); + break; + + case ValueSource.Inherited: + Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-inherited-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-inherited-mac-10"); + break; + + case ValueSource.Resource: + Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-inherited-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-inherited-mac-10"); + break; + + case ValueSource.Unset: + Image = focused ? this.hostResources.GetNamedImage ("pe-property-button-default-mac-active-10") : this.hostResources.GetNamedImage ("pe-property-button-default-mac-10"); + break; + + default: + // To Handle ValueSource.DefaultStyle, ValueSource.Style etc. + Image = null; + break; } } } @@ -293,5 +303,18 @@ private void OnBindingRequested (object sender, CreateBindingRequestedEventArgs e.BindingObject = bindingEditorWindow.ViewModel.SelectedObjects.Single (); } } + + private void OnCreateVariantRequested (object sender, CreateVariantEventArgs e) + { + using (var createVariantWindow = new CreateVariantWindow (this.hostResources, this.viewModel) { + Appearance = EffectiveAppearance, + }) + { + var result = (NSModalResponse)(int)NSApplication.SharedApplication.RunModalForWindow (createVariantWindow); + if (result == NSModalResponse.OK) { + e.Variation = Task.FromResult (createVariantWindow.ViewModel.Variation); + } + } + } } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableButton.cs index e00482dae..fb383e17f 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableButton.cs @@ -10,7 +10,7 @@ public abstract class UnfocusableButton : NSImageView public event EventHandler OnMouseLeftDown; public event EventHandler OnMouseRightDown; - NSTrackingArea trackingArea; + private NSTrackingArea trackingArea; public UnfocusableButton () { @@ -54,12 +54,12 @@ public override void UpdateTrackingAreas () base.UpdateTrackingAreas (); // Add tracking so our MouseEntered and MouseExited get called. - if (trackingArea == null) { - var options = NSTrackingAreaOptions.MouseEnteredAndExited | NSTrackingAreaOptions.ActiveAlways; + if (this.trackingArea == null) { + NSTrackingAreaOptions options = NSTrackingAreaOptions.MouseEnteredAndExited | NSTrackingAreaOptions.ActiveAlways; - trackingArea = new NSTrackingArea (this.Bounds, options, this, null); + this.trackingArea = new NSTrackingArea (Bounds, options, this, null); - AddTrackingArea (trackingArea); + AddTrackingArea (this.trackingArea); } } #endregion @@ -78,6 +78,7 @@ private void NotifyMouseExited () private void NotifyMouseLeftDown () { + //this.command?.Execute (null); OnMouseLeftDown?.Invoke (this, EventArgs.Empty); } @@ -85,7 +86,6 @@ private void NotifyMouseRightDown () { OnMouseRightDown?.Invoke (this, EventArgs.Empty); } - #endregion } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs index c449d664f..0fe3bcfe5 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/UnfocusableTextField.cs @@ -39,6 +39,11 @@ public NSColor TextColor { internal set { this.label.TextColor = value; } } + public bool Bordered { + get { return this.label.Bordered; } + internal set { this.label.Bordered = value; } + } + public virtual NSBackgroundStyle BackgroundStyle { [Export ("backgroundStyle")] get => this.label.Cell.BackgroundStyle; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/VariationButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/VariationButton.cs new file mode 100644 index 000000000..e6b99c9e0 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/VariationButton.cs @@ -0,0 +1,60 @@ +using System; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class VariationButton + : FocusableCommandButton + { + private readonly IHostResourceProvider hostResources; + + private readonly string imageFocused; + private readonly string imageUnfocused; + + public VariationButton (IHostResourceProvider hostResources, string imageFocused, string imageUnfocused) + { + if (hostResources == null) + throw new ArgumentNullException (nameof (hostResources)); + + this.hostResources = hostResources; + + if (string.IsNullOrEmpty(imageFocused)) + throw new ArgumentNullException (nameof (imageFocused)); + + this.imageFocused = imageFocused; + + if (string.IsNullOrEmpty (imageUnfocused)) + throw new ArgumentNullException (nameof (imageUnfocused)); + + this.imageUnfocused = imageUnfocused; + + Bordered = false; + + OnMouseEntered += (sender, e) => { + ToggleFocusImage (true); + }; + + OnMouseExited += (sender, e) => { + ToggleFocusImage (); + }; + + AppearanceChanged (); + } + + private void ToggleFocusImage (bool focused = false) + { + Image = focused ? this.hostResources.GetNamedImage (this.imageFocused) : this.hostResources.GetNamedImage (this.imageUnfocused); + } + + public sealed override void ViewDidChangeEffectiveAppearance () + { + base.ViewDidChangeEffectiveAppearance (); + + AppearanceChanged (); + } + + protected void AppearanceChanged () + { + ToggleFocusImage (); + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs index 370c7fcab..cc5761226 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs @@ -15,8 +15,6 @@ internal class CustomExpressionView : BasePopOverViewModelControl private const string PreviewCustomExpressionString = "PreviewCustomExpression"; private const string AutocompleteItemsString = "AutocompleteItems"; - public AutoClosePopOver PopOver { get; internal set; } - public CustomExpressionView (IHostResourceProvider hostResources, PropertyViewModel viewModel) : base (hostResources, viewModel, Properties.Resources.CustomExpression, "pe-custom-expression-32") { @@ -56,7 +54,7 @@ public CustomExpressionView (IHostResourceProvider hostResources, PropertyViewMo AddSubview (editorControl); - this.AddConstraints (new[] { + AddConstraints (new[] { NSLayoutConstraint.Create (editorControl, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 37f), NSLayoutConstraint.Create (editorControl, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 38f), NSLayoutConstraint.Create (editorControl, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -57f), diff --git a/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs index 36532e26c..1a6ac5c47 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/DateTimeEditorControl.cs @@ -25,10 +25,9 @@ public DateTimeEditorControl (IHostResourceProvider hostResources) AddSubview (this.datePicker); AddConstraints (new[] { - NSLayoutConstraint.Create (this.datePicker, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.datePicker, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset), NSLayoutConstraint.Create (this.datePicker, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this, NSLayoutAttribute.Leading, 1f, 0f), NSLayoutConstraint.Create (this.datePicker, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), - NSLayoutConstraint.Create (this.datePicker, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, -6f), }); } @@ -47,7 +46,7 @@ protected override void UpdateValue () protected override void SetEnabled () { - this.datePicker.Enabled = ViewModel.Property.CanWrite; + this.datePicker.Enabled = ViewModel.IsInputEnabled; } protected override void UpdateAccessibilityValues () diff --git a/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs b/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs index 2fee93f00..1ee3921b9 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs @@ -1,4 +1,9 @@ +using System; +using System.Collections.Generic; using AppKit; +using CoreAnimation; +using CoreGraphics; +using Foundation; using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac @@ -11,27 +16,49 @@ public EditorContainer (IHostResourceProvider hostResources, IEditorView editorV { } + private const string FrameChangedObservableProperty = "frame"; + private readonly NSString observerKeyPath = new NSString (FrameChangedObservableProperty); + public IEditorView EditorView => (IEditorView)NativeContainer; - public EditorViewModel ViewModel - { + public EditorViewModel ViewModel { get => EditorView?.ViewModel; set { if (EditorView == null) return; + if (this.viewModelAsPropertyViewModel != null) + this.viewModelAsPropertyViewModel.PropertyChanged -= PropertyChanged; + EditorView.ViewModel = value; + this.viewModelAsPropertyViewModel = value as PropertyViewModel; + if (PropertyButton != null) - PropertyButton.ViewModel = value as PropertyViewModel; + PropertyButton.ViewModel = this.viewModelAsPropertyViewModel; + + if (this.viewModelAsPropertyViewModel != null) + this.viewModelAsPropertyViewModel.PropertyChanged += PropertyChanged; + + UpdateLabelVerticalConstraint (); + + UpdateVariations (); + + FrameChanged (); + } + } + + private void PropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof (PropertyViewModel.HasVariantChildren)) { + FrameChanged (); } } public NSView LeftEdgeView { get { return this.leftEdgeView; } - set - { + set { if (this.leftEdgeView != null) { this.leftEdgeView.RemoveFromSuperview (); RemoveConstraints (new[] { this.leftEdgeLeftConstraint, this.leftEdgeVCenterConstraint }); @@ -47,14 +74,229 @@ public NSView LeftEdgeView AddSubview (value); value.TranslatesAutoresizingMaskIntoConstraints = false; - this.leftEdgeLeftConstraint = NSLayoutConstraint.Create (this.leftEdgeView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 4); - this.leftEdgeVCenterConstraint = NSLayoutConstraint.Create (this.leftEdgeView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0); + this.leftEdgeLeftConstraint = NSLayoutConstraint.Create (this.leftEdgeView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 9); + this.leftEdgeVCenterConstraint = NSLayoutConstraint.Create (this.leftEdgeView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 8); AddConstraints (new[] { this.leftEdgeLeftConstraint, this.leftEdgeVCenterConstraint }); } } } + public override bool CanBecomeKeyView { get { return true; } } + + public sealed override void ViewDidChangeEffectiveAppearance () + { + base.ViewDidChangeEffectiveAppearance (); + + AppearanceChanged (); + } + + public override void Layout () + { + base.Layout (); + + FrameChanged (); + } + + protected void AppearanceChanged () + { + CGColor fgColour = HostResources.GetNamedColor (NamedResources.ForegroundColor).CGColor; + + // Repaint those lines + foreach (CALayer variationLayer in this.variationParentLayersList) { + if (variationLayer is CAShapeLayer lineShape) { + lineShape.StrokeColor = fgColour; + } + } + + foreach (CALayer variationLayer in this.variationChildLayersList) { + if (variationLayer is CAShapeLayer lineShape) { + lineShape.StrokeColor = fgColour; + } + } + } + + private void UpdateVariations () + { + ClearSubViews (); + + if (this.viewModelAsPropertyViewModel != null && this.viewModelAsPropertyViewModel.IsInputEnabled) { + if (this.viewModelAsPropertyViewModel.HasVariations) { + + if (this.viewModelAsPropertyViewModel.IsVariant) { + this.deleteVariantButton = new VariationButton (HostResources, "pe-variation-delete-button-active-mac-10", "pe-variation-delete-button-mac-10") { + AccessibilityEnabled = true, + AccessibilityTitle = Properties.Resources.AccessibilityDeleteVariationButton, + Command = this.viewModelAsPropertyViewModel.RemoveVariationCommand, + ToolTip = Properties.Resources.RemoveVariant, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + AddSubview (this.deleteVariantButton); + AddConstraints (new[] { + NSLayoutConstraint.Create (this.deleteVariantButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 8f), + NSLayoutConstraint.Create (this.deleteVariantButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 20f), + }); + + this.variationControlsList.Add (this.deleteVariantButton); + + // Hook into the delete button's frame change, so we can fire off some drawing. If there's a better way, let me know. + this.deleteVariantButton.AddObserver (this, this.observerKeyPath, NSKeyValueObservingOptions.New, IntPtr.Zero); + + NextKeyView = this.deleteVariantButton; + + // Cache these before the loop + var variationBgColour = HostResources.GetNamedColor (NamedResources.FrameBoxButtonBackgroundColor); + + NSView previousControl = this.deleteVariantButton; + foreach (PropertyVariationOption item in this.viewModelAsPropertyViewModel.Variation) { + var selectedVariationTextField = new UnfocusableTextField { + BackgroundColor = variationBgColour, + Bordered = false, + Font = VariationOptionFont, + TranslatesAutoresizingMaskIntoConstraints = false, + StringValue = string.Format (" {0}: {1} ", item.Category, item.Name), + }; + + AddSubview (selectedVariationTextField); + AddConstraints (new[] { + NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, VariationBorderOffset), + NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Left, NSLayoutRelation.Equal, previousControl, NSLayoutAttribute.Right, 1f, 6f), + NSLayoutConstraint.Create (selectedVariationTextField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 16f), + }); + + previousControl = selectedVariationTextField; + this.variationControlsList.Add (selectedVariationTextField); + } + } else { + this.addVariantButton = new VariationButton (HostResources, "pe-variation-add-button-active-mac-10", "pe-variation-add-button-mac-10") { + AccessibilityEnabled = true, + AccessibilityTitle = Properties.Resources.AccessibilityAddVariationButton, + Command = this.viewModelAsPropertyViewModel.RequestCreateVariantCommand, + ToolTip = Properties.Resources.AddVariant, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + LeftEdgeView = this.addVariantButton; + NextKeyView = this.addVariantButton; + + this.variationControlsList.Add (this.addVariantButton); + } + } + } + } + + private void ClearSubViews () + { + foreach (NSView item in this.variationControlsList) { + item.RemoveFromSuperview (); + } + + this.variationControlsList.Clear (); + + this.addVariantButton = null; + + if (this.deleteVariantButton != null) { + this.deleteVariantButton.RemoveObserver (this, this.observerKeyPath); + this.deleteVariantButton = null; + } + } + + private void ClearChildLayers () + { + WantsLayer = false; + + foreach (CALayer item in this.variationChildLayersList) { + item.RemoveFromSuperLayer (); + } + + this.variationChildLayersList.Clear (); + } + + private void ClearParentLayers () + { + WantsLayer = false; + + foreach (CALayer item in this.variationParentLayersList) { + item.RemoveFromSuperLayer (); + } + + this.variationParentLayersList.Clear (); + } + + private CAShapeLayer GetVariantLines (CGPoint start1, CGPoint[] end1, CGPoint start2, CGPoint[] end2) + { + var endLineShape = new CAShapeLayer (); + var endLinePath = new NSBezierPath (); + + endLinePath.MoveTo (start1); + endLinePath.Append (end1); + if (!start2.IsEmpty) { + endLinePath.MoveTo (start2); + endLinePath.Append (end2); + // other dash + start2.X += 18; + endLinePath.MoveTo (start2); + end2[0].X += 18; + endLinePath.Append (end2); + } + endLineShape.Path = endLinePath.ToCGPath (); + endLineShape.FillColor = null; + endLineShape.Opacity = 1.0f; + endLineShape.StrokeColor = HostResources.GetNamedColor (NamedResources.ForegroundColor).CGColor; + return endLineShape; + } + + // the deleteButton's AddObserver fires this method when the observed property changes + public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context) + { + if (keyPath == FrameChangedObservableProperty) { + FrameChanged (); + return; + } + + base.ObserveValue (keyPath, ofObject, change, context); + } + + private void FrameChanged () + { + ClearParentLayers (); + ClearChildLayers (); + + if (this.viewModelAsPropertyViewModel == null) + return; + + if (this.viewModelAsPropertyViewModel.IsVariant) { + if (this.deleteVariantButton != null) { + WantsLayer = true; + + CAShapeLayer childLineShape = GetVariantLines ( + new CGPoint (treeLineLeftEdge, this.viewModelAsPropertyViewModel.GetIsLastVariant () ? ViewVariationChildVerticalDrawPoint : 0), + new CGPoint[] { new CGPoint (treeLineLeftEdge, Bounds.Height) }, + new CGPoint (treeLineLeftEdge, ViewVariationChildVerticalDrawPoint), + new CGPoint[] { new CGPoint (treeLineLeftEdge + treeLineLeafIndent, ViewVariationChildVerticalDrawPoint) } + ); + Layer.AddSublayer (childLineShape); + + this.variationChildLayersList.Add (childLineShape); + } + } else if (this.viewModelAsPropertyViewModel.HasVariantChildren) { + if (this.addVariantButton != null) { + WantsLayer = true; + + CAShapeLayer parentLineShape = GetVariantLines ( + new CGPoint (treeLineLeftEdge, 0), + new CGPoint[] { new CGPoint (treeLineLeftEdge, ViewVariationParentVerticalDrawPoint) }, + new CGPoint (CGPoint.Empty), + new CGPoint[] { new CGPoint (CGPoint.Empty) } + ); + Layer.AddSublayer (parentLineShape); + + this.variationParentLayersList.Add (parentLineShape); + } + } + } + #if DEBUG // Currently only used to highlight which controls haven't been implemented public NSColor LabelTextColor { set { LabelControl.TextColor = value; } @@ -63,5 +305,18 @@ public NSColor LabelTextColor { private NSView leftEdgeView; private NSLayoutConstraint leftEdgeLeftConstraint, leftEdgeVCenterConstraint; + + private List variationControlsList = new List (); + private List variationChildLayersList = new List (); + private List variationParentLayersList = new List (); + private VariationButton deleteVariantButton; + private VariationButton addVariantButton; + private const float treeLineLeftEdge = 14f; + private const float treeLineLeafIndent = 4f; + internal const float VariationBorderOffset = 5f; + internal static NSFont VariationOptionFont = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small) - 1f); + private nfloat ViewVariationChildVerticalDrawPoint => this.deleteVariantButton.Frame.Top + 5; + private nfloat ViewVariationParentVerticalDrawPoint => this.addVariantButton.Frame.Top - 2; + private PropertyViewModel viewModelAsPropertyViewModel; } -} +} \ No newline at end of file diff --git a/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs index f1d92ac53..1d1e5a05d 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs @@ -21,10 +21,9 @@ public EntryPropertyEditor (IHostResourceProvider hostResources) RightEdgeConstraint = NSLayoutConstraint.Create (Entry, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0); AddConstraints (new[] { - NSLayoutConstraint.Create (Entry, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0), + NSLayoutConstraint.Create (Entry, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset), NSLayoutConstraint.Create (Entry, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0), RightEdgeConstraint, - NSLayoutConstraint.Create (Entry, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6), }); } @@ -51,7 +50,7 @@ protected override void UpdateValue () protected override void SetEnabled () { - Entry.Enabled = ViewModel.Property.CanWrite; + Entry.Enabled = ViewModel.IsInputEnabled; } protected override void UpdateAccessibilityValues () diff --git a/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs b/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs index 725779ed8..edbf24a25 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs @@ -46,7 +46,7 @@ public ErrorMessageView (IHostResourceProvider hostResources, IEnumerable errors AddSubview (this.errorMessages); - this.AddConstraints (new[] { + AddConstraints (new[] { NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 5f), NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 5f), NSLayoutConstraint.Create (iconView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, DefaultIconButtonSize), diff --git a/Xamarin.PropertyEditing.Mac/Controls/FilePathEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/FilePathEditorControl.cs index 731b5d2bc..ac32b3ac5 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/FilePathEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/FilePathEditorControl.cs @@ -59,11 +59,11 @@ protected override void UpdateValue () protected override void SetEnabled () { - this.currentTextField.Enabled = ViewModel.Property.CanWrite; - this.browsePathButton.Enabled = ViewModel.Property.CanWrite; + this.currentTextField.Enabled = + this.browsePathButton.Enabled = ViewModel.IsInputEnabled; //button states - this.revealPathButton.Enabled = ViewModel.Property.CanWrite && File.Exists (this.currentTextField.StringValue); + this.revealPathButton.Enabled = ViewModel.IsInputEnabled && File.Exists (this.currentTextField.StringValue); Window?.RecalculateKeyViewLoop (); } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs index fc15eb667..913b7f1a7 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/GroupEditorControl.cs @@ -216,6 +216,8 @@ public PropertyViewModel ViewModel } PropertyButton.ViewModel = value; + + UpdateLabelVerticalConstraint (); } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs index e56debf39..c726aeb13 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs @@ -42,11 +42,10 @@ public NumericEditorControl (IHostResourceProvider hostResources) this.editorRightConstraint = NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0); - this.AddConstraints (new[] { - NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0), + AddConstraints (new[] { + NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset), NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0), this.editorRightConstraint, - NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6), }); } @@ -60,8 +59,6 @@ protected NSNumberFormatter Formatter { public override NSView FirstKeyView => NumericEditor; public override NSView LastKeyView => NumericEditor.DecrementButton; - private bool CanEnable => ViewModel.Property.CanWrite && (((ViewModel.InputMode != null) && !ViewModel.InputMode.IsSingleValue) || (this.inputModePopup == null)); - protected NSNumberFormatterStyle NumberStyle { get { return NumericEditor.NumberStyle; } @@ -72,9 +69,9 @@ protected NSNumberFormatterStyle NumberStyle { protected override void SetEnabled () { - NumericEditor.Enabled = CanEnable; + NumericEditor.Enabled = ViewModel.IsInputEnabled; if (this.inputModePopup != null) - this.inputModePopup.Enabled = ViewModel.Property.CanWrite; + this.inputModePopup.Enabled = ViewModel.IsInputEnabled; } protected virtual void OnValueChanged (object sender, EventArgs e) @@ -89,7 +86,7 @@ protected override void UpdateValue() { if (this.underlyingType != null) { NumericEditor.StringValue = ViewModel.Value == null ? string.Empty : ViewModel.Value.ToString (); - NumericEditor.Enabled = CanEnable; + NumericEditor.Enabled = ViewModel.IsInputEnabled; if (this.inputModePopup != null) this.inputModePopup.SelectItem ((ViewModel.InputMode == null) ? string.Empty : ViewModel.InputMode.Identifier); @@ -136,9 +133,10 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel) AddSubview (this.inputModePopup); this.editorInputModeConstraint = NSLayoutConstraint.Create (NumericEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.inputModePopup, NSLayoutAttribute.Left, 1, -4); + AddConstraints (new[] { this.editorInputModeConstraint, - NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset), NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0f), NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, DefaultButtonWidth), }); diff --git a/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs index 273c3a00c..2df3c0146 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs @@ -26,8 +26,6 @@ public ObjectEditorControl (IHostResourceProvider hostResources) this.createObject.Activated += OnNewPressed; AddSubview (this.createObject); - //this.buttonConstraint = NSLayoutConstraint.Create (this.createObject, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this.typeLabel, NSLayoutAttribute.Trailing, 1f, 12); - AddConstraints (new[] { NSLayoutConstraint.Create (this.typeLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f), NSLayoutConstraint.Create (this.typeLabel, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), @@ -50,7 +48,7 @@ protected override void UpdateValue () protected override void SetEnabled () { - this.createObject.Enabled = ViewModel.Property.CanWrite; + this.createObject.Enabled = ViewModel.IsInputEnabled; } protected override void UpdateAccessibilityValues () diff --git a/Xamarin.PropertyEditing.Mac/Controls/PanelHeaderEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PanelHeaderEditorControl.cs index 5ad60e78c..83234f6d6 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PanelHeaderEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PanelHeaderEditorControl.cs @@ -56,7 +56,7 @@ public PanelHeaderEditorControl (IHostResourceProvider hostResources) }; AddSubview (this.propertyIcon); - this.AddConstraints (new[] { + AddConstraints (new[] { NSLayoutConstraint.Create (this.propertyIcon, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, 32), NSLayoutConstraint.Create (this.propertyIcon, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, 32), NSLayoutConstraint.Create (this.propertyIcon, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 5), diff --git a/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs index d51479889..74d2cff9a 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PointEditorControl.cs @@ -21,11 +21,6 @@ public PointEditorControl (IHostResourceProvider hostResources) YEditor.Frame = new CGRect (132, 13, 90, 20); } - - public override nint GetHeight (EditorViewModel vm) - { - return 33; - } } internal class SystemPointEditorControl diff --git a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs index 4cac9a128..2073645c9 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs @@ -23,9 +23,9 @@ public PredefinedValuesEditor (IHostResourceProvider hostResources) protected override void SetEnabled () { if (ViewModel.IsConstrainedToPredefined) { - this.popupButton.Enabled = ViewModel.Property.CanWrite; + this.popupButton.Enabled = ViewModel.IsInputEnabled; } else { - this.comboBox.Enabled = ViewModel.Property.CanWrite; + this.comboBox.Enabled = ViewModel.IsInputEnabled; } } @@ -119,7 +119,7 @@ private void RequirePopup() AddSubview (this.popupButton); AddConstraints (new[] { - NSLayoutConstraint.Create (this.popupButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.popupButton, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset), 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), }); @@ -165,7 +165,7 @@ private void RequireComboBox() AddSubview (this.comboBox); AddConstraints (new[] { - NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.comboBox, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset), 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), }); diff --git a/Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs b/Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs index 712b1bcd0..4dcef1931 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PropertyContainer.cs @@ -11,6 +11,8 @@ public PropertyContainer (IHostResourceProvider hostResources, INativeContainer if (hostResources == null) throw new ArgumentNullException (nameof (hostResources)); + HostResources = hostResources; + NativeContainer = nativeView; AddSubview (this.label); @@ -25,12 +27,6 @@ public PropertyContainer (IHostResourceProvider hostResources, INativeContainer AddSubview (NativeContainer.NativeView); NativeContainer.NativeView.TranslatesAutoresizingMaskIntoConstraints = false; - if (NativeContainer.NativeView is PropertyEditorControl pec && pec.FirstKeyView != null) { - AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, pec.FirstKeyView, NSLayoutAttribute.CenterY, 1, 0)); - } else { - AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 3)); - } - AddConstraints (new[] { NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.Right, 1f, LabelToControlSpacing), @@ -52,9 +48,25 @@ public PropertyContainer (IHostResourceProvider hostResources, INativeContainer } else { AddConstraint (NSLayoutConstraint.Create (NativeContainer.NativeView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0f)); } + } + } + + protected void UpdateLabelVerticalConstraint () + { + if (NativeContainer != null) { + if (NativeContainer.NativeView is PropertyEditorControl pec) { + if (pec.FirstKeyView != null) { + LabelVerticalContraint = NSLayoutConstraint.Create (LabelControl, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, pec.FirstKeyView, NSLayoutAttribute.CenterY, 1, 0); + } else { + LabelVerticalContraint = NSLayoutConstraint.Create (LabelControl, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, pec, NSLayoutAttribute.CenterY, 1, 0); + } + } } else { - AddConstraint (NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0)); + LabelVerticalContraint = NSLayoutConstraint.Create (LabelControl, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0); } + + if (LabelVerticalContraint != null) + AddConstraint (LabelVerticalContraint); } public string Label @@ -77,6 +89,7 @@ protected INativeContainer NativeContainer private const float EditorToButtonSpacing = 4f; private const float ButtonToWallSpacing = 17f; + protected NSLayoutConstraint LabelVerticalContraint { get; set; } private readonly PropertyButton propertyButton; private readonly UnfocusableTextField label = new UnfocusableTextField { @@ -86,5 +99,7 @@ protected INativeContainer NativeContainer }, TranslatesAutoresizingMaskIntoConstraints = false, }; + + protected IHostResourceProvider HostResources { get; private set; } } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs index bdbef9282..f877efc1a 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using AppKit; using Foundation; using Xamarin.PropertyEditing.ViewModels; @@ -35,12 +36,14 @@ public IHostResourceProvider HostResources public const string DefaultFontName = ".AppleSystemUIFont"; public const float DefaultButtonWidth = 70f; public virtual bool IsDynamicallySized => false; + public const float BottomOffset = -2f; + protected virtual nint BaseHeight => 24; PropertyViewModel viewModel; public PropertyViewModel ViewModel { get { return this.viewModel; } set { - if (this.ViewModel == value) + if (this.viewModel == value) return; PropertyViewModel oldModel = this.viewModel; @@ -90,7 +93,13 @@ public void UpdateKeyViews () } while (row > 0 && ctrl == null); if (ctrl != null) { - ctrl.LastKeyView.NextKeyView = FirstKeyView; + if (Superview is EditorContainer editorContainer && editorContainer.NextKeyView != null) { + editorContainer.NextKeyView.NextKeyView = FirstKeyView; + ctrl.LastKeyView.NextKeyView = editorContainer.NextKeyView; + } + else { + ctrl.LastKeyView.NextKeyView = FirstKeyView; + } ctrl.UpdateKeyViews (); } else if (row == 0 && view is PanelHeaderEditorControl header) { header.SetNextKeyView (FirstKeyView); @@ -98,10 +107,13 @@ public void UpdateKeyViews () } } - /// You should treat the implementation of this as static. public virtual nint GetHeight (EditorViewModel vm) { - return 24; + if (vm is PropertyViewModel realVm && realVm.IsVariant) { + return (nint)(BaseHeight + EditorContainer.VariationOptionFont.BoundingRectForFont.Height + (EditorContainer.VariationBorderOffset * 2)); // * 2 for upper and lower borders + } + + return BaseHeight; } protected virtual void UpdateValue () @@ -158,5 +170,7 @@ public PropertyEditorControl (IHostResourceProvider hostResources) get { return (TViewModel)base.ViewModel; } set { base.ViewModel = value; } } + + public override bool IsDynamicallySized => true; } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs index 7591c2b85..126d7e842 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs @@ -8,7 +8,7 @@ namespace Xamarin.PropertyEditing.Mac { internal class RatioEditorControl : PropertyEditorControl { - private RatioEditor ratioEditor; + private readonly RatioEditor ratioEditor; public RatioEditorControl (IHostResourceProvider hostResources) : base (hostResources) @@ -26,19 +26,19 @@ public RatioEditorControl (IHostResourceProvider hostResources) }; AddSubview (this.ratioEditor); - this.AddConstraints (new[] { - NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0), - NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0), - NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6), + AddConstraints (new[] { + NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1f, BottomOffset), + NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0), + NSLayoutConstraint.Create (this.ratioEditor, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), }); } - public override NSView FirstKeyView => ratioEditor.NumericEditor; - public override NSView LastKeyView => ratioEditor.DecrementButton; + public override NSView FirstKeyView => this.ratioEditor.NumericEditor; + public override NSView LastKeyView => this.ratioEditor.DecrementButton; protected override void SetEnabled () { - this.ratioEditor.Enabled = ViewModel.Property.CanWrite; + this.ratioEditor.Enabled = ViewModel.IsInputEnabled; } protected override void UpdateAccessibilityValues () diff --git a/Xamarin.PropertyEditing.Mac/Controls/RectangleEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/RectangleEditorControl.cs index 6341cee26..e85100d4e 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/RectangleEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/RectangleEditorControl.cs @@ -31,11 +31,6 @@ protected RectangleEditorControl (IHostResourceProvider hostResources) HeightEditor.Frame = new CGRect (132, 13, 90, 20); } - - public override nint GetHeight (EditorViewModel vm) - { - return 66; - } } internal class SystemRectangleEditorControl diff --git a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourceView.cs b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourceView.cs index 798342e03..5da920c30 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourceView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/RequestResource/RequestResourceView.cs @@ -26,9 +26,6 @@ internal class RequestResourceView NSSegmentedControl segmentedControl; NSButton showPreviewImage; RequestResourcePanel resourceSelectorPanel; - - public NSPopover PopOver { get; internal set; } - private bool showPreview; public bool ShowPreview { diff --git a/Xamarin.PropertyEditing.Mac/Controls/SizeEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/SizeEditorControl.cs index 7dad3f416..6f90de965 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/SizeEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/SizeEditorControl.cs @@ -23,11 +23,6 @@ public SizeEditorControl (IHostResourceProvider hostResource) YEditor.Frame = new CGRect (132, 13, 90, 20); } - public override nint GetHeight (EditorViewModel vm) - { - return 33; - } - protected override void UpdateAccessibilityValues () { XEditor.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityWidthEditor, ViewModel.Property.Name); diff --git a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs index e10ec78a8..e4a3f7183 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs @@ -57,7 +57,7 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel) AddConstraints (new[] { this.editorInputModeConstraint, - NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, Entry, NSLayoutAttribute.CenterY, 1f, 0), NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, DefaultButtonWidth), NSLayoutConstraint.Create (this.inputModePopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, Entry, NSLayoutAttribute.Height, 1, 0), @@ -85,10 +85,10 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel) protected override void SetEnabled () { - Entry.Enabled = ViewModel.Property.CanWrite && (((ViewModel.InputMode != null) && !ViewModel.InputMode.IsSingleValue) || (this.inputModePopup == null)); + Entry.Enabled = ViewModel.IsInputEnabled; if (this.inputModePopup != null) - this.inputModePopup.Enabled = ViewModel.Property.CanWrite; + this.inputModePopup.Enabled = ViewModel.IsInputEnabled; } protected override void UpdateAccessibilityValues () diff --git a/Xamarin.PropertyEditing.Mac/Controls/ThicknessEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/ThicknessEditorControl.cs index 05618d137..1e7395ba2 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/ThicknessEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/ThicknessEditorControl.cs @@ -30,11 +30,6 @@ public CommonThicknessEditorControl (IHostResourceProvider hostResources) HeightEditor.Frame = new CGRect (132, 13, 90, 20); } - public override nint GetHeight (EditorViewModel vm) - { - return 66; - } - protected override void OnInputUpdated (object sender, EventArgs e) { ViewModel.Value = (CommonThickness)Activator.CreateInstance (typeof (CommonThickness), HeightEditor.Value, XEditor.Value, WidthEditor.Value, YEditor.Value); diff --git a/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs index 9ee86d12b..01fa7d05c 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs @@ -48,7 +48,7 @@ protected override void UpdateValue () protected override void SetEnabled () { - this.selectType.Enabled = ViewModel.Property.CanWrite; + this.selectType.Enabled = ViewModel.IsInputEnabled; } protected override void UpdateAccessibilityValues () diff --git a/Xamarin.PropertyEditing.Mac/Controls/Variations/CreateVariantView.cs b/Xamarin.PropertyEditing.Mac/Controls/Variations/CreateVariantView.cs new file mode 100644 index 000000000..58b1f05aa --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/Variations/CreateVariantView.cs @@ -0,0 +1,124 @@ +using System; +using System.Reflection; +using System.Threading.Tasks; +using AppKit; +using CoreGraphics; +using Foundation; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class CreateVariantView + : NSView + { + private const int ControlSpacing = 7; + private const int HorizontalControlSpacing = 10; + internal const int RightEdgeMargin = 12; + + private readonly IHostResourceProvider hostResources; + + public CreateVariantView (IHostResourceProvider hostResources, CGSize windowWidthHeight, CreateVariantViewModel createVariantViewModel) + { + if (hostResources == null) + throw new ArgumentNullException (nameof (hostResources)); + + this.hostResources = hostResources; + + if (createVariantViewModel == null) + throw new ArgumentNullException (nameof (createVariantViewModel)); + + Initialize (createVariantViewModel, windowWidthHeight); + } + + private void Initialize (CreateVariantViewModel createVariantViewModel, CGSize windowWidthHeight) + { + Frame = new CGRect (CGPoint.Empty, windowWidthHeight); + + int editorHeight = 18; + + var FrameWidthThird = Frame.Width / 3; + + var introduceVariation = new UnfocusableTextField { + StringValue = Properties.Resources.AddVariationHelpText, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + AddSubview (introduceVariation); + + AddConstraints (new[] { + NSLayoutConstraint.Create (introduceVariation, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 8f), + NSLayoutConstraint.Create (introduceVariation, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 18f), + NSLayoutConstraint.Create (introduceVariation, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f), + NSLayoutConstraint.Create (introduceVariation, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight), + }); + + var controlTop = 33; + + foreach (VariationViewModel viewModel in createVariantViewModel.VariationCategories) { + + var name = new UnfocusableTextField { + Alignment = NSTextAlignment.Right, + StringValue = viewModel.Name + ":", + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + AddSubview (name); + + AddConstraints (new[] { + NSLayoutConstraint.Create (name, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, controlTop), + NSLayoutConstraint.Create (name, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, FrameWidthThird), + NSLayoutConstraint.Create (name, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight) + }); + + var popUpButton = new FocusablePopUpButton { + ControlSize = NSControlSize.Small, + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + popUpButton.Activated += (o, e) => { + if (o is FocusablePopUpButton fpb) { + if (fpb.SelectedItem.RepresentedObject is NSObjectFacade menuObjectFacade) { + if (menuObjectFacade.Target is VariationFacade vf) { + vf.ViewModel.SelectedOption = vf.Option; + } + } + } + }; + + var popUpButtonList = new NSMenu (); + popUpButton.Menu = popUpButtonList; + + AddSubview (popUpButton); + + AddConstraints (new[] { + NSLayoutConstraint.Create (popUpButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, controlTop), + NSLayoutConstraint.Create (popUpButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, FrameWidthThird + ControlSpacing), + NSLayoutConstraint.Create (popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -FrameWidthThird - ControlSpacing - RightEdgeMargin), + NSLayoutConstraint.Create (popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, editorHeight) + }); + + foreach (var variation in viewModel.Variations) { + popUpButtonList.AddItem (new NSMenuItem (variation.Name) { + RepresentedObject = new NSObjectFacade ( + new VariationFacade { + Option = variation, + ViewModel = viewModel + } + ) + }); + } + + controlTop += editorHeight + HorizontalControlSpacing; + } + + Frame = new CGRect (CGPoint.Empty, new CGSize (Frame.Width, controlTop)); + } + + private class VariationFacade + { + public PropertyVariationOption Option { get; set; } + public VariationViewModel ViewModel { get; set; } + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/Variations/CreateVariantWindow.cs b/Xamarin.PropertyEditing.Mac/Controls/Variations/CreateVariantWindow.cs new file mode 100644 index 000000000..3cb16d605 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/Variations/CreateVariantWindow.cs @@ -0,0 +1,94 @@ +using System; +using AppKit; +using CoreGraphics; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class CreateVariantWindow : NSPanel + { + public CreateVariantViewModel ViewModel { get; } + + private new ModalWindowCloseDelegate Delegate + { + get => (ModalWindowCloseDelegate)base.Delegate; + set => base.Delegate = value; + } + + private const int minWindowWidth = 250; + private const int minWindowHeight = 150; + + internal CreateVariantWindow (IHostResourceProvider hostResources, PropertyViewModel propertyViewModel) + : base (new CGRect (0, 0, minWindowWidth, minWindowHeight), NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable, NSBackingStore.Buffered, true) + { + if (hostResources == null) + throw new ArgumentNullException (nameof (hostResources)); + if (propertyViewModel == null) + throw new ArgumentNullException (nameof (propertyViewModel)); + + Delegate = new ModalWindowCloseDelegate (); + + FloatingPanel = true; + + Title = Properties.Resources.AddVariationTitle; + + MinSize = new CGSize (minWindowWidth, minWindowHeight); + + // put the MainContainer inside this panel's ContentView + ViewModel = new CreateVariantViewModel (propertyViewModel.Property); + var createVariantView = new CreateVariantView (hostResources, new CGSize(minWindowWidth, minWindowHeight), ViewModel) { + TranslatesAutoresizingMaskIntoConstraints = false + }; + ContentView.AddSubview (createVariantView); + + ContentView.AddConstraints (new[] { + NSLayoutConstraint.Create (createVariantView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (createVariantView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Left, 1f, 0f), + NSLayoutConstraint.Create (createVariantView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Height, 1f, 0f), + NSLayoutConstraint.Create (createVariantView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Width, 1f, 0f), + + }); + + var buttonOK = new FocusableCommandButton { + BezelStyle = NSBezelStyle.Rounded, + KeyEquivalent = "\r", + Command = ViewModel.CreateVariantCommand, + Enabled = false, + Highlighted = true, + Title = Properties.Resources.AddVariation, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + buttonOK.Activated += (sender, e) => { + Delegate.Response = NSModalResponse.OK; + Close (); + }; + + ContentView.AddSubview (buttonOK); + + ContentView.AddConstraints (new[] { + NSLayoutConstraint.Create (buttonOK, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Bottom, 1, -CreateVariantView.RightEdgeMargin), + NSLayoutConstraint.Create (buttonOK, NSLayoutAttribute.Right, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Right, 1, -CreateVariantView.RightEdgeMargin), + NSLayoutConstraint.Create (buttonOK, NSLayoutAttribute.Width, NSLayoutRelation.GreaterThanOrEqual, 1, 80) + }); + + var buttonCancel = new FocusableCommandButton { + BezelStyle = NSBezelStyle.Rounded, + Title = Properties.Resources.Cancel, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + buttonCancel.Activated += (sender, e) => { + Close (); + }; + + ContentView.AddSubview (buttonCancel); + + ContentView.AddConstraints (new[] { + NSLayoutConstraint.Create (buttonCancel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, buttonOK, NSLayoutAttribute.Top, 1f, 0f), + NSLayoutConstraint.Create (buttonCancel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, buttonOK, NSLayoutAttribute.Left, 1f, -10f), + NSLayoutConstraint.Create (buttonCancel, NSLayoutAttribute.Width, NSLayoutRelation.GreaterThanOrEqual, 1f, 80f), + }); + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-active-mac-10.png b/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-active-mac-10.png new file mode 100644 index 0000000000000000000000000000000000000000..41970fa90373811496804b5b64f5ae21a575a2f1 GIT binary patch literal 134 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4`FgrIhEy;nGc}ujJ*Xbu2W-ev^a$g|ir~WBkb|u@8OIsSa*bEGqyJJ|No@8=mk_y-$ zWRmrC{u@@=HQrVg{xg?siqYD=p;orz#FE_n2B8+NQ^K;*EDM8UEjkW8bW-Lz+gj`& zcT96miQ?Z=UzS}s-ez~>&hq2&e1EbP0l+XkK D+7?V5 literal 0 HcmV?d00001 diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-active-mac-10~dark.png b/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-active-mac-10~dark.png new file mode 100644 index 0000000000000000000000000000000000000000..aaeedf09216697e36f42e1696a8e227ea9307144 GIT binary patch literal 134 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4`FgrIhEy;nGc+FU|0~+CL#m^n z@gu(g?^A7q21cigK??u+S@m1B+g`YMFtuI~4L>X*r@Y{UgwI3%6-*&L7d|wH2y^b9 hs1h&C=N`n!Aa1nl3FpTRML>fYJYD@<);T3K0RW5*DKG#4 literal 0 HcmV?d00001 diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-active-mac-10~dark@2x.png b/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-active-mac-10~dark@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..3a03986109775b349d3c41f85bb7666c55208c17 GIT binary patch literal 204 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqEidBqD}?_&W#1w{_4U?8i3c{wwKcZ=@?OUwTH;fY zv}ke7QN24KoXywShFyw~(|w=NUjJ~~1lQlc8I~zn1S;Qn(3FrND0ApR#{$k~v4dM} zYf`xNDg*wV`s6&Zzqe+?*7@`5EMHuoUU%?RJ!Adi4>@t?H@5r-I*-BA)z4*}Q$iB} DvQAO5 literal 0 HcmV?d00001 diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-mac-10.png b/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-mac-10.png new file mode 100644 index 0000000000000000000000000000000000000000..237a216100d2b31f5cb3b5ee30f520f31435664a GIT binary patch literal 91 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2VkYHF5IUx~9F_i@Q1v4;|O+IS@BlKmvv4FO#l&76X*Z{ literal 0 HcmV?d00001 diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-mac-10~dark@2x.png b/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-add-button-mac-10~dark@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..e5a2dfcd5425baa16f4039d9ebc5fc4a683285b7 GIT binary patch literal 96 zcmeAS@N?(olHy`uVBq!ia0vp^A|T8GBp6maa=Hklm`Z~Df*BafCZDwc@+3W7978G? rlNV^-*gyYU)9;B4VUD{jI;Sx(d=yf++R1U838dB2)z4*}Q$iB}A3_=^ literal 0 HcmV?d00001 diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-active-mac-10.png b/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-active-mac-10.png new file mode 100644 index 0000000000000000000000000000000000000000..a288e71823ca92d247bb7af2b502210c120ffcda GIT binary patch literal 135 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4`FXlHhEy;nGc>N>`H#yXhWE(v zh9B%5ZJ$IX4lpdt&=mN8ylMI&QRmWs>`XhDOzKR19vX^x`uHAC;HpnB8-gMJ>)lmJKOxh4UT)0?z7TmudW&0+OU zd#rzx!AO@s`M*Y&`B@ zE@BkKe16)TS(7G;RU|yE(v*Bzx3K=yKi`k?((ey$i?{v%_(A=?Km2RHa_?Z6)NriJ TK%G4r=v)R*S3j3^P6f4`FXlHhEy;nGc^8hb>wo0;XQJ^ z;Rkz1+b2Bc)VcH@yU|0g3qP(Jv>p#oF*KEJ*8J0WRfXlBI|>F*$;qCZamC;grMXnpVY8{hoT*IWGP*Z`H&RMP+e literal 0 HcmV?d00001 diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-mac-10.png b/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variation-delete-button-mac-10.png new file mode 100755 index 0000000000000000000000000000000000000000..af9b55d85c5c083455215a95d6f048c41ec196d5 GIT binary patch literal 208 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4aTa()7Bet#3xhBt!>l*8o|0J>k`Kg{Rjv*C{Tl)`kHW=`@3VVMqU#xoy|4V0n6Qng=rbBl>&_V`JS3j3^P64lnuGc)x7?C%LnQkzxOr zd+W|>b{tM{D9O!rQCQ!iz5B$1b=%Bhd9&E1go>UYIl{CI=t2fhS3j3^P6f4aTa()7Bet#3xhBt!>l*8o|0J>k`Cgtbjv*C{Tl)`kGAQscFP?1Cq;1hO*~%%r zfW_Ug^;ba6mxb(&mt>|e#S2a>nLV{Y9PqMJJr&Kr+BSguXm{Px5o zEWPFCaeE2B#!-I$4xzp5M;Ul_9ridXu~<7;Qy}ww>rR5K9Z@bB=*%MN{U`wys n8r_L~+Y>Iac-`i)N@4Wh;<$BV^I>bCvlu*G{an^LB{Ts5oJ~&} literal 0 HcmV?d00001 diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variations-editor-32.png b/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variations-editor-32.png new file mode 100755 index 0000000000000000000000000000000000000000..976177be9833b6f5437e59b83bd1ff8c2f5c3469 GIT binary patch literal 282 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?2=RS;(M3{v?36l5$8 za(7}_cTVOdki(Mh=qIvR+m`y=v9^oO_P`=lOH( zHf-vc@wei0a6pJdn&Vm*oB2#zH^&#n@vkumDz$#!?Pzv|>q20ap6`~%iOn25hYeWj Y+qq4gH;DZ?0dzWpr>mdKI;Vst0AFZhI{*Lx literal 0 HcmV?d00001 diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variations-editor-32@2x.png b/Xamarin.PropertyEditing.Mac/PropertyEditingResource/Contents/Resources/pe-variations-editor-32@2x.png new file mode 100755 index 0000000000000000000000000000000000000000..f8767b4c06f1202a6f5b42c46e6d6c624ab5243a GIT binary patch literal 407 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=oCO|{#S9E$svykh8Km+7D9BhG zreIy?qZZ(sBGYP>3ayDV1f>xAIJOulP5IgO!;xL?uNb)(Ab8KRWa?$ zGLOCdzVH3!{gIQS4hk}`mT#Nqf4%11tzsr`hl3NDi)3%G+gLCuFmSASVYeXn_VYrS z{cno0=l7_3~Yl$)R?|aw6nlL-7`jXExJ7=Hb>F1k5?6)1_(yL*}JIAo?H5a=f}ml9}an}TKlB%N9_O237PEcxt2F;D*}VJv*Z=BqU6KZ6TY91hyPeg1Er{>&=h1a1wBEQgiM&l}|3nOGPacg|yebGI@y^!K)0@oyHF z59GXQ?%lg}hW<{wy!%X4b&#&R?>^%T$X*!U`S=e<NaUF@`a{w%>W(L1RYgyWt0K1o7OCSscx@D|^M#dnxxLXZ + + + diff --git a/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs b/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs index 991ef5b42..b4ab905fc 100644 --- a/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs +++ b/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs @@ -13,18 +13,68 @@ public MockSampleControl () { AddProperty ("Autoresizing", ReadWrite, valueSources: ValueSources.Local, ignoreEnum: true); AddProperty ("TimeSpan", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding); - AddProperty ("TimeSpanReadOnly", ReadOnly, canWrite: false, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding); + AddProperty ("ReadOnlyTimeSpan", ReadOnly, canWrite: false, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding); + AddProperty ("TimeSpanV", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding, + options: new[] { + new PropertyVariationOption ("Width", "Compact"), + new PropertyVariationOption ("Width", "Regular"), + new PropertyVariationOption ("Gamut", "P3"), + new PropertyVariationOption ("Gamut", "sRGB"), + new PropertyVariationOption ("OnPlatform", "iOS"), + new PropertyVariationOption ("OnPlatform", "Android"), + new PropertyVariationOption ("OnPlatform", "UWP"), + }); AddProperty ("Boolean", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding); + AddProperty ("BooleanV", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding, + options: new[] { + new PropertyVariationOption ("Width", "Compact"), + new PropertyVariationOption ("Width", "Regular"), + new PropertyVariationOption ("Gamut", "P3"), + new PropertyVariationOption ("Gamut", "sRGB"), + new PropertyVariationOption ("OnPlatform", "iOS"), + new PropertyVariationOption ("OnPlatform", "Android"), + new PropertyVariationOption ("OnPlatform", "UWP"), + }); AddProperty ("UnsetBoolean", ReadWrite, valueSources: ValueSources.Local); AddProperty ("Integer", ReadWrite); AddProperty ("UnsetInteger", ReadWrite, valueSources: ValueSources.Local); AddProperty ("FloatingPoint", ReadWrite); + AddProperty ("FloatingPointV", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding, + options: new[] { + new PropertyVariationOption ("Width", "Compact"), + new PropertyVariationOption ("Width", "Regular"), + new PropertyVariationOption ("Gamut", "P3"), + new PropertyVariationOption ("Gamut", "sRGB"), + new PropertyVariationOption ("OnPlatform", "iOS"), + new PropertyVariationOption ("OnPlatform", "Android"), + new PropertyVariationOption ("OnPlatform", "UWP"), + }); AddProperty ("Char", ReadWrite, valueSources: ValueSources.Local); - AddProperty ("CharReadOnly", ReadOnly, canWrite: false, valueSources: ValueSources.Local); + AddProperty ("CharV", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding, + options: new[] { + new PropertyVariationOption ("Width", "Compact"), + new PropertyVariationOption ("Width", "Regular"), + new PropertyVariationOption ("Gamut", "P3"), + new PropertyVariationOption ("Gamut", "sRGB"), + new PropertyVariationOption ("OnPlatform", "iOS"), + new PropertyVariationOption ("OnPlatform", "Android"), + new PropertyVariationOption ("OnPlatform", "UWP"), + }); + AddProperty ("ReadOnlyChar", ReadOnly, canWrite: false, valueSources: ValueSources.Local); AddProperty ("String", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding); AddProperty ("Width", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding, inputModes: new[] { new InputMode("Auto", true), new InputMode("Star"), new InputMode("Pixel"), }); AddProperty ("Enumeration", ReadWrite, constrained: false); AddProperty ("ConstrainedList", ReadWrite, constrained: true); + AddProperty ("EnumerationV", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding, + options: new[] { + new PropertyVariationOption ("Width", "Compact"), + new PropertyVariationOption ("Width", "Regular"), + new PropertyVariationOption ("Gamut", "P3"), + new PropertyVariationOption ("Gamut", "sRGB"), + new PropertyVariationOption ("OnPlatform", "iOS"), + new PropertyVariationOption ("OnPlatform", "Android"), + new PropertyVariationOption ("OnPlatform", "UWP"), + }); AddProperty ("StringV", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding, options: new [] { new PropertyVariationOption ("Width", "Compact"), @@ -39,8 +89,28 @@ public MockSampleControl () AddProperty ("FlagsWithValues", ReadWrite, canWrite: true, flag: true); AddProperty ("prefix:FlagsWithColonInLabel", ReadWrite, canWrite: true, flag: true); AddProperty ("Point", ReadWrite, isUncommon: true); + AddProperty ("PointV", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding, + options: new[] { + new PropertyVariationOption ("Width", "Compact"), + new PropertyVariationOption ("Width", "Regular"), + new PropertyVariationOption ("Gamut", "P3"), + new PropertyVariationOption ("Gamut", "sRGB"), + new PropertyVariationOption ("OnPlatform", "iOS"), + new PropertyVariationOption ("OnPlatform", "Android"), + new PropertyVariationOption ("OnPlatform", "UWP"), + }); AddProperty ("Size", ReadWrite, isUncommon: true); AddProperty ("Rectangle", ReadWrite); + AddProperty ("RectangleV", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding, + options: new[] { + new PropertyVariationOption ("Width", "Compact"), + new PropertyVariationOption ("Width", "Regular"), + new PropertyVariationOption ("Gamut", "P3"), + new PropertyVariationOption ("Gamut", "sRGB"), + new PropertyVariationOption ("OnPlatform", "iOS"), + new PropertyVariationOption ("OnPlatform", "Android"), + new PropertyVariationOption ("OnPlatform", "UWP"), + }); AddProperty ("Ratio", ReadWrite); AddProperty ("Thickness", ReadWrite); AddProperty ("Object", ReadWrite); @@ -51,6 +121,16 @@ public MockSampleControl () AddReadOnlyProperty ("ReadOnlyInteger", ReadOnly); AddReadOnlyProperty ("ReadOnlyFloatingPoint", ReadOnly); AddReadOnlyProperty ("ReadOnlyString", ReadOnly); + AddProperty ("ReadOnlyStringV", ReadOnly, canWrite: false, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding, + options: new[] { + new PropertyVariationOption ("Width", "Compact"), + new PropertyVariationOption ("Width", "Regular"), + new PropertyVariationOption ("Gamut", "P3"), + new PropertyVariationOption ("Gamut", "sRGB"), + new PropertyVariationOption ("OnPlatform", "iOS"), + new PropertyVariationOption ("OnPlatform", "Android"), + new PropertyVariationOption ("OnPlatform", "UWP"), + }); AddReadOnlyProperty ("ReadOnlyEnumeration", ReadOnly); AddProperty ("ReadOnlyFlagsNotValue", ReadOnly, canWrite: false, flag: true); AddProperty ("ReadOnlyFlagsWithValues", ReadOnly, canWrite: false, flag: true); @@ -102,7 +182,7 @@ public MockSampleControl () AddProperty ("FilePath", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding); AddReadOnlyProperty ("ReadOnlyFilePath", ReadOnly); AddProperty ("DateTime", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding); - AddReadOnlyProperty ("ReadDateTime", ReadOnly); + AddReadOnlyProperty ("ReadOnlyDateTime", ReadOnly); AddEvents ("Click", "Hover", "Focus"); diff --git a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs index 2218d2664..a82a4102f 100644 --- a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs +++ b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs @@ -1480,5 +1480,23 @@ public static string FilterTypePlaceholder { return ResourceManager.GetString("FilterTypePlaceholder", resourceCulture); } } + + public static string AddVariation { + get { + return ResourceManager.GetString("AddVariation", resourceCulture); + } + } + + public static string AccessibilityAddVariationButton { + get { + return ResourceManager.GetString("AccessibilityAddVariationButton", resourceCulture); + } + } + + public static string AccessibilityDeleteVariationButton { + get { + return ResourceManager.GetString("AccessibilityDeleteVariationButton", resourceCulture); + } + } } } diff --git a/Xamarin.PropertyEditing/Properties/Resources.resx b/Xamarin.PropertyEditing/Properties/Resources.resx index 87e56310f..0adb89054 100644 --- a/Xamarin.PropertyEditing/Properties/Resources.resx +++ b/Xamarin.PropertyEditing/Properties/Resources.resx @@ -1043,5 +1043,17 @@ Filter Types Placeholder for filter type control + + + Add + Button text telling the user clicking this will add the variation + + + Add a variation to this property + Button to add a variatione + + + Delete the variation associated with this property + Button to delete a variation \ No newline at end of file From 9ebc78351702013b5b962c59e6c48d67acaf0267 Mon Sep 17 00:00:00 2001 From: CartBlanche Date: Mon, 16 Dec 2019 10:41:45 +0000 Subject: [PATCH 2/2] [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;