From 09fad01cd1d5ccd70874730f4788e989bf550d26 Mon Sep 17 00:00:00 2001 From: psyGamer Date: Sat, 14 Dec 2024 16:03:59 +0100 Subject: [PATCH] fix(Studio): Drag-n-Drop support on WPF WPF does not allow Drag-n-Drop on a Form, but requires a Control --- Studio/CelesteStudio/Studio.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Studio/CelesteStudio/Studio.cs b/Studio/CelesteStudio/Studio.cs index d443ccc6..9a2e6f72 100644 --- a/Studio/CelesteStudio/Studio.cs +++ b/Studio/CelesteStudio/Studio.cs @@ -84,7 +84,6 @@ public Studio(string[] args, Action windowCreationCallback) { Instance = this; Icon = Assets.AppIcon; MinimumSize = new Size(250, 250); - AllowDrop = true; WindowCreationCallback = windowCreationCallback; @@ -180,6 +179,17 @@ public Studio(string[] args, Action windowCreationCallback) { Editor = new Editor(Document.Dummy, editorScrollable); editorScrollable.Content = Editor; + // WPF requires a control for drag n' drop support + Editor.AllowDrop = true; + Editor.DragDrop += (_, e) => { + if (e.Data.ContainsUris && e.Data.Uris.Length > 0) { + OpenFile(Uri.UnescapeDataString(e.Data.Uris[0].AbsolutePath)); + } + }; + Editor.DragEnter += (_, e) => { + e.Effects = DragEffects.Copy; + }; + // On GTK, prevent the scrollable from reacting to Home/End if (Eto.Platform.Instance.IsGtk) { editorScrollable.KeyDown += (_, e) => e.Handled = true; @@ -352,15 +362,6 @@ private void ApplySettings() { Menu = CreateMenu(); // Recreate menu to reflect changes } - protected override void OnDragDrop(DragEventArgs e) { - if (e.Data.ContainsUris && e.Data.Uris.Length > 0) { - OpenFile(Uri.UnescapeDataString(e.Data.Uris[0].AbsolutePath)); - } - } - protected override void OnDragEnter(DragEventArgs e) { - e.Effects = DragEffects.Copy; - } - protected override void OnClosing(CancelEventArgs e) { if (!ShouldDiscardChanges(checkTempFile: false)) { e.Cancel = true;