mirror of
https://github.com/Stone-Red-Code/Decho.git
synced 2026-09-06 07:46:12 +02:00
Code cleanup
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
using Decho.ViewModels;
|
||||
|
||||
namespace Decho.Views;
|
||||
@@ -19,18 +19,24 @@ public partial class MessageComposerView : UserControl
|
||||
|
||||
private async void OnFileUploadClicked(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is not MessageComposerViewModel vm) return;
|
||||
if (DataContext is not MessageComposerViewModel vm)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
if (topLevel?.StorageProvider is null) return;
|
||||
TopLevel? topLevel = TopLevel.GetTopLevel(this);
|
||||
if (topLevel?.StorageProvider is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
IReadOnlyList<IStorageFile> files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
AllowMultiple = false,
|
||||
Title = "Select a file to upload",
|
||||
});
|
||||
|
||||
var file = files?.FirstOrDefault();
|
||||
IStorageFile? file = files?.FirstOrDefault();
|
||||
if (file?.TryGetLocalPath() is string path)
|
||||
{
|
||||
vm.RequestFileUpload(path);
|
||||
@@ -41,21 +47,28 @@ public partial class MessageComposerView : UserControl
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
if (e.Data.Contains(DataFormats.Files))
|
||||
{
|
||||
#pragma warning restore CS0618
|
||||
e.DragEffects = DragDropEffects.Copy;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrop(object? sender, DragEventArgs e)
|
||||
{
|
||||
if (DataContext is not MessageComposerViewModel vm) return;
|
||||
if (DataContext is not MessageComposerViewModel vm)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#pragma warning disable CS0618
|
||||
var paths = e.Data.GetFiles()?
|
||||
string? paths = e.Data.GetFiles()?
|
||||
.Select(f => f.TryGetLocalPath())
|
||||
.FirstOrDefault(p => p is not null);
|
||||
#pragma warning restore CS0618
|
||||
|
||||
if (paths is string path)
|
||||
{
|
||||
vm.RequestFileUpload(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user