blob: 04c7c4851b3fce79fceedead330cfb79ec862a03 (
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
|
using System;
using System.Collections;
using AppKit;
using CoreGraphics;
using Foundation;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
internal abstract class PropertyEditorControl : BaseEditorControl
{
public string Label { get; set; }
public abstract NSView FirstKeyView { get; }
public abstract NSView LastKeyView { get; }
public nint TableRow { get; set; } = -1;
public NSTableView TableView { get; set; }
public const int DefaultControlHeight = 22;
public const int DefaultFontSize = 11;
public const int DefaultPropertyLabelFontSize = 11;
public const int DefaultDescriptionLabelFontSize = 10;
public const string DefaultFontName = ".AppleSystemUIFont";
public virtual bool TriggerRowChange => false;
PropertyViewModel viewModel;
public PropertyViewModel ViewModel {
get { return viewModel; }
set {
if (viewModel == value)
return;
PropertyViewModel oldModel = this.viewModel;
if (oldModel != null) {
oldModel.PropertyChanged -= OnPropertyChanged;
oldModel.ErrorsChanged -= HandleErrorsChanged;
}
this.viewModel = value;
OnViewModelChanged (oldModel);
viewModel.PropertyChanged += OnPropertyChanged;
// FIXME: figure out what we want errors to display as (tooltip, etc.)
viewModel.ErrorsChanged += HandleErrorsChanged;
}
}
[Export ("_primitiveSetDefaultNextKeyView:")]
public void SetDefaultNextKeyView (NSView child)
{
if (child == FirstKeyView || child == LastKeyView) {
UpdateKeyViews ();
}
}
public void UpdateKeyViews (bool backward = true, bool forward = true)
{
if (TableRow < 0)
return;
PropertyEditorControl ctrl = null;
//FIXME: don't hardcode column
if (backward && TableRow > 0 && (ctrl = TableView.GetView (1, TableRow - 1, false) as PropertyEditorControl) != null) {
ctrl.LastKeyView.NextKeyView = FirstKeyView;
ctrl.UpdateKeyViews (forward: false);
}
//FIXME: don't hardcode column
if (forward && TableRow < TableView.RowCount - 1 && (ctrl = TableView.GetView (1, TableRow + 1, false) as PropertyEditorControl) != null) {
LastKeyView.NextKeyView = ctrl.FirstKeyView;
ctrl.UpdateKeyViews (backward: false);
}
}
/// <remarks>You should treat the implementation of this as static.</remarks>
public virtual nint GetHeight (PropertyViewModel vm)
{
return DefaultControlHeight;
}
protected abstract void UpdateValue ();
protected virtual void OnViewModelChanged (PropertyViewModel oldModel)
{
SetEnabled ();
UpdateValue ();
UpdateAccessibilityValues ();
// Hook this up so we know when to reset values
PropertyButton.ViewModel = viewModel;
}
protected virtual void OnPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Value") {
UpdateValue ();
}
}
/// <summary>
/// Update the display with any errors we need to show or remove
/// </summary>
/// <param name="errors">The error messages to display to the user</param>
protected abstract void UpdateErrorsDisplayed (IEnumerable errors);
protected abstract void HandleErrorsChanged (object sender, System.ComponentModel.DataErrorsChangedEventArgs e);
protected abstract void SetEnabled ();
protected abstract void UpdateAccessibilityValues ();
}
internal abstract class PropertyEditorControl<TViewModel> : PropertyEditorControl
where TViewModel : PropertyViewModel
{
internal new TViewModel ViewModel
{
get { return (TViewModel)base.ViewModel; }
set { base.ViewModel = value; }
}
}
}
|