Skip to content

Commit

Permalink
fix(Studio): Drag-n-Drop support on WPF
Browse files Browse the repository at this point in the history
WPF does not allow Drag-n-Drop on a Form, but requires a Control
  • Loading branch information
psyGamer committed Dec 14, 2024
1 parent 3158244 commit 09fad01
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Studio/CelesteStudio/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public Studio(string[] args, Action<Window> windowCreationCallback) {
Instance = this;
Icon = Assets.AppIcon;
MinimumSize = new Size(250, 250);
AllowDrop = true;

WindowCreationCallback = windowCreationCallback;

Expand Down Expand Up @@ -180,6 +179,17 @@ public Studio(string[] args, Action<Window> 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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 09fad01

Please sign in to comment.