Skip to content

Commit

Permalink
(chocolatey#852) Add ShowLoginAsync to DialogService
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 authored and gep13 committed May 8, 2021
1 parent c525236 commit a8ad728
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 49 deletions.
17 changes: 17 additions & 0 deletions Source/ChocolateyGui.Common.Windows/Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,22 @@ public async Task<MessageDialogResult> ShowConfirmationMessageAsync(string title
: MessageDialogResult.Negative;
}
}

/// <inheritdoc />
public async Task<LoginDialogData> ShowLoginAsync(string title, string message, LoginDialogSettings settings = null)
{
using (await _lock.EnterAsync())
{
if (ShellView != null)
{
return await ShellView.ShowLoginAsync(
Resources.SettingsViewModel_SetSourceUsernameAndPasswordTitle,
Resources.SettingsViewModel_SetSourceUsernameAndPasswordMessage,
settings);
}

return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,14 @@ public interface IDialogService
/// <param name="message">The message contained within the Dialog.</param>
/// <returns>A task promising the result of which button was pressed.</returns>
Task<MessageDialogResult> ShowConfirmationMessageAsync(string title, string message);

/// <summary>
/// Creates a Login dialog inside of the ShellView.
/// </summary>
/// <param name="title">The title of the Dialog.</param>
/// <param name="message">The message contained within the Dialog.</param>
/// <param name="settings">Optional settings that override the global dialog settings.</param>
/// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
Task<LoginDialogData> ShowLoginAsync(string title, string message, LoginDialogSettings settings = null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ protected override void Load(ContainerBuilder builder)
});

builder.RegisterType<BundledThemeService>().As<IBundledThemeService>().SingleInstance();
builder.RegisterInstance(DialogCoordinator.Instance).As<IDialogCoordinator>();
builder.RegisterInstance(mapperConfiguration.CreateMapper()).As<IMapper>();

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ 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;
Expand All @@ -72,8 +71,7 @@ public LocalSourceViewModel(
IAllowedCommandsService allowedCommandsService,
IEventAggregator eventAggregator,
string displayName,
IMapper mapper,
IDialogCoordinator dialogCoordinator)
IMapper mapper)
{
_chocolateyService = chocolateyService;
_dialogService = dialogService;
Expand All @@ -97,7 +95,6 @@ public LocalSourceViewModel(

_eventAggregator = eventAggregator;
_mapper = mapper;
_dialogCoordinator = dialogCoordinator;
_eventAggregator.Subscribe(this);
}

Expand Down Expand Up @@ -189,16 +186,9 @@ public async void UpdateAll()
{
try
{
var result = await _dialogCoordinator.ShowMessageAsync(
this,
var result = await _dialogService.ShowConfirmationMessageAsync(
Resources.Dialog_AreYouSureTitle,
Resources.Dialog_AreYouSureUpdateAllMessage,
MessageDialogStyle.AffirmativeAndNegative,
new MetroDialogSettings
{
AffirmativeButtonText = Resources.Dialog_Yes,
NegativeButtonText = Resources.Dialog_No
});
Resources.Dialog_AreYouSureUpdateAllMessage);

if (result == MessageDialogResult.Affirmative)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public sealed class SettingsViewModel : Screen
private readonly IProgressService _progressService;
private readonly IConfigService _configService;
private readonly IEventAggregator _eventAggregator;
private readonly IDialogCoordinator _dialogCoordinator;
private readonly IChocolateyGuiCacheService _chocolateyGuiCacheService;
private readonly IFileSystem _fileSystem;

Expand All @@ -61,7 +60,6 @@ public SettingsViewModel(
IProgressService progressService,
IConfigService configService,
IEventAggregator eventAggregator,
IDialogCoordinator dialogCoordinator,
IChocolateyGuiCacheService chocolateyGuiCacheService,
IFileSystem fileSystem)
{
Expand All @@ -70,7 +68,6 @@ public SettingsViewModel(
_progressService = progressService;
_configService = configService;
_eventAggregator = eventAggregator;
_dialogCoordinator = dialogCoordinator;
_chocolateyGuiCacheService = chocolateyGuiCacheService;
_fileSystem = fileSystem;
DisplayName = Resources.SettingsViewModel_DisplayName;
Expand Down Expand Up @@ -322,16 +319,9 @@ public async Task UpdateChocolateySetting(ChocolateySetting setting)

public async Task PurgeIconCache()
{
var result = await _dialogCoordinator.ShowMessageAsync(
this,
var result = await _dialogService.ShowConfirmationMessageAsync(
Resources.Dialog_AreYouSureTitle,
Resources.Dialog_AreYouSureIconsMessage,
MessageDialogStyle.AffirmativeAndNegative,
new MetroDialogSettings
{
AffirmativeButtonText = Resources.Dialog_Yes,
NegativeButtonText = Resources.Dialog_No
});
Resources.Dialog_AreYouSureIconsMessage);

if (result == MessageDialogResult.Affirmative)
{
Expand All @@ -341,16 +331,9 @@ public async Task PurgeIconCache()

public async Task PurgeOutdatedPackagesCache()
{
var result = await _dialogCoordinator.ShowMessageAsync(
this,
var result = await _dialogService.ShowConfirmationMessageAsync(
Resources.Dialog_AreYouSureTitle,
Resources.Dialog_AreYouSureOutdatedPackagesMessage,
MessageDialogStyle.AffirmativeAndNegative,
new MetroDialogSettings
{
AffirmativeButtonText = Resources.Dialog_Yes,
NegativeButtonText = Resources.Dialog_No
});
Resources.Dialog_AreYouSureOutdatedPackagesMessage);

if (result == MessageDialogResult.Affirmative)
{
Expand Down Expand Up @@ -433,16 +416,9 @@ await _dialogService.ShowMessageAsync(

public async Task Remove()
{
var result = await _dialogCoordinator.ShowMessageAsync(
this,
var result = await _dialogService.ShowConfirmationMessageAsync(
Resources.Dialog_AreYouSureTitle,
string.Format(Resources.Dialog_AreYourSureRemoveSourceMessage, _originalId),
MessageDialogStyle.AffirmativeAndNegative,
new MetroDialogSettings
{
AffirmativeButtonText = Resources.Dialog_Yes,
NegativeButtonText = Resources.Dialog_No
});
string.Format(Resources.Dialog_AreYourSureRemoveSourceMessage, _originalId));

if (result == MessageDialogResult.Affirmative)
{
Expand Down Expand Up @@ -495,7 +471,7 @@ public async void SetUserAndPassword()
loginDialogSettings.EnablePasswordPreview = true;
}

var result = await _dialogCoordinator.ShowLoginAsync(this, Resources.SettingsViewModel_SetSourceUsernameAndPasswordTitle, Resources.SettingsViewModel_SetSourceUsernameAndPasswordMessage, loginDialogSettings);
var result = await _dialogService.ShowLoginAsync(Resources.SettingsViewModel_SetSourceUsernameAndPasswordTitle, Resources.SettingsViewModel_SetSourceUsernameAndPasswordMessage, loginDialogSettings);

if (result != null)
{
Expand Down Expand Up @@ -525,7 +501,7 @@ public async void SetCertificateAndPassword()
loginDialogSettings.EnablePasswordPreview = true;
}

var result = await _dialogCoordinator.ShowLoginAsync(this, Resources.SettingsViewModel_SetSourceCertificateAndPasswordTitle, Resources.SettingsViewModel_SetSourceCertificateAndPasswordMessage, loginDialogSettings);
var result = await _dialogService.ShowLoginAsync(Resources.SettingsViewModel_SetSourceCertificateAndPasswordTitle, Resources.SettingsViewModel_SetSourceCertificateAndPasswordMessage, loginDialogSettings);

if (result != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
mc:Ignorable="d"
d:DesignHeight="768" d:DesignWidth="1366"
d:DataContext="{d:DesignInstance viewModels:LocalSourceViewModel}"
Background="{DynamicResource MahApps.Brushes.ThemeBackground}"
mahapps:DialogParticipation.Register="{Binding}">
Background="{DynamicResource MahApps.Brushes.ThemeBackground}">

<UserControl.Resources>
<utilities:BindingProxy x:Key="BindingProxy" Data="{Binding}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
xmlns:theming="clr-namespace:ChocolateyGui.Common.Windows.Theming"
mc:Ignorable="d"
Background="{DynamicResource {x:Static theming:ChocolateyBrushes.BackgroundKey}}"
metro:DialogParticipation.Register="{Binding}"
d:DataContext="{d:DesignInstance Type=viewModels:SettingsViewModel, IsDesignTimeCreatable=False}"
d:DesignHeight="786" d:DesignWidth="1366">

Expand Down

0 comments on commit a8ad728

Please sign in to comment.