Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit e0dbfec

Browse files
authored
Merge pull request #8958 from mono/jstedfast-baseline-offset-fixes
[Debugger] Let Cocoa Do The Right Thing(tm)
2 parents e319e57 + 3a5b5cb commit e0dbfec

File tree

7 files changed

+147
-181
lines changed

7 files changed

+147
-181
lines changed

main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
<Compile Include="MonoDevelop.Debugger\ObjectValue\Mac\MacDebuggerObjectTypeView.cs" />
208208
<Compile Include="MonoDevelop.Debugger\ObjectValue\Mac\MacDebuggerObjectPinView.cs" />
209209
<Compile Include="MonoDevelop.Debugger\ObjectValue\ExpressionEventArgs.cs" />
210+
<Compile Include="MonoDevelop.Debugger\ObjectValue\Mac\MacDebuggerTextField.cs" />
210211
</ItemGroup>
211212
<ItemGroup Condition="$(OS) != 'Windows_NT'">
212213
<Compile Include="MonoDevelop.Debugger.VSTextView\ExceptionCaught\ExceptionCaughtProvider.cs" />

main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ObjectValue/Mac/MacDebuggerObjectCellViewBase.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
// THE SOFTWARE.
2626

2727
using System;
28+
using System.Globalization;
29+
using System.Collections.Generic;
2830

2931
using AppKit;
3032
using Foundation;
3133
using CoreGraphics;
34+
using CoreText;
3235

3336
using Xwt.Drawing;
3437

@@ -54,7 +57,7 @@ protected MacDebuggerObjectCellViewBase (IntPtr handle) : base (handle)
5457
{
5558
}
5659

57-
protected MacObjectValueTreeView TreeView {
60+
public MacObjectValueTreeView TreeView {
5861
get; private set;
5962
}
6063

@@ -150,24 +153,14 @@ protected static CGColor GetCGColor (Color color)
150153
return new CGColor ((nfloat) color.Red, (nfloat) color.Green, (nfloat) color.Blue);
151154
}
152155

153-
protected static NSAttributedString GetAttributedString (string text, bool center = false)
154-
{
155-
var paragraphStyle = center ? new NSMutableParagraphStyle { Alignment = NSTextAlignment.Center } : null;
156-
157-
return new NSAttributedString (text ?? string.Empty, baselineOffset: 1, paragraphStyle: paragraphStyle);
158-
}
159-
160156
protected static NSAttributedString GetAttributedPlaceholderString (string text)
161157
{
162-
return new NSAttributedString (text ?? string.Empty, baselineOffset: 1, strokeColor: NSColor.PlaceholderTextColor);
158+
return new NSAttributedString (text ?? string.Empty, strokeColor: NSColor.PlaceholderTextColor);
163159
}
164160

