diff --git a/Flow.Launcher/MessageBoxEx.xaml b/Flow.Launcher/MessageBoxEx.xaml index c7e39b97188..e56e826ac10 100644 --- a/Flow.Launcher/MessageBoxEx.xaml +++ b/Flow.Launcher/MessageBoxEx.xaml @@ -33,6 +33,7 @@ _button switch + { + MessageBoxButton.OK => MessageBoxResult.OK, + MessageBoxButton.OKCancel => MessageBoxResult.Cancel, + MessageBoxButton.YesNoCancel => MessageBoxResult.Cancel, + + // For YesNo this should only be used in a forced close edge case (e.g. alt f4) + // Most callers make the mistake of checking for No instead of not Yes - so best not to return None etc + MessageBoxButton.YesNo => MessageBoxResult.No, + + // covers unsupported types, e.g. AbortRetryIgnore + _ => MessageBoxResult.None + }; + + private void KeyEsc_OnPress(object sender, ExecutedRoutedEventArgs e) { if (_button == MessageBoxButton.YesNo) // Follow System.Windows.MessageBox behavior return; - else if (_button == MessageBoxButton.OK) - _result = MessageBoxResult.OK; - else - _result = MessageBoxResult.Cancel; + DialogResult = false; Close(); } @@ -192,12 +217,12 @@ private void Button_Cancel(object sender, RoutedEventArgs e) e.Handled = true; if (_button == MessageBoxButton.YesNo) - // Follow System.Windows.MessageBox behavior + { + // For YesNo, the close button should be hidden and inaccessible. + App.API.LogWarn(ClassName, "Close button was invoked despite being hidden for YesNo dialog"); return; - else if (_button == MessageBoxButton.OK) - _result = MessageBoxResult.OK; - else - _result = MessageBoxResult.Cancel; + } + msgBox.Close(); msgBox = null; } diff --git a/Flow.Launcher/Resources/Controls/CustomWindowTitleBar.xaml.cs b/Flow.Launcher/Resources/Controls/CustomWindowTitleBar.xaml.cs index 05e3148a939..7048a257248 100644 --- a/Flow.Launcher/Resources/Controls/CustomWindowTitleBar.xaml.cs +++ b/Flow.Launcher/Resources/Controls/CustomWindowTitleBar.xaml.cs @@ -3,6 +3,7 @@ using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; +using System.Windows.Shell; namespace Flow.Launcher.Resources.Controls { @@ -113,6 +114,7 @@ public WindowStateChangedEventArgs(WindowState previousState, WindowState curren private Window _hostWindow; private WindowState _lastNonMinimizedWindowState = WindowState.Normal; + private bool? _savedUseAeroCaptionButtons; private Button MinimizeButtonElement => FindName("MinimizeButton") as Button; private Button MaximizeButtonElement => FindName("MaximizeButton") as Button; @@ -242,6 +244,14 @@ private void AttachToHostWindow() return; } + // Disable system caption buttons since this control provides custom ones + var chrome = WindowChrome.GetWindowChrome(_hostWindow); + if (chrome != null) + { + _savedUseAeroCaptionButtons = chrome.UseAeroCaptionButtons; + chrome.UseAeroCaptionButtons = false; + } + if (IconSource is null) { IconSource = _hostWindow.Icon ?? DefaultWindowIcon; @@ -269,6 +279,17 @@ private void DetachFromHostWindow() return; } + // Restore original system caption buttons if we disabled them + if (_savedUseAeroCaptionButtons.HasValue) + { + var chrome = WindowChrome.GetWindowChrome(_hostWindow); + if (chrome != null) + { + chrome.UseAeroCaptionButtons = _savedUseAeroCaptionButtons.Value; + } + _savedUseAeroCaptionButtons = null; + } + _hostWindow.StateChanged -= HostWindow_StateChanged; _hostWindow.Activated -= HostWindow_Activated; _hostWindow.Closed -= HostWindow_Closed;