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: 74d415015f870b28af552c50d63ce5dfc9cb2cc8 (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
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Collections;
using System.Collections.Generic;
using AppKit;
using CoreGraphics;

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

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

		public event EventHandler PropertyButtonClicked;
		NSButton propertyButton;
		public NSButton PropertyButton {
			get { return propertyButton; }
		}

		public BaseEditorControl ()
		{
			propertyButton = new NSButton {
				Bordered = false,
				AlternateImage = NSImage.ImageNamed ("property-button-default-mac-active-10"),
				Cell = {
					HighlightsBy = 1,
				},
				Image = NSImage.ImageNamed ("property-button-default-mac-10"),
				ImageScaling = NSImageScale.AxesIndependently,
				Title = string.Empty,
				TranslatesAutoresizingMaskIntoConstraints = false,
			};

			propertyButton.Activated += (object sender, EventArgs e) => {
				NotifyPropertyButtonClicked ();
			};

			AddSubview (propertyButton);

			actionButton = new NSButton {
				Bordered = false,
				Enabled = false,
#if DEBUG
				Image = NSImage.ImageNamed ("action-warning-16"),
#endif
				ImageScaling = NSImageScale.AxesIndependently,
				Title = string.Empty,
				TranslatesAutoresizingMaskIntoConstraints = false,
			};

			actionButton.Activated += (object sender, EventArgs e) => {
				if (errorList != null) {
					var Container = new ErrorMessageView (errorList) {
						Frame = new CGRect (CGPoint.Empty, new CGSize (320, 200))
					};

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

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

				NotifyActioButtonClicked ();
			};

			AddSubview (actionButton);

			this.DoConstraints (new[] {
				propertyButton.ConstraintTo (this, (ab, c) => ab.Width == DefaultPropertyButtonSize),
				propertyButton.ConstraintTo (this, (ab, c) => ab.Height == DefaultPropertyButtonSize),
				propertyButton.ConstraintTo (this, (ab, c) => ab.Top == c.Top + 6), // TODO: Better centering based on the icon height
				propertyButton.ConstraintTo (this, (ab, c) => ab.Left == c.Right - 28),
				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 + 10),
				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;

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

		void NotifyPropertyButtonClicked ()
		{
			PropertyButtonClicked?.Invoke (this, EventArgs.Empty);
		}

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