Skip to content

Commit

Permalink
Improving readability by creating separate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Aug 25, 2018
1 parent 67eb4e9 commit 0a1d9c4
Showing 1 changed file with 45 additions and 25 deletions.
70 changes: 45 additions & 25 deletions Fluent.Ribbon/Services/PopupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,41 +263,61 @@ public static void OnDismissPopup(object sender, DismissPopupEventArgs e)
return;
}

if (e.DismissMode == DismissPopupMode.Always)
switch (e.DismissMode)
{
control.IsDropDownOpen = false;
case DismissPopupMode.Always:
DismisPopupForAlways(control, e);
break;

case DismissPopupMode.MouseNotOver:
DismisPopupForMouseNotOver(control, e);
break;

default:
throw new ArgumentOutOfRangeException(nameof(e.DismissMode), e.DismissMode, "Unknown DismissMode.");
}
else if (control.IsDropDownOpen)
}

private static void DismisPopupForAlways(IDropDownControl control, DismissPopupEventArgs e)
{
control.IsDropDownOpen = false;
}

private static void DismisPopupForMouseNotOver(IDropDownControl control, DismissPopupEventArgs e)
{
if (control.IsDropDownOpen == false)
{
// Prevent eager closing of the Ribbon-Popup and forward mouse focus to the ribbon popup instead.
if (control is RibbonTabControl ribbonTabControl
&& ribbonTabControl.IsMinimized
&& IsAncestorOf(control as DependencyObject, e.OriginalSource as DependencyObject))
{
// Don't prevent closing if the new target is an ApplicationMenu (#581)
if (Mouse.Captured is ApplicationMenu)
{
control.IsDropDownOpen = false;
return;
}
return;
}

Mouse.Capture(control as IInputElement, CaptureMode.SubTree);
// Prevent eager closing of the Ribbon-Popup and forward mouse focus to the ribbon popup instead.
if (control is RibbonTabControl ribbonTabControl
&& ribbonTabControl.IsMinimized
&& IsAncestorOf(control as DependencyObject, e.OriginalSource as DependencyObject))
{
// Don't prevent closing if the new target is an ApplicationMenu (#581)
if (Mouse.Captured is ApplicationMenu)
{
control.IsDropDownOpen = false;
return;
}

if (IsMousePhysicallyOver(control.DropDownPopup.Child) == false)
Mouse.Capture(control as IInputElement, CaptureMode.SubTree);
return;
}

if (IsMousePhysicallyOver(control.DropDownPopup) == false)
{
control.IsDropDownOpen = false;
}
else
{
if (Mouse.Captured != control)
{
control.IsDropDownOpen = false;
Mouse.Capture(control as IInputElement, CaptureMode.SubTree);
}
else
{
if (Mouse.Captured != control)
{
Mouse.Capture(sender as IInputElement, CaptureMode.SubTree);
}

e.Handled = true;
}
e.Handled = true;
}
}

Expand Down

0 comments on commit 0a1d9c4

Please sign in to comment.