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

Commit f4273f4

Browse files
authored
Merge pull request #532 from xamarin/dominique-Fix531
[Mac] Add PropertyTextField for overflow
2 parents f3fb78d + 2cae9a1 commit f4273f4

File tree

9 files changed

+67
-36
lines changed

9 files changed

+67
-36
lines changed

Xamarin.PropertyEditing.Mac/Controls/CombinablePropertyEditor.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public CombinablePropertyEditor (IHostResourceProvider hostResources)
3131
public override nint GetHeight (EditorViewModel vm)
3232
{
3333
var realVm = (CombinablePropertyViewModel<T>)vm;
34-
return checkHeight * realVm.Choices.Count;
34+
return DefaultControlHeight * realVm.Choices.Count;
3535
}
3636

3737
protected override void HandleErrorsChanged (object sender, DataErrorsChangedEventArgs e)
@@ -63,9 +63,7 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel)
6363
if (ViewModel == null)
6464
return;
6565

66-
nint rowHeight = GetHeight (ViewModel);
67-
68-
float top = checkHeight;
66+
float top = 0;
6967

7068
while (this.combinableList.Count > ViewModel.Choices.Count) {
7169
var child = this.combinableList.KeyAt (ViewModel.Choices.Count);
@@ -80,7 +78,12 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel)
8078
NSButton checkbox;
8179
if (i >= this.combinableList.Count) {
8280
checkbox = new NSButton {
81+
AllowsExpansionToolTips = true,
8382
AllowsMixedState = true,
83+
Cell = {
84+
LineBreakMode = NSLineBreakMode.TruncatingTail,
85+
UsesSingleLineMode = true,
86+
},
8487
ControlSize = NSControlSize.Small,
8588
Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize),
8689
TranslatesAutoresizingMaskIntoConstraints = false,
@@ -90,15 +93,21 @@ protected override void OnViewModelChanged (PropertyViewModel oldModel)
9093
checkbox.Activated += SelectionChanged;
9194

9295
AddSubview (checkbox);
96+
97+
this.AddConstraints (new[] {
98+
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, top),
99+
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
100+
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -33f),
101+
NSLayoutConstraint.Create (checkbox, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, DefaultControlHeight),
102+
});
93103
} else {
94104
checkbox = this.combinableList.KeyAt (i);
95105
}
96106

97107
checkbox.Title = choice.Name;
98-
checkbox.Frame = new CGRect (0, rowHeight - top, Frame.Width, checkHeight);
99108

100109
this.combinableList[checkbox] = choice;
101-
top += checkHeight;
110+
top += DefaultControlHeight;
102111
}
103112

104113
// Set our tabable order
@@ -127,7 +136,6 @@ protected override void UpdateAccessibilityValues ()
127136
}
128137
}
129138

130-
private const int checkHeight = 22;
131139
private readonly OrderedDictionary<NSButton, FlaggableChoiceViewModel<T>> combinableList = new OrderedDictionary<NSButton, FlaggableChoiceViewModel<T>> ();
132140
private NSView firstKeyView;
133141
private NSView lastKeyView;

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
using System;
1+
using System;
22
using AppKit;
33
using CoreGraphics;
44
using Foundation;
55
using ObjCRuntime;
66

