diff options
author | CartBlanche <savagesoftware@gmail.com> | 2019-09-26 14:39:54 +0300 |
---|---|---|
committer | CartBlanche <savagesoftware@gmail.com> | 2019-10-16 19:21:42 +0300 |
commit | 60f61ea12d0e2449bc1f72cab473902dff78fcd3 (patch) | |
tree | 0debceb725714552d41620864b6544f2c540108f | |
parent | 723122c1579c45feea7157b206e3da5937e96caf (diff) |
[Mac] Stateful Group Editor Control Initial Implementationdominique-StatefulProperties
15 files changed, 510 insertions, 16 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs index c62c822..f8292d3 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs @@ -40,7 +40,7 @@ namespace Xamarin.PropertyEditing.Mac } } - protected override void OnViewModelChanged (PropertyViewModel oldModel) + protected override void OnViewModelChanged (EditorViewModel oldModel) { base.OnViewModelChanged (oldModel); diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs index 0f1846a..2b68304 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BasePopOverViewModelControl.cs @@ -7,9 +7,9 @@ namespace Xamarin.PropertyEditing.Mac { internal class BasePopOverViewModelControl : BasePopOverControl { - internal PropertyViewModel ViewModel { get; } + internal EditorViewModel ViewModel { get; } - public BasePopOverViewModelControl (IHostResourceProvider hostResources, PropertyViewModel viewModel, string title, string imageNamed) + public BasePopOverViewModelControl (IHostResourceProvider hostResources, EditorViewModel viewModel, string title, string imageNamed) : base (hostResources, title, imageNamed) { if (viewModel == null) diff --git a/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs index f1d92ac..3587c6d 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs @@ -38,7 +38,7 @@ namespace Xamarin.PropertyEditing.Mac protected NSLayoutConstraint RightEdgeConstraint { get; } - protected override void OnViewModelChanged (PropertyViewModel oldModel) + protected override void OnViewModelChanged (EditorViewModel oldModel) { base.OnViewModelChanged (oldModel); Entry.Delegate = (ViewModel != null) ? CreateDelegate (ViewModel) : null; diff --git a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs index a7a67bb..1fc5d92 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs @@ -112,7 +112,7 @@ namespace Xamarin.PropertyEditing.Mac } } - protected override void OnViewModelChanged (PropertyViewModel oldModel) + protected override void OnViewModelChanged (EditorViewModel oldModel) { base.OnViewModelChanged (oldModel); diff --git a/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs index a98a6b3..08139b6 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs @@ -57,7 +57,7 @@ namespace Xamarin.PropertyEditing.Mac this.createObject.AccessibilityTitle = String.Format (Properties.Resources.NewInstanceForProperty, ViewModel.Property.Name); } - protected override void OnViewModelChanged (PropertyViewModel oldModel) + protected override void OnViewModelChanged (EditorViewModel oldModel) { base.OnViewModelChanged (oldModel); diff --git a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs index d7abd38..0f731ae 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs @@ -73,7 +73,7 @@ namespace Xamarin.PropertyEditing.Mac } } - protected override void OnViewModelChanged (PropertyViewModel oldModel) + protected override void OnViewModelChanged (EditorViewModel oldModel) { base.OnViewModelChanged (oldModel); diff --git a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs index aff0ae5..6211494 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/PropertyEditorControl.cs @@ -35,14 +35,14 @@ namespace Xamarin.PropertyEditing.Mac public const string DefaultFontName = ".AppleSystemUIFont"; public virtual bool IsDynamicallySized => false; - PropertyViewModel viewModel; - public PropertyViewModel ViewModel { + EditorViewModel viewModel; + public EditorViewModel ViewModel { get { return this.viewModel; } set { if (this.ViewModel == value) return; - PropertyViewModel oldModel = this.viewModel; + EditorViewModel oldModel = this.viewModel; if (oldModel != null) { oldModel.PropertyChanged -= OnPropertyChanged; } @@ -58,7 +58,7 @@ namespace Xamarin.PropertyEditing.Mac EditorViewModel IEditorView.ViewModel { get { return this.ViewModel; } - set { ViewModel = (PropertyViewModel)value; } + set { ViewModel = (EditorViewModel)value; } } NSView INativeContainer.NativeView => this; @@ -107,7 +107,7 @@ namespace Xamarin.PropertyEditing.Mac { } - protected virtual void OnViewModelChanged (PropertyViewModel oldModel) + protected virtual void OnViewModelChanged (EditorViewModel oldModel) { if (ViewModel != null) { SetEnabled (); @@ -145,7 +145,7 @@ namespace Xamarin.PropertyEditing.Mac internal abstract class PropertyEditorControl<TViewModel> : PropertyEditorControl - where TViewModel : PropertyViewModel + where TViewModel : EditorViewModel { public PropertyEditorControl (IHostResourceProvider hostResources) : base (hostResources) diff --git a/Xamarin.PropertyEditing.Mac/Controls/StateGroupEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/StateGroupEditorControl.cs new file mode 100644 index 0000000..9e5c260 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/StateGroupEditorControl.cs @@ -0,0 +1,161 @@ +using System; +using System.ComponentModel; +using AppKit; +using Foundation; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class StateGroupEditorControl : PropertyEditorControl<StatePropertyGroupViewModel> + { + private FocusableComboBox stateGroupComboBox; + private StateGroupEditor stateGroupEditor; + + private NSView firstkeyView; + private NSView lastkeyView; + public override NSView FirstKeyView => firstkeyView; + public override NSView LastKeyView => lastkeyView; + + public StateGroupEditorControl (IHostResourceProvider hostResources) + : base (hostResources) + { + base.TranslatesAutoresizingMaskIntoConstraints = false; + + AppearanceChanged (); + } + + #region Overridden properties and Methods + + protected override void AppearanceChanged () + { + base.AppearanceChanged (); + } + + protected override void UpdateValue () + { + + } + + protected override void SetEnabled () + { + if (ViewModel != null) { + if (ViewModel.CanDelve) { + this.stateGroupComboBox.Enabled = ViewModel.HostedProperty.Property.CanWrite; + } else { + this.stateGroupEditor.Enabled = ViewModel.HostedProperty.Property.CanWrite; + } + } + } + + protected override void OnViewModelChanged (EditorViewModel oldModel) + { + if (ViewModel != null) { + if (ViewModel.CanDelve) { + RequireStateGroupComboBox (ViewModel.HostedProperty); + } else { + RequireStateGroupEditor (ViewModel.HostedProperty); + } + + OnPropertyChanged (ViewModel, new PropertyChangedEventArgs (null)); + } + + base.OnViewModelChanged (oldModel); + } + + protected override void OnPropertyChanged (object sender, PropertyChangedEventArgs e) + { + base.OnPropertyChanged (sender, e); + } + #endregion + + private void RequireStateGroupEditor (PropertyViewModel hostedProperty) + { + if (this.stateGroupEditor != null) + return; + + RemoveStateGroupComboBox (); + + this.stateGroupEditor = new StateGroupEditor(HostResources, ViewModel) { + AllowsExpansionToolTips = true, + ControlSize = NSControlSize.Small, + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + this.stateGroupEditor.UpdateAccessibilityValues (); + this.stateGroupEditor.Enabled = ViewModel.HostedProperty.Property.CanWrite; + + AddSubview (this.stateGroupEditor); + + AddConstraints (new[] { + NSLayoutConstraint.Create (this.stateGroupEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.stateGroupEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f), + }); + + this.firstkeyView = this.stateGroupEditor.StateGroupCombobox; + this.lastkeyView = this.stateGroupEditor.StateGroupEditButton; + } + + private void RemoveStateGroupEditor () + { + if (this.stateGroupEditor == null) + return; + + this.stateGroupEditor.RemoveFromSuperview (); + this.stateGroupEditor.Dispose (); + this.stateGroupEditor = null; + } + + private void RequireStateGroupComboBox (PropertyViewModel hostedProperty) + { + if (this.stateGroupComboBox != null) + return; + + RemoveStateGroupEditor (); + + this.stateGroupComboBox = new FocusableComboBox { + AllowsExpansionToolTips = true, + BackgroundColor = NSColor.Clear, + Cell = { + LineBreakMode = NSLineBreakMode.TruncatingTail, + UsesSingleLineMode = true, + }, + ControlSize = NSControlSize.Small, + Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), + TranslatesAutoresizingMaskIntoConstraints = false, + StringValue = String.Empty, + }; + + this.stateGroupComboBox.SelectionChanged += (sender, e) => { + //hostedProperty.Value = this.stateGroupComboBox.SelectedValue.ToString (); + }; + + // Once the VM is loaded we need a one time population + foreach (var item in ViewModel.Properties) { + this.stateGroupComboBox.Add (new NSString (item.Name)); + } + + this.stateGroupComboBox.Enabled = ViewModel.HostedProperty.Property.CanWrite; + + AddSubview (this.stateGroupComboBox); + + AddConstraints (new[] { + NSLayoutConstraint.Create (this.stateGroupComboBox, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.stateGroupComboBox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f), + }); + + this.firstkeyView = this.stateGroupComboBox; + this.lastkeyView = this.stateGroupComboBox; + } + + private void RemoveStateGroupComboBox () + { + if (this.stateGroupComboBox == null) + return; + + this.stateGroupComboBox.RemoveFromSuperview (); + this.stateGroupComboBox.Dispose (); + this.stateGroupComboBox = null; + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/StatefulProperties/StateGroupEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/StatefulProperties/StateGroupEditor.cs new file mode 100644 index 0000000..ae7c4a5 --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/StatefulProperties/StateGroupEditor.cs @@ -0,0 +1,142 @@ +using System; +using AppKit; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class StateGroupEditor : NSControl + { + private readonly IHostResourceProvider hostResources; + private readonly FocusableComboBox stateGroupCombobox; + private readonly FocusableButton stateGroupEditButton; + private readonly StatePropertyGroupViewModel statePropertyGroupVM; + + private NSControlSize controlSize; + public override NSControlSize ControlSize { + get { return this.controlSize; } + set { + if (this.controlSize == value) + return; + + this.controlSize = value; + + this.stateGroupCombobox.ControlSize = this.controlSize; + this.stateGroupEditButton.ControlSize = this.controlSize; + } + } + + private NSFont font; + public override NSFont Font { + get { return this.font; } + set + { + if (this.font == value) + return; + + this.font = value; + + this.stateGroupCombobox.Font = this.font; + this.stateGroupEditButton.Font = this.font; + } + } + + private bool enabled; + public override bool Enabled { + get { return this.enabled; } + set { + if (this.enabled == value) + return; + + this.enabled = value; + + this.stateGroupCombobox.Enabled = this.enabled; + this.stateGroupEditButton.Enabled = this.enabled; + } + } + + internal FocusableButton StateGroupEditButton => this.stateGroupEditButton; + internal FocusableComboBox StateGroupCombobox => this.stateGroupCombobox; + + public StateGroupEditor (IHostResourceProvider hostResources, StatePropertyGroupViewModel statePropertyGroupVM) + { + if (hostResources == null) + throw new ArgumentNullException (nameof (hostResources)); + + this.hostResources = hostResources; + + if (statePropertyGroupVM == null) + throw new ArgumentNullException (nameof (statePropertyGroupVM)); + + this.statePropertyGroupVM = statePropertyGroupVM; + + this.stateGroupCombobox = new FocusableComboBox { + AllowsExpansionToolTips = true, + BackgroundColor = NSColor.Clear, + Cell = { + LineBreakMode = NSLineBreakMode.TruncatingTail, + UsesSingleLineMode = true, + }, + TranslatesAutoresizingMaskIntoConstraints = false, + StringValue = String.Empty, + }; + + AddSubview (this.stateGroupCombobox); + + this.stateGroupEditButton = new FocusableButton { + BezelStyle = NSBezelStyle.Rounded, + Title = Properties.Resources.StateGroupEditButton, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + this.stateGroupEditButton.Activated += EditButtonActivated; + + AddSubview (this.stateGroupEditButton); + + AddConstraints (new[] { + NSLayoutConstraint.Create (this.stateGroupCombobox, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.stateGroupCombobox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0f), + NSLayoutConstraint.Create (this.stateGroupCombobox, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.stateGroupEditButton, NSLayoutAttribute.Left, 1, -4), + NSLayoutConstraint.Create (this.stateGroupCombobox, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -2), + NSLayoutConstraint.Create (this.stateGroupEditButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f), + NSLayoutConstraint.Create (this.stateGroupEditButton, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0), + NSLayoutConstraint.Create (this.stateGroupEditButton, NSLayoutAttribute.Width, NSLayoutRelation.GreaterThanOrEqual, 1, 70f), + }); + + AppearanceChanged (); + } + + private void EditButtonActivated (object sender, EventArgs e) + { + var statefulPropertyPopOverView = new StatefulPropertyPopOverView (this.hostResources, this.statePropertyGroupVM) { + Appearance = EffectiveAppearance + }; + + var statefulPropertyPopOver = new AutoClosePopOver (this.hostResources, EffectiveAppearance) { + CloseOnEnter = false, + ContentViewController = new NSViewController (null, null) { View = statefulPropertyPopOverView }, + }; + + statefulPropertyPopOver.Show (statefulPropertyPopOverView.Frame, this.stateGroupEditButton, NSRectEdge.MinYEdge); + } + + public override void ViewDidChangeEffectiveAppearance () + { + AppearanceChanged (); + base.ViewDidChangeEffectiveAppearance (); + } + + internal void AppearanceChanged () + { + + } + + internal void UpdateAccessibilityValues () + { + this.stateGroupCombobox.AccessibilityEnabled = this.stateGroupCombobox.Enabled; + this.stateGroupCombobox.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityInputModeEditor, this.statePropertyGroupVM.HostedProperty.Property.Name); + + this.stateGroupEditButton.AccessibilityEnabled = this.stateGroupEditButton.Enabled; + this.stateGroupEditButton.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityInputModeEditor, this.statePropertyGroupVM.HostedProperty.Property.Name); + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/StatefulProperties/StatefulPropertyPopOverView.cs b/Xamarin.PropertyEditing.Mac/Controls/StatefulProperties/StatefulPropertyPopOverView.cs new file mode 100644 index 0000000..1f31dbf --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/StatefulProperties/StatefulPropertyPopOverView.cs @@ -0,0 +1,44 @@ +using System; +using System.Reflection; +using AppKit; +using CoreGraphics; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class StatefulPropertyPopOverView + : BasePopOverViewModelControl + { + private readonly StatefulPropertySelectorControl selector; + + public StatefulPropertyPopOverView (IHostResourceProvider hostResources, StatePropertyGroupViewModel viewModel) + : base (hostResources, viewModel, Properties.Resources.Properties, "pe-custom-expression-32") + { + + Frame = new CGRect (CGPoint.Empty, new CGSize (250, 160)); + + Type vmType = viewModel.HostedProperty.GetType (); + + /* PropertyInfo previewCustomExpressionPropertyInfo = vmType.GetProperty (PreviewCustomExpressionString); + previewCustomExpressionPropertyInfo.SetValue (viewModel, string.Empty); + + PropertyInfo customExpressionPropertyInfo = vmType.GetProperty (CustomExpressionPropertyString); + var value = customExpressionPropertyInfo.GetValue (viewModel);*/ + + this.selector = new StatefulPropertySelectorControl (hostResources) { + ViewModel = viewModel, + TranslatesAutoresizingMaskIntoConstraints = false, + }; + + AddSubview (this.selector); + + AddConstraints (new[] { + NSLayoutConstraint.Create (this.selector, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 37f), + NSLayoutConstraint.Create (this.selector, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1, -2), + NSLayoutConstraint.Create (this.selector, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -2), + NSLayoutConstraint.Create (this.selector, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterX, 1, 0), + NSLayoutConstraint.Create (this.selector, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0), + }); + } + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/StatefulProperties/StatefulPropertySelectorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/StatefulProperties/StatefulPropertySelectorControl.cs new file mode 100644 index 0000000..5e3472d --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Controls/StatefulProperties/StatefulPropertySelectorControl.cs @@ -0,0 +1,144 @@ +using System; +using System.Collections.Generic; +using AppKit; +using Foundation; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Mac +{ + internal class StatefulPropertySelectorControl + : NotifyingView<StatePropertyGroupViewModel> + { + private readonly NSOutlineView outlineView; + + public StatefulPropertySelectorControl (IHostResourceProvider hostResources) + { + if (hostResources == null) + throw new ArgumentNullException (nameof (hostResources)); + + var scroll = new NSScrollView { + TranslatesAutoresizingMaskIntoConstraints = false + }; + + var datasource = new StatefulPropertySelectorDataSource (ViewModel); + + var statefulPropertySelectorDelegate = new StatefulPropertySelectorDelegate (hostResources, datasource); + this.outlineView = new NSOutlineView { + Delegate = statefulPropertySelectorDelegate, + AutoresizingMask = NSViewResizingMask.WidthSizable, + HeaderView = null, + Action = new ObjCRuntime.Selector ("onActivatedItem"), + Target = this + }; + + var col = new NSTableColumn (); + this.outlineView.AddColumn (col); + this.outlineView.OutlineTableColumn = col; + scroll.DocumentView = this.outlineView; + + AddSubview (scroll); + } + } + + internal class StatefulPropertySelectorDataSource + : NSOutlineViewDataSource + { + public StatefulPropertySelectorDataSource (StatePropertyGroupViewModel viewModel) + { + this.viewModel = viewModel; + } + + public override nint GetChildrenCount (NSOutlineView outlineView, NSObject item) + { + if (item == null) { + return this.viewModel.Properties?.Count ?? 0; + } else if (((NSObjectFacade)item).Target is KeyValuePair<string, SimpleCollectionView> kvp) { + return kvp.Value.Count; + } + + return base.GetChildrenCount (outlineView, item); + } + + public override NSObject GetChild (NSOutlineView outlineView, nint childIndex, NSObject item) + { + if (item == null) { + return new NSObjectFacade (this.viewModel.Properties[(int)childIndex]); + } else if (((NSObjectFacade)item).Target is KeyValuePair<string, SimpleCollectionView> kvp) { + return new NSObjectFacade (kvp.Value[(int)childIndex]); + } + + return base.GetChild (outlineView, childIndex, item); + } + + public override bool ItemExpandable (NSOutlineView outlineView, NSObject item) + { + return !(((NSObjectFacade)item).Target is ITypeInfo); + } + + private StatePropertyGroupViewModel viewModel; + } + + internal class StatefulPropertySelectorDelegate + : NSOutlineViewDelegate + { + private readonly PropertyEditorSelector editorSelector = new PropertyEditorSelector (); + private IHostResourceProvider hostResources; + private StatefulPropertySelectorDataSource dataSource; + + public StatefulPropertySelectorDelegate (IHostResourceProvider hostResources, StatefulPropertySelectorDataSource dataSource) + { + if (hostResources == null) + throw new ArgumentNullException (nameof (hostResources)); + if (dataSource == null) + throw new ArgumentNullException (nameof (dataSource)); + + this.hostResources = hostResources; + this.dataSource = dataSource; + } + + private NSView GetEditor (string identifier, EditorViewModel vm, NSOutlineView outlineView) + { + var view = outlineView.MakeView (identifier, this); + if (view != null) + return view; + + if (vm != null) { + IEditorView editor = this.editorSelector.GetEditor (this.hostResources, vm); + + var editorControl = editor?.NativeView as PropertyEditorControl; + if (editorControl != null) { + editorControl.TableView = outlineView; + } else if (editor?.NativeView != null) { + editor.NativeView.Identifier = identifier; + return editor.NativeView; + } + + return new EditorContainer (this.hostResources, editor) { Identifier = identifier }; + } + + return null; // TODO + } + + public override NSView GetView (NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item) + { + var label = (UnfocusableTextField)outlineView.MakeView (LabelId, outlineView); + if (label == null) { + label = new UnfocusableTextField { + Identifier = LabelId + }; + } + + string text = String.Empty; + var facade = (NSObjectFacade)item; + if (facade.Target is KeyValuePair<string, SimpleCollectionView> kvp) + text = kvp.Key; + else if (facade.Target is ITypeInfo type) + text = type.Name; + + label.StringValue = text; + return label; + } + + private const string LabelId = "label"; + } +} diff --git a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs index e20e85a..85c3869 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs @@ -29,7 +29,7 @@ namespace Xamarin.PropertyEditing.Mac SetEnabled (); } - protected override void OnViewModelChanged (PropertyViewModel oldModel) + protected override void OnViewModelChanged (EditorViewModel oldModel) { base.OnViewModelChanged (oldModel); diff --git a/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs index 44a61a8..67d1378 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs @@ -57,7 +57,7 @@ namespace Xamarin.PropertyEditing.Mac this.selectType.AccessibilityTitle = String.Format (Properties.Resources.SelectTypeForProperty, ViewModel.Property.Name); } - protected override void OnViewModelChanged (PropertyViewModel oldModel) + protected override void OnViewModelChanged (EditorViewModel oldModel) { base.OnViewModelChanged (oldModel); diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditorSelector.cs b/Xamarin.PropertyEditing.Mac/PropertyEditorSelector.cs index bff6d97..2d6b7f2 100644 --- a/Xamarin.PropertyEditing.Mac/PropertyEditorSelector.cs +++ b/Xamarin.PropertyEditing.Mac/PropertyEditorSelector.cs @@ -61,7 +61,7 @@ namespace Xamarin.PropertyEditing.Mac {typeof (ObjectPropertyViewModel), typeof (ObjectEditorControl)}, {typeof (TypePropertyViewModel), typeof (TypeEditorControl)}, {typeof (CollectionPropertyViewModel), typeof (CollectionInlineEditorControl)}, - + {typeof (StatePropertyGroupViewModel), typeof (StateGroupEditorControl)}, }; } } diff --git a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj index eb49853..0ab8b9d 100644 --- a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj +++ b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj @@ -18,6 +18,9 @@ <ProjectReference Include="..\Xamarin.PropertyEditing\Xamarin.PropertyEditing.csproj" />
</ItemGroup>
+ <ItemGroup>
+ <Folder Include="Controls\StatefulProperties\" />
+ </ItemGroup>
<Target Name="IncludeIconsInBundle" BeforeTargets="AssignTargetPaths">
<ItemGroup>
<PropertyEditingResourceBundlePath Include="PropertyEditingResource\**\*" />
|