blob: e8e93ce7af3e81cf383051c7e4e9e77663306f55 (
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
|
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; }
const int DefaultRowHeight = 22;
protected 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 nfloat RowHeight { get; set; } = DefaultRowHeight;
public bool TriggerRowChange => RowHeight != DefaultRowHeight;
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);
}
}
protected abstract void UpdateValue ();
protected virtual void OnViewModelChanged (PropertyViewModel oldModel)
{
SetEnabled ();
UpdateValue ();
UpdateAccessibilityValues ();
}
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 ();
}
}
|