diff options
author | Dominique Louis <savagesoftware@gmail.com> | 2018-09-06 19:39:20 +0300 |
---|---|---|
committer | Dominique Louis <dominique@DIPRAJ1.northamerica.corp.microsoft.com> | 2019-05-01 17:28:53 +0300 |
commit | ed2c36589052687c65bfd5c969211d859c236c85 (patch) | |
tree | ff7e0b183680066e262a6c3e882721e5bd312ed8 /Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs | |
parent | f74e027bd387a82be39e9458ddea1d9edfefaa0a (diff) |
[Mac] Initial implementation of Autocompletion.dominique-Autocompletion
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs')
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs index 49ed8b0..ed82e78 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CustomExpressionView.cs @@ -4,43 +4,57 @@ using AppKit; using CoreGraphics; using Foundation; using ObjCRuntime; +using Xamarin.PropertyEditing.Mac.Controls; using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Mac { internal class CustomExpressionView : BasePopOverViewModelControl { - Type vmType; - const string CustomExpressionPropertyString = "CustomExpression"; - PropertyInfo customExpressionPropertyInfo; + private const string CustomExpressionPropertyString = "CustomExpression"; + 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") { Frame = new CGRect (CGPoint.Empty, new CGSize (250, 80)); - var customExpressionField = new NSTextField { - StringValue = string.Empty, - TranslatesAutoresizingMaskIntoConstraints = false, - }; + Type vmType = viewModel.GetType (); + + PropertyInfo previewCustomExpressionPropertyInfo = vmType.GetProperty (PreviewCustomExpressionString); + previewCustomExpressionPropertyInfo.SetValue (viewModel, string.Empty); + + PropertyInfo customExpressionPropertyInfo = vmType.GetProperty (CustomExpressionPropertyString); + var value = customExpressionPropertyInfo.GetValue (viewModel); + + NSControl editorControl = null; + PropertyInfo customAutocompleteItemsPropertyInfo = vmType.GetProperty (AutocompleteItemsString); + if (customAutocompleteItemsPropertyInfo.GetValue (viewModel) is ObservableCollectionEx<string> values) { + if (values != null && values.Count > 0) { + editorControl = new AutocompleteComboBox (hostResources, viewModel, values, previewCustomExpressionPropertyInfo); + } else { + editorControl = new NSTextField (); + } + } - this.vmType = viewModel.GetType (); - this.customExpressionPropertyInfo = vmType.GetProperty (CustomExpressionPropertyString); - var value = this.customExpressionPropertyInfo.GetValue (viewModel); - if (value != null) - customExpressionField.StringValue = (string)value; + editorControl.TranslatesAutoresizingMaskIntoConstraints = false; + editorControl.StringValue = (string)value ?? string.Empty; - customExpressionField.Activated += (sender, e) => { - this.customExpressionPropertyInfo.SetValue (viewModel, customExpressionField.StringValue); + editorControl.Activated += (sender, e) => { + PopOver.CloseOnEnter = true; + customExpressionPropertyInfo.SetValue (viewModel, editorControl.StringValue); }; - AddSubview (customExpressionField); + AddSubview (editorControl); this.AddConstraints (new[] { - NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 37f), - NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 38f), - NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -57f), - NSLayoutConstraint.Create (customExpressionField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 18), + 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), + NSLayoutConstraint.Create (editorControl, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, PropertyEditorControl.DefaultControlHeight), }); } } |