diff options
author | Dominique Louis <savagesoftware@gmail.com> | 2017-10-05 21:53:34 +0300 |
---|---|---|
committer | Dominique Louis <savagesoftware@gmail.com> | 2017-10-23 14:38:02 +0300 |
commit | 9763016b448fe40067d4cb1d6e07054feb7b7e21 (patch) | |
tree | be9c79f4d0ad6c305362eca5dd70a9e20517e70d | |
parent | cde79776ba284270af7d9a02f3c8ddc373ebb555 (diff) |
[Mac]Initial implementation of ErrorButton.
11 files changed, 121 insertions, 72 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs new file mode 100644 index 0000000..6070fc5 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using AppKit; +using CoreGraphics; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class BaseEditorControl : NSView + { + NSButton errorButton; + IEnumerable errorList; + + public BaseEditorControl () + { + errorButton = new NSButton () { + Bordered = false, + Cell = { BackgroundColor = NSColor.Clear }, + Enabled = false, + Title = string.Empty, + TranslatesAutoresizingMaskIntoConstraints = false, + ImageScaling = NSImageScale.AxesIndependently, + }; + + errorButton.Activated += (object sender, EventArgs e) => { + var Container = new ErrorMessageView (errorList) { + Frame = new CGRect (CGPoint.Empty, new CGSize (320, 200)) + }; + + var errorMessagePopUp = new NSPopover { + Behavior = NSPopoverBehavior.Semitransient, + ContentViewController = new NSViewController (null, null) { View = Container }, + }; + + errorMessagePopUp.Show (default (CGRect), errorButton, NSRectEdge.MinYEdge); + }; + + AddSubview (errorButton); + + this.DoConstraints (new[] { + errorButton.ConstraintTo (this, (cb, c) => cb.Width == 20), + errorButton.ConstraintTo (this, (cb, c) => cb.Height == 20), + errorButton.ConstraintTo (this, (cb, c) => cb.Left == c.Right - 22), + errorButton.ConstraintTo (this, (cb, c) => cb.Top == c.Top + 4), + }); + + PropertyEditorPanel.ThemeManager.ThemeChanged += (object sender, EventArgs e) => { + UpdateTheme (); + }; + } + + protected void UpdateTheme () + { + this.Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance; + } + + protected void SetErrors (IEnumerable errors) + { + errorList = errors; + + errorButton.Enabled = errors != null; + // Using NSImageName.Caution for now, we can change this later at the designers behest + errorButton.Image = errorButton.Enabled ? NSImage.ImageNamed (NSImageName.Caution) : null; + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseNumericEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseNumericEditorControl.cs index 0b1d1c6..bcad27d 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BaseNumericEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BaseNumericEditorControl.cs @@ -19,7 +19,7 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (NumericEditor); this.DoConstraints ( new[] { - NumericEditor.ConstraintTo (this, (n, c) => n.Width == c.Width), + NumericEditor.ConstraintTo (this, (n, c) => n.Width == c.Width - 27), }); } @@ -48,14 +48,9 @@ namespace Xamarin.PropertyEditing.Mac protected override void UpdateErrorsDisplayed (IEnumerable errors) { if (ViewModel.HasErrors) { - NumericEditor.BackgroundColor = NSColor.Red; - Debug.WriteLine ("Your input triggered an error:"); - foreach (var error in errors) { - Debug.WriteLine (error.ToString () + "\n"); - } - } - else { - NumericEditor.BackgroundColor = NSColor.Clear; + SetErrors (errors); + } else { + SetErrors (null); SetEnabled (); } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs index 80e735b..0ac3759 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BasePointEditorControl.cs @@ -60,15 +60,9 @@ namespace Xamarin.PropertyEditing.Mac protected override void UpdateErrorsDisplayed (IEnumerable errors) { if (ViewModel.HasErrors) { - XEditor.BackgroundColor = NSColor.Red; - YEditor.BackgroundColor = NSColor.Red; - Debug.WriteLine ("Your input triggered 1 or more errors:"); - foreach (var error in errors) { - Debug.WriteLine (error.ToString () + "\n"); - } + SetErrors (errors); } else { - XEditor.BackgroundColor = NSColor.Clear; - YEditor.BackgroundColor = NSColor.Clear; + SetErrors (null); SetEnabled (); } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs index 67dddc3..0eef688 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BaseRectangleEditorControl.cs @@ -80,20 +80,9 @@ namespace Xamarin.PropertyEditing.Mac protected override void UpdateErrorsDisplayed (IEnumerable errors) { if (ViewModel.HasErrors) { - XEditor.BackgroundColor = NSColor.Red; - YEditor.BackgroundColor = NSColor.Red; - WidthEditor.BackgroundColor = NSColor.Red; - HeightEditor.BackgroundColor = NSColor.Red; - Debug.WriteLine ("Your input triggered an error:"); - foreach (var error in errors) { - Debug.WriteLine (error.ToString () + "\n"); - } - } - else { - XEditor.BackgroundColor = NSColor.Clear; - YEditor.BackgroundColor = NSColor.Clear; - WidthEditor.BackgroundColor = NSColor.Clear; - HeightEditor.BackgroundColor = NSColor.Clear; + SetErrors (errors); + } else { + SetErrors (null); SetEnabled (); } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs index b5fe876..95f70e3 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs @@ -59,17 +59,9 @@ namespace Xamarin.PropertyEditing.Mac protected override void UpdateErrorsDisplayed (IEnumerable errors) { if (ViewModel.HasErrors) { - if (this.BooleanEditor.RespondsToSelector (new Selector (setBezelColorSelector))) { - BooleanEditor.BezelColor = NSColor.Red; - } - Debug.WriteLine ("Your input triggered an error:"); - foreach (var error in errors) { - Debug.WriteLine (error.ToString () + "\n"); - } + SetErrors (errors); } else { - if (this.BooleanEditor.RespondsToSelector (new Selector (setBezelColorSelector)) && BooleanEditor.Enabled) { - BooleanEditor.BezelColor = NSColor.Clear; - } + SetErrors (null); SetEnabled (); } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs b/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs new file mode 100644 index 0000000..7fb8de4 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections; +using AppKit; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class ErrorMessageView : BaseEditorControl + { + NSTextField ErrorMessages; + + public ErrorMessageView (IEnumerable errors) + { + if (errors == null) + throw new ArgumentNullException ("errors"); + + ErrorMessages = new NSTextField { + TranslatesAutoresizingMaskIntoConstraints = false, + BackgroundColor = NSColor.Clear, + Editable = false, + }; + + foreach (var error in errors) { + ErrorMessages.StringValue += error + "\n"; + } + + AddSubview (ErrorMessages); + + this.DoConstraints (new[] { + ErrorMessages.ConstraintTo (this, (s, c) => s.Width == c.Width - 5), + ErrorMessages.ConstraintTo (this, (s, c) => s.Height == c.Height - 5), + }); + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs index f8bdebc..7e17dae 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs @@ -36,7 +36,7 @@ namespace Xamarin.PropertyEditing.Mac AddSubview (this.comboBox); this.DoConstraints (new[] { - comboBox.ConstraintTo (this, (cb, c) => cb.Width == c.Width), + comboBox.ConstraintTo (this, (cb, c) => cb.Width == c.Width - 28), comboBox.ConstraintTo (this, (cb, c) => cb.Left == c.Left), }); @@ -61,13 +61,9 @@ namespace Xamarin.PropertyEditing.Mac protected override void UpdateErrorsDisplayed (IEnumerable errors) { if (ViewModel.HasErrors) { - this.comboBox.BackgroundColor = NSColor.Red; - Debug.WriteLine ("Your input triggered an error:"); - foreach (var error in errors) { - Debug.WriteLine (error.ToString () + "\n"); - } + SetErrors (errors); } else { - comboBox.BackgroundColor = NSColor.Clear; + SetErrors (null); SetEnabled (); } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs index efcd4c1..92a71ac 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs @@ -7,7 +7,7 @@ using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { - internal abstract class PropertyEditorControl : ThemedControl + internal abstract class PropertyEditorControl : BaseEditorControl { public string Label { get; set; } @@ -96,19 +96,4 @@ namespace Xamarin.PropertyEditing.Mac protected abstract void UpdateAccessibilityValues (); } - - internal class ThemedControl : NSView - { - public ThemedControl () - { - PropertyEditorPanel.ThemeManager.ThemeChanged += (object sender, EventArgs e) => { - UpdateTheme (); - }; - } - - protected void UpdateTheme () - { - this.Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance; - } - } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs index aa27bee..d5f28d0 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs @@ -24,8 +24,8 @@ namespace Xamarin.PropertyEditing.Mac }; AddSubview (StringEditor); - this.DoConstraints (new[] { - StringEditor.ConstraintTo (this, (s, c) => s.Width == c.Width), + this.DoConstraints (new[] { + StringEditor.ConstraintTo (this, (s, c) => s.Width == c.Width - 30), }); UpdateTheme (); @@ -54,13 +54,9 @@ namespace Xamarin.PropertyEditing.Mac protected override void UpdateErrorsDisplayed (IEnumerable errors) { if (ViewModel.HasErrors) { - StringEditor.BackgroundColor = NSColor.Red; - Debug.WriteLine ("Your input triggered an error:"); - foreach (var error in errors) { - Debug.WriteLine (error.ToString () + "\n"); - } + SetErrors (errors); } else { - StringEditor.BackgroundColor = NSColor.Clear; + SetErrors (null); SetEnabled (); } } diff --git a/Xamarin.PropertyEditing.Mac/Icons/warning-16@2x.png b/Xamarin.PropertyEditing.Mac/Icons/warning-16@2x.png Binary files differnew file mode 100644 index 0000000..8dd44e1 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Icons/warning-16@2x.png diff --git a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj index ca93c3f..b491216 100644 --- a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj +++ b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj @@ -86,6 +86,8 @@ <Folder Include="Controls\Custom\" />
<Folder Include="Resources\" />
<Compile Include="Themes\MacThemeManager.cs" />
+ <Compile Include="Controls\BaseEditorControl.cs" />
+ <Compile Include="Controls\ErrorMessageView.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controls\" />
|