165161
protected void UpdateFont (NSControl control, int sizeDelta = 0)
166162
{
167-
var font = TreeView.CustomFont ?? TreeView.Font;
168-
169-
if (font == null)
170-
return;
163+
var font = TreeView.CustomFont;
171164

172165
if (sizeDelta != 0) {
173166
control.Font = NSFont.FromDescription (font.FontDescriptor, font.PointSize + sizeDelta);
@@ -192,7 +185,7 @@ public override NSBackgroundStyle BackgroundStyle {
192185

193186
protected abstract void UpdateContents ();
194187

195-
protected void Refresh ()
188+
public void Refresh ()
196189
{
197190
UpdateContents ();
198191
SetNeedsDisplayInRect (Frame);

main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ObjectValue/Mac/MacDebuggerObjectNameView.cs

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
using System.Collections.Generic;
2929

3030
using AppKit;
31-
using Foundation;
3231

3332
using MonoDevelop.Core;
3433
using MonoDevelop.Ide;
@@ -42,81 +41,6 @@ namespace MonoDevelop.Debugger
4241
/// </summary>
4342
class MacDebuggerObjectNameView : MacDebuggerObjectCellViewBase
4443
{
45-
class EditableTextField : NSTextField
46-
{
47-
readonly MacDebuggerObjectNameView nameView;
48-
string oldValue, newValue;
49-
bool editing;
50-
51-
public EditableTextField (MacDebuggerObjectNameView nameView)
52-
{
53-
this.nameView = nameView;
54-
}
55-
56-
public override bool AcceptsFirstResponder ()
57-
{
58-
if (!base.AcceptsFirstResponder ())
59-
return false;
60-
61-
// Note: The MacDebuggerObjectNameView sets the PlaceholderAttributedString property
62-
// so that it can control the font color and the baseline offset. Unfortunately, this
63-
// breaks once the NSTextField is in "edit" mode because the placeholder text ends up
64-
// being rendered as black instead of gray. By reverting to using the basic
65-
// PlaceholderString property once we enter "edit" mode, it fixes the text color.
66-
var placeholder = PlaceholderAttributedString;
67-
68-
if (placeholder != null)
69-
PlaceholderString = placeholder.Value;
70-
71-
TextColor = NSColor.ControlText;
72-
73-
return true;
74-
}
75-
76-
public override void DidBeginEditing (NSNotification notification)
77-
{
78-
base.DidBeginEditing (notification);
79-
nameView.TreeView.OnStartEditing ();
80-
oldValue = newValue = StringValue.Trim ();
81-
editing = true;
82-
}
83-
84-
public override void DidChange (NSNotification notification)
85-
{
86-
newValue = StringValue.Trim ();
87-
base.DidChange (notification);
88-
}
89-
90-
public override void DidEndEditing (NSNotification notification)
91-
{
92-
base.DidEndEditing (notification);
93-
94-
if (!editing)
95-
return;
96-
97-
editing = false;
98-
99-
nameView.TreeView.OnEndEditing ();
100-
101-
if (nameView.Node is AddNewExpressionObjectValueNode) {
102-
if (newValue.Length > 0)
103-
nameView.TreeView.OnExpressionAdded (newValue);
104-
} else if (newValue != oldValue) {
105-
nameView.TreeView.OnExpressionEdited (nameView.Node, newValue);
106-
}
107-
108-
oldValue = newValue = null;
109-
}
110-
111-
protected override void Dispose (bool disposing)
112-
{
113-
if (disposing)
114-
nameView.Dispose ();
115-
116-
base.Dispose (disposing);
117-
}
118-
}
119-
12044
readonly List<NSLayoutConstraint> constraints = new List<NSLayoutConstraint> ();
12145
PreviewButtonIcon currentIcon;
12246
bool previewIconVisible;
@@ -128,15 +52,13 @@ public MacDebuggerObjectNameView (MacObjectValueTreeView treeView) : base (treeV
12852
TranslatesAutoresizingMaskIntoConstraints = false
12953
};
13054

131-
TextField = new EditableTextField (this) {
132-
AutoresizingMask = NSViewResizingMask.WidthSizable,
55+
TextField = new MacDebuggerTextField (this) {
13356
TranslatesAutoresizingMaskIntoConstraints = false,
57+
MaximumNumberOfLines = 1,
13458
DrawsBackground = false,
13559
Bordered = false,
13660
Editable = false
13761
};
138-
TextField.Cell.UsesSingleLineMode = true;
139-
TextField.Cell.Wraps = false;
14062

14163
AddSubview (ImageView);
14264
AddSubview (TextField);
@@ -205,7 +127,7 @@ protected override void UpdateContents ()
205127
}
206128

207129
TextField.PlaceholderAttributedString = GetAttributedPlaceholderString (placeholder);
208-
TextField.AttributedStringValue = GetAttributedString (name);
130+
TextField.StringValue = name;
209131
TextField.TextColor = textColor;
210132
TextField.Editable = editable;
211133
UpdateFont (TextField);

main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ObjectValue/Mac/MacDebuggerObjectTypeView.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ class MacDebuggerObjectTypeView : MacDebuggerObjectCellViewBase
3737
{
3838
public MacDebuggerObjectTypeView (MacObjectValueTreeView treeView) : base (treeView, "type")
3939
{
40-
TextField = new NSTextField {
41-
AutoresizingMask = NSViewResizingMask.WidthSizable,
40+
TextField = new MacDebuggerTextField (this) {
4241
TranslatesAutoresizingMaskIntoConstraints = false,
4342
BackgroundColor = NSColor.Clear,
43+
MaximumNumberOfLines = 1,
4444
Bordered = false,
4545
Editable = false
4646
};
47-
TextField.Cell.UsesSingleLineMode = true;
48-
TextField.Cell.Wraps = false;
4947

5048
AddSubview (TextField);
5149

@@ -60,7 +58,7 @@ public MacDebuggerObjectTypeView (IntPtr handle) : base (handle)
6058

6159
protected override void UpdateContents ()
6260
{
63-
TextField.AttributedStringValue = GetAttributedString (Node?.TypeName);
61+
TextField.StringValue = Node?.TypeName ?? string.Empty;
6462
UpdateFont (TextField);
6563
TextField.SizeToFit ();
6664

main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ObjectValue/Mac/MacDebuggerObjectValueView.cs

Lines changed: 5 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
using System.Collections.Generic;
2929

3030
using AppKit;
31-
using Foundation;
3231
using CoreGraphics;
3332

3433
using Xwt.Drawing;
@@ -42,77 +41,6 @@ namespace MonoDevelop.Debugger
4241
/// </summary>
4342
class MacDebuggerObjectValueView : MacDebuggerObjectCellViewBase
4443
{
45-
class EditableTextField : NSTextField
46-
{
47-
readonly MacDebuggerObjectValueView valueView;
48-
string oldValue, newValue;
49-
bool editing;
50-
51-
public EditableTextField (MacDebuggerObjectValueView valueView)
52-
{
53-
this.valueView = valueView;
54-
}
55-
56-
public override bool AcceptsFirstResponder ()
57-
{
58-
if (!base.AcceptsFirstResponder ())
59-
return false;
60-
61-
// Note: The MacDebuggerObjectValueView sets the PlaceholderAttributedString property
62-
// so that it can control the font color and the baseline offset. Unfortunately, this
63-
// breaks once the NSTextField is in "edit" mode because the placeholder text ends up
64-
// being rendered as black instead of gray. By reverting to using the basic
65-
// PlaceholderString property once we enter "edit" mode, it fixes the text color.
66-
var placeholder = PlaceholderAttributedString;
67-
68-
if (placeholder != null)
69-
PlaceholderString = placeholder.Value;
70-
71-
TextColor = NSColor.ControlText;
72-
73-
return true;
74-
}
75-
76-
public override void DidBeginEditing (NSNotification notification)
77-
{
78-
base.DidBeginEditing (notification);
79-
valueView.TreeView.OnStartEditing ();
80-
oldValue = newValue = StringValue.Trim ();
81-
editing = true;
82-
}
83-
84-
public override void DidChange (NSNotification notification)
85-
{
86-
newValue = StringValue.Trim ();
87-
base.DidChange (notification);
88-
}
89-
90-
public override void DidEndEditing (NSNotification notification)
91-
{
92-
base.DidEndEditing (notification);
93-
94-
if (!editing)
95-
return;
96-
97-
editing = false;
98-
99-
valueView.TreeView.OnEndEditing ();
100-
101-
if (newValue != oldValue && valueView.TreeView.GetEditValue (valueView.Node, newValue))
102-
valueView.Refresh ();
103-
104-
oldValue = newValue = null;
105-
}
106-
107-
protected override void Dispose (bool disposing)
108-
{
109-
if (disposing)
110-
valueView.Dispose ();
111-
112-
base.Dispose (disposing);
113-
}
114-
}
115-
11644
readonly List<NSLayoutConstraint> constraints = new List<NSLayoutConstraint> ();
11745
NSProgressIndicator spinner;
11846
bool spinnerVisible;
@@ -160,15 +88,13 @@ public MacDebuggerObjectValueView (MacObjectValueTreeView treeView) : base (tree
16088
viewerButton.Bordered = false;
16189
viewerButton.Activated += OnViewerButtonActivated;
16290

163-
TextField = new EditableTextField (this) {
164-
AutoresizingMask = NSViewResizingMask.WidthSizable,
91+
TextField = new MacDebuggerTextField (this) {
16592
TranslatesAutoresizingMaskIntoConstraints = false,
93+
MaximumNumberOfLines = 1,
16694
DrawsBackground = false,
16795
Bordered = false,
16896
Editable = false
16997
};
170-
TextField.Cell.UsesSingleLineMode = true;
171-
TextField.Cell.Wraps = false;
17298

17399
AddSubview (TextField);
174100
}
@@ -318,7 +244,7 @@ protected override void UpdateContents ()
318244

319245
// Third Item: Value Button
320246
if (valueButtonText != null && !((MacObjectValueNode) ObjectValue).HideValueButton) {
321-
valueButton.AttributedTitle = GetAttributedString (valueButtonText, true);
247+
valueButton.Title = valueButtonText;
322248
UpdateFont (valueButton, -3);
323249
valueButton.SizeToFit ();
324250

@@ -357,10 +283,11 @@ protected override void UpdateContents ()
357283
}
358284

359285
// Fifth Item: Text Value
360-
TextField.AttributedStringValue = GetAttributedString (strval);
286+
TextField.StringValue = strval;
361287
TextField.TextColor = textColor;
362288
TextField.Editable = editable;
363289
UpdateFont (TextField);
290+
TextField.SizeToFit ();
364291

365292
constraints.Add (TextField.CenterYAnchor.ConstraintEqualToAnchor (CenterYAnchor));
366293
views.Add (TextField);
@@ -380,8 +307,6 @@ protected override void UpdateContents ()
380307
foreach (var constraint in constraints)
381308
constraint.Active = true;
382309

383-
TextField.SizeToFit ();
384-
385310
OptimalWidth += TextField.Frame.Width;
386311
OptimalWidth += MarginSize;
387312
}

0 commit comments

Comments
 (0)