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
|
using System;
using System.Collections;
using AppKit;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
internal class BooleanEditorControl
: PropertyEditorControl<PropertyViewModel<bool?>>
{
public BooleanEditorControl (IHostResourceProvider hostResource)
: base (hostResource)
{
BooleanEditor = new FocusableBooleanButton ();
BooleanEditor.Title = string.Empty;
// update the value on 'enter'
BooleanEditor.Activated += (sender, e) => {
switch (BooleanEditor.State) {
case NSCellStateValue.Off:
ViewModel.Value = false;
break;
case NSCellStateValue.On:
ViewModel.Value = true;
break;
}
};
AddSubview (BooleanEditor);
this.AddConstraints (new[] {
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f),
NSLayoutConstraint.Create (BooleanEditor, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f),
});
}
internal NSButton BooleanEditor { get; set; }
public override NSView FirstKeyView => BooleanEditor;
public override NSView LastKeyView => BooleanEditor;
public string Title {
get { return BooleanEditor.Title; }
set { BooleanEditor.Title = value; }
}
protected override void UpdateValue ()
{
if (ViewModel.Value.HasValue) {
BooleanEditor.State = ViewModel.Value.Value ? NSCellStateValue.On : NSCellStateValue.Off;
BooleanEditor.AllowsMixedState = false;
} else {
BooleanEditor.AllowsMixedState = true;
BooleanEditor.State = NSCellStateValue.Mixed;
}
}
protected override void SetEnabled ()
{
BooleanEditor.Enabled = ViewModel.Property.CanWrite;
}
protected override void UpdateAccessibilityValues ()
{
BooleanEditor.AccessibilityEnabled = BooleanEditor.Enabled;
BooleanEditor.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityBoolean, ViewModel.Property.Name);
}
}
}
|