Removing UWP project.
This commit is contained in:
67
Wino.Mail.WinUI/MenuFlyouts/AccountSelectorFlyout.cs
Normal file
67
Wino.Mail.WinUI/MenuFlyouts/AccountSelectorFlyout.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Wino.Controls;
|
||||
using Wino.Core.Domain.Entities;
|
||||
using Wino.Helpers;
|
||||
|
||||
#if NET8_0
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml;
|
||||
#else
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml;
|
||||
#endif
|
||||
|
||||
namespace Wino.MenuFlyouts
|
||||
{
|
||||
public class AccountSelectorFlyout : MenuFlyout, IDisposable
|
||||
{
|
||||
private readonly IEnumerable<MailAccount> _accounts;
|
||||
private readonly Func<MailAccount, Task> _onItemSelection;
|
||||
|
||||
public AccountSelectorFlyout(IEnumerable<MailAccount> accounts, Func<MailAccount, Task> onItemSelection)
|
||||
{
|
||||
_accounts = accounts;
|
||||
_onItemSelection = onItemSelection;
|
||||
|
||||
foreach (var account in _accounts)
|
||||
{
|
||||
var pathData = new WinoFontIcon() { Icon = XamlHelpers.GetProviderIcon(account.ProviderType) };
|
||||
var menuItem = new MenuFlyoutItem() { Tag = account.Address, Icon = pathData, Text = $"{account.Name} ({account.Address})", MinHeight = 55 };
|
||||
|
||||
menuItem.Click += AccountClicked;
|
||||
Items.Add(menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var menuItem in Items)
|
||||
{
|
||||
if (menuItem is MenuFlyoutItem flyoutItem)
|
||||
{
|
||||
flyoutItem.Click -= AccountClicked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void AccountClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is MenuFlyoutItem menuItem && menuItem.Tag is string accountAddress)
|
||||
{
|
||||
var selectedMenuItem = _accounts.FirstOrDefault(a => a.Address == accountAddress);
|
||||
|
||||
if (selectedMenuItem != null)
|
||||
{
|
||||
await _onItemSelection(selectedMenuItem);
|
||||
}
|
||||
}
|
||||
|
||||
Dispose();
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
225
Wino.Mail.WinUI/MenuFlyouts/FilterMenuFlyout.cs
Normal file
225
Wino.Mail.WinUI/MenuFlyouts/FilterMenuFlyout.cs
Normal file
@@ -0,0 +1,225 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Wino.Controls;
|
||||
using Wino.Core.Domain.Models.Reader;
|
||||
using Wino.Helpers;
|
||||
|
||||
#if NET8_0
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml;
|
||||
#else
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml;
|
||||
#endif
|
||||
namespace Wino.MenuFlyouts
|
||||
{
|
||||
public class FilterMenuFlyout : MenuFlyout
|
||||
{
|
||||
public static readonly DependencyProperty SelectedFilterChangedCommandProperty = DependencyProperty.Register(nameof(SelectedFilterChangedCommand), typeof(IRelayCommand<FilterOption>), typeof(FilterMenuFlyout), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty FilterOptionsProperty = DependencyProperty.Register(nameof(FilterOptions), typeof(List<FilterOption>), typeof(FilterMenuFlyout), new PropertyMetadata(null, new PropertyChangedCallback(OnOptionsChanged)));
|
||||
public static readonly DependencyProperty SelectedFilterOptionProperty = DependencyProperty.Register(nameof(SelectedFilterOption), typeof(FilterOption), typeof(FilterMenuFlyout), new PropertyMetadata(null, OnSelectedFilterOptionChanged));
|
||||
public static readonly DependencyProperty SelectedSortingOptionProperty = DependencyProperty.Register(nameof(SelectedSortingOption), typeof(SortingOption), typeof(FilterMenuFlyout), new PropertyMetadata(null, new PropertyChangedCallback(OnSelectedSortingOptionChanged)));
|
||||
public static readonly DependencyProperty SortingOptionsProperty = DependencyProperty.Register(nameof(SortingOptions), typeof(List<SortingOption>), typeof(FilterMenuFlyout), new PropertyMetadata(null, new PropertyChangedCallback(OnOptionsChanged)));
|
||||
public static readonly DependencyProperty SelectedSortingOptionChangedCommandProperty = DependencyProperty.Register(nameof(SelectedSortingOptionChangedCommand), typeof(IRelayCommand<SortingOption>), typeof(FilterMenuFlyout), new PropertyMetadata(null));
|
||||
|
||||
public IRelayCommand<FilterOption> SelectedFilterChangedCommand
|
||||
{
|
||||
get { return (IRelayCommand<FilterOption>)GetValue(SelectedFilterChangedCommandProperty); }
|
||||
set { SetValue(SelectedFilterChangedCommandProperty, value); }
|
||||
}
|
||||
|
||||
public IRelayCommand<SortingOption> SelectedSortingOptionChangedCommand
|
||||
{
|
||||
get { return (IRelayCommand<SortingOption>)GetValue(SelectedSortingOptionChangedCommandProperty); }
|
||||
set { SetValue(SelectedSortingOptionChangedCommandProperty, value); }
|
||||
}
|
||||
|
||||
public List<FilterOption> FilterOptions
|
||||
{
|
||||
get { return (List<FilterOption>)GetValue(FilterOptionsProperty); }
|
||||
set { SetValue(FilterOptionsProperty, value); }
|
||||
}
|
||||
|
||||
public List<SortingOption> SortingOptions
|
||||
{
|
||||
get { return (List<SortingOption>)GetValue(SortingOptionsProperty); }
|
||||
set { SetValue(SortingOptionsProperty, value); }
|
||||
}
|
||||
|
||||
public FilterOption SelectedFilterOption
|
||||
{
|
||||
get { return (FilterOption)GetValue(SelectedFilterOptionProperty); }
|
||||
set { SetValue(SelectedFilterOptionProperty, value); }
|
||||
}
|
||||
|
||||
public SortingOption SelectedSortingOption
|
||||
{
|
||||
get { return (SortingOption)GetValue(SelectedSortingOptionProperty); }
|
||||
set { SetValue(SelectedSortingOptionProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnSelectedFilterOptionChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
if (obj is FilterMenuFlyout bar)
|
||||
{
|
||||
bar.SelectFilterOption(bar.SelectedFilterOption);
|
||||
bar.SelectedFilterChangedCommand?.Execute(bar.SelectedFilterOption);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnSelectedSortingOptionChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
if (obj is FilterMenuFlyout bar)
|
||||
{
|
||||
bar.SelectSortingOption(bar.SelectedSortingOption);
|
||||
bar.SelectedSortingOptionChangedCommand?.Execute(bar.SelectedSortingOption);
|
||||
}
|
||||
}
|
||||
|
||||
private ToggleMenuFlyoutItem CreateFilterToggleButton(FilterOption option)
|
||||
{
|
||||
var button = new ToggleMenuFlyoutItem()
|
||||
{
|
||||
Text = option.Title,
|
||||
Tag = option,
|
||||
Icon = new WinoFontIcon() { Icon = XamlHelpers.GetWinoIconGlyph(option.Type) },
|
||||
IsChecked = option == SelectedFilterOption
|
||||
};
|
||||
|
||||
button.Click += FilterToggleChecked;
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
private ToggleMenuFlyoutItem CreateSortingToggleButton(SortingOption option)
|
||||
{
|
||||
var button = new ToggleMenuFlyoutItem()
|
||||
{
|
||||
Text = option.Title,
|
||||
Tag = option,
|
||||
IsChecked = option == SelectedSortingOption
|
||||
};
|
||||
|
||||
button.Click += SortingOptionChecked;
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
private void SortingOptionChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is ToggleMenuFlyoutItem button)
|
||||
{
|
||||
button.IsHitTestVisible = false;
|
||||
|
||||
var optionModel = button.Tag as SortingOption;
|
||||
|
||||
SelectSortingOption(optionModel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void FilterToggleChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is ToggleMenuFlyoutItem button)
|
||||
{
|
||||
button.IsHitTestVisible = false;
|
||||
|
||||
var optionModel = button.Tag as FilterOption;
|
||||
|
||||
SelectFilterOption(optionModel);
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectFilterOption(FilterOption option)
|
||||
{
|
||||
SelectedFilterOption = option;
|
||||
|
||||
UncheckOtherFilterOptions();
|
||||
}
|
||||
|
||||
private void SelectSortingOption(SortingOption option)
|
||||
{
|
||||
SelectedSortingOption = option;
|
||||
|
||||
UncheckOtherSortingOptions();
|
||||
}
|
||||
|
||||
private void UnregisterCheckedHandler(ToggleMenuFlyoutItem button)
|
||||
{
|
||||
button.Click -= FilterToggleChecked;
|
||||
}
|
||||
|
||||
private void UncheckOtherFilterOptions()
|
||||
{
|
||||
if (Items.Any())
|
||||
{
|
||||
foreach (var item in Items)
|
||||
{
|
||||
if (item is ToggleMenuFlyoutItem toggleButton && toggleButton.Tag is FilterOption option && option != SelectedFilterOption)
|
||||
{
|
||||
toggleButton.IsChecked = false;
|
||||
toggleButton.IsHitTestVisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UncheckOtherSortingOptions()
|
||||
{
|
||||
if (Items.Any())
|
||||
{
|
||||
foreach (var item in Items)
|
||||
{
|
||||
if (item is ToggleMenuFlyoutItem toggleButton && toggleButton.Tag is SortingOption option && option != SelectedSortingOption)
|
||||
{
|
||||
toggleButton.IsChecked = false;
|
||||
toggleButton.IsHitTestVisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var item in Items)
|
||||
{
|
||||
if (item is ToggleMenuFlyoutItem toggleButton)
|
||||
{
|
||||
UnregisterCheckedHandler(toggleButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnOptionsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
if (obj is FilterMenuFlyout bar && bar.SortingOptions != null && bar.FilterOptions != null)
|
||||
{
|
||||
bar.Dispose();
|
||||
|
||||
bar.Items.Clear();
|
||||
|
||||
if (bar.FilterOptions != null)
|
||||
{
|
||||
foreach (var item in bar.FilterOptions)
|
||||
{
|
||||
bar.Items.Add(bar.CreateFilterToggleButton(item));
|
||||
}
|
||||
}
|
||||
|
||||
bar.Items.Add(new MenuFlyoutSeparator());
|
||||
|
||||
// Sorting options.
|
||||
|
||||
if (bar.SortingOptions != null)
|
||||
{
|
||||
foreach (var item in bar.SortingOptions)
|
||||
{
|
||||
bar.Items.Add(bar.CreateSortingToggleButton(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Wino.Mail.WinUI/MenuFlyouts/FolderOperationFlyout.cs
Normal file
34
Wino.Mail.WinUI/MenuFlyouts/FolderOperationFlyout.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Models.Folders;
|
||||
|
||||
#if NET8_0
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
#else
|
||||
using Windows.UI.Xaml.Controls;
|
||||
#endif
|
||||
|
||||
namespace Wino.MenuFlyouts.Context
|
||||
{
|
||||
public class FolderOperationFlyout : WinoOperationFlyout<FolderOperationMenuItem>
|
||||
{
|
||||
public FolderOperationFlyout(IEnumerable<FolderOperationMenuItem> availableActions, TaskCompletionSource<FolderOperationMenuItem> completionSource) : base(availableActions, completionSource)
|
||||
{
|
||||
if (AvailableActions == null) return;
|
||||
|
||||
foreach (var action in AvailableActions)
|
||||
{
|
||||
if (action.Operation == FolderOperation.Seperator)
|
||||
Items.Add(new MenuFlyoutSeparator());
|
||||
else
|
||||
{
|
||||
var menuFlyoutItem = new FolderOperationMenuFlyoutItem(action, (c) => MenuItemClicked(c));
|
||||
|
||||
Items.Add(menuFlyoutItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Wino.Mail.WinUI/MenuFlyouts/FolderOperationMenuFlyoutItem.cs
Normal file
12
Wino.Mail.WinUI/MenuFlyouts/FolderOperationMenuFlyoutItem.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using Wino.Core.Domain.Models.Folders;
|
||||
|
||||
namespace Wino.MenuFlyouts
|
||||
{
|
||||
public class FolderOperationMenuFlyoutItem : WinoOperationFlyoutItem<FolderOperationMenuItem>
|
||||
{
|
||||
public FolderOperationMenuFlyoutItem(FolderOperationMenuItem operationMenuItem, Action<FolderOperationMenuItem> clicked) : base(operationMenuItem, clicked)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Wino.Mail.WinUI/MenuFlyouts/MailOperationFlyout.cs
Normal file
34
Wino.Mail.WinUI/MenuFlyouts/MailOperationFlyout.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Models.Menus;
|
||||
|
||||
|
||||
#if NET8_0
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
#else
|
||||
using Windows.UI.Xaml.Controls;
|
||||
#endif
|
||||
namespace Wino.MenuFlyouts.Context
|
||||
{
|
||||
public class MailOperationFlyout : WinoOperationFlyout<MailOperationMenuItem>
|
||||
{
|
||||
public MailOperationFlyout(IEnumerable<MailOperationMenuItem> availableActions, TaskCompletionSource<MailOperationMenuItem> completionSource) : base(availableActions, completionSource)
|
||||
{
|
||||
if (AvailableActions == null) return;
|
||||
|
||||
foreach (var action in AvailableActions)
|
||||
{
|
||||
if (action.Operation == MailOperation.Seperator)
|
||||
Items.Add(new MenuFlyoutSeparator());
|
||||
else
|
||||
{
|
||||
var menuFlyoutItem = new MailOperationMenuFlyoutItem(action, (c) => MenuItemClicked(c));
|
||||
|
||||
Items.Add(menuFlyoutItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Wino.Mail.WinUI/MenuFlyouts/MailOperationMenuFlyoutItem.cs
Normal file
12
Wino.Mail.WinUI/MenuFlyouts/MailOperationMenuFlyoutItem.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using Wino.Core.Domain.Models.Menus;
|
||||
|
||||
namespace Wino.MenuFlyouts.Context
|
||||
{
|
||||
public class MailOperationMenuFlyoutItem : WinoOperationFlyoutItem<MailOperationMenuItem>
|
||||
{
|
||||
public MailOperationMenuFlyoutItem(MailOperationMenuItem operationMenuItem, Action<MailOperationMenuItem> clicked) : base(operationMenuItem, clicked)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
94
Wino.Mail.WinUI/MenuFlyouts/MoveButtonFlyout.cs
Normal file
94
Wino.Mail.WinUI/MenuFlyouts/MoveButtonFlyout.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Windows.Foundation;
|
||||
using Wino.Core.Domain.Entities;
|
||||
|
||||
#if NET8_0
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
#else
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
#endif
|
||||
|
||||
namespace Wino.MenuFlyouts
|
||||
{
|
||||
public class MoveButtonMenuItemClickedEventArgs
|
||||
{
|
||||
public Guid ClickedFolderId { get; set; }
|
||||
}
|
||||
|
||||
public class MoveButtonFlyout : MenuFlyout
|
||||
{
|
||||
public event TypedEventHandler<MoveButtonFlyout, MoveButtonMenuItemClickedEventArgs> MenuItemClick;
|
||||
public static readonly DependencyProperty FoldersProperty = DependencyProperty.Register(nameof(Folders), typeof(List<MailItemFolder>), typeof(MoveButtonFlyout), new PropertyMetadata(null, new PropertyChangedCallback(OnFoldersChanged)));
|
||||
|
||||
public List<MailItemFolder> Folders
|
||||
{
|
||||
get { return (List<MailItemFolder>)GetValue(FoldersProperty); }
|
||||
set { SetValue(FoldersProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnFoldersChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
if (obj is MoveButtonFlyout menu)
|
||||
{
|
||||
menu.InitializeMenu();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void InitializeMenu()
|
||||
{
|
||||
Dispose();
|
||||
|
||||
Items.Clear();
|
||||
|
||||
if (Folders == null || !Folders.Any())
|
||||
return;
|
||||
|
||||
// TODO: Child folders.
|
||||
|
||||
foreach (var item in Folders)
|
||||
{
|
||||
// We don't expect this, but it crashes startup.
|
||||
// Just to be on the safe side.
|
||||
if (item.FolderName != null)
|
||||
{
|
||||
var folderMenuItem = new MenuFlyoutItem()
|
||||
{
|
||||
Tag = item,
|
||||
Text = item.FolderName
|
||||
};
|
||||
|
||||
folderMenuItem.Click += MenuItemClicked;
|
||||
|
||||
Items.Add(folderMenuItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MenuItemClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var clickedFolder = (sender as MenuFlyoutItem).Tag as MailItemFolder;
|
||||
|
||||
MenuItemClick?.Invoke(this, new MoveButtonMenuItemClickedEventArgs()
|
||||
{
|
||||
ClickedFolderId = clickedFolder.Id
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var item in Items)
|
||||
{
|
||||
if (item is MenuFlyoutItem menuItem)
|
||||
{
|
||||
menuItem.Click -= MenuItemClicked;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Wino.Mail.WinUI/MenuFlyouts/RendererCommandBarItem.cs
Normal file
45
Wino.Mail.WinUI/MenuFlyouts/RendererCommandBarItem.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
|
||||
using Wino.Controls;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Helpers;
|
||||
|
||||
#if NET8_0
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
#else
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
#endif
|
||||
namespace Wino.MenuFlyouts
|
||||
{
|
||||
public class RendererCommandBarItem : AppBarButton, IDisposable
|
||||
{
|
||||
public MailOperation Operation { get; set; }
|
||||
Action<MailOperation> Clicked { get; set; }
|
||||
|
||||
public RendererCommandBarItem(MailOperation operation, Action<MailOperation> clicked)
|
||||
{
|
||||
Margin = new Thickness(6, 0, 6, 0);
|
||||
CornerRadius = new CornerRadius(6);
|
||||
|
||||
Operation = operation;
|
||||
Clicked = clicked;
|
||||
|
||||
Label = XamlHelpers.GetOperationString(operation);
|
||||
Icon = new WinoFontIcon() { Icon = WinoIconGlyph.Archive };
|
||||
|
||||
Click += MenuClicked;
|
||||
}
|
||||
|
||||
private void MenuClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Clicked(Operation);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Click -= MenuClicked;
|
||||
}
|
||||
}
|
||||
}
|
||||
56
Wino.Mail.WinUI/MenuFlyouts/WinoOperationFlyout.cs
Normal file
56
Wino.Mail.WinUI/MenuFlyouts/WinoOperationFlyout.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#if NET8_0
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
#else
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
#endif
|
||||
namespace Wino.MenuFlyouts
|
||||
{
|
||||
public class WinoOperationFlyout<TActionType> : MenuFlyout, IDisposable where TActionType : class
|
||||
{
|
||||
public TActionType ClickedOperation { get; set; }
|
||||
|
||||
protected readonly IEnumerable<TActionType> AvailableActions;
|
||||
|
||||
private readonly TaskCompletionSource<TActionType> _completionSource;
|
||||
|
||||
public WinoOperationFlyout(IEnumerable<TActionType> availableActions, TaskCompletionSource<TActionType> completionSource)
|
||||
{
|
||||
_completionSource = completionSource;
|
||||
|
||||
AvailableActions = availableActions;
|
||||
|
||||
Closing += FlyoutClosing;
|
||||
}
|
||||
|
||||
private void FlyoutClosing(FlyoutBase sender, FlyoutBaseClosingEventArgs args)
|
||||
{
|
||||
Closing -= FlyoutClosing;
|
||||
|
||||
_completionSource.TrySetResult(ClickedOperation);
|
||||
}
|
||||
|
||||
protected void MenuItemClicked(TActionType operation)
|
||||
{
|
||||
ClickedOperation = operation;
|
||||
|
||||
Hide();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var item in Items)
|
||||
{
|
||||
if (item is IDisposable disposableItem)
|
||||
{
|
||||
disposableItem.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
65
Wino.Mail.WinUI/MenuFlyouts/WinoOperationFlyoutItem.cs
Normal file
65
Wino.Mail.WinUI/MenuFlyouts/WinoOperationFlyoutItem.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
|
||||
using Wino.Controls;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Folders;
|
||||
using Wino.Core.Domain.Models.Menus;
|
||||
using Wino.Helpers;
|
||||
|
||||
#if NET8_0
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
#else
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
#endif
|
||||
|
||||
namespace Wino.MenuFlyouts
|
||||
{
|
||||
public class WinoOperationFlyoutItem<TOperationMenuItem> : MenuFlyoutItem, IDisposable where TOperationMenuItem : IMenuOperation
|
||||
{
|
||||
private const double CustomHeight = 35;
|
||||
|
||||
public TOperationMenuItem Operation { get; set; }
|
||||
Action<TOperationMenuItem> Clicked { get; set; }
|
||||
|
||||
public WinoOperationFlyoutItem(TOperationMenuItem operationMenuItem, Action<TOperationMenuItem> clicked)
|
||||
{
|
||||
Margin = new Thickness(4, 2, 4, 2);
|
||||
CornerRadius = new CornerRadius(6, 6, 6, 6);
|
||||
|
||||
MinHeight = CustomHeight;
|
||||
|
||||
Operation = operationMenuItem;
|
||||
IsEnabled = operationMenuItem.IsEnabled;
|
||||
|
||||
if (Operation is FolderOperationMenuItem folderOperationMenuItem)
|
||||
{
|
||||
var internalOperation = folderOperationMenuItem.Operation;
|
||||
|
||||
Icon = new WinoFontIcon() { Icon = XamlHelpers.GetPathGeometry(internalOperation) };
|
||||
Text = XamlHelpers.GetOperationString(internalOperation);
|
||||
}
|
||||
else if (Operation is MailOperationMenuItem mailOperationMenuItem)
|
||||
{
|
||||
var internalOperation = mailOperationMenuItem.Operation;
|
||||
|
||||
Icon = new WinoFontIcon() { Icon = XamlHelpers.GetWinoIconGlyph(internalOperation) };
|
||||
Text = XamlHelpers.GetOperationString(internalOperation);
|
||||
}
|
||||
|
||||
Clicked = clicked;
|
||||
Click += MenuClicked;
|
||||
}
|
||||
|
||||
private void MenuClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Clicked(Operation);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Click -= MenuClicked;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user