diff --git a/RedBookPlayer/GUI/MainWindow.xaml b/RedBookPlayer/GUI/MainWindow.xaml
index 89d5f64..56dbf79 100644
--- a/RedBookPlayer/GUI/MainWindow.xaml
+++ b/RedBookPlayer/GUI/MainWindow.xaml
@@ -1,6 +1,7 @@
+ x:Class="RedBookPlayer.GUI.MainWindow" Title="RedBookPlayer" SizeToContent="WidthAndHeight"
+ DragDrop.AllowDrop="True">
\ No newline at end of file
diff --git a/RedBookPlayer/GUI/MainWindow.xaml.cs b/RedBookPlayer/GUI/MainWindow.xaml.cs
index 70fae17..474037b 100644
--- a/RedBookPlayer/GUI/MainWindow.xaml.cs
+++ b/RedBookPlayer/GUI/MainWindow.xaml.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.IO;
using System.Xml;
using Avalonia.Controls;
@@ -62,15 +63,9 @@ namespace RedBookPlayer.GUI
Instance.Height = ((PlayerView)Instance.ContentControl.Content).Height;
}
- public void OnKeyDown(object sender, KeyEventArgs e)
- {
- if(e.Key == Key.F1)
- {
- settingsWindow = new SettingsWindow(App.Settings);
- settingsWindow.Show();
- }
- }
-
+ ///
+ /// Initialize the main window
+ ///
void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
@@ -97,6 +92,36 @@ namespace RedBookPlayer.GUI
{
PlayerView.Player.Stop();
};
+
+ AddHandler(DragDrop.DropEvent, MainWindow_Drop);
}
+
+ #region Event Handlers
+
+ public async void MainWindow_Drop(object sender, DragEventArgs e)
+ {
+ PlayerView playerView = ContentControl.Content as PlayerView;
+ if(playerView == null)
+ return;
+
+ IEnumerable fileNames = e.Data.GetFileNames();
+ foreach(string filename in fileNames)
+ {
+ bool loaded = await playerView.LoadImage(filename);
+ if(loaded)
+ break;
+ }
+ }
+
+ public void OnKeyDown(object sender, KeyEventArgs e)
+ {
+ if(e.Key == Key.F1)
+ {
+ settingsWindow = new SettingsWindow(App.Settings);
+ settingsWindow.Show();
+ }
+ }
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/RedBookPlayer/GUI/PlayerView.xaml.cs b/RedBookPlayer/GUI/PlayerView.xaml.cs
index fa4e8ae..ef733d3 100644
--- a/RedBookPlayer/GUI/PlayerView.xaml.cs
+++ b/RedBookPlayer/GUI/PlayerView.xaml.cs
@@ -58,6 +58,29 @@ namespace RedBookPlayer.GUI
return (await dialog.ShowAsync((Window)Parent.Parent))?.FirstOrDefault();
}
+ ///
+ /// Load an image from the path
+ ///
+ /// Path to the image to load
+ public async Task LoadImage(string path)
+ {
+ bool result = await Task.Run(() =>
+ {
+ Player.Init(path, App.Settings.AutoPlay);
+ return Player.Initialized;
+ });
+
+ if(result)
+ {
+ await Dispatcher.UIThread.InvokeAsync(() =>
+ {
+ MainWindow.Instance.Title = "RedBookPlayer - " + path.Split('/').Last().Split('\\').Last();
+ });
+ }
+
+ return result;
+ }
+
///
/// Load the png image for a given character based on the theme
///
@@ -90,6 +113,7 @@ namespace RedBookPlayer.GUI
{
DataContext = new PlayerViewModel();
+ // Load the theme
if (xaml != null)
new AvaloniaXamlLoader().Load(xaml, null, this);
else
@@ -150,27 +174,6 @@ namespace RedBookPlayer.GUI
};
}
- ///
- /// Load an image from the path
- ///
- /// Path to the image to load
- private async void LoadImage(string path)
- {
- bool result = await Task.Run(() =>
- {
- Player.Init(path, App.Settings.AutoPlay);
- return Player.Initialized;
- });
-
- if(result)
- {
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- MainWindow.Instance.Title = "RedBookPlayer - " + path.Split('/').Last().Split('\\').Last();
- });
- }
- }
-
///
/// Update the UI with the most recent information from the Player
///
diff --git a/RedBookPlayer/Program.cs b/RedBookPlayer/Program.cs
index 532003a..731908b 100644
--- a/RedBookPlayer/Program.cs
+++ b/RedBookPlayer/Program.cs
@@ -1,3 +1,4 @@
+using System;
#if WindowsDebug
using System.Runtime.InteropServices;
#endif
@@ -8,6 +9,7 @@ namespace RedBookPlayer
{
internal class Program
{
+ [STAThread]
public static void Main(string[] args)
{
#if WindowsDebug