WIP memory iconstorage

This commit is contained in:
dan_clark@outlook.com
2022-03-24 20:09:10 +00:00
parent 04df2d2ff6
commit 506161e4b9
14 changed files with 79 additions and 54 deletions
+13
View File
@@ -0,0 +1,13 @@
namespace TheXamlGuy.TaskbarGroup.Core
{
public static class Class1
{
public static void Test(Stream s)
{
using (FileStream outputFileStream = new(@"C:\Users\Daniel Clark\Pictures\trst.png", FileMode.Create))
{
s.CopyTo(outputFileStream);
}
}
}
}
@@ -0,0 +1,4 @@
namespace TheXamlGuy.TaskbarGroup.Core
{
public record IconStorage(string Path, Stream IconStream);
}
@@ -0,0 +1,12 @@
using System.Diagnostics;
namespace TheXamlGuy.TaskbarGroup.Core
{
public class IconStorageHandler : IMessageHandler<IconStorage>
{
public void Handle(IconStorage message)
{
Debug.WriteLine("Store icon");
}
}
}
@@ -2,8 +2,5 @@
namespace TheXamlGuy.TaskbarGroup.Flyout.Foundation
{
public record class Drag<TTarget>(DragEventArgs DragEventArgs) where TTarget : UIElement
{
public TTarget Target { get; }
}
public record class Drag<TTarget>(DragEventArgs DragEventArgs) where TTarget : UIElement;
}
@@ -2,8 +2,5 @@
namespace TheXamlGuy.TaskbarGroup.Flyout.Foundation
{
public record class Drop<TTarget>(DragEventArgs DropEventArgs) where TTarget : UIElement
{
public TTarget Target { get; }
}
public record class Drop<TTarget>(DragEventArgs DropEventArgs) where TTarget : UIElement;
}
@@ -1,7 +1,6 @@
using Microsoft.Xaml.Interactivity;
using System;
using TheXamlGuy.TaskbarGroup.Core;
using Windows.ApplicationModel.DataTransfer;
using Windows.UI.Xaml;
namespace TheXamlGuy.TaskbarGroup.Flyout.Foundation
@@ -30,24 +29,19 @@ namespace TheXamlGuy.TaskbarGroup.Flyout.Foundation
base.OnAttached();
}
private object CreateDragMessage(object sender, DragEventArgs args)
protected override void OnDetaching()
{
var dropMessageType = typeof(Drag<>).MakeGenericType(sender.GetType());
return Activator.CreateInstance(dropMessageType, args);
}
AssociatedObject.DragOver -= OnDragOver;
AssociatedObject.Drop -= OnDrop;
private object CreateDropMessage(object sender, DragEventArgs args)
{
var dropMessageType = typeof(Drop<>).MakeGenericType(sender.GetType());
return Activator.CreateInstance(dropMessageType, args);
base.OnDetaching();
}
private void OnDragOver(object sender, DragEventArgs args)
{
if (Mediator is not null)
{
var message = CreateDragMessage(sender, args);
Mediator.HandleAsync(message);
Mediator.Handle(Activator.CreateInstance(typeof(Drag<>).MakeGenericType(sender.GetType()), args));
}
}
@@ -55,8 +49,7 @@ namespace TheXamlGuy.TaskbarGroup.Flyout.Foundation
{
if (Mediator is not null)
{
var message = CreateDropMessage(sender, args);
Mediator.HandleAsync(message);
Mediator.Handle(Activator.CreateInstance(typeof(Drop<>).MakeGenericType(sender.GetType()), args));
}
}
}
@@ -3,7 +3,7 @@ using Windows.UI.Xaml;
namespace TheXamlGuy.TaskbarGroup.Flyout.Foundation
{
public interface IDragHandler<TTarget> : IAsyncMessageHandler<Drag<TTarget>> where TTarget : UIElement
public interface IDragHandler<TTarget> : IMessageHandler<Drag<TTarget>> where TTarget : UIElement
{
}
@@ -3,7 +3,7 @@ using Windows.UI.Xaml;
namespace TheXamlGuy.TaskbarGroup.Flyout.Foundation
{
public interface IDropHandler<TTarget> : IAsyncMessageHandler<Drop<TTarget>> where TTarget : UIElement
public interface IDropHandler<TTarget> : IMessageHandler<Drop<TTarget>> where TTarget : UIElement
{
}
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Windows.Storage;
namespace TheXamlGuy.TaskbarGroup.Flyout.Foundation
{
public static class IStorageItemExtensions
{
public static async Task<IDictionary<string, object>> RetrievePropertiesAsync(this IStorageItem storageFile, params string[] paramaters)
{
return await (await storageFile.GetBasicPropertiesAsync()).RetrievePropertiesAsync(paramaters);
}
}
}
@@ -130,6 +130,7 @@
<Compile Include="IDragHandler.cs" />
<Compile Include="IDropHandler.cs" />
<Compile Include="IServiceCollectionExtensions.cs" />
<Compile Include="IStorageItemExtensions.cs" />
<Compile Include="IWindowPrivate.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TemplateSelector.cs" />
@@ -7,7 +7,7 @@ namespace TheXamlGuy.TaskbarGroup.Flyout
{
public class TaskbarButtonGroupDragHandler : IDragHandler<TaskbarButtonGroupView>
{
public Task Handle(Drag<TaskbarButtonGroupView> message, CancellationToken canellationToken = default)
public void Handle(Drag<TaskbarButtonGroupView> message)
{
message.DragEventArgs.AcceptedOperation = DataPackageOperation.Link;
@@ -17,8 +17,6 @@ namespace TheXamlGuy.TaskbarGroup.Flyout
message.DragEventArgs.DragUIOverride.IsGlyphVisible = false;
message.DragEventArgs.DragUIOverride.IsCaptionVisible = false;
}
return Task.CompletedTask;
}
}
}
@@ -1,46 +1,41 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using TheXamlGuy.TaskbarGroup.Core;
using TheXamlGuy.TaskbarGroup.Flyout.Foundation;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
using Windows.Storage.FileProperties;
namespace TheXamlGuy.TaskbarGroup.Flyout
{
public class TaskbarButtonGroupDropHandler : IDropHandler<TaskbarButtonGroupView>
{
public async Task Handle(Drop<TaskbarButtonGroupView> message, CancellationToken canellationToken = default)
private readonly IMediator mediator;
public TaskbarButtonGroupDropHandler(IMediator mediator)
{
this.mediator = mediator;
}
public async void Handle(Drop<TaskbarButtonGroupView> message)
{
if (message.DropEventArgs.DataView.Contains(StandardDataFormats.StorageItems))
{
var items = await message.DropEventArgs.DataView.GetStorageItemsAsync();
foreach (var storageItem in items)
foreach (IStorageItem storageItem in items)
{
if (storageItem is StorageFile storageFile)
if ((await storageItem.RetrievePropertiesAsync("System.AppUserModel.ID"))
.TryGetValue("System.AppUserModel.ID", out var appUserModelId)
|| File.Exists(storageItem.Path))
{
if (storageFile.Path is { Length: > 0 })
if (storageItem is IStorageItemProperties storageItemProperties)
{
using var thumbnail = await storageItemProperties.GetThumbnailAsync(ThumbnailMode.SingleItem, 94);
using var stream = thumbnail.AsStreamForWrite();
mediator.Handle(new IconStorage(appUserModelId is not null ? $"{appUserModelId}" : storageItem.Path, stream));
}
else
{
var properties = await storageFile.Properties.RetrievePropertiesAsync(new List<string>
{
"System.AppUserModel.ID"
});
var appUserModelId = properties["System.AppUserModel.ID"];
if (appUserModelId is not null)
{
}
}
}
if (storageItem is StorageFolder storageFolder)
{
}
}
}
+4 -3
View File
@@ -41,9 +41,10 @@ namespace TheXamlGuy.TaskbarGroup
.AddTransient<TaskbarButtonView>()
.AddTransient<TaskbarButtonViewModel>()
.AddTransient<TaskbarButtonGroupView>()
.AddAsyncHandler<TaskbarButtonGroupDragHandler>()
.AddAsyncHandler<TaskbarButtonGroupDropHandler>()
.AddTransient<TaskbarButtonGroupViewModel>();
.AddHandler<TaskbarButtonGroupDragHandler>()
.AddHandler<TaskbarButtonGroupDropHandler>()
.AddTransient<TaskbarButtonGroupViewModel>()
.AddHandler<IconStorageHandler>();
}
}
}
@@ -8,7 +8,6 @@ namespace TheXamlGuy.TaskbarGroup
{
public class TaskbarButtonFlyoutWindow : TransparentXamlWindow<TaskbarButtonFlyout>
{
public TaskbarButtonFlyoutWindow()
{
Deactivated += OnDeactivated;