77
namespace Xamarin.PropertyEditing.Mac
88
{
9-
public class NumericTextField : NSTextField
9+
internal class NumericTextField : PropertyTextField
1010
{
11-
NSText CachedCurrentEditor {
11+
private NSText CachedCurrentEditor {
1212
get; set;
1313
}
1414

15-
string cachedValueString;
15+
private string cachedValueString;
1616

1717
public bool AllowNegativeValues {
1818
get; set;
@@ -54,7 +54,7 @@ public NumericTextField ()
5454
public override bool ShouldBeginEditing (NSText textObject)
5555
{
5656
CachedCurrentEditor = textObject;
57-
cachedValueString = textObject.Value;
57+
this.cachedValueString = textObject.Value;
5858

5959
if (AllowRatios)
6060
CachedCurrentEditor.Delegate = new RatioValidateDelegate (this);
@@ -81,7 +81,7 @@ public virtual void NotifyValidatedEditingEnded ()
8181

8282
public virtual void ResetInvalidInput ()
8383
{
84-
this.StringValue = cachedValueString;
84+
this.StringValue = this.cachedValueString;
8585
}
8686

8787
public static bool CheckIfNumber (string finalString, ValidationType mode, bool allowNegativeValues)
@@ -93,9 +93,8 @@ public static bool CheckIfNumber (string finalString, ValidationType mode, bool
9393

9494
public static bool ValidateDecimal (string finalString, bool allowNegativeValues)
9595
{
96-
double value;
9796
//Checks parsing to number
98-
if (!double.TryParse (finalString, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentUICulture, out value))
97+
if (!double.TryParse (finalString, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentUICulture, out var value))
9998
return false;
10099
//Checks if needs to be possitive value
101100
if (!allowNegativeValues && value < 0)
@@ -106,9 +105,8 @@ public static bool ValidateDecimal (string finalString, bool allowNegativeValues
106105

107106
public static bool ValidateInteger (string finalString, bool allowNegativeValues)
108107
{
109-
int value;
110108
//Checks parsing to number
111-
if (!int.TryParse (finalString, out value))
109+
if (!int.TryParse (finalString, out var value))
112110
return false;
113111
//Checks if needs to be possitive value
114112
if (!allowNegativeValues && value < 0)
@@ -156,7 +154,7 @@ public override void DidEndEditing (NSNotification notification)
156154
}
157155
}
158156

159-
class KeyUpDownDelegate : NSTextFieldDelegate
157+
internal class KeyUpDownDelegate : NSTextFieldDelegate
160158
{
161159
public event EventHandler<bool> KeyArrowUp;
162160
public event EventHandler<bool> KeyArrowDown;
@@ -194,7 +192,7 @@ protected virtual void OnKeyArrowDown (bool shiftPressed = false)
194192
}
195193
}
196194

197-
public abstract class TextViewValidationDelegate : NSTextViewDelegate
195+
internal abstract class TextViewValidationDelegate : NSTextViewDelegate
198196
{
199197
protected NumericTextField TextField {
200198
get; set;
@@ -233,7 +231,7 @@ public override void TextDidEndEditing (NSNotification notification)
233231
protected abstract bool ValidateFinalString (string value);
234232
}
235233

236-
public class NumericValidationDelegate : TextViewValidationDelegate
234+
internal class NumericValidationDelegate : TextViewValidationDelegate
237235
{
238236
public NumericValidationDelegate (NumericTextField textField)
239237
: base (textField)
@@ -249,7 +247,7 @@ protected override bool ValidateFinalString (string value)
249247
}
250248
}
251249

252-
public class RatioValidateDelegate : TextViewValidationDelegate
250+
internal class RatioValidateDelegate : TextViewValidationDelegate
253251
{
254252
public RatioValidateDelegate (NumericTextField textField)
255253
: base (textField)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using AppKit;
3+
4+
namespace Xamarin.PropertyEditing.Mac
5+
{
6+
internal class PropertyTextField : NSTextField
7+
{
8+
public PropertyTextField ()
9+
{
10+
AllowsExpansionToolTips = true;
11+
Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
12+
Cell.UsesSingleLineMode = true;
13+
}
14+
}
15+
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using AppKit;
33
using CoreGraphics;
44
using Foundation;
@@ -59,14 +59,10 @@ public UnfocusableTextField (CGRect frameRect, string text) : base (frameRect)
5959

6060
private void SetDefaultTextProperties ()
6161
{
62-
this.label = new NSTextField {
62+
this.label = new PropertyTextField {
6363
AccessibilityElement = false,
6464
BackgroundColor = NSColor.Clear,
6565
Bordered = false,
66-
Cell = {
67-
LineBreakMode = NSLineBreakMode.TruncatingTail,
68-
UsesSingleLineMode = true,
69-
},
7066
ControlSize = NSControlSize.Small,
7167
Editable = false,
7268
Font = NSFont.FromFontName (PropertyEditorControl.DefaultFontName, PropertyEditorControl.DefaultPropertyLabelFontSize),

Xamarin.PropertyEditing.Mac/Controls/EditorContainer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public override void ViewWillMoveToSuperview (NSView newSuperview)
8181

8282
private UnfocusableTextField label = new UnfocusableTextField {
8383
Alignment = NSTextAlignment.Right,
84-
TranslatesAutoresizingMaskIntoConstraints = false
84+
Cell = {
85+
LineBreakMode = NSLineBreakMode.TruncatingHead,
86+
},
87+
TranslatesAutoresizingMaskIntoConstraints = false,
8588
};
8689

8790
#if DEBUG // Currently only used to highlight which controls haven't been implemented

Xamarin.PropertyEditing.Mac/Controls/PanelHeaderEditorControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public PanelHeaderEditorControl (IHostResourceProvider hostResources)
2222
NSControlSize controlSize = NSControlSize.Small;
2323
TranslatesAutoresizingMaskIntoConstraints = false;
2424

25-
this.propertyObjectName = new NSTextField {
25+
this.propertyObjectName = new PropertyTextField {
2626
ControlSize = controlSize,
2727
PlaceholderString = LocalizationResources.ObjectNamePlaceholder,
2828
TranslatesAutoresizingMaskIntoConstraints = false,

Xamarin.PropertyEditing.Mac/Controls/PredefinedValuesEditor.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,32 @@ public PredefinedValuesEditor (IHostResourceProvider hostResources)
2121
base.TranslatesAutoresizingMaskIntoConstraints = false;
2222

2323
this.comboBox = new FocusableComboBox {
24-
TranslatesAutoresizingMaskIntoConstraints = false,
24+
AllowsExpansionToolTips = true,
2525
BackgroundColor = NSColor.Clear,
26-
StringValue = String.Empty,
26+
Cell = {
27+
LineBreakMode = NSLineBreakMode.TruncatingTail,
28+
UsesSingleLineMode = true,
29+
},
2730
ControlSize = NSControlSize.Small,
28-
Font = NSFont.FromFontName(DefaultFontName, DefaultFontSize),
31+
Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize),
32+
TranslatesAutoresizingMaskIntoConstraints = false,
33+
StringValue = String.Empty,
2934
};
3035

3136
this.comboBox.SelectionChanged += (sender, e) => {
32-
ViewModel.ValueName = comboBox.SelectedValue.ToString ();
37+
ViewModel.ValueName = this.comboBox.SelectedValue.ToString ();
3338
};
3439

3540
this.popUpButton = new NSPopUpButton {
36-
TranslatesAutoresizingMaskIntoConstraints = false,
37-
StringValue = String.Empty,
41+
AllowsExpansionToolTips = true,
42+
Cell = {
43+
LineBreakMode = NSLineBreakMode.TruncatingTail,
44+
UsesSingleLineMode = true,
45+
},
3846
ControlSize = NSControlSize.Small,
3947
Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize),
48+
TranslatesAutoresizingMaskIntoConstraints = false,
49+
StringValue = String.Empty,
4050
};
4151

4252
popupButtonList = new NSMenu ();

Xamarin.PropertyEditing.Mac/Controls/StringEditorControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal class StringEditorControl
2727
public StringEditorControl (IHostResourceProvider hostResource)
2828
: base (hostResource)
2929
{
30-
this.stringEditor = new NSTextField {
30+
this.stringEditor = new PropertyTextField {
3131
BackgroundColor = NSColor.Clear,
3232
ControlSize = NSControlSize.Small,
3333
Font = NSFont.FromFontName (DefaultFontName, DefaultFontSize),

Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
<Compile Include="Controls\ObjectEditorControl.cs" />
149149
<Compile Include="Controls\TypeSelectorControl.cs" />
150150
<Compile Include="Controls\TypeSelectorWindow.cs" />
151+
<Compile Include="Controls\Custom\PropertyTextField.cs" />
151152
</ItemGroup>
152153
<ItemGroup>
153154
<Folder Include="Controls\" />

0 commit comments

Comments
 (0)