From dd01e74369834c313ead28b14cb15dadc3873de2 Mon Sep 17 00:00:00 2001 From: Royce551 Date: Sun, 9 Aug 2020 22:15:24 -0500 Subject: [PATCH] add drag and drop support for library pages --- .../Forms/TagEditor.xaml | 18 +++++----- .../MainWindow.xaml.cs | 11 +++--- .../Pages/ImportPage.xaml | 2 +- .../Pages/ImportPage.xaml.cs | 14 ++++++++ .../Pages/Library/LibraryPage.xaml | 2 +- .../Pages/Library/LibraryPage.xaml.cs | 35 +++++++++++++++++++ .../Resources/DarkTheme.xaml | 2 +- 7 files changed, 68 insertions(+), 16 deletions(-) diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Forms/TagEditor.xaml b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Forms/TagEditor.xaml index 278fe9b..a99c837 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Forms/TagEditor.xaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Forms/TagEditor.xaml @@ -47,11 +47,11 @@ - - - - - + + + + + @@ -72,10 +72,10 @@ - - - - + + + + diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/MainWindow.xaml.cs b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/MainWindow.xaml.cs index 32ffffb..dcf2f94 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/MainWindow.xaml.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/MainWindow.xaml.cs @@ -30,12 +30,12 @@ namespace FRESHMusicPlayer { Winforms.Timer progressTimer; public static SelectedMenus SelectedMenu = SelectedMenus.Tracks; - // TODO: i dunno how to pass this to the pages, if there is a way to i can avoid making this static public static Player Player = new Player(); public static NotificationHandler NotificationHandler = new NotificationHandler(); public static List Library = new List(); public static bool MiniPlayerMode = false; public static bool PreventAuxilliaryPaneHiding = false; + public static EventHandler TabChanged; public MainWindow() { InitializeComponent(); @@ -147,17 +147,17 @@ namespace FRESHMusicPlayer { case SelectedMenus.Tracks: ContentFrame.Source = new Uri(@"\Pages\Library\LibraryPage.xaml", UriKind.Relative); - RightFrame.NavigationService.RemoveBackEntry(); + ContentFrame.NavigationService.RemoveBackEntry(); tab = TracksTab; break; case SelectedMenus.Artists: ContentFrame.Source = new Uri(@"\Pages\Library\LibraryPage.xaml", UriKind.Relative); - RightFrame.NavigationService.RemoveBackEntry(); + ContentFrame.NavigationService.RemoveBackEntry(); tab = ArtistsTab; break; case SelectedMenus.Albums: ContentFrame.Source = new Uri(@"\Pages\Library\LibraryPage.xaml", UriKind.Relative); - RightFrame.NavigationService.RemoveBackEntry(); + ContentFrame.NavigationService.RemoveBackEntry(); tab = AlbumsTab; break; case SelectedMenus.Import: @@ -167,6 +167,7 @@ namespace FRESHMusicPlayer default: throw new InvalidOperationException("you are idoit"); } + TabChanged?.Invoke(null, EventArgs.Empty); TracksTab.FontWeight = ArtistsTab.FontWeight = AlbumsTab.FontWeight = ImportTab.FontWeight = FontWeights.Normal; tab.FontWeight = FontWeights.Bold; } @@ -314,6 +315,8 @@ namespace FRESHMusicPlayer e.Handled = true; break; case Key.F5: + Library.Clear(); + Library = DatabaseHandler.ReadSongs(); ContentFrame.Refresh(); e.Handled = true; break; diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/ImportPage.xaml b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/ImportPage.xaml index 0349c3e..e5d5246 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/ImportPage.xaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/ImportPage.xaml @@ -7,7 +7,7 @@ xmlns:resx = "clr-namespace:FRESHMusicPlayer_WPF_UI_Test.Properties" mc:Ignorable="d" d:DesignHeight="372" d:DesignWidth="694" - Title="ImportPage"> + Title="ImportPage" DragEnter="Page_DragEnter" Drop="Page_Drop" AllowDrop="True"> diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/ImportPage.xaml.cs b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/ImportPage.xaml.cs index 25fb6d1..873d9f5 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/ImportPage.xaml.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/ImportPage.xaml.cs @@ -5,6 +5,7 @@ using FRESHMusicPlayer.Handlers.Notifications; using Microsoft.Win32; using System.IO; using System.Linq; +using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using WinForms = System.Windows.Forms; @@ -73,5 +74,18 @@ namespace FRESHMusicPlayer_WPF_UI_Test.Pages } } } + + private void Page_DragEnter(object sender, DragEventArgs e) + { + e.Effects = DragDropEffects.Copy; + } + + private void Page_Drop(object sender, DragEventArgs e) + { + string[] tracks = (string[])e.Data.GetData(DataFormats.FileDrop); + MainWindow.Player.AddQueue(tracks); + DatabaseHandler.ImportSong(tracks); + MainWindow.Player.PlayMusic(); + } } } diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/Library/LibraryPage.xaml b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/Library/LibraryPage.xaml index bf4e1cd..f83d1bb 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/Library/LibraryPage.xaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/Library/LibraryPage.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:FRESHMusicPlayer_WPF_UI_Test.Pages.Library" mc:Ignorable="d" d:DesignHeight="372" d:DesignWidth="694" - Title="LibraryPage"> + Title="LibraryPage" Unloaded="Page_Unloaded" DragEnter="Page_DragEnter" Drop="Page_Drop" AllowDrop="True"> diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/Library/LibraryPage.xaml.cs b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/Library/LibraryPage.xaml.cs index fe1ca6b..c3a82d5 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/Library/LibraryPage.xaml.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Pages/Library/LibraryPage.xaml.cs @@ -14,8 +14,10 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using ATL; +using FRESHMusicPlayer.Handlers; using FRESHMusicPlayer.Handlers.Notifications; using System.Threading; +using System.ComponentModel; namespace FRESHMusicPlayer_WPF_UI_Test.Pages.Library { @@ -28,7 +30,9 @@ namespace FRESHMusicPlayer_WPF_UI_Test.Pages.Library { InitializeComponent(); LoadLibrary(); + MainWindow.TabChanged += MainWindow_TabChanged; } + public void LoadLibrary() { switch (MainWindow.SelectedMenu) // all of this stuff is here so that i can avoid copying and pasting the same page thrice, maybe there's a better way? @@ -138,6 +142,37 @@ namespace FRESHMusicPlayer_WPF_UI_Test.Pages.Library if (MainWindow.SelectedMenu == SelectedMenus.Artists) ShowTracksforArtist(); else ShowTracksforAlbum(); } + private void MainWindow_TabChanged(object sender, EventArgs e) + { + TracksPanel.Items.Clear(); + CategoryPanel.Items.Clear(); + LeftSide.Width = new GridLength(222); + DetailsPane.Height = new GridLength(75); + LoadLibrary(); + } + private void Page_Unloaded(object sender, RoutedEventArgs e) + { + MainWindow.TabChanged -= MainWindow_TabChanged; + CategoryPanel.Items.Clear(); + TracksPanel.Items.Clear(); + } + + private void Page_DragEnter(object sender, DragEventArgs e) + { + e.Effects = DragDropEffects.Copy; + } + + private void Page_Drop(object sender, DragEventArgs e) + { + string[] tracks = (string[])e.Data.GetData(DataFormats.FileDrop); // TODO: move logic to mainwindow + MainWindow.Player.AddQueue(tracks); + DatabaseHandler.ImportSong(tracks); + MainWindow.Player.PlayMusic(); + + MainWindow.Library.Clear(); + MainWindow.Library = DatabaseHandler.ReadSongs(); + LoadLibrary(); + } } } diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Resources/DarkTheme.xaml b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Resources/DarkTheme.xaml index 2cc963a..98a97aa 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Resources/DarkTheme.xaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-WPF-UI-Test/Resources/DarkTheme.xaml @@ -6,6 +6,6 @@ - + \ No newline at end of file