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

ErrorMessageView.cs « Controls « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0b55b7205241ea747be51799424458d197a998ea (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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using AppKit;
using CoreGraphics;

namespace Xamarin.PropertyEditing.Mac
{
	internal class ErrorMessageView : NSView
	{
		const int DefaultIconButtonSize = 24;

		NSTextField ErrorMessages;

		public ErrorMessageView (IEnumerable errors)
		{
			if (errors == null)
				throw new ArgumentNullException (nameof (errors));

			Frame = new CGRect (CGPoint.Empty, new CGSize (320, 240));

			var iconView = new NSButton (new CGRect (5, Frame.Height - 25, DefaultIconButtonSize, DefaultIconButtonSize)) {
				Bordered = false,
				Image = PropertyEditorPanel.ThemeManager.GetImageForTheme ("action-warning-16"),
				Title = string.Empty,
				TranslatesAutoresizingMaskIntoConstraints = false,
			};

			AddSubview (iconView);

			var viewTitle = new UnfocusableTextField (new CGRect (30, Frame.Height - 26, 120, 24), "Errors");

			AddSubview (viewTitle);

			ErrorMessages = new NSTextField {
				BackgroundColor = NSColor.Clear,
				Editable = false,
				TranslatesAutoresizingMaskIntoConstraints = false,
			};
			ErrorMessages.Cell.Wraps = true;

			foreach (var error in errors) {
				ErrorMessages.StringValue += error + "\n";
			}

			AddSubview (ErrorMessages);

			this.DoConstraints (new[] {
				iconView.ConstraintTo (this, (iv, c) => iv.Top == c.Top + 5),
				iconView.ConstraintTo (this, (iv, c) => iv.Left == c.Left + 5),
				iconView.ConstraintTo (this, (iv, c) => iv.Width == DefaultIconButtonSize),
				iconView.ConstraintTo (this, (iv, c) => iv.Height == DefaultIconButtonSize),
				viewTitle.ConstraintTo (this, (vt, c) => vt.Top == c.Top + 7),
				viewTitle.ConstraintTo (this, (vt, c) => vt.Width == 120),
				viewTitle.ConstraintTo (this, (vt, c) => vt.Height == 24),
				ErrorMessages.ConstraintTo (this, (s, c) => s.Top == c.Top + 35),
				ErrorMessages.ConstraintTo (this, (s, c) => s.Left == c.Left + 5),
				ErrorMessages.ConstraintTo (this, (s, c) => s.Width == c.Width - 10),
				ErrorMessages.ConstraintTo (this, (s, c) => s.Height == c.Height - 40),
			});

			this.Appearance = PropertyEditorPanel.ThemeManager.CurrentAppearance;
		}
	}
}