Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3675. Adds ObjectDisposedExceptions #3676

Draft
wants to merge 20 commits into
base: v2_develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions Terminal.Gui/Application/Application.Mouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,8 @@ public static void GrabMouse (View? view)
return;
}

#if DEBUG_IDISPOSABLE
ObjectDisposedException.ThrowIf (view.WasDisposed, typeof (View));
#endif

if (!OnGrabbingMouse (view))
{
OnGrabbedMouse (view);
MouseGrabView = view;
}
OnGrabbedMouse (view);
MouseGrabView = view;
}

/// <summary>Releases the mouse grab, so mouse events will be routed to the view on which the mouse is.</summary>
Expand All @@ -62,7 +55,7 @@ public static void UngrabMouse ()
}

#if DEBUG_IDISPOSABLE
ObjectDisposedException.ThrowIf (MouseGrabView.WasDisposed, typeof (View));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof was better

Copy link
Collaborator

@dodexahedron dodexahedron Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you would like the consumer to benefit from better specificity of the most-derived type, rather than always calling it just a View, you can just make that method generic:

public static void GrabMouse<T> (T? view) where T : View

and then the only change necessary should likely be that the typeof uses turn into typeof(T) instead of typeof(View). There could be other small tweaks needed in the method, and in callers, if they're making comparisons to specific types without calling that method with something more specific than a View, but they'd likely be pretty trivial to adapt, as well, if any exist.

ObjectDisposedException.ThrowIf (MouseGrabView.WasDisposed, MouseGrabView);
#endif

if (!OnUnGrabbingMouse (MouseGrabView))
Expand Down Expand Up @@ -234,19 +227,7 @@ internal static void OnMouseEvent (MouseEvent mouseEvent)

if (view is { } && view != ApplicationOverlapped.OverlappedTop && top != Current && top is { })
{
// This occurs when there are multiple overlapped "tops"
// E.g. "Mdi" - in the Background Worker Scenario
View? top = ApplicationOverlapped.FindDeepestTop (Top!, mouseEvent.Position);

#if DEBUG_IDISPOSABLE
ObjectDisposedException.ThrowIf (top is { WasDisposed: true }, typeof (View));
#endif
view = View.FindDeepestView (top, mouseEvent.Position);

if (view is { } && view != ApplicationOverlapped.OverlappedTop && top != Current && top is { })
{
ApplicationOverlapped.MoveCurrent ((Toplevel)top);
}
ApplicationOverlapped.MoveCurrent ((Toplevel)top);
}
}

Expand Down
4 changes: 0 additions & 4 deletions Terminal.Gui/Application/ApplicationNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ internal void SetFocused (View? value)
return;
}

#if DEBUG_IDISPOSABLE
ObjectDisposedException.ThrowIf (value is { WasDisposed: true }, typeof (View));
#endif

_focused = value;

FocusedChanged?.Invoke (null, EventArgs.Empty);
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.