diff options
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs')
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs index 3e3c983..a3dfaff 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs @@ -11,31 +11,27 @@ namespace Xamarin.PropertyEditing.Mac { internal abstract class BaseEditorControl : NSView { - IEnumerable errorList; - const int DefaultActioButtonSize = 16; + private IEnumerable errorList; + private const int DefaultActioButtonSize = 16; public event EventHandler ActionButtonClicked; - NSButton actionButton; - public NSButton ActionButton - { - get { return actionButton; } - } - PropertyButton propertyButton; - public PropertyButton PropertyButton - { - get { return propertyButton; } - } + private NSButton actionButton; + public NSButton ActionButton => this.actionButton; + + private PropertyButton propertyButton; + public PropertyButton PropertyButton => this.propertyButton; + public BaseEditorControl () { - propertyButton = new PropertyButton { + this.propertyButton = new PropertyButton { TranslatesAutoresizingMaskIntoConstraints = false }; - AddSubview (propertyButton); + AddSubview (this.propertyButton); - actionButton = new NSButton { + this.actionButton = new NSButton { Bordered = false, Enabled = false, ImageScaling = NSImageScale.AxesIndependently, @@ -46,19 +42,19 @@ namespace Xamarin.PropertyEditing.Mac }; #if DESIGNER_DEBUG - actionButton.Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("action-warning-16"); + this.actionButton.Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("action-warning-16"); #endif - actionButton.Activated += (object sender, EventArgs e) => { - if (errorList != null) { - var Container = new ErrorMessageView (errorList); + this.actionButton.Activated += (object sender, EventArgs e) => { + if (this.errorList != null) { + var Container = new ErrorMessageView (this.errorList); var errorMessagePopUp = new NSPopover { Behavior = NSPopoverBehavior.Semitransient, ContentViewController = new NSViewController (null, null) { View = Container }, }; - errorMessagePopUp.Show (default (CGRect), actionButton, NSRectEdge.MinYEdge); + errorMessagePopUp.Show (default (CGRect), this.actionButton, NSRectEdge.MinYEdge); } NotifyActionButtonClicked (); @@ -66,15 +62,16 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (actionButton); - this.DoConstraints (new[] { - propertyButton.ConstraintTo (this, (ab, c) => ab.Width == PropertyButton.DefaultSize), - propertyButton.ConstraintTo (this, (ab, c) => ab.Height == PropertyButton.DefaultSize), - propertyButton.ConstraintTo (this, (ab, c) => ab.Top == c.Top + 1), - propertyButton.ConstraintTo (this, (ab, c) => ab.Left == c.Right - 33), - actionButton.ConstraintTo (this, (eb, c) => eb.Width == DefaultActioButtonSize), - actionButton.ConstraintTo (this, (eb, c) => eb.Height == DefaultActioButtonSize), - actionButton.ConstraintTo (propertyButton, (eb, ab) => eb.Left == ab.Left + PropertyButton.DefaultSize), - actionButton.ConstraintTo (this, (eb, c) => eb.Top == c.Top + 3), // TODO: Better centering based on the icon height + this.AddConstraints (new[] { + NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 1f), + NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, -33f), + NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, PropertyButton.DefaultSize), + NSLayoutConstraint.Create (this.propertyButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyButton.DefaultSize), + + NSLayoutConstraint.Create (this.actionButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 3f), // TODO: Better centering based on the icon height + NSLayoutConstraint.Create (this.actionButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.propertyButton, NSLayoutAttribute.Left, 1f, 20f), + NSLayoutConstraint.Create (this.actionButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1f, DefaultActioButtonSize), + NSLayoutConstraint.Create (this.actionButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultActioButtonSize), }); PropertyEditorPanel.ThemeManager.ThemeChanged += ThemeManager_ThemeChanged; @@ -99,13 +96,13 @@ namespace Xamarin.PropertyEditing.Mac protected void SetErrors (IEnumerable errors) { - errorList = errors; + this.errorList = errors; - actionButton.Enabled = errors != null; - actionButton.Hidden = !actionButton.Enabled; + this.actionButton.Enabled = errors != null; + this.actionButton.Hidden = !this.actionButton.Enabled; // Using NSImageName.Caution for now, we can change this later at the designers behest - actionButton.Image = actionButton.Enabled ? PropertyEditorPanel.ThemeManager.GetImageForTheme ("action-warning-16") : null; + this.actionButton.Image = this.actionButton.Enabled ? PropertyEditorPanel.ThemeManager.GetImageForTheme ("action-warning-16") : null; } void NotifyActionButtonClicked () |