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

75 lines
2.3 KiB
C#
Raw Normal View History

2024-04-18 01:44:37 +02:00
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Wino.Core.Domain;
using Wino.Core.Domain.Models.Folders;
2025-02-16 11:54:23 +01:00
namespace Wino.Dialogs;
public sealed partial class MoveMailDialog : ContentDialog
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
public IMailItemFolder SelectedFolder
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
get { return (IMailItemFolder)GetValue(SelectedFolderProperty); }
set { SetValue(SelectedFolderProperty, value); }
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public static readonly DependencyProperty SelectedFolderProperty = DependencyProperty.Register(nameof(SelectedFolder), typeof(IMailItemFolder), typeof(MoveMailDialog), new PropertyMetadata(null, OnSelectedFolderChanged));
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public List<IMailItemFolder> FolderList { get; set; }
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public MoveMailDialog(List<IMailItemFolder> allFolders)
{
InitializeComponent();
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
if (allFolders == null) return;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
FolderList = allFolders;
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private static void OnSelectedFolderChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
if (obj is MoveMailDialog dialog)
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
dialog.VerifySelection();
2024-04-18 01:44:37 +02:00
}
2025-02-16 11:54:23 +01:00
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private void VerifySelection()
{
if (SelectedFolder != null)
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
// Don't select non-move capable folders like Categories or More.
if (!SelectedFolder.IsMoveTarget)
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
// Warn users for only proper mail folders. Not ghost folders.
InvalidFolderText.Visibility = Visibility.Visible;
InvalidFolderText.Text = string.Format(Translator.MoveMailDialog_InvalidFolderMessage, SelectedFolder.FolderName);
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
if (FolderTreeView.SelectedItem != null)
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
// Toggle the expansion for the selected container if available.
// I don't like the expand arrow touch area. It's better this way.
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
if (FolderTreeView.ContainerFromItem(FolderTreeView.SelectedItem) is Microsoft.UI.Xaml.Controls.TreeViewItem container)
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
container.IsExpanded = !container.IsExpanded;
2024-04-18 01:44:37 +02:00
}
}
2025-02-16 11:54:23 +01:00
SelectedFolder = null;
}
else
{
Hide();
2024-04-18 01:44:37 +02:00
}
}
2025-02-16 11:54:23 +01:00
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
private void CancelClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
Hide();
2024-04-18 01:44:37 +02:00
}
}