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

CollectionInlineEditorControl.cs « Controls « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 54056ac98eec72935168f93334469a9e449775e7 (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
using System;
using AppKit;
using Xamarin.PropertyEditing.ViewModels;

namespace Xamarin.PropertyEditing.Mac
{
	internal class CollectionInlineEditorControl
		: PropertyEditorControl<CollectionPropertyViewModel>
	{
		public CollectionInlineEditorControl (IHostResourceProvider hostResources)
			: base (hostResources)
		{
			this.label = new UnfocusableTextField {
				TranslatesAutoresizingMaskIntoConstraints = false,
				StringValue = Properties.Resources.CollectionValue,
			};

			AddSubview (this.label);

			this.openCollection = new FocusableButton {
				Title = Properties.Resources.CollectionEditButton,
				BezelStyle = NSBezelStyle.Rounded,
				AccessibilityEnabled = true,
				AccessibilityHelp = Properties.Resources.AccessibilityCollectionHelp
			};

			this.openCollection.Activated += (o, e) => {
				CollectionEditorWindow.EditCollection (EffectiveAppearance, HostResources, ViewModel);
			};

			AddSubview (this.openCollection);

			AddConstraints (new[] {
				NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this, NSLayoutAttribute.Leading, 1, 0),
				NSLayoutConstraint.Create (this.label, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0),
				NSLayoutConstraint.Create (this.label, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, 0),
				NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this.label, NSLayoutAttribute.Trailing, 1, 12),
				NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1, 0),
				NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.Width, NSLayoutRelation.GreaterThanOrEqual, 1, 70),
				NSLayoutConstraint.Create (this.openCollection, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6)
			});

			AppearanceChanged ();
		}

		public override NSView FirstKeyView => this.openCollection;
		public override NSView LastKeyView => this.openCollection;

		protected override void SetEnabled ()
		{
			base.SetEnabled ();
			this.openCollection.Enabled = ViewModel?.Property.CanWrite ?? false;
		}

		protected override void UpdateAccessibilityValues ()
		{
			base.UpdateAccessibilityValues ();

			this.openCollection.AccessibilityTitle = (ViewModel != null) ? String.Format (Properties.Resources.AccessibilityCollection, ViewModel.Property.Name) : null;
		}

		private readonly UnfocusableTextField label;
		private readonly NSButton openCollection;

		protected override void AppearanceChanged ()
		{
			base.AppearanceChanged ();

			this.label.TextColor = HostResources.GetNamedColor (NamedResources.DescriptionLabelColor);
		}
	}
}