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

BindingObjectSelectorControl.cs « BindingEditor « Controls « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8e82477b5cb83dfaea470e751a6316468c6f68d0 (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
using System;
using System.Collections.Generic;
using AppKit;
using Foundation;
using Xamarin.PropertyEditing.ViewModels;

namespace Xamarin.PropertyEditing.Mac
{
	internal class BindingObjectSelectorControl 
		: NotifyingView<CreateBindingViewModel>
	{
		private ObjectOutlineView objectOutlineView;

		private const string ObjectSelectorColId = "ObjectSelectorColumn";

		internal BindingObjectSelectorControl (CreateBindingViewModel viewModel)
		{
			if (viewModel == null)
				throw new ArgumentNullException (nameof (viewModel));

			ViewModel = viewModel;

			this.objectOutlineView = new ObjectOutlineView ();
			TranslatesAutoresizingMaskIntoConstraints = false;

			this.objectOutlineView.Activated += OnObjectOutlineViewSelected;

			var resourceColumn = new NSTableColumn (ObjectSelectorColId);
			this.objectOutlineView.AddColumn (resourceColumn);

			// Set OutlineTableColumn or the arrows showing children/expansion will not be drawn
			this.objectOutlineView.OutlineTableColumn = resourceColumn;

			// create a table view and a scroll view
			var outlineViewContainer = new NSScrollView {
				TranslatesAutoresizingMaskIntoConstraints = false,
			};

			// add the panel to the window
			outlineViewContainer.DocumentView = this.objectOutlineView;
			AddSubview (outlineViewContainer);

			AddConstraints (new[] {
				NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 28f),
				NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f),
				NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterX, 1, 0),
				NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal,this, NSLayoutAttribute.Bottom, 1f, 0f),
			});

			viewModel.PropertyChanged += OnPropertyChanged;
		}

		public override void OnPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e)
		{
			if (e.PropertyName == nameof (CreateBindingViewModel.ShowObjectSelector)) {
				Hidden = !ViewModel.ShowObjectSelector;

				if (ViewModel.ShowObjectSelector && ViewModel.ObjectElementRoots != null) {
					this.objectOutlineView.ItemsSource = ViewModel.ObjectElementRoots.Value;
				};
			}
		}

		private void OnObjectOutlineViewSelected (object sender, EventArgs e)
		{
			if (sender is ObjectOutlineView rov) {
				if (rov.SelectedRow != -1) {
					if (rov.ItemAtRow (rov.SelectedRow) is NSObjectFacade item) {
						if (item.Target is Resource resource) {
							ViewModel.SelectedResource = resource;
						}
					}
				}
			}
		}

	}
}