[mac] Manually handle disclosure arrows
This is largely required to get control over the left most column for coloring and icon use.
This commit is contained in:
Родитель
0ff7c089e4
Коммит
96561f19bf
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче