diff --git a/Source/ChocolateyGui.Common.Windows/Bootstrapper.cs b/Source/ChocolateyGui.Common.Windows/Bootstrapper.cs index 371f5f1a4..3805e8c2a 100644 --- a/Source/ChocolateyGui.Common.Windows/Bootstrapper.cs +++ b/Source/ChocolateyGui.Common.Windows/Bootstrapper.cs @@ -24,6 +24,7 @@ using ChocolateyGui.Common.Utilities; using ChocolateyGui.Common.ViewModels.Items; using ChocolateyGui.Common.Windows.Startup; +using ChocolateyGui.Common.Windows.Utilities; using ChocolateyGui.Common.Windows.ViewModels; using LiteDB; using Serilog; @@ -135,7 +136,7 @@ protected override async void OnStartup(object sender, StartupEventArgs e) } catch (Exception ex) { - MessageBox.Show(string.Format(Resources.Fatal_Startup_Error_Formatted, ex.Message)); + ChocolateyMessageBox.Show(string.Format(Resources.Fatal_Startup_Error_Formatted, ex.Message)); Logger.Fatal(ex, Resources.Fatal_Startup_Error); await OnExitAsync(); } @@ -192,7 +193,7 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc return; } - MessageBox.Show( + ChocolateyMessageBox.Show( e.ExceptionObject.ToString(), Resources.Bootstrapper_UnhandledException, MessageBoxButton.OK, diff --git a/Source/ChocolateyGui.Common.Windows/ChocolateyGui.Common.Windows.csproj b/Source/ChocolateyGui.Common.Windows/ChocolateyGui.Common.Windows.csproj index 175a91a29..d8ba50484 100644 --- a/Source/ChocolateyGui.Common.Windows/ChocolateyGui.Common.Windows.csproj +++ b/Source/ChocolateyGui.Common.Windows/ChocolateyGui.Common.Windows.csproj @@ -229,6 +229,7 @@ + diff --git a/Source/ChocolateyGui.Common.Windows/Services/DialogService.cs b/Source/ChocolateyGui.Common.Windows/Services/DialogService.cs index 89c6d3321..5fffd1f0a 100644 --- a/Source/ChocolateyGui.Common.Windows/Services/DialogService.cs +++ b/Source/ChocolateyGui.Common.Windows/Services/DialogService.cs @@ -12,6 +12,7 @@ using System.Windows.Media; using ChocolateyGui.Common.Properties; using ChocolateyGui.Common.Windows.Controls.Dialogs; +using ChocolateyGui.Common.Windows.Utilities; using ChocolateyGui.Common.Windows.Views; using ControlzEx.Theming; using MahApps.Metro.Controls.Dialogs; @@ -48,7 +49,7 @@ public async Task ShowMessageAsync(string title, string mes return await ShellView.ShowMessageAsync(title, message, MessageDialogStyle.Affirmative, dialogSettings); } - return MessageBox.Show(message, title) == MessageBoxResult.OK + return ChocolateyMessageBox.Show(message, title) == MessageBoxResult.OK ? MessageDialogResult.Affirmative : MessageDialogResult.Negative; } @@ -70,7 +71,7 @@ public async Task ShowConfirmationMessageAsync(string title return await ShellView.ShowMessageAsync(title, message, MessageDialogStyle.AffirmativeAndNegative, dialogSettings); } - return MessageBox.Show(message, title, MessageBoxButton.YesNo) == MessageBoxResult.Yes + return ChocolateyMessageBox.Show(message, title, MessageBoxButton.YesNo) == MessageBoxResult.Yes ? MessageDialogResult.Affirmative : MessageDialogResult.Negative; } diff --git a/Source/ChocolateyGui.Common.Windows/Utilities/ChocolateyMessageBox.cs b/Source/ChocolateyGui.Common.Windows/Utilities/ChocolateyMessageBox.cs new file mode 100644 index 000000000..aa2a36581 --- /dev/null +++ b/Source/ChocolateyGui.Common.Windows/Utilities/ChocolateyMessageBox.cs @@ -0,0 +1,65 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright 2017 - Present Chocolatey Software, LLC +// Copyright 2014 - 2017 Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ChocolateyGui.Common.Windows.Utilities +{ + using System.Windows; + + public static class ChocolateyMessageBox + { + public static MessageBoxResult Show(string messageBoxText) + { + var dummyWindow = DummyWindow(); + dummyWindow.Show(); + var result = MessageBox.Show(messageBoxText); + dummyWindow.Close(); + return result; + } + + public static MessageBoxResult Show(string messageBoxText, string caption) + { + var dummyWindow = DummyWindow(); + dummyWindow.Show(); + var result = MessageBox.Show(messageBoxText, caption); + dummyWindow.Close(); + return result; + } + + public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button) + { + var dummyWindow = DummyWindow(); + dummyWindow.Show(); + var result = MessageBox.Show(messageBoxText, caption, button); + dummyWindow.Close(); + return result; + } + + public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult, MessageBoxOptions options) + { + var dummyWindow = DummyWindow(); + dummyWindow.Show(); + var result = MessageBox.Show(messageBoxText, caption, button, icon, defaultResult, options); + dummyWindow.Show(); + return result; + } + + private static Window DummyWindow() + { + return new Window + { + AllowsTransparency = true, + Background = System.Windows.Media.Brushes.Transparent, + WindowStyle = WindowStyle.None, + Top = 0, + Left = 0, + Width = 1, + Height = 1, + ShowInTaskbar = false + }; + } + } +} \ No newline at end of file diff --git a/Source/ChocolateyGui.Common.Windows/ViewModels/RemoteSourceViewModel.cs b/Source/ChocolateyGui.Common.Windows/ViewModels/RemoteSourceViewModel.cs index 602dfa51b..4cbad5d6b 100644 --- a/Source/ChocolateyGui.Common.Windows/ViewModels/RemoteSourceViewModel.cs +++ b/Source/ChocolateyGui.Common.Windows/ViewModels/RemoteSourceViewModel.cs @@ -24,6 +24,7 @@ using ChocolateyGui.Common.ViewModels; using ChocolateyGui.Common.ViewModels.Items; using ChocolateyGui.Common.Windows.Services; +using ChocolateyGui.Common.Windows.Utilities; using ChocolateyGui.Common.Windows.Utilities.Extensions; using NuGet; using Serilog; @@ -402,7 +403,7 @@ protected override void OnInitialize() catch (InvalidOperationException ex) { Logger.Error(ex, "Failed to initialize remote source view model."); - MessageBox.Show( + ChocolateyMessageBox.Show( string.Format( CultureInfo.InvariantCulture, Resources.RemoteSourceViewModel_UnableToConnectToFeed, diff --git a/Source/ChocolateyGui.Common.Windows/Views/ShellView.xaml.cs b/Source/ChocolateyGui.Common.Windows/Views/ShellView.xaml.cs index ce5df7855..d49942e48 100644 --- a/Source/ChocolateyGui.Common.Windows/Views/ShellView.xaml.cs +++ b/Source/ChocolateyGui.Common.Windows/Views/ShellView.xaml.cs @@ -18,6 +18,7 @@ using ChocolateyGui.Common.Services; using ChocolateyGui.Common.Windows.Controls.Dialogs; using ChocolateyGui.Common.Windows.Services; +using ChocolateyGui.Common.Windows.Utilities; using MahApps.Metro.Controls.Dialogs; using ChocolateyDialog = ChocolateyGui.Common.Windows.Controls.Dialogs.ChocolateyDialog; @@ -74,7 +75,7 @@ public void CheckOperatingSystemCompatibility() if (operatingSystemVersion.Version.Major == 10 && !_chocolateyConfigurationProvider.IsChocolateyExecutableBeingUsed) { - MessageBox.Show( + ChocolateyMessageBox.Show( "Usage of the PowerShell Version of Chocolatey (i.e. <= 0.9.8.33) has been detected. Chocolatey GUI does not support using this version of Chocolatey on Windows 10. Please update Chocolatey to the new C# Version (i.e. > 0.9.9.0) and restart Chocolatey GUI. This application will now close.", "Incompatible Operating System Version", MessageBoxButton.OK, diff --git a/Source/ChocolateyGui/App.xaml.cs b/Source/ChocolateyGui/App.xaml.cs index ceb9809e5..c068c34b2 100644 --- a/Source/ChocolateyGui/App.xaml.cs +++ b/Source/ChocolateyGui/App.xaml.cs @@ -15,6 +15,7 @@ using ChocolateyGui.Common.Startup; using ChocolateyGui.Common.Windows; using ChocolateyGui.Common.Windows.Theming; +using ChocolateyGui.Common.Windows.Utilities; namespace ChocolateyGui { @@ -80,7 +81,7 @@ public App() catch (Exception ex) { var errorMessage = string.Format("Unable to load Chocolatey GUI assembly. {0}", ex.Message); - MessageBox.Show(errorMessage); + ChocolateyMessageBox.Show(errorMessage); throw new ApplicationException(errorMessage); }