diff options
author | Eric Maupin <ermaup@microsoft.com> | 2019-02-05 22:47:15 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2019-02-15 21:00:44 +0300 |
commit | 96561f19bf1c81e24c852e0a88ef46bd72e05e38 (patch) | |
tree | 409dcdf59876a78a968f636efbee4ed1c73a4b5e /Xamarin.PropertyEditing.Mac | |
parent | 0ff7c089e4ff137dbf535445df8da88ece02a0ec (diff) |
[mac] Manually handle disclosure arrows
This is largely required to get control over the left most column for
coloring and icon use.
Diffstat (limited to 'Xamarin.PropertyEditing.Mac')
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs | 31 | ||||
-rw-r--r-- | Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs | 16 | ||||
-rw-r--r-- | Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs | 60 |
3 files changed, 80 insertions, 27 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs b/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs index 5f5cc3e..5183419 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs @@ -43,6 +43,34 @@ namespace Xamarin.PropertyEditing.Mac set { this.label.StringValue = value; } } + public NSView LeftEdgeView + { + get { return this.leftEdgeView; } + set + { + if (this.leftEdgeView != null) { + this.leftEdgeView.RemoveFromSuperview (); + RemoveConstraints (new[] { this.leftEdgeLeftConstraint, this.leftEdgeVCenterConstraint }); + this.leftEdgeLeftConstraint.Dispose (); + this.leftEdgeLeftConstraint = null; + this.leftEdgeVCenterConstraint.Dispose (); + this.leftEdgeVCenterConstraint = null; + } + + this.leftEdgeView = value; + + if (value != null) { + AddSubview (value); + + value.TranslatesAutoresizingMaskIntoConstraints = false; + this.leftEdgeLeftConstraint = NSLayoutConstraint.Create (this.leftEdgeView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 4); + this.leftEdgeVCenterConstraint = NSLayoutConstraint.Create (this.leftEdgeView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0); + + AddConstraints (new[] { this.leftEdgeLeftConstraint, this.leftEdgeVCenterConstraint }); + } + } + } + public override void ViewWillMoveToSuperview (NSView newSuperview) { if (newSuperview == null && EditorView != null) @@ -61,5 +89,8 @@ namespace Xamarin.PropertyEditing.Mac set { this.label.TextColor = value; } } #endif + + private NSView leftEdgeView; + private NSLayoutConstraint leftEdgeLeftConstraint, leftEdgeVCenterConstraint; } } diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs b/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs index a42d166..8b6d96b 100644 --- a/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs +++ b/Xamarin.PropertyEditing.Mac/PropertyEditorPanel.cs @@ -175,6 +175,7 @@ namespace Xamarin.PropertyEditing.Mac ((NSView)this.header.ContentView).AddSubview (this.tabStack); this.propertyTable = new FirstResponderOutlineView { + IndentationPerLevel = 0, RefusesFirstResponder = true, SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.None, HeaderView = null, @@ -184,9 +185,6 @@ namespace Xamarin.PropertyEditing.Mac var propertyEditors = new NSTableColumn (PropertyEditorColId); this.propertyTable.AddColumn (propertyEditors); - // Set OutlineTableColumn or the arrows showing children/expansion or they will not be drawn - this.propertyTable.OutlineTableColumn = propertyEditors; - var tableContainer = new NSScrollView { TranslatesAutoresizingMaskIntoConstraints = false, }; @@ -279,18 +277,6 @@ namespace Xamarin.PropertyEditing.Mac { return true; } - - public override CGRect GetCellFrame (nint column, nint row) - { - var super = base.GetCellFrame (column, row); - if (column == 0) { - var obj = (NSObjectFacade)ItemAtRow (row); - if (obj.Target is PropertyGroupViewModel) - return new CGRect (0, super.Top, super.Right - (super.Left / 2), super.Height); - } - - return super; - } } } }
\ No newline at end of file diff --git a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs index b9ef018..608d18b 100644 --- a/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs +++ b/Xamarin.PropertyEditing.Mac/PropertyTableDelegate.cs @@ -53,14 +53,30 @@ namespace Xamarin.PropertyEditing.Mac GetVMGroupCellItendifiterFromFacade (item, out evm, out group, out cellIdentifier); if (group != null) { - var labelContainer = (UnfocusableTextField)outlineView.MakeView (LabelIdentifier, this); + var labelContainer = (NSView)outlineView.MakeView (CategoryIdentifier, this); if (labelContainer == null) { - labelContainer = new UnfocusableTextField { - Identifier = LabelIdentifier, + labelContainer = new NSView { + Identifier = CategoryIdentifier, }; + + var disclosure = outlineView.MakeView ("NSOutlineViewDisclosureButtonKey", outlineView); + disclosure.TranslatesAutoresizingMaskIntoConstraints = false; + labelContainer.AddSubview (disclosure); + + var label = new UnfocusableTextField { + TranslatesAutoresizingMaskIntoConstraints = false + }; + labelContainer.AddSubview (label); + + labelContainer.AddConstraints (new[] { + NSLayoutConstraint.Create (disclosure, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, labelContainer, NSLayoutAttribute.CenterY, 1, 0), + NSLayoutConstraint.Create (disclosure, NSLayoutAttribute.Left, NSLayoutRelation.Equal, labelContainer, NSLayoutAttribute.Left, 1, 4), + NSLayoutConstraint.Create (label, NSLayoutAttribute.Left, NSLayoutRelation.Equal, disclosure, NSLayoutAttribute.Right, 1, 0), + NSLayoutConstraint.Create (label, NSLayoutAttribute.Height, NSLayoutRelation.Equal, labelContainer, NSLayoutAttribute.Height, 1, 0), + }); } - labelContainer.StringValue = group.Category; + ((UnfocusableTextField)labelContainer.Subviews[1]).StringValue = group.Category; if (this.dataSource.DataContext.GetIsExpanded (group.Category)) { SynchronizationContext.Current.Post (s => { @@ -92,7 +108,17 @@ namespace Xamarin.PropertyEditing.Mac if (editor != null) { editor.ViewModel = evm; - bool openObjectRow = evm is ObjectPropertyViewModel && outlineView.IsItemExpanded (item); + var ovm = evm as ObjectPropertyViewModel; + if (ovm != null && editorOrContainer is EditorContainer container) { + if (container.LeftEdgeView == null) { + if (ovm.CanDelve) + container.LeftEdgeView = outlineView.MakeView ("NSOutlineViewDisclosureButtonKey", outlineView); + } else if (!ovm.CanDelve) { + container.LeftEdgeView = null; + } + } + + bool openObjectRow = ovm != null && outlineView.IsItemExpanded (item); if (!openObjectRow) { var parent = outlineView.GetParent (item); openObjectRow = (parent != null && ((NSObjectFacade)parent).Target is ObjectPropertyViewModel); @@ -119,13 +145,18 @@ namespace Xamarin.PropertyEditing.Mac public override void ItemDidExpand (NSNotification notification) { - if (this.isExpanding) - return; - NSObjectFacade facade = notification.UserInfo.Values[0] as NSObjectFacade; var outline = (NSOutlineView)notification.Object; nint row = outline.RowForItem (facade); + if (this.isExpanding) { + NSView view = outline.GetView (0, row, makeIfNecessary: true); + if (view.Subviews[0] is NSButton expander) + expander.State = NSCellStateValue.On; + + return; + } + if (facade.Target is PanelGroupViewModel group) this.dataSource.DataContext.SetIsExpanded (group.Category, isExpanded: true); else if (facade.Target is ObjectPropertyViewModel ovm) { @@ -136,13 +167,18 @@ namespace Xamarin.PropertyEditing.Mac public override void ItemDidCollapse (NSNotification notification) { - if (this.isExpanding) - return; - NSObjectFacade facade = notification.UserInfo.Values[0] as NSObjectFacade; var outline = (NSOutlineView)notification.Object; nint row = outline.RowForItem (facade); + if (this.isExpanding) { + NSView view = outline.GetView (0, row, makeIfNecessary: true); + if (view.Subviews[0] is NSButton expander) + expander.State = NSCellStateValue.Off; + + return; + } + if (facade.Target is PanelGroupViewModel group) this.dataSource.DataContext.SetIsExpanded (group.Category, isExpanded: false); else if (facade.Target is ObjectPropertyViewModel ovm) { @@ -203,7 +239,7 @@ namespace Xamarin.PropertyEditing.Mac } } - public const string LabelIdentifier = "label"; + public const string CategoryIdentifier = "label"; private PropertyTableDataSource dataSource; private bool isExpanding; |