From c8789157ba0ca2dbf635e52e787604c822dca47e Mon Sep 17 00:00:00 2001 From: Scrub <72096833+ScrubN@users.noreply.github.com> Date: Wed, 28 Aug 2024 20:03:10 -0400 Subject: [PATCH] Add buttons for reordering tasks (#1200) * Add buttons and logic for rearranging tasks * Use FontAwesome for close button * Fix potential race condition --- TwitchDownloaderWPF/PageQueue.xaml | 12 +++++++- TwitchDownloaderWPF/PageQueue.xaml.cs | 41 +++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/TwitchDownloaderWPF/PageQueue.xaml b/TwitchDownloaderWPF/PageQueue.xaml index 31733e35..1f8431cb 100644 --- a/TwitchDownloaderWPF/PageQueue.xaml +++ b/TwitchDownloaderWPF/PageQueue.xaml @@ -87,7 +87,17 @@ - + + + diff --git a/TwitchDownloaderWPF/PageQueue.xaml.cs b/TwitchDownloaderWPF/PageQueue.xaml.cs index 47ce873f..a12fee62 100644 --- a/TwitchDownloaderWPF/PageQueue.xaml.cs +++ b/TwitchDownloaderWPF/PageQueue.xaml.cs @@ -290,9 +290,12 @@ private static void RemoveTask(TwitchTask task) return; } - if (!taskList.Remove(task)) + lock (taskLock) { - MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.TaskCouldNotBeRemoved, Translations.Strings.UnknownErrorOccurred, MessageBoxButton.OK, MessageBoxImage.Error); + if (!taskList.Remove(task)) + { + MessageBox.Show(Application.Current.MainWindow!, Translations.Strings.TaskCouldNotBeRemoved, Translations.Strings.UnknownErrorOccurred, MessageBoxButton.OK, MessageBoxImage.Error); + } } } @@ -333,5 +336,39 @@ private static void RetryTask(TwitchTask task) task.Reinitialize(); } } + + private void BtnMoveTaskUp_Click(object sender, RoutedEventArgs e) + { + if (sender is not Button { DataContext: TwitchTask task }) + { + return; + } + + lock (taskLock) + { + var index = taskList.IndexOf(task); + if (index < 1) + return; + + taskList.Move(index, index - 1); + } + } + + private void BtnMoveTaskDown_Click(object sender, RoutedEventArgs e) + { + if (sender is not Button { DataContext: TwitchTask task }) + { + return; + } + + lock (taskLock) + { + var index = taskList.IndexOf(task); + if (index == -1 || index == taskList.Count - 1) + return; + + taskList.Move(index, index + 1); + } + } } }