Make TopBar dynamic
This commit is contained in:
@@ -64,6 +64,8 @@ namespace Wino.Mail.ViewModels
|
||||
public ObservableCollection<MailItemViewModel> SelectedItems { get; set; } = [];
|
||||
public ObservableCollection<FolderPivotViewModel> PivotFolders { get; set; } = [];
|
||||
|
||||
public ObservableCollection<MailOperationMenuItem> ActionItems { get; set; } = new ObservableCollection<MailOperationMenuItem>();
|
||||
|
||||
private readonly SemaphoreSlim listManipulationSemepahore = new SemaphoreSlim(1);
|
||||
private CancellationTokenSource listManipulationCancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
@@ -200,6 +202,13 @@ namespace Wino.Mail.ViewModels
|
||||
};
|
||||
}
|
||||
|
||||
private void SetupTopBarActions()
|
||||
{
|
||||
ActionItems.Clear();
|
||||
var actions = GetAvailableMailActions(SelectedItems);
|
||||
actions.ForEach(a => ActionItems.Add(a));
|
||||
}
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
@@ -365,6 +374,8 @@ namespace Wino.Mail.ViewModels
|
||||
|
||||
NotifyItemSelected();
|
||||
|
||||
SetupTopBarActions();
|
||||
|
||||
Messenger.Send(new SelectedMailItemsChanged(SelectedItems.Count));
|
||||
}
|
||||
|
||||
@@ -415,19 +426,31 @@ namespace Wino.Mail.ViewModels
|
||||
[RelayCommand]
|
||||
public Task ExecuteHoverAction(MailOperationPreperationRequest request) => ExecuteMailOperationAsync(request);
|
||||
|
||||
[RelayCommand]
|
||||
private async Task OperationClicked(MailOperationMenuItem menuItem)
|
||||
{
|
||||
if (menuItem == null || !SelectedItems.Any()) return;
|
||||
|
||||
await HandleMailOperation(menuItem.Operation, SelectedItems);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the requested mail operation for currently selected items.
|
||||
/// </summary>
|
||||
/// <param name="operation">Action to execute for selected items.</param>
|
||||
[RelayCommand]
|
||||
private async Task MailOperationAsync(int mailOperationIndex)
|
||||
private async Task MailOperationAsync(MailOperation mailOperation)
|
||||
{
|
||||
if (!SelectedItems.Any()) return;
|
||||
|
||||
// Commands don't like enums. So it has to be int.
|
||||
var operation = (MailOperation)mailOperationIndex;
|
||||
await HandleMailOperation(mailOperation, SelectedItems);
|
||||
}
|
||||
|
||||
var package = new MailOperationPreperationRequest(operation, SelectedItems.Select(a => a.MailCopy));
|
||||
private async Task HandleMailOperation(MailOperation mailOperation, IEnumerable<MailItemViewModel> mailItems)
|
||||
{
|
||||
if (!mailItems.Any()) return;
|
||||
|
||||
var package = new MailOperationPreperationRequest(mailOperation, mailItems.Select(a => a.MailCopy));
|
||||
|
||||
await ExecuteMailOperationAsync(package);
|
||||
}
|
||||
@@ -649,6 +672,8 @@ namespace Wino.Mail.ViewModels
|
||||
Debug.WriteLine($"Updating {updatedMail.Id}-> {updatedMail.UniqueId}");
|
||||
|
||||
await MailCollection.UpdateMailCopy(updatedMail);
|
||||
|
||||
await ExecuteUIThread(() => { SetupTopBarActions(); });
|
||||
}
|
||||
|
||||
protected override async void OnMailRemoved(MailCopy removedMail)
|
||||
|
||||
Reference in New Issue
Block a user