diff options
10 files changed, 182 insertions, 13 deletions
diff --git a/Xamarin.PropertyEditing.Mac.Standalone/ViewController.cs b/Xamarin.PropertyEditing.Mac.Standalone/ViewController.cs index 4f1d6e8..5f4acef 100644 --- a/Xamarin.PropertyEditing.Mac.Standalone/ViewController.cs +++ b/Xamarin.PropertyEditing.Mac.Standalone/ViewController.cs @@ -17,8 +17,8 @@ namespace Xamarin.PropertyEditing.Mac.Standalone public override void ViewDidLoad () { base.ViewDidLoad (); - // Do any additional setup after loading the view. + // Do any additional setup after loading the view. PropertyPanel.TargetPlatform = new TargetPlatform (new MockEditorProvider ()) { SupportsCustomExpressions = true, SupportsMaterialDesign = true, diff --git a/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs index 8454162..1549c3a 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BaseEditorControl.cs @@ -20,7 +20,6 @@ namespace Xamarin.PropertyEditing.Mac get { return actionButton; } } - public event EventHandler PropertyButtonClicked; PropertyButton propertyButton; public PropertyButton PropertyButton { @@ -103,11 +102,6 @@ namespace Xamarin.PropertyEditing.Mac actionButton.Image = actionButton.Enabled ? NSImage.ImageNamed ("action-warning-16") : null; } - void NotifyPropertyButtonClicked () - { - PropertyButtonClicked?.Invoke (this, EventArgs.Empty); - } - void NotifyActioButtonClicked () { ActionButtonClicked?.Invoke (this, EventArgs.Empty); diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/AutoClosePopOver.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/AutoClosePopOver.cs new file mode 100644 index 0000000..2c2355f --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/AutoClosePopOver.cs @@ -0,0 +1,21 @@ +using System; +using AppKit; + +namespace Xamarin.PropertyEditing.Mac +{ + public class AutoClosePopOver : NSPopover + { + public AutoClosePopOver () : base () + { + Behavior = NSPopoverBehavior.Semitransient; + } + + public override void KeyUp (NSEvent theEvent) + { + // If Enter Kit, close the pop-up + if (theEvent.KeyCode == 36) { + this.Close (); + } + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs new file mode 100644 index 0000000..ff851b0 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverControl.cs @@ -0,0 +1,51 @@ +using System; +using AppKit; +using CoreGraphics; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class BasePopOverControl : NSView + { + const int DefaultIconButtonSize = 24; + + public BasePopOverControl (string title, string imageNamed) : base () + { + if (title == null) + throw new ArgumentNullException (nameof (title)); + if (imageNamed == null) + throw new ArgumentNullException (nameof (imageNamed)); + + TranslatesAutoresizingMaskIntoConstraints = false; + WantsLayer = true; + + var iconView = new NSImageView { + Image = NSImage.ImageNamed (imageNamed), + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + iconView.Image = NSImage.ImageNamed (PropertyEditorPanel.ThemeManager.Theme == Themes.PropertyEditorTheme.Dark ? imageNamed + "~dark" : imageNamed); + + AddSubview (iconView); + + var viewTitle = new UnfocusableTextField () { + StringValue = title, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + AddSubview (viewTitle); + + this.DoConstraints (new[] { + iconView.ConstraintTo (this, (iv, c) => iv.Top == c.Top + 5), + iconView.ConstraintTo (this, (iv, c) => iv.Left == c.Left + 5), + iconView.ConstraintTo (this, (iv, c) => iv.Width == DefaultIconButtonSize), + iconView.ConstraintTo (this, (iv, c) => iv.Height == DefaultIconButtonSize), + viewTitle.ConstraintTo (this, (vt, c) => vt.Top == c.Top + 6), + viewTitle.ConstraintTo (this, (vt, c) => vt.Left == c.Left + 30), + viewTitle.ConstraintTo (this, (vt, c) => vt.Width == 120), + viewTitle.ConstraintTo (this, (vt, c) => vt.Height == 24), + }); + + this.Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance; + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs new file mode 100644 index 0000000..8cb139d --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class BasePopOverViewModelControl : BasePopOverControl + { + internal PropertyViewModel ViewModel { get; } + + public BasePopOverViewModelControl (PropertyViewModel viewModel, string title, string imageNamed) : base (title, imageNamed) + { + if (viewModel == null) + throw new ArgumentNullException (nameof (viewModel)); + + this.ViewModel = viewModel; + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs index 1cdc73e..fd1039a 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommandMenuItem.cs @@ -32,8 +32,9 @@ namespace Xamarin.PropertyEditing.Mac private void HookUpCommandEvents () { Activated += (object sender, EventArgs e) => { - if (this.command != null) - this.command.Execute (null); + if (this.command != null) { + this.command.Execute (null); + } }; ValidateMenuItem = ValidatePropertyMenuItem; diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs index 8d13bfa..41a555f 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyButton.cs @@ -1,5 +1,4 @@ using System; -using System.Windows.Input; using AppKit; using CoreGraphics; using Xamarin.PropertyEditing.ViewModels; @@ -15,8 +14,9 @@ namespace Xamarin.PropertyEditing.Mac { get { return viewModel; } set { - if (viewModel != null) + if (viewModel != null) { viewModel.PropertyChanged -= OnPropertyChanged; + } viewModel = value; viewModel.PropertyChanged += OnPropertyChanged; @@ -46,8 +46,29 @@ namespace Xamarin.PropertyEditing.Mac if (this.popUpContextMenu == null) { this.popUpContextMenu = new NSMenu (); + if (this.viewModel.TargetPlatform.SupportsCustomExpressions) { + var mi = new NSMenuItem (Properties.Resources.CustomExpressionEllipsis) { + AttributedTitle = new Foundation.NSAttributedString ( + Properties.Resources.CustomExpressionEllipsis, + new CoreText.CTStringAttributes () { + Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1), + }) + }; + + mi.Activated += OnCustomExpression; + + this.popUpContextMenu.AddItem (mi); + this.popUpContextMenu.AddItem (NSMenuItem.SeparatorItem); + } + // TODO If we add more menu items consider making the Label/Command a dictionary that we can iterate over to populate everything. - this.popUpContextMenu.AddItem (new CommandMenuItem (Properties.Resources.Reset, viewModel.ClearValueCommand)); + this.popUpContextMenu.AddItem (new CommandMenuItem (Properties.Resources.Reset, viewModel.ClearValueCommand) { + AttributedTitle = new Foundation.NSAttributedString ( + Properties.Resources.Reset, + new CoreText.CTStringAttributes () { + Font = new CoreText.CTFont (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize + 1), + }) + }); } var menuOrigin = this.Superview.ConvertPointToView (new CGPoint (Frame.Location.X - 1, Frame.Location.Y + Frame.Size.Height + 4), null); @@ -112,5 +133,16 @@ namespace Xamarin.PropertyEditing.Mac ValueSourceChanged (viewModel.ValueSource); } } + + private void OnCustomExpression (object sender, EventArgs e) + { + var customExpressionView = new CustomExpressionView (viewModel); + + var customExpressionPopOver = new AutoClosePopOver { + ContentViewController = new NSViewController (null, null) { View = customExpressionView }, + }; + + customExpressionPopOver.Show (customExpressionView.Frame, (NSView)this, NSRectEdge.MinYEdge); + } } } diff --git a/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs new file mode 100644 index 0000000..17be2bc --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs @@ -0,0 +1,46 @@ +using System; +using System.Reflection; +using AppKit; +using CoreGraphics; +using Foundation; +using ObjCRuntime; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class CustomExpressionView : BasePopOverViewModelControl + { + Type vmType; + const string CustomExpressionPropertyString = "CustomExpression"; + PropertyInfo customExpressionPropertyInfo; + + public CustomExpressionView (PropertyViewModel viewModel) : base (viewModel, Properties.Resources.CustomExpression, "custom-expression-32") + { + Frame = new CGRect (CGPoint.Empty, new CGSize (250, 60)); + + var customExpressionField = new NSTextField { + StringValue = string.Empty, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + vmType = viewModel.GetType (); + customExpressionPropertyInfo = vmType.GetProperty (CustomExpressionPropertyString); + var value = customExpressionPropertyInfo.GetValue (viewModel); + if (value != null) + customExpressionField.StringValue = (string)value; + + customExpressionField.Activated += (sender, e) => { + customExpressionPropertyInfo.SetValue (viewModel, customExpressionField.StringValue); + }; + + AddSubview (customExpressionField); + + this.DoConstraints (new[] { + customExpressionField.ConstraintTo (this, (s, c) => s.Top == c.Top + 30), + customExpressionField.ConstraintTo (this, (s, c) => s.Left == c.Left + 30), + customExpressionField.ConstraintTo (this, (s, c) => s.Width == c.Width - 37), + customExpressionField.ConstraintTo (this, (s, c) => s.Height == 24), + }); + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs b/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs index 398c27c..9d1a814 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/ErrorMessageView.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using AppKit; using CoreGraphics; -using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { @@ -39,6 +38,7 @@ namespace Xamarin.PropertyEditing.Mac Editable = false, TranslatesAutoresizingMaskIntoConstraints = false, }; + ErrorMessages.Cell.Wraps = true; foreach (var error in errors) { ErrorMessages.StringValue += error + "\n"; diff --git a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj index 04bc0e4..4cb237f 100644 --- a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj +++ b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj @@ -88,6 +88,10 @@ <Compile Include="Controls\CombinablePropertyEditor.cs" />
<Compile Include="Controls\Custom\PropertyButton.cs" />
<Compile Include="Controls\Custom\CommandMenuItem.cs" />
+ <Compile Include="Controls\Custom\BasePopOverControl.cs" />
+ <Compile Include="Controls\Custom\BasePopOverViewModelControl.cs" />
+ <Compile Include="Controls\CustomExpressionView.cs" />
+ <Compile Include="Controls\Custom\AutoClosePopOver.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controls\" />
|