diff --git a/Source/ChocolateyGui.Common.Windows/ViewModels/LocalSourceViewModel.cs b/Source/ChocolateyGui.Common.Windows/ViewModels/LocalSourceViewModel.cs index 24f38da39..d784f412a 100644 --- a/Source/ChocolateyGui.Common.Windows/ViewModels/LocalSourceViewModel.cs +++ b/Source/ChocolateyGui.Common.Windows/ViewModels/LocalSourceViewModel.cs @@ -29,6 +29,7 @@ using ChocolateyGui.Common.ViewModels.Items; using ChocolateyGui.Common.Windows.Services; using ChocolateyGui.Common.Windows.Utilities.Extensions; +using MahApps.Metro.Controls.Dialogs; using Serilog; namespace ChocolateyGui.Common.Windows.ViewModels @@ -45,6 +46,7 @@ public sealed class LocalSourceViewModel : Screen, ISourceViewModelBase, IHandle private readonly IAllowedCommandsService _allowedCommandsService; private readonly IEventAggregator _eventAggregator; private readonly IMapper _mapper; + private readonly IDialogCoordinator _dialogCoordinator; private bool _exportAll = true; private bool _hasLoaded; private bool _matchWord; @@ -68,7 +70,8 @@ public LocalSourceViewModel( IAllowedCommandsService allowedCommandsService, IEventAggregator eventAggregator, string displayName, - IMapper mapper) + IMapper mapper, + IDialogCoordinator dialogCoordinator) { _chocolateyService = chocolateyService; _progressService = progressService; @@ -91,6 +94,7 @@ public LocalSourceViewModel( _eventAggregator = eventAggregator; _mapper = mapper; + _dialogCoordinator = dialogCoordinator; _eventAggregator.Subscribe(this); } @@ -182,30 +186,44 @@ public async void UpdateAll() { try { - await _progressService.StartLoading(Resources.LocalSourceViewModel_Packages, true); - IsLoading = true; - - _progressService.WriteMessage(Resources.LocalSourceViewModel_FetchingPackages); - var token = _progressService.GetCancellationToken(); - var packages = Packages.Where(p => p.CanUpdate && !p.IsPinned).ToList(); - double current = 0.0f; - foreach (var package in packages) + var result = await _dialogCoordinator.ShowMessageAsync( + this, + Resources.Dialog_AreYouSureTitle, + Resources.Dialog_AreYouSureUpdateAllMessage, + MessageDialogStyle.AffirmativeAndNegative, + new MetroDialogSettings + { + AffirmativeButtonText = Resources.Dialog_Yes, + NegativeButtonText = Resources.Dialog_No + }); + + if (result == MessageDialogResult.Affirmative) { - if (token.IsCancellationRequested) + await _progressService.StartLoading(Resources.LocalSourceViewModel_Packages, true); + IsLoading = true; + + _progressService.WriteMessage(Resources.LocalSourceViewModel_FetchingPackages); + var token = _progressService.GetCancellationToken(); + var packages = Packages.Where(p => p.CanUpdate && !p.IsPinned).ToList(); + double current = 0.0f; + foreach (var package in packages) { - await _progressService.StopLoading(); - IsLoading = false; - return; + if (token.IsCancellationRequested) + { + await _progressService.StopLoading(); + IsLoading = false; + return; + } + + _progressService.Report(Math.Min(current++ / packages.Count, 100)); + await package.Update(); } - _progressService.Report(Math.Min(current++ / packages.Count, 100)); - await package.Update(); + await _progressService.StopLoading(); + IsLoading = false; + ShowOnlyPackagesWithUpdate = false; + RefreshPackages(); } - - await _progressService.StopLoading(); - IsLoading = false; - ShowOnlyPackagesWithUpdate = false; - RefreshPackages(); } catch (Exception ex) { diff --git a/Source/ChocolateyGui.Common.Windows/Views/LocalSourceView.xaml b/Source/ChocolateyGui.Common.Windows/Views/LocalSourceView.xaml index 0ac64193b..0c275b24c 100644 --- a/Source/ChocolateyGui.Common.Windows/Views/LocalSourceView.xaml +++ b/Source/ChocolateyGui.Common.Windows/Views/LocalSourceView.xaml @@ -17,7 +17,8 @@ mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="1366" d:DataContext="{d:DesignInstance viewModels:LocalSourceViewModel}" - Background="{DynamicResource MahApps.Brushes.ThemeBackground}"> + Background="{DynamicResource MahApps.Brushes.ThemeBackground}" + mahapps:DialogParticipation.Register="{Binding}"> diff --git a/Source/ChocolateyGui.Common/Properties/Resources.Designer.cs b/Source/ChocolateyGui.Common/Properties/Resources.Designer.cs index 9882611dd..a06598583 100644 --- a/Source/ChocolateyGui.Common/Properties/Resources.Designer.cs +++ b/Source/ChocolateyGui.Common/Properties/Resources.Designer.cs @@ -758,6 +758,15 @@ public static string Dialog_AreYouSureTitle { } } + /// + /// Looks up a localized string similar to This action, depending on the number of currently outdated packages, may take a long time to complete. Are you sure that you want to continue?. + /// + public static string Dialog_AreYouSureUpdateAllMessage { + get { + return ResourceManager.GetString("Dialog_AreYouSureUpdateAllMessage", resourceCulture); + } + } + /// /// Looks up a localized string similar to No. /// diff --git a/Source/ChocolateyGui.Common/Properties/Resources.resx b/Source/ChocolateyGui.Common/Properties/Resources.resx index e0bdede5e..ea788a9c3 100644 --- a/Source/ChocolateyGui.Common/Properties/Resources.resx +++ b/Source/ChocolateyGui.Common/Properties/Resources.resx @@ -1044,4 +1044,7 @@ Please contact your System Administrator to enable this operation. This action will remove the '{0}' source from both Chocolatey and Chocolatey GUI. Are you sure you want to proceed (this action cannot be undone)? {0} = The id of the source which is away to be deleted, i.e. chocolatey, chocolatey.licensed, etc + + This action, depending on the number of currently outdated packages, may take a long time to complete. Are you sure that you want to continue? + \ No newline at end of file