From 16cacf45b690a5e84b8d50276963c938f7d8c59d Mon Sep 17 00:00:00 2001 From: lhhxxxxx Date: Wed, 8 Jun 2022 18:23:22 +0800 Subject: [PATCH] feat. allow drag a file --- src/MeoAsstGui/ViewModels/CopilotViewModel.cs | 26 +++++++++++++++++++ src/MeoAsstGui/Views/CopilotView.xaml | 4 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/MeoAsstGui/ViewModels/CopilotViewModel.cs b/src/MeoAsstGui/ViewModels/CopilotViewModel.cs index b397ae7900..67a85efb4d 100644 --- a/src/MeoAsstGui/ViewModels/CopilotViewModel.cs +++ b/src/MeoAsstGui/ViewModels/CopilotViewModel.cs @@ -18,12 +18,15 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Threading.Tasks; +using System.Windows.Forms; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Notification.Wpf.Constants; using Notification.Wpf.Controls; using Stylet; using StyletIoC; +using DragEventArgs = System.Windows.DragEventArgs; +using Screen = Stylet.Screen; namespace MeoAsstGui { @@ -182,6 +185,29 @@ namespace MeoAsstGui } } + public void DropFile(object sender, DragEventArgs e) + { + if (!e.Data.GetDataPresent(DataFormats.FileDrop)) + { + return; + } + var filename = ((Array)e.Data.GetData(DataFormats.FileDrop))?.GetValue(0).ToString(); + if (filename == null) + { + return; + } + if (filename.EndsWith(".json")) + { + Filename = filename; + } + else + { + Filename = ""; + ClearLog(); + AddLog("此文件非json文件","darkred"); + } + } + private bool _form = false; public bool Form diff --git a/src/MeoAsstGui/Views/CopilotView.xaml b/src/MeoAsstGui/Views/CopilotView.xaml index 089862a50e..4b273e3ab0 100644 --- a/src/MeoAsstGui/Views/CopilotView.xaml +++ b/src/MeoAsstGui/Views/CopilotView.xaml @@ -9,7 +9,9 @@ mc:Ignorable="d" xmlns:vm="clr-namespace:MeoAsstGui;assembly=MeoAsstGui" d:DataContext="{d:DesignInstance {x:Type vm:CopilotViewModel}}" - d:DesignHeight="495" d:DesignWidth="800"> + d:DesignHeight="495" d:DesignWidth="800" + AllowDrop="True" + Drop="{s:Action DropFile}">