Skip to content

Commit 9b71b6d

Browse files
committed
[1] Make ObjectTextBox and ValueTextBox be inheritable by outside of library.
[2] Fix warnings reported by ReSharper.
1 parent 8db4417 commit 9b71b6d

12 files changed

+27
-33
lines changed

Avalonia/Controls/ControlExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public static bool RemoveFromParent(this Control control)
2121
return false;
2222
if (parent is ContentControl contentControl)
2323
{
24-
if (contentControl.Content != control)
24+
if (!ReferenceEquals(contentControl.Content, control))
2525
return false;
2626
contentControl.Content = null;
2727
}
2828
else if (parent is ContentPresenter contentPresenter)
2929
{
30-
if (contentPresenter.Content != control)
30+
if (!ReferenceEquals(contentPresenter.Content, control))
3131
return false;
3232
contentPresenter.Content = null;
3333
}
@@ -39,22 +39,22 @@ public static bool RemoveFromParent(this Control control)
3939
}
4040
else if (parent is HeaderedContentControl headeredContentControl)
4141
{
42-
if (headeredContentControl.Header == control)
42+
if (ReferenceEquals(headeredContentControl.Header, control))
4343
headeredContentControl.Header = null;
44-
else if (headeredContentControl.Content == control)
44+
else if (ReferenceEquals(headeredContentControl.Content, control))
4545
headeredContentControl.Content = null;
4646
else
4747
return false;
4848
}
4949
else if (parent is HeaderedItemsControl headeredItemsControl)
5050
{
51-
if (headeredItemsControl.Header != control)
51+
if (!ReferenceEquals(headeredItemsControl.Header, control))
5252
return false;
5353
headeredItemsControl.Header = null;
5454
}
5555
else if (parent is HeaderedSelectingItemsControl headeredSelectingItemsControl)
5656
{
57-
if (headeredSelectingItemsControl.Header != control)
57+
if (!ReferenceEquals(headeredSelectingItemsControl.Header, control))
5858
return false;
5959
headeredSelectingItemsControl.Header = null;
6060
}

Avalonia/Controls/DateTimeTextBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DateTimeTextBox : ValueTextBox<DateTime>
1414
/// <summary>
1515
/// Property of <see cref="ValueTextBox{DateTime}.Value"/>.
1616
/// </summary>
17-
public static readonly new DirectProperty<DateTimeTextBox, DateTime?> ValueProperty = AvaloniaProperty.RegisterDirect<DateTimeTextBox, DateTime?>(nameof(Value), t => t.Value, (t, v) => t.Value = v);
17+
public static new readonly DirectProperty<DateTimeTextBox, DateTime?> ValueProperty = AvaloniaProperty.RegisterDirect<DateTimeTextBox, DateTime?>(nameof(Value), t => t.Value, (t, v) => t.Value = v);
1818

1919

2020
// Constants.

Avalonia/Controls/IPAddressTextBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class IPAddressTextBox : ObjectTextBox<IPAddress>
1717
/// <summary>
1818
/// Property of <see cref="ObjectTextBox{IPAddress}.Object"/>.
1919
/// </summary>
20-
public static readonly new DirectProperty<IPAddressTextBox, IPAddress?> ObjectProperty = AvaloniaProperty.RegisterDirect<IPAddressTextBox, IPAddress?>(nameof(Object), t => t.Object, (t, o) => t.Object = o);
20+
public static new readonly DirectProperty<IPAddressTextBox, IPAddress?> ObjectProperty = AvaloniaProperty.RegisterDirect<IPAddressTextBox, IPAddress?>(nameof(Object), t => t.Object, (t, o) => t.Object = o);
2121

2222

2323
/// <summary>

Avalonia/Controls/IntegerTextBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class IntegerTextBox : ValueTextBox<long>
2626
/// <summary>
2727
/// Property of <see cref="ValueTextBox{Int64}.Value"/>.
2828
/// </summary>
29-
public static readonly new DirectProperty<IntegerTextBox, long?> ValueProperty = AvaloniaProperty.RegisterDirect<IntegerTextBox, long?>(nameof(Value), t => t.Value, (t, v) => t.Value = v);
29+
public static new readonly DirectProperty<IntegerTextBox, long?> ValueProperty = AvaloniaProperty.RegisterDirect<IntegerTextBox, long?>(nameof(Value), t => t.Value, (t, v) => t.Value = v);
3030

3131

3232
// Constants.

Avalonia/Controls/ObjectTextBox.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public abstract class ObjectTextBox : TextBox
3838
/// <summary>
3939
/// Initialize new <see cref="ObjectTextBox"/> instance.
4040
/// </summary>
41-
internal ObjectTextBox()
41+
protected ObjectTextBox()
4242
{
4343
this.validateAction = new ScheduledAction(() => this.Validate());
4444
this.PastingFromClipboard += (_, e) =>
@@ -113,10 +113,7 @@ protected virtual void OnPastingFromClipboard(string? text)
113113
{
114114
if (text is null)
115115
return;
116-
if (this.AcceptsReturn)
117-
this.SelectedText = text;
118-
else
119-
this.SelectedText = text.RemoveLineBreaks();
116+
this.SelectedText = this.AcceptsReturn ? text : text.RemoveLineBreaks();
120117
}
121118

122119

@@ -300,7 +297,7 @@ protected ObjectTextBox()
300297

301298

302299
/// <inheritdoc/>
303-
protected override sealed bool CheckObjectEquality(object? x, object? y) =>
300+
protected sealed override bool CheckObjectEquality(object? x, object? y) =>
304301
this.CheckObjectEquality(x as T, y as T);
305302

306303

@@ -314,7 +311,7 @@ protected override sealed bool CheckObjectEquality(object? x, object? y) =>
314311

315312

316313
/// <inheritdoc/>
317-
protected override sealed string? ConvertToText(object obj) =>
314+
protected sealed override string? ConvertToText(object obj) =>
318315
obj is T t ? this.ConvertToText(t) : null;
319316

320317

@@ -350,7 +347,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
350347

351348

352349
/// <inheritdoc/>
353-
protected override sealed bool TryConvertToObject(string text, out object? obj)
350+
protected sealed override bool TryConvertToObject(string text, out object? obj)
354351
{
355352
if (this.TryConvertToObject(text, out var t))
356353
{

Avalonia/Controls/RealNumberTextBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class RealNumberTextBox : ValueTextBox<double>
2727
/// <summary>
2828
/// Property of <see cref="ValueTextBox{Double}.Value"/>.
2929
/// </summary>
30-
public static readonly new DirectProperty<RealNumberTextBox, double?> ValueProperty = AvaloniaProperty.RegisterDirect<RealNumberTextBox, double?>(nameof(Value), t => t.Value, (t, v) => t.Value = v);
30+
public static new readonly DirectProperty<RealNumberTextBox, double?> ValueProperty = AvaloniaProperty.RegisterDirect<RealNumberTextBox, double?>(nameof(Value), t => t.Value, (t, v) => t.Value = v);
3131

3232

3333
/// <summary>

Avalonia/Controls/SelectableTextBlock.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using CarinaStudio.Threading;
99
using Microsoft.Extensions.Logging;
1010
using System;
11-
using System.Diagnostics.CodeAnalysis;
1211

1312
namespace CarinaStudio.Controls
1413
{
@@ -142,7 +141,7 @@ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
142141
this.window = TopLevel.GetTopLevel(this) as Avalonia.Controls.Window;
143142
if (Platform.IsMacOS)
144143
{
145-
this.isWindowActiveObserverToken = this.window?.GetObservable(Window.IsActiveProperty).Subscribe(_ =>
144+
this.isWindowActiveObserverToken = this.window?.GetObservable(WindowBase.IsActiveProperty).Subscribe(_ =>
146145
this.updateToolTipAction.Schedule());
147146
this.updateToolTipAction.Schedule();
148147
}

Avalonia/Controls/TextBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
141141
this.window = TopLevel.GetTopLevel(this) as Avalonia.Controls.Window;
142142
if (Platform.IsMacOS)
143143
{
144-
this.isWindowActiveObserverToken = this.window?.GetObservable(Window.IsActiveProperty).Subscribe(_ =>
144+
this.isWindowActiveObserverToken = this.window?.GetObservable(WindowBase.IsActiveProperty).Subscribe(_ =>
145145
this.updateToolTipAction.Schedule());
146146
this.updateToolTipAction.Schedule();
147147
}

Avalonia/Controls/TimeSpanTextBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class TimeSpanTextBox : ValueTextBox<TimeSpan>
1414
/// <summary>
1515
/// Property of <see cref="ValueTextBox{TimeSpan}.Value"/>.
1616
/// </summary>
17-
public static readonly new DirectProperty<TimeSpanTextBox, TimeSpan?> ValueProperty = AvaloniaProperty.RegisterDirect<TimeSpanTextBox, TimeSpan?>(nameof(Value), t => t.Value, (t, v) => t.Value = v);
17+
public static new readonly DirectProperty<TimeSpanTextBox, TimeSpan?> ValueProperty = AvaloniaProperty.RegisterDirect<TimeSpanTextBox, TimeSpan?>(nameof(Value), t => t.Value, (t, v) => t.Value = v);
1818

1919

2020
// Static fields.

Avalonia/Controls/UriTextBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class UriTextBox : ObjectTextBox<Uri>
1818
/// <summary>
1919
/// Property of <see cref="ObjectTextBox{Uri}.Object"/>.
2020
/// </summary>
21-
public static readonly new DirectProperty<UriTextBox, Uri?> ObjectProperty = AvaloniaProperty.RegisterDirect<UriTextBox, Uri?>(nameof(Object), t => t.Object, (t, o) => t.Object = o);
21+
public static new readonly DirectProperty<UriTextBox, Uri?> ObjectProperty = AvaloniaProperty.RegisterDirect<UriTextBox, Uri?>(nameof(Object), t => t.Object, (t, o) => t.Object = o);
2222
/// <summary>
2323
/// Property of <see cref="UriKind"/>.
2424
/// </summary>

Avalonia/Controls/ValueTextBox.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public abstract class ValueTextBox : TextBox
6565
/// <summary>
6666
/// Initialize new <see cref="ValueTextBox"/> instance.
6767
/// </summary>
68-
internal ValueTextBox()
68+
protected ValueTextBox()
6969
{
7070
if (!IsNullValueAllowedProperty.GetDefaultValue(this.GetType()))
7171
this.lastValidValue = this.GetValue(DefaultValueProperty);
@@ -178,10 +178,7 @@ protected virtual void OnPastingFromClipboard(string? text)
178178
{
179179
if (text is null)
180180
return;
181-
if (this.AcceptsReturn)
182-
this.SelectedText = text;
183-
else
184-
this.SelectedText = text.RemoveLineBreaks();
181+
this.SelectedText = this.AcceptsReturn ? text : text.RemoveLineBreaks();
185182
}
186183

187184

@@ -461,7 +458,7 @@ protected ValueTextBox()
461458

462459

463460
/// <inheritdoc/>
464-
protected override sealed bool CheckValueEquality(object? x, object? y)
461+
protected sealed override bool CheckValueEquality(object? x, object? y)
465462
{
466463
var valueX = x is T tx ? (T?)tx : null;
467464
var valueY = y is T ty ? (T?)ty : null;
@@ -479,7 +476,7 @@ protected override sealed bool CheckValueEquality(object? x, object? y)
479476

480477

481478
/// <inheritdoc/>
482-
protected override sealed object CoerceValue(object value) =>
479+
protected sealed override object CoerceValue(object value) =>
483480
this.CoerceValue((T)value);
484481

485482

@@ -492,7 +489,7 @@ protected override sealed object CoerceValue(object value) =>
492489

493490

494491
/// <inheritdoc/>
495-
protected override sealed string? ConvertToText(object value) =>
492+
protected sealed override string? ConvertToText(object value) =>
496493
this.ConvertToText((T)value);
497494

498495

@@ -530,7 +527,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
530527

531528

532529
/// <inheritdoc/>
533-
protected override sealed bool TryConvertToValue(string text, out object? value)
530+
protected sealed override bool TryConvertToValue(string text, out object? value)
534531
{
535532
if (this.TryConvertToValue(text, out var t))
536533
{

Avalonia/Controls/Window.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Avalonia.Threading;
44
using CarinaStudio.Collections;
55
using CarinaStudio.MacOS.AppKit;
6+
using CarinaStudio.MacOS.ObjectiveC;
67
using CarinaStudio.Threading;
78
using System;
89
using System.Collections.Generic;
@@ -82,7 +83,7 @@ static void RefreshChildWindowPositions(Avalonia.Controls.Window parent)
8283
if (!isDialog)
8384
{
8485
var handle = (childWindow.TryGetPlatformHandle()?.Handle).GetValueOrDefault();
85-
var childNSWindow = NSWindow.FromHandle<NSWindow>(handle);
86+
var childNSWindow = NSObject.FromHandle<NSWindow>(handle);
8687
childNSWindow?.OrderFront();
8788
}
8889
RefreshChildWindowPositions(childWindow);

0 commit comments

Comments
 (0)