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

BaseEditorControl.cs « Controls « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3e3c9839710916f88d1896634038572b25a7f891 (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
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections;
using System.ComponentModel;
using AppKit;
using CoreGraphics;
using System.Windows.Input;

using Xamarin.PropertyEditing.Mac.Resources;

namespace Xamarin.PropertyEditing.Mac
{
	internal abstract class BaseEditorControl : NSView
	{
		IEnumerable errorList;
		const int DefaultActioButtonSize = 16;

		public event EventHandler ActionButtonClicked;
		NSButton actionButton;
		public NSButton ActionButton
		{
			get { return actionButton; }
		}

		PropertyButton propertyButton;
		public PropertyButton PropertyButton
		{
			get { return propertyButton; }
		}

		public BaseEditorControl ()
		{
			propertyButton = new PropertyButton {
				TranslatesAutoresizingMaskIntoConstraints = false
			};

			AddSubview (propertyButton);

			actionButton = new NSButton {
				Bordered = false,
				Enabled = false,
				ImageScaling = NSImageScale.AxesIndependently,
				Title = string.Empty,
				TranslatesAutoresizingMaskIntoConstraints = false,
				AccessibilityTitle = LocalizationResources.AccessibilityActionButton,
				AccessibilityHelp = LocalizationResources.AccessibilityActionButtonDescription,
			};

#if DESIGNER_DEBUG
			actionButton.Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("action-warning-16");
#endif

			actionButton.Activated += (object sender, EventArgs e) => {
				if (errorList != null) {
					var Container = new ErrorMessageView (errorList);

					var errorMessagePopUp = new NSPopover {
						Behavior = NSPopoverBehavior.Semitransient,
						ContentViewController = new NSViewController (null, null) { View = Container },
					};

					errorMessagePopUp.Show (default (CGRect), actionButton, NSRectEdge.MinYEdge);
				}

				NotifyActionButtonClicked ();
			};

			AddSubview (actionButton);

			this.DoConstraints (new[] {
				propertyButton.ConstraintTo (this, (ab, c) => ab.Width == PropertyButton.DefaultSize),
				propertyButton.ConstraintTo (this, (ab, c) => ab.Height == PropertyButton.DefaultSize),
				propertyButton.ConstraintTo (this, (ab, c) => ab.Top == c.Top + 1),
				propertyButton.ConstraintTo (this, (ab, c) => ab.Left == c.Right - 33),
				actionButton.ConstraintTo (this, (eb, c) => eb.Width == DefaultActioButtonSize),
				actionButton.ConstraintTo (this, (eb, c) => eb.Height == DefaultActioButtonSize),
				actionButton.ConstraintTo (propertyButton, (eb, ab) => eb.Left == ab.Left + PropertyButton.DefaultSize),
				actionButton.ConstraintTo (this, (eb, c) => eb.Top == c.Top + 3), // TODO: Better centering based on the icon height
			});

			PropertyEditorPanel.ThemeManager.ThemeChanged += ThemeManager_ThemeChanged;
		}

		protected override void Dispose (bool disposing)
		{
			if (disposing) {
				PropertyEditorPanel.ThemeManager.ThemeChanged -= ThemeManager_ThemeChanged;
			}
		}

		void ThemeManager_ThemeChanged (object sender, EventArgs e)
		{
			UpdateTheme ();
		}

		protected void UpdateTheme ()
		{
			this.Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance;
		}

		protected void SetErrors (IEnumerable errors)
		{
			errorList = errors;

			actionButton.Enabled = errors != null;
			actionButton.Hidden = !actionButton.Enabled;

			// Using NSImageName.Caution for now, we can change this later at the designers behest
			actionButton.Image = actionButton.Enabled ? PropertyEditorPanel.ThemeManager.GetImageForTheme ("action-warning-16") : null;
		}

		void NotifyActionButtonClicked ()
		{
			ActionButtonClicked?.Invoke (this, EventArgs.Empty);
		}
	}
}