Browse Source

Nullability annotation fixes

pull/165/head
Ionite 1 year ago
parent
commit
abb0cbad90
No known key found for this signature in database
  1. 39
      StabilityMatrix.Avalonia/Controls/CodeCompletion/CompletionWindowBase.cs

39
StabilityMatrix.Avalonia/Controls/CodeCompletion/CompletionWindowBase.cs

@ -38,13 +38,9 @@ namespace StabilityMatrix.Avalonia.Controls.CodeCompletion;
/// <summary> /// <summary>
/// Base class for completion windows. Handles positioning the window at the caret. /// Base class for completion windows. Handles positioning the window at the caret.
/// </summary> /// </summary>
[SuppressMessage("ReSharper", "MemberCanBeProtected.Global")]
public class CompletionWindowBase : Popup public class CompletionWindowBase : Popup
{ {
static CompletionWindowBase()
{
//BackgroundProperty.OverrideDefaultValue(typeof(CompletionWindowBase), Brushes.White);
}
protected override Type StyleKeyOverride => typeof(PopupRoot); protected override Type StyleKeyOverride => typeof(PopupRoot);
/// <summary> /// <summary>
@ -52,8 +48,8 @@ public class CompletionWindowBase : Popup
/// </summary> /// </summary>
public TextArea TextArea { get; } public TextArea TextArea { get; }
private readonly Window _parentWindow; private readonly Window? _parentWindow;
private TextDocument _document; private TextDocument? _document;
/// <summary> /// <summary>
/// Gets/Sets the start of the text range in which the completion window stays open. /// Gets/Sets the start of the text range in which the completion window stays open.
@ -75,11 +71,11 @@ public class CompletionWindowBase : Popup
/// <summary> /// <summary>
/// Creates a new CompletionWindowBase. /// Creates a new CompletionWindowBase.
/// </summary> /// </summary>
public CompletionWindowBase(TextArea textArea) : base() public CompletionWindowBase(TextArea textArea)
{ {
TextArea = textArea ?? throw new ArgumentNullException(nameof(textArea)); TextArea = textArea ?? throw new ArgumentNullException(nameof(textArea));
_parentWindow = textArea.GetVisualRoot() as Window; _parentWindow = textArea.GetVisualRoot() as Window ??
throw new InvalidOperationException("CompletionWindow requires a visual root.");
AddHandler(PointerReleasedEvent, OnMouseUp, handledEventsToo: true); AddHandler(PointerReleasedEvent, OnMouseUp, handledEventsToo: true);
@ -92,7 +88,7 @@ public class CompletionWindowBase : Popup
//Deactivated += OnDeactivated; //Not needed? //Deactivated += OnDeactivated; //Not needed?
Closed += (sender, args) => DetachEvents(); Closed += (_, _) => DetachEvents();
AttachEvents(); AttachEvents();
@ -188,7 +184,7 @@ public class CompletionWindowBase : Popup
#region InputHandler #region InputHandler
private InputHandler _myInputHandler; private InputHandler? _myInputHandler;
/// <summary> /// <summary>
/// A dummy input handler (that justs invokes the default input handler). /// A dummy input handler (that justs invokes the default input handler).
@ -231,7 +227,7 @@ public class CompletionWindowBase : Popup
} }
#endregion #endregion
private void TextViewScrollOffsetChanged(object sender, EventArgs e) private void TextViewScrollOffsetChanged(object? sender, EventArgs e)
{ {
ILogicalScrollable textView = TextArea; ILogicalScrollable textView = TextArea;
var visibleRect = new Rect(textView.Offset.X, textView.Offset.Y, textView.Viewport.Width, textView.Viewport.Height); var visibleRect = new Rect(textView.Offset.X, textView.Offset.Y, textView.Viewport.Width, textView.Viewport.Height);
@ -246,31 +242,31 @@ public class CompletionWindowBase : Popup
} }
} }
private void TextAreaDocumentChanged(object sender, EventArgs e) private void TextAreaDocumentChanged(object? sender, EventArgs e)
{ {
Hide(); Hide();
} }
private void TextAreaLostFocus(object sender, RoutedEventArgs e) private void TextAreaLostFocus(object? sender, RoutedEventArgs e)
{ {
Dispatcher.UIThread.Post(CloseIfFocusLost, DispatcherPriority.Background); Dispatcher.UIThread.Post(CloseIfFocusLost, DispatcherPriority.Background);
} }
private void ParentWindow_Deactivated(object sender, EventArgs e) private void ParentWindow_Deactivated(object? sender, EventArgs e)
{ {
Hide(); Hide();
} }
private void ParentWindow_LocationChanged(object sender, EventArgs e) private void ParentWindow_LocationChanged(object? sender, EventArgs e)
{ {
UpdatePosition(); UpdatePosition();
} }
/// <inheritdoc/> /*
private void OnDeactivated(object sender, EventArgs e) private void OnDeactivated(object sender, EventArgs e)
{ {
Dispatcher.UIThread.Post(CloseIfFocusLost, DispatcherPriority.Background); Dispatcher.UIThread.Post(CloseIfFocusLost, DispatcherPriority.Background);
} }*/
#endregion #endregion
@ -282,8 +278,7 @@ public class CompletionWindowBase : Popup
/// <param name="event">The bubbling event.</param> /// <param name="event">The bubbling event.</param>
/// <param name="args">The event args to use.</param> /// <param name="args">The event args to use.</param>
/// <returns>The <see cref="RoutedEventArgs.Handled"/> value of the event args.</returns> /// <returns>The <see cref="RoutedEventArgs.Handled"/> value of the event args.</returns>
[SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate")] protected static bool RaiseEventPair(Control target, RoutedEvent? previewEvent, RoutedEvent @event, RoutedEventArgs args)
protected static bool RaiseEventPair(Control target, RoutedEvent previewEvent, RoutedEvent @event, RoutedEventArgs args)
{ {
if (target == null) if (target == null)
throw new ArgumentNullException(nameof(target)); throw new ArgumentNullException(nameof(target));
@ -300,7 +295,7 @@ public class CompletionWindowBase : Popup
} }
// Special handler: handledEventsToo // Special handler: handledEventsToo
private void OnMouseUp(object sender, PointerReleasedEventArgs e) private void OnMouseUp(object? sender, PointerReleasedEventArgs e)
{ {
ActivateParentWindow(); ActivateParentWindow();
} }

Loading…
Cancel
Save