Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PropertyTableDataSource.cs « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5153562a10d844562a24d8689fb0a8ef8766bfa6 (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
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
	{
		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;

			if (this.vm.ArrangeMode == PropertyArrangeMode.Name)
				return this.vm.ArrangedEditors[0].Count;

			if (item == null)
				return this.vm.ArrangedEditors.Count;
			else {
				return ((IGroupingList<string, EditorViewModel>)((NSObjectFacade)item).Target).Count;
			}
		}

		public override NSObject GetChild (NSOutlineView outlineView, nint childIndex, NSObject item)
		{
			object element;
			if (this.vm.ArrangeMode == PropertyArrangeMode.Name) {
				element = (this.vm.ArrangedEditors[0][(int)childIndex]);
			} else {
				if (item == null)
					element = this.vm.ArrangedEditors[(int)childIndex];
				else {
					element = ((IGroupingList<string, EditorViewModel>)((NSObjectFacade)item).Target)[(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 IGroupingList<string, EditorViewModel>;
		}

		public NSObject GetFacade (object element)
		{
			NSObject facade;
			if (element is IGrouping<string, PropertyViewModel>) {
				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> ();
	}
}