Code cleanup

This commit is contained in:
Stone_Red
2026-07-15 20:42:43 +02:00
parent ebac2b4eb7
commit b08358baed
21 changed files with 1065 additions and 980 deletions
+22 -9
View File
@@ -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);
}
}
}
}