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"
|
<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:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
|
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" />
|
<ContentControl Name="Content" />
|
||||||
</Window>
|
</Window>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
@@ -62,15 +63,9 @@ namespace RedBookPlayer.GUI
|
|||||||
Instance.Height = ((PlayerView)Instance.ContentControl.Content).Height;
|
Instance.Height = ((PlayerView)Instance.ContentControl.Content).Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnKeyDown(object sender, KeyEventArgs e)
|
/// <summary>
|
||||||
{
|
/// Initialize the main window
|
||||||
if(e.Key == Key.F1)
|
/// </summary>
|
||||||
{
|
|
||||||
settingsWindow = new SettingsWindow(App.Settings);
|
|
||||||
settingsWindow.Show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeComponent()
|
void InitializeComponent()
|
||||||
{
|
{
|
||||||
AvaloniaXamlLoader.Load(this);
|
AvaloniaXamlLoader.Load(this);
|
||||||
@@ -97,6 +92,36 @@ namespace RedBookPlayer.GUI
|
|||||||
{
|
{
|
||||||
PlayerView.Player.Stop();
|
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();
|
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>
|
/// <summary>
|
||||||
/// Load the png image for a given character based on the theme
|
/// Load the png image for a given character based on the theme
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -90,6 +113,7 @@ namespace RedBookPlayer.GUI
|
|||||||
{
|
{
|
||||||
DataContext = new PlayerViewModel();
|
DataContext = new PlayerViewModel();
|
||||||
|
|
||||||
|
// Load the theme
|
||||||
if (xaml != null)
|
if (xaml != null)
|
||||||
new AvaloniaXamlLoader().Load(xaml, null, this);
|
new AvaloniaXamlLoader().Load(xaml, null, this);
|
||||||
else
|
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>
|
/// <summary>
|
||||||
/// Update the UI with the most recent information from the Player
|
/// Update the UI with the most recent information from the Player
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
#if WindowsDebug
|
#if WindowsDebug
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
#endif
|
#endif
|
||||||
@@ -8,6 +9,7 @@ namespace RedBookPlayer
|
|||||||
{
|
{
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
#if WindowsDebug
|
#if WindowsDebug
|
||||||
|
|||||||
Reference in New Issue
Block a user