New list view items.
This commit is contained in:
@@ -724,6 +724,27 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
||||
await NotifySelectionChangesAsync();
|
||||
}
|
||||
|
||||
private IEnumerable<IMailListItem> AllItemsIncludingThreads
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var group in _mailItemSource)
|
||||
{
|
||||
foreach (var item in group)
|
||||
{
|
||||
if (item is ThreadMailItemViewModel threadMailItemViewModel)
|
||||
{
|
||||
foreach (var child in threadMailItemViewModel.ThreadEmails)
|
||||
{
|
||||
yield return child;
|
||||
}
|
||||
}
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<MailItemViewModel> AllItems
|
||||
{
|
||||
get
|
||||
@@ -752,7 +773,7 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
||||
public bool IsAllItemsSelected => AllItems.Any() && AllItems.All(a => a.IsSelected);
|
||||
public bool HasSingleItemSelected => SelectedItemsCount == 1;
|
||||
|
||||
public async Task ExecuteWithoutRaiseSelectionChangedAsync(Action<MailItemViewModel> action)
|
||||
public async Task ExecuteWithoutRaiseSelectionChangedAsync(Action<IMailListItem> action, bool includeThreads)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -761,9 +782,19 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
foreach (var item in AllItems)
|
||||
if (includeThreads)
|
||||
{
|
||||
action(item);
|
||||
foreach (var item in AllItemsIncludingThreads)
|
||||
{
|
||||
action(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in AllItems)
|
||||
{
|
||||
action(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -816,8 +847,9 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
||||
return -1;
|
||||
}
|
||||
|
||||
public Task SelectAllAsync() => ExecuteWithoutRaiseSelectionChangedAsync(a => a.IsSelected = true);
|
||||
public Task UnselectAllAsync() => ExecuteWithoutRaiseSelectionChangedAsync(a => a.IsSelected = false);
|
||||
public Task SelectAllAsync() => ExecuteWithoutRaiseSelectionChangedAsync(a => a.IsSelected = true, true);
|
||||
public Task UnselectAllAsync() => ExecuteWithoutRaiseSelectionChangedAsync(a => a.IsSelected = false, true);
|
||||
public Task CollapseAllThreadsAsync() => ExecuteWithoutRaiseSelectionChangedAsync(a => { if (a is ThreadMailItemViewModel thread) thread.IsThreadExpanded = false; }, true);
|
||||
|
||||
private async Task ExecuteUIThread(Action action) => await CoreDispatcher?.ExecuteOnUIThread(action);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Wino.Mail.ViewModels.Data;
|
||||
/// <summary>
|
||||
/// Single view model for IMailItem representation.
|
||||
/// </summary>
|
||||
public partial class MailItemViewModel(MailCopy mailCopy) : ObservableObject, IMailListItem
|
||||
public partial class MailItemViewModel(MailCopy mailCopy) : ObservableRecipient, IMailListItem
|
||||
{
|
||||
public DateTime CreationDate => MailCopy.CreationDate;
|
||||
[ObservableProperty]
|
||||
@@ -18,6 +18,7 @@ public partial class MailItemViewModel(MailCopy mailCopy) : ObservableObject, IM
|
||||
public partial bool ThumbnailUpdatedEvent { get; set; } = false;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedRecipients]
|
||||
public partial bool IsSelected { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -89,10 +90,6 @@ public partial class MailItemViewModel(MailCopy mailCopy) : ObservableObject, IM
|
||||
set => SetProperty(MailCopy.HasAttachments, value, MailCopy, (u, n) => u.HasAttachments = n);
|
||||
}
|
||||
|
||||
partial void OnIsSelectedChanged(bool oldValue, bool newValue)
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerable<Guid> GetContainingIds() => [MailCopy.UniqueId];
|
||||
|
||||
public IEnumerable<MailItemViewModel> GetSelectedMailItems()
|
||||
|
||||
@@ -17,11 +17,16 @@ public partial class ThreadMailItemViewModel : ObservableRecipient, IDisposable,
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedRecipients]
|
||||
[NotifyPropertyChangedFor(nameof(IsSelectedOrExpanded))]
|
||||
public partial bool IsThreadExpanded { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedRecipients]
|
||||
[NotifyPropertyChangedFor(nameof(IsSelectedOrExpanded))]
|
||||
public partial bool IsSelected { get; set; }
|
||||
|
||||
public bool IsSelectedOrExpanded => IsSelected || IsThreadExpanded;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of emails in this thread
|
||||
/// </summary>
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using CommunityToolkit.Mvvm.Messaging.Messages;
|
||||
using MoreLinq;
|
||||
using Nito.AsyncEx;
|
||||
using Serilog;
|
||||
@@ -39,7 +40,8 @@ public partial class MailListPageViewModel : MailBaseViewModel,
|
||||
IRecipient<NewMailSynchronizationRequested>,
|
||||
IRecipient<AccountSynchronizerStateChanged>,
|
||||
IRecipient<AccountCacheResetMessage>,
|
||||
IRecipient<ThumbnailAdded>
|
||||
IRecipient<ThumbnailAdded>,
|
||||
IRecipient<PropertyChangedMessage<bool>>
|
||||
{
|
||||
private bool isChangingFolder = false;
|
||||
|
||||
@@ -221,7 +223,7 @@ public partial class MailListPageViewModel : MailBaseViewModel,
|
||||
var selectedItem = MailCollection.SelectedItems.ElementAtOrDefault(0);
|
||||
ActiveMailItemChanged(selectedItem);
|
||||
}
|
||||
else if (MailCollection.SelectedItemsCount > 1)
|
||||
else if (MailCollection.SelectedItemsCount == 0)
|
||||
{
|
||||
ActiveMailItemChanged(null);
|
||||
}
|
||||
@@ -311,20 +313,6 @@ public partial class MailListPageViewModel : MailBaseViewModel,
|
||||
{
|
||||
if (_activeMailItem == selectedMailItemViewModel) return;
|
||||
|
||||
// Don't update active mail item if Ctrl key is pressed or multi selection is enabled.
|
||||
// User is probably trying to select multiple items.
|
||||
// This is not the same behavior in Windows Mail,
|
||||
// but it's a trash behavior.
|
||||
|
||||
var isCtrlKeyPressed = _keyPressService.IsCtrlKeyPressed();
|
||||
|
||||
bool isMultiSelecting = isCtrlKeyPressed || IsMultiSelectionModeEnabled;
|
||||
|
||||
if (isMultiSelecting && StatePersistenceService.IsReaderNarrowed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_activeMailItem = selectedMailItemViewModel;
|
||||
|
||||
Messenger.Send(new ActiveMailItemChangedEvent(_activeMailItem));
|
||||
@@ -1102,6 +1090,7 @@ public partial class MailListPageViewModel : MailBaseViewModel,
|
||||
Messenger.Register<AccountSynchronizerStateChanged>(this);
|
||||
Messenger.Register<AccountCacheResetMessage>(this);
|
||||
Messenger.Register<ThumbnailAdded>(this);
|
||||
Messenger.Register<PropertyChangedMessage<bool>>(this);
|
||||
}
|
||||
|
||||
protected override void UnregisterRecipients()
|
||||
@@ -1115,5 +1104,26 @@ public partial class MailListPageViewModel : MailBaseViewModel,
|
||||
Messenger.Unregister<AccountSynchronizerStateChanged>(this);
|
||||
Messenger.Unregister<AccountCacheResetMessage>(this);
|
||||
Messenger.Unregister<ThumbnailAdded>(this);
|
||||
Messenger.Unregister<PropertyChangedMessage<bool>>(this);
|
||||
}
|
||||
|
||||
public void Receive(PropertyChangedMessage<bool> message)
|
||||
{
|
||||
// Handle IsSelected property changes from MailItemViewModel
|
||||
if (message.PropertyName == nameof(MailItemViewModel.IsSelected) && message.Sender is MailItemViewModel mailItemViewModel)
|
||||
{
|
||||
Messenger.Send(new SelectedItemsChangedMessage());
|
||||
}
|
||||
else if (message.Sender is ThreadMailItemViewModel threadMailItemViewModel)
|
||||
{
|
||||
if (message.PropertyName == nameof(ThreadMailItemViewModel.IsSelected))
|
||||
{
|
||||
// Thread selected.
|
||||
}
|
||||
else if (message.PropertyName == nameof(ThreadMailItemViewModel.IsThreadExpanded))
|
||||
{
|
||||
// Thread expanded.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user