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

PropertyEditorControl.cs « Controls « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0f2cec0c60a1f474e80f7b26f3d17cba6697ec8f (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using AppKit;
using Foundation;
using Xamarin.PropertyEditing.ViewModels;

namespace Xamarin.PropertyEditing.Mac
{
	internal abstract class PropertyEditorControl
		: NSView, IEditorView
	{
		protected PropertyEditorControl (IHostResourceProvider hostResources)
		{
			if (hostResources == null)
				throw new ArgumentNullException (nameof (hostResources));

			HostResources = hostResources;
		}

		public IHostResourceProvider HostResources
		{
			get;
		}

		public string Label { get; set; }

		public abstract NSView FirstKeyView { get; }
		public abstract NSView LastKeyView { get; }

		public NSTableView TableView { get; set; }

		public const int DefaultControlHeight = 24;
		public const int DefaultFontSize = 11;
		public const int DefaultPropertyLabelFontSize = 11;
		public const int DefaultDescriptionLabelFontSize = 9;
		public const string DefaultFontName = ".AppleSystemUIFont";
		public const float DefaultButtonWidth = 70f;
		public virtual bool IsDynamicallySized => false;

		PropertyViewModel viewModel;
		public PropertyViewModel ViewModel {
			get { return this.viewModel; }
			set {
				if (this.ViewModel == value)
					return;

				PropertyViewModel oldModel = this.viewModel;
				if (oldModel != null) {
					oldModel.PropertyChanged -= OnPropertyChanged;
				}

				this.viewModel = value;
				OnViewModelChanged (oldModel);
				if (this.viewModel != null) {
					this.viewModel.PropertyChanged += OnPropertyChanged;
				}
			}
		}

		EditorViewModel IEditorView.ViewModel
		{
			get { return this.ViewModel; }
			set { ViewModel = (PropertyViewModel)value; }
		}

		NSView INativeContainer.NativeView => this;


		public virtual bool NeedsPropertyButton => true;


		/// <remarks>You should treat the implementation of this as static.</remarks>
		public virtual nint GetHeight (EditorViewModel vm)
		{
			return 24;
		}

		protected virtual void UpdateValue ()
		{
		}

		protected virtual void OnViewModelChanged (PropertyViewModel oldModel)
		{
			if (ViewModel != null) {
				SetEnabled ();
				UpdateValue ();
				UpdateAccessibilityValues ();
			}
		}

		protected virtual void OnPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e)
		{
			if (e.PropertyName == "Value") {
				UpdateValue ();
			}
		}

		protected virtual void SetEnabled ()
		{
		}

		protected virtual void UpdateAccessibilityValues ()
		{
		}

		protected virtual void AppearanceChanged ()
		{
		}

		public sealed override void ViewDidChangeEffectiveAppearance ()
		{
			base.ViewDidChangeEffectiveAppearance ();

			AppearanceChanged ();
		}

		public void OnNextResponderRequested (bool reverse)
		{
			if (TableView != null) {
				var modifier = reverse ? -1 : 1;

				nint row = TableView.RowForView (this) + modifier;

				NSView view;
				PropertyEditorControl ctrl = null;

				var rowCount = TableView.RowCount;
				for (; reverse ? row > 0 : row < rowCount; row += modifier) {

					view = TableView.GetView (0, row, makeIfNecessary: false);
					if (view is PropertyEditorControl pec) { // This is to include the CategoryContainer
						ctrl = pec;
					} else {
						ctrl = (view as EditorContainer)?.EditorView?.NativeView as PropertyEditorControl;
					}

					if (ctrl?.viewModel != null && !ctrl.viewModel.IsInputEnabled) {
						ctrl = null;
					}

					if (ctrl != null) {
						var targetView = reverse ? ctrl.LastKeyView : ctrl.FirstKeyView;
						Window?.MakeFirstResponder (targetView);
						return;
					} else if (row == 0 && view is PanelHeaderEditorControl header) {
						Window?.MakeFirstResponder (header);
						return;
					}
				}
			}
		}
	}

	internal abstract class PropertyEditorControl<TViewModel>
		: PropertyEditorControl
		where TViewModel : PropertyViewModel
	{
		public PropertyEditorControl (IHostResourceProvider hostResources)
			: base (hostResources)
		{
		}

		internal new TViewModel ViewModel
		{
			get { return (TViewModel)base.ViewModel; }
			set { base.ViewModel = value; }
		}
	}
}