Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit 1b4da57

Browse files
authored
Merge pull request #545 from xamarin/dominique-ScrollControlIntoViewWhenTabbing
[Mac] When tabbing scroll focused control into view.
2 parents 6e97c78 + 743e3fa commit 1b4da57

14 files changed

+122
-44
lines changed

Xamarin.PropertyEditing.Mac/Controls/BooleanEditorControl.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ internal class BooleanEditorControl
1414
public BooleanEditorControl (IHostResourceProvider hostResource)
1515
: base (hostResource)
1616
{
17-
BooleanEditor = new NSButton {
18-
AllowsMixedState = true,
19-
ControlSize = NSControlSize.Small,
20-
Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize),
21-
Title = string.Empty,
22-
TranslatesAutoresizingMaskIntoConstraints = false,
23-
};
24-
BooleanEditor.SetButtonType (NSButtonType.Switch);
17+
BooleanEditor = new FocusableBooleanButton ();
2518

2619
// update the value on 'enter'
2720
BooleanEditor.Activated += (sender, e) => {

Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,8 @@
99

1010
namespace Xamarin.PropertyEditing.Mac
1111
{
12-
internal class ColorPopUpButton : NSPopUpButton
12+
internal class ColorPopUpButton : FocusablePopUpButton
1313
{
14-
public ColorPopUpButton () : base ()
15-
{
16-
}
17-
18-
public ColorPopUpButton (CGRect frame) : base (frame, true)
19-
{
20-
}
21-
22-
public ColorPopUpButton (IntPtr handle) : base (handle)
23-
{
24-
}
25-
2614
public NSPopover Popover { get; set; }
2715

2816
public override void MouseDown (NSEvent theEvent)

Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,8 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel)
7777

7878
NSButton checkbox;
7979
if (i >= this.combinableList.Count) {
80-
checkbox = new NSButton {
81-
AllowsExpansionToolTips = true,
82-
AllowsMixedState = true,
83-
Cell = {
84-
LineBreakMode = NSLineBreakMode.TruncatingTail,
85-
UsesSingleLineMode = true,
86-
},
87-
ControlSize = NSControlSize.Small,
88-
Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize),
89-
TranslatesAutoresizingMaskIntoConstraints = false,
90-
};
91-
92-
checkbox.SetButtonType (NSButtonType.Switch);
80+
checkbox = new FocusableBooleanButton ();
81+
9382
checkbox.Activated += SelectionChanged;
9483

9584
AddSubview (checkbox);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using AppKit;
3+
4+
namespace Xamarin.PropertyEditing.Mac
5+
{
6+
internal class FocusableBooleanButton : NSButton
7+
{
8+
public override bool CanBecomeKeyView { get { return Enabled; } }
9+
10+
public FocusableBooleanButton ()
11+
{
12+
AllowsExpansionToolTips = true;
13+
AllowsMixedState = true;
14+
Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
15+
Cell.UsesSingleLineMode = true;
16+
ControlSize = NSControlSize.Small;
17+
Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize);
18+
Title = string.Empty;
19+
TranslatesAutoresizingMaskIntoConstraints = false;
20+
21+
SetButtonType (NSButtonType.Switch);
22+
}
23+
24+
public override bool BecomeFirstResponder ()
25+
{
26+
var willBecomeFirstResponder = base.BecomeFirstResponder ();
27+
if (willBecomeFirstResponder) {
28+
ScrollRectToVisible (Bounds);
29+
}
30+
return willBecomeFirstResponder;
31+
}
32+
}
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using AppKit;
3+
4+
namespace Xamarin.PropertyEditing.Mac
5+
{
6+
internal class FocusableButton : NSButton
7+
{
8+
public override bool CanBecomeKeyView { get { return Enabled; } }
9+
10+
public FocusableButton ()
11+
{
12+
AllowsExpansionToolTips = true;
13+
AllowsMixedState = true;
14+
Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
15+
Cell.UsesSingleLineMode = true;
16+
ControlSize = NSControlSize.Small;
17+
Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultFontSize);
18+
Title = string.Empty;
19+
TranslatesAutoresizingMaskIntoConstraints = false;
20+
}
21+
22+
public override bool BecomeFirstResponder ()
23+
{
24+
var willBecomeFirstResponder = base.BecomeFirstResponder ();
25+
if (willBecomeFirstResponder) {
26+
ScrollRectToVisible (Bounds);
27+
}
28+
return willBecomeFirstResponder;
29+
}
30+
}
31+
}

Xamarin.PropertyEditing.Mac/Controls/Custom/FocusableComboBox.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
using Foundation;
1+
using Foundation;
22
using AppKit;
33

44
namespace Xamarin.PropertyEditing.Mac
55
{
6-
class FocusableComboBox : NSComboBox
6+
internal class FocusableComboBox : NSComboBox
77
{
8+
public override bool BecomeFirstResponder ()
9+
{
10+
var willBecomeFirstResponder = base.BecomeFirstResponder ();
11+
if (willBecomeFirstResponder) {
12+
ScrollRectToVisible (Bounds);
13+
}
14+
return willBecomeFirstResponder;
15+
}
16+
817
public override bool ShouldBeginEditing (NSText textObject)
918
{
1019
textObject.Delegate = new FocusableComboBoxDelegate ();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using AppKit;
3+
using CoreGraphics;
4+
5+
namespace Xamarin.PropertyEditing.Mac
6+
{
7+
internal class FocusablePopUpButton : NSPopUpButton
8+
{
9+
public override bool CanBecomeKeyView { get { return Enabled; } }
10+
11+
public override bool BecomeFirstResponder ()
12+
{
13+
var willBecomeFirstResponder = base.BecomeFirstResponder ();
14+
if (willBecomeFirstResponder) {
15+
ScrollRectToVisible (Bounds);
16+
}
17+
return willBecomeFirstResponder;
18+
}
19+
}
20+
}

Xamarin.PropertyEditing.Mac/Controls/Custom/PropertyTextField.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,14 @@ public PropertyTextField ()
1111
Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
1212
Cell.UsesSingleLineMode = true;
1313
}
14+
15+
public override bool BecomeFirstResponder ()
16+
{
17+
var willBecomeFirstResponder = base.BecomeFirstResponder ();
18+
if (willBecomeFirstResponder) {
19+
ScrollRectToVisible (Bounds);
20+
}
21+
return willBecomeFirstResponder;
22+
}
1423
}
1524
}

Xamarin.PropertyEditing.Mac/Controls/NumericEditorControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel)
140140

141141
if (ViewModel.HasInputModes) {
142142
if (this.inputModePopup == null) {
143-
this.inputModePopup = new NSPopUpButton {
143+
this.inputModePopup = new FocusablePopUpButton {
144144
Menu = new NSMenu (),
145145
TranslatesAutoresizingMaskIntoConstraints = false,
146146
};

Xamarin.PropertyEditing.Mac/Controls/ObjectEditorControl.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ public ObjectEditorControl (IHostResourceProvider hostResources)
1919
};
2020
AddSubview (this.typeLabel);
2121

22-
this.createObject = new NSButton {
22+
this.createObject = new FocusableButton {
2323
Title = Properties.Resources.New,
24-
TranslatesAutoresizingMaskIntoConstraints = false,
2524
BezelStyle = NSBezelStyle.Rounded
2625
};
2726
this.createObject.Activated += OnNewPressed;

0 commit comments

Comments
 (0)