blob: da4003478c66c6bf39d384bfaffbf19c1925c9eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
using System;
using System.Collections.Generic;
using System.Linq;
using AppKit;
using Foundation;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
internal class PropertyTableDataSource
: NSOutlineViewDataSource
{
bool Filtering => !string.IsNullOrEmpty (this.vm.FilterText);
internal PropertyTableDataSource (PanelViewModel panelVm)
{
if (panelVm == null)
throw new ArgumentNullException (nameof (panelVm));
this.vm = panelVm;
}
public PanelViewModel DataContext => this.vm;
public override nint GetChildrenCount (NSOutlineView outlineView, NSObject item)
{
if (this.vm.ArrangedEditors.Count == 0)
return 0;
var childCount = 0;
if (this.vm.ArrangeMode == PropertyArrangeMode.Name)
childCount = Filtering ? this.vm.ArrangedEditors[0].Editors.Count : this.vm.ArrangedEditors[0].Editors.Count + 1;
else {
if (item == null)
childCount = Filtering ? this.vm.ArrangedEditors.Count : this.vm.ArrangedEditors.Count + 1;
else {
var group = (PanelGroupViewModel)((NSObjectFacade)item).Target;
childCount = group.Editors.Count + group.UncommonEditors.Count;
}
}
return childCount;
}
public override NSObject GetChild (NSOutlineView outlineView, nint childIndex, NSObject item)
{
object element;
// We only want the Header to appear at the top of both Category and Name Modes, which means item is null in both.
if (childIndex == 0 && item == null && !Filtering)
element = null;
else {
if (this.vm.ArrangeMode == PropertyArrangeMode.Name)
element = Filtering ? this.vm.ArrangedEditors[0].Editors[(int)childIndex] : this.vm.ArrangedEditors[0].Editors[(int)childIndex - 1];
else {
if (item == null)
element = Filtering ? this.vm.ArrangedEditors[(int)childIndex] : this.vm.ArrangedEditors[(int)childIndex - 1];
else {
var group = (PanelGroupViewModel)((NSObjectFacade)item).Target;
var list = group.Editors;
if (childIndex >= list.Count) {
childIndex -= list.Count;
list = group.UncommonEditors;
}
element = list[(int)childIndex];
}
}
}
return GetFacade (element);
}
public override bool ItemExpandable (NSOutlineView outlineView, NSObject item)
{
if (this.vm.ArrangeMode == PropertyArrangeMode.Name)
return false;
return ((NSObjectFacade)item).Target is PanelGroupViewModel;
}
public NSObject GetFacade (object element)
{
NSObject facade;
if (element is PanelGroupViewModel) {
if (!this.groupFacades.TryGetValue (element, out facade)) {
this.groupFacades[element] = facade = new NSObjectFacade (element);
}
} else
facade = new NSObjectFacade (element);
return facade;
}
public bool TryGetFacade (object element, out NSObject facade)
{
return this.groupFacades.TryGetValue (element, out facade);
}
private readonly PanelViewModel vm;
private readonly Dictionary<object, NSObject> groupFacades = new Dictionary<object, NSObject> ();
}
}
|