Skip to content

Commit

Permalink
catching exceptions in GetEverythingInToWorkAreaWithTabTipClosed method
Browse files Browse the repository at this point in the history
  • Loading branch information
maximcus committed Jan 17, 2017
1 parent f5bfe8d commit 7e9543c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
29 changes: 18 additions & 11 deletions WPFTabTip/AnimationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,25 @@ private static Rectangle GetWindowRectangle(Window window)

internal static void GetEverythingInToWorkAreaWithTabTipClosed()
{
foreach (KeyValuePair<FrameworkElement, Storyboard> moveRootVisualStoryboard in MoveRootVisualStoryboards)
try
{
Window window = moveRootVisualStoryboard.Key as Window;
// if window exist also check if it has not been closed
if (window != null && new WindowInteropHelper(window).Handle != IntPtr.Zero)
MoveRootVisualBy(
rootVisual: window,
moveBy: GetYOffsetToMoveUIElementInToWorkArea(
uiElementRectangle: GetWindowRectangle(window),
workAreaRectangle: GetWorkAreaWithTabTipClosed(window)));
else
MoveRootVisualTo(rootVisual: moveRootVisualStoryboard.Key, moveTo: 0);
foreach (KeyValuePair<FrameworkElement, Storyboard> moveRootVisualStoryboard in MoveRootVisualStoryboards)
{
Window window = moveRootVisualStoryboard.Key as Window;
// if window exist also check if it has not been closed
if (window != null && new WindowInteropHelper(window).Handle != IntPtr.Zero)
MoveRootVisualBy(
rootVisual: window,
moveBy: GetYOffsetToMoveUIElementInToWorkArea(
uiElementRectangle: GetWindowRectangle(window),
workAreaRectangle: GetWorkAreaWithTabTipClosed(window)));
else
MoveRootVisualTo(rootVisual: moveRootVisualStoryboard.Key, moveTo: 0);
}
}
catch (Exception ex)
{
ExceptionCatched?.Invoke(ex);
}
}

Expand Down
7 changes: 6 additions & 1 deletion WPFTabTip/TabTipAutomation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ static TabTipAutomation()

AutomateTabTipOpen(FocusSubject.AsObservable());
AutomateTabTipClose(FocusSubject.AsObservable(), TabTipClosedSubject);
AnimationHelper.ExceptionCatched += obj => ExceptionCatched?.Invoke(obj);

AnimationHelper.ExceptionCatched += exception => ExceptionCatched?.Invoke(exception);
}

private static readonly Subject<Tuple<UIElement, bool>> FocusSubject = new Subject<Tuple<UIElement, bool>>();
Expand All @@ -37,7 +38,11 @@ public static HardwareKeyboardIgnoreOptions IgnoreHardwareKeyboard
set { HardwareKeyboard.IgnoreOptions = value; }
}

/// <summary>
/// Subscribe to this event if you want to know about exceptions (errors) in this library
/// </summary>
public static event Action<Exception> ExceptionCatched;

/// <summary>
/// Description of keyboards to ignore if there is only one instance of given keyboard.
/// If you want to ignore some ghost keyboard, add it's description to this list
Expand Down

0 comments on commit 7e9543c

Please sign in to comment.