From 0a1d9c477d06759c44b676e43eddcb44b4c3644e Mon Sep 17 00:00:00 2001 From: Bastian Schmidt Date: Sat, 25 Aug 2018 13:31:09 +0200 Subject: [PATCH] Improving readability by creating separate methods --- Fluent.Ribbon/Services/PopupService.cs | 70 +++++++++++++++++--------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/Fluent.Ribbon/Services/PopupService.cs b/Fluent.Ribbon/Services/PopupService.cs index e77cf16b6..45317432a 100644 --- a/Fluent.Ribbon/Services/PopupService.cs +++ b/Fluent.Ribbon/Services/PopupService.cs @@ -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; } }