Merge pull request #191 from Tiktack/features/dropzone
Added attachments drag & drop support
This commit is contained in:
@@ -46,6 +46,8 @@
|
|||||||
"ClipboardTextCopied_Title": "Copied",
|
"ClipboardTextCopied_Title": "Copied",
|
||||||
"ClipboardTextCopyFailed_Message": "Failed to copy {0} to clipboard.",
|
"ClipboardTextCopyFailed_Message": "Failed to copy {0} to clipboard.",
|
||||||
"ComposerToPlaceholder": "click enter to input addresses",
|
"ComposerToPlaceholder": "click enter to input addresses",
|
||||||
|
"ComposerAttachmentsDropZone_Message": "Drop your files here",
|
||||||
|
"ComposerAttachmentsDragDropAttach_Message": "Attach",
|
||||||
"CustomThemeBuilder_AccentColorDescription": "Set custom accent color if you wish. Not selecting a color will use your Windows accent color.",
|
"CustomThemeBuilder_AccentColorDescription": "Set custom accent color if you wish. Not selecting a color will use your Windows accent color.",
|
||||||
"CustomThemeBuilder_AccentColorTitle": "Accent color",
|
"CustomThemeBuilder_AccentColorTitle": "Accent color",
|
||||||
"CustomThemeBuilder_PickColor": "Pick",
|
"CustomThemeBuilder_PickColor": "Pick",
|
||||||
|
|||||||
10
Wino.Core.Domain/Translator.Designer.cs
generated
10
Wino.Core.Domain/Translator.Designer.cs
generated
@@ -253,6 +253,16 @@ namespace Wino.Core.Domain
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string ComposerToPlaceholder => Resources.GetTranslatedString(@"ComposerToPlaceholder");
|
public static string ComposerToPlaceholder => Resources.GetTranslatedString(@"ComposerToPlaceholder");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Drop your files here
|
||||||
|
/// </summary>
|
||||||
|
public static string ComposerAttachmentsDropZone_Message => Resources.GetTranslatedString(@"ComposerAttachmentsDropZone_Message");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attach
|
||||||
|
/// </summary>
|
||||||
|
public static string ComposerAttachmentsDragDropAttach_Message => Resources.GetTranslatedString(@"ComposerAttachmentsDragDropAttach_Message");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set custom accent color if you wish. Not selecting a color will use your Windows accent color.
|
/// Set custom accent color if you wish. Not selecting a color will use your Windows accent color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -64,6 +64,12 @@ namespace Wino.Mail.ViewModels
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private MailAccount composingAccount;
|
private MailAccount composingAccount;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool isDraggingOverComposerGrid;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool isDraggingOverDropZone;
|
||||||
|
|
||||||
public ObservableCollection<MailAttachmentViewModel> IncludedAttachments { get; set; } = new ObservableCollection<MailAttachmentViewModel>();
|
public ObservableCollection<MailAttachmentViewModel> IncludedAttachments { get; set; } = new ObservableCollection<MailAttachmentViewModel>();
|
||||||
|
|
||||||
public ObservableCollection<MailAccount> Accounts { get; set; } = new ObservableCollection<MailAccount>();
|
public ObservableCollection<MailAccount> Accounts { get; set; } = new ObservableCollection<MailAccount>();
|
||||||
|
|||||||
@@ -107,7 +107,10 @@
|
|||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
|
|
||||||
<Grid Background="{ThemeResource AppBarBackgroundColor}">
|
<Grid Background="{ThemeResource AppBarBackgroundColor}"
|
||||||
|
AllowDrop="True"
|
||||||
|
DragOver="OnComposeGridDragOver"
|
||||||
|
DragLeave="OnComposeGridDragLeave">
|
||||||
<Grid.Resources>
|
<Grid.Resources>
|
||||||
<SolidColorBrush x:Key="AutoSuggestBoxBorderThemeBrush">Transparent</SolidColorBrush>
|
<SolidColorBrush x:Key="AutoSuggestBoxBorderThemeBrush">Transparent</SolidColorBrush>
|
||||||
</Grid.Resources>
|
</Grid.Resources>
|
||||||
@@ -620,9 +623,36 @@
|
|||||||
</ItemsPanelTemplate>
|
</ItemsPanelTemplate>
|
||||||
</ListView.ItemsPanel>
|
</ListView.ItemsPanel>
|
||||||
</ListView>
|
</ListView>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
<!-- Attachments -->
|
<!-- Dropzone -->
|
||||||
|
<Grid
|
||||||
|
Grid.Row="0"
|
||||||
|
Grid.RowSpan="3"
|
||||||
|
Visibility="{x:Bind ViewModel.IsDraggingOverComposerGrid, Mode=OneWay}"
|
||||||
|
Drop="OnFileDropGridFileDropped"
|
||||||
|
DragOver="OnFileDropGridDragOver"
|
||||||
|
DragLeave="OnFileDropGridDragLeave"
|
||||||
|
AllowDrop="True">
|
||||||
|
<Grid Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}" CornerRadius="9" Margin="0,7,5,0">
|
||||||
|
<Rectangle
|
||||||
|
x:Name="DropZoneBorder"
|
||||||
|
RadiusX="9"
|
||||||
|
RadiusY="9"
|
||||||
|
Fill="Transparent"
|
||||||
|
Stroke="{ThemeResource TextFillColorPrimaryBrush}"
|
||||||
|
Opacity="0.5"
|
||||||
|
StrokeDashArray="3,4"
|
||||||
|
StrokeThickness="2"/>
|
||||||
|
<TextBlock
|
||||||
|
x:Name="DropZoneText"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Opacity="0.5"
|
||||||
|
FontSize="20"
|
||||||
|
FontWeight="SemiBold"
|
||||||
|
Text="{x:Bind domain:Translator.ComposerAttachmentsDropZone_Message}"/>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid
|
<Grid
|
||||||
@@ -654,6 +684,18 @@
|
|||||||
|
|
||||||
<VisualState x:Name="LightMode" />
|
<VisualState x:Name="LightMode" />
|
||||||
</VisualStateGroup>
|
</VisualStateGroup>
|
||||||
|
<VisualStateGroup x:Name="DropZoneState">
|
||||||
|
<VisualState x:Name="Hovered">
|
||||||
|
<VisualState.StateTriggers>
|
||||||
|
<StateTrigger IsActive="{x:Bind ViewModel.IsDraggingOverDropZone, Mode=OneWay}" />
|
||||||
|
</VisualState.StateTriggers>
|
||||||
|
<VisualState.Setters>
|
||||||
|
<Setter Target="DropZoneText.Opacity" Value="1" />
|
||||||
|
<Setter Target="DropZoneBorder.Opacity" Value="1" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
<VisualState x:Name="NotHovered" />
|
||||||
|
</VisualStateGroup>
|
||||||
</VisualStateManager.VisualStateGroups>
|
</VisualStateManager.VisualStateGroups>
|
||||||
</Grid>
|
</Grid>
|
||||||
</abstract:ComposePageAbstract>
|
</abstract:ComposePageAbstract>
|
||||||
|
|||||||
@@ -13,13 +13,16 @@ using Microsoft.UI.Xaml.Controls;
|
|||||||
using Microsoft.Web.WebView2.Core;
|
using Microsoft.Web.WebView2.Core;
|
||||||
using MimeKit;
|
using MimeKit;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Windows.ApplicationModel.DataTransfer;
|
||||||
using Windows.Foundation;
|
using Windows.Foundation;
|
||||||
|
using Windows.Storage;
|
||||||
using Windows.Storage.Pickers;
|
using Windows.Storage.Pickers;
|
||||||
using Windows.UI.ViewManagement.Core;
|
using Windows.UI.ViewManagement.Core;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Media.Animation;
|
using Windows.UI.Xaml.Media.Animation;
|
||||||
using Windows.UI.Xaml.Navigation;
|
using Windows.UI.Xaml.Navigation;
|
||||||
|
using Wino.Core.Domain;
|
||||||
using Wino.Core.Domain.Entities;
|
using Wino.Core.Domain.Entities;
|
||||||
using Wino.Core.Domain.Enums;
|
using Wino.Core.Domain.Enums;
|
||||||
using Wino.Core.Domain.Interfaces;
|
using Wino.Core.Domain.Interfaces;
|
||||||
@@ -105,20 +108,61 @@ namespace Wino.Views
|
|||||||
picker.FileTypeFilter.Add("*");
|
picker.FileTypeFilter.Add("*");
|
||||||
var files = await picker.PickMultipleFilesAsync();
|
var files = await picker.PickMultipleFilesAsync();
|
||||||
|
|
||||||
if (files == null) return;
|
await AttachFiles(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnComposeGridDragOver(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
ViewModel.IsDraggingOverComposerGrid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnComposeGridDragLeave(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
ViewModel.IsDraggingOverComposerGrid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFileDropGridDragOver(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
ViewModel.IsDraggingOverDropZone = true;
|
||||||
|
|
||||||
|
e.AcceptedOperation = DataPackageOperation.Copy;
|
||||||
|
e.DragUIOverride.Caption = Translator.ComposerAttachmentsDragDropAttach_Message;
|
||||||
|
e.DragUIOverride.IsCaptionVisible = true;
|
||||||
|
e.DragUIOverride.IsGlyphVisible = true;
|
||||||
|
e.DragUIOverride.IsContentVisible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFileDropGridDragLeave(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
ViewModel.IsDraggingOverDropZone = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnFileDropGridFileDropped(object sender, DragEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.DataView.Contains(StandardDataFormats.StorageItems))
|
||||||
|
{
|
||||||
|
var storageItems = await e.DataView.GetStorageItemsAsync();
|
||||||
|
var files = storageItems.OfType<StorageFile>();
|
||||||
|
|
||||||
|
await AttachFiles(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewModel.IsDraggingOverComposerGrid = false;
|
||||||
|
ViewModel.IsDraggingOverDropZone = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AttachFiles(IEnumerable<StorageFile> files)
|
||||||
|
{
|
||||||
|
if (files?.Any() != true) return;
|
||||||
|
|
||||||
// Convert files to MailAttachmentViewModel.
|
// Convert files to MailAttachmentViewModel.
|
||||||
|
foreach (var file in files)
|
||||||
if (files.Any())
|
|
||||||
{
|
{
|
||||||
foreach (var file in files)
|
if (!ViewModel.IncludedAttachments.Any(a => a.FileName == file.Path))
|
||||||
{
|
{
|
||||||
if (!ViewModel.IncludedAttachments.Any(a => a.FileName == file.Path))
|
var attachmentViewModel = await file.ToAttachmentViewModelAsync();
|
||||||
{
|
|
||||||
var attachmentViewModel = await file.ToAttachmentViewModelAsync();
|
|
||||||
|
|
||||||
ViewModel.IncludedAttachments.Add(attachmentViewModel);
|
ViewModel.IncludedAttachments.Add(attachmentViewModel);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user