mirror of
https://github.com/aaru-dps/RedBookPlayer.git
synced 2025-12-16 19:24:41 +00:00
Enable drag and drop support
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
|
||||
x:Class="RedBookPlayer.GUI.MainWindow" Title="RedBookPlayer" SizeToContent="WidthAndHeight">
|
||||
x:Class="RedBookPlayer.GUI.MainWindow" Title="RedBookPlayer" SizeToContent="WidthAndHeight"
|
||||
DragDrop.AllowDrop="True">
|
||||
<ContentControl Name="Content" />
|
||||
</Window>
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the main window
|
||||
/// </summary>
|
||||
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<string> 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
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,29 @@ namespace RedBookPlayer.GUI
|
||||
return (await dialog.ShowAsync((Window)Parent.Parent))?.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load an image from the path
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the image to load</param>
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load the png image for a given character based on the theme
|
||||
/// </summary>
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load an image from the path
|
||||
/// </summary>
|
||||
/// <param name="path">Path to the image to load</param>
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the UI with the most recent information from the Player
|
||||
/// </summary>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user