Files
Wino-Mail/Wino.Mail/Dialogs/NewAccountDialog.xaml.cs

77 lines
2.7 KiB
C#
Raw Normal View History

2024-06-07 23:58:51 +02:00
using System.Collections.Generic;
2024-04-18 01:44:37 +02:00
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Accounts;
namespace Wino.Dialogs
{
public sealed partial class NewAccountDialog : ContentDialog
{
/// <summary>
/// Gets or sets current selected mail provider in the dialog.
/// </summary>
public ProviderDetail SelectedMailProvider
{
get { return (ProviderDetail)GetValue(SelectedMailProviderProperty); }
set { SetValue(SelectedMailProviderProperty, value); }
}
public static readonly DependencyProperty SelectedMailProviderProperty = DependencyProperty.Register(nameof(SelectedMailProvider), typeof(ProviderDetail), typeof(NewAccountDialog), new PropertyMetadata(null, new PropertyChangedCallback(OnSelectedProviderChanged)));
// List of available mail providers for now.
public List<IProviderDetail> Providers { get; set; }
2024-06-07 23:58:51 +02:00
public AccountCreationDialogResult Result = null;
2024-04-18 01:44:37 +02:00
public NewAccountDialog()
{
InitializeComponent();
// AccountColorPicker.Color = Colors.Blue;
}
private static void OnSelectedProviderChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
if (obj is NewAccountDialog dialog)
dialog.ValidateCreateButton();
}
private void CancelClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
Hide();
}
private void CreateClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
ValidateCreateButton();
if (IsSecondaryButtonEnabled)
{
2024-06-07 23:58:51 +02:00
Result = new AccountCreationDialogResult(SelectedMailProvider.Type, AccountNameTextbox.Text.Trim(), SenderNameTextbox.Text.Trim());
2024-04-18 01:44:37 +02:00
Hide();
}
}
2024-06-07 23:58:51 +02:00
private void AccountNameChanged(object sender, TextChangedEventArgs e) => ValidateCreateButton();
private void SenderNameChanged(object sender, TextChangedEventArgs e) => ValidateCreateButton();
2024-04-18 01:44:37 +02:00
// Returns whether we can create account or not.
private void ValidateCreateButton()
{
bool shouldEnable = SelectedMailProvider != null
&& SelectedMailProvider.IsSupported
2024-06-07 23:58:51 +02:00
&& !string.IsNullOrEmpty(AccountNameTextbox.Text)
&& !string.IsNullOrWhiteSpace(SenderNameTextbox.Text);
2024-04-18 01:44:37 +02:00
IsPrimaryButtonEnabled = shouldEnable;
}
private void DialogOpened(ContentDialog sender, ContentDialogOpenedEventArgs args)
{
ValidateCreateButton();
}
}
}