From afda7a3fce7446ef55dcd7df78d9e5311fee5fa1 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 27 Jan 2019 20:46:19 +0000 Subject: [PATCH] WinGui: Basic implementation of Queue Up/Down Buttons. Does not yet handle post selection. --- .../HandBrakeWPF/Extensions/ListExtensions.cs | 79 +++++++++++++++++++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 10 +-- .../Queue/Interfaces/IQueueProcessor.cs | 3 +- .../Services/Queue/QueueProcessor.cs | 5 +- .../HandBrakeWPF/ViewModels/QueueViewModel.cs | 26 +++++- 5 files changed, 110 insertions(+), 13 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Extensions/ListExtensions.cs diff --git a/win/CS/HandBrakeWPF/Extensions/ListExtensions.cs b/win/CS/HandBrakeWPF/Extensions/ListExtensions.cs new file mode 100644 index 000000000..b45b778a0 --- /dev/null +++ b/win/CS/HandBrakeWPF/Extensions/ListExtensions.cs @@ -0,0 +1,79 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// IList Extensions +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Extensions +{ + using System; + using System.Collections; + + public static class ListExtensions + { + public static void Swap(this IList list, int firstIndex, int secondIndex) + { + if (list == null) + { + throw new ArgumentNullException("List was null"); + } + + if (firstIndex > list.Count - 1) + { + throw new IndexOutOfRangeException("First Index: " + firstIndex); + } + + if (firstIndex > list.Count - 1 || secondIndex < 0) + { + throw new IndexOutOfRangeException("Second Index: " + secondIndex); + } + + T temp = (T)list[firstIndex]; + list[firstIndex] = list[secondIndex]; + list[secondIndex] = temp; + } + + public static void MoveUp(this IList list, T item) + { + if (list == null) + { + throw new ArgumentNullException("List was null"); + } + + if (item == null) + { + throw new ArgumentNullException("Item was null"); + } + + int index = list.IndexOf(item); + + if (index > 0) + { + list.Swap(index, index - 1); + } + } + + public static void MoveDown(this IList list, T item) + { + if (list == null) + { + throw new ArgumentNullException("List was null"); + } + + if (item == null) + { + throw new ArgumentNullException("Item was null"); + } + + int index = list.IndexOf(item); + + if (index >= 0) + { + list.Swap(index, index + 1); + } + } + } +} diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 2e4860bef..b47ed425c 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -149,6 +149,7 @@ + @@ -681,9 +682,9 @@ - + False - Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 + Microsoft .NET Framework 4.7.1 %28x86 and x64%29 true @@ -696,11 +697,6 @@ .NET Framework 3.5 SP1 false - - False - Windows Installer 3.1 - true - diff --git a/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs b/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs index 33dc42fe2..90723c7a8 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs @@ -10,6 +10,7 @@ namespace HandBrakeWPF.Services.Queue.Interfaces { using System; + using System.Collections.ObjectModel; using System.ComponentModel; using HandBrakeWPF.Services.Queue.Model; @@ -77,7 +78,7 @@ namespace HandBrakeWPF.Services.Queue.Interfaces /// /// Gets The current queue. /// - BindingList Queue { get; } + ObservableCollection Queue { get; } #endregion diff --git a/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs b/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs index 5e4726bcb..ec0867f2a 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs @@ -11,6 +11,7 @@ namespace HandBrakeWPF.Services.Queue { using System; using System.Collections.Generic; + using System.Collections.ObjectModel; using System.ComponentModel; using System.IO; using System.Linq; @@ -46,7 +47,7 @@ namespace HandBrakeWPF.Services.Queue #region Constants and Fields private static readonly object QueueLock = new object(); private readonly IUserSettingService userSettingService; - private readonly BindingList queue = new BindingList(); + private readonly ObservableCollection queue = new ObservableCollection(); private readonly string queueFile; private bool clearCompleted; @@ -174,7 +175,7 @@ namespace HandBrakeWPF.Services.Queue /// /// Gets The current queue. /// - public BindingList Queue + public ObservableCollection Queue { get { diff --git a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs index ee5dfb583..0b4e954a5 100644 --- a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs @@ -11,6 +11,7 @@ namespace HandBrakeWPF.ViewModels { using System; using System.Collections.Generic; + using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.IO; @@ -21,6 +22,7 @@ namespace HandBrakeWPF.ViewModels using Caliburn.Micro; using HandBrakeWPF.EventArgs; + using HandBrakeWPF.Extensions; using HandBrakeWPF.Properties; using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.Services.Queue.Interfaces; @@ -162,7 +164,7 @@ namespace HandBrakeWPF.ViewModels /// /// Gets the queue tasks. /// - public BindingList QueueTasks + public ObservableCollection QueueTasks { get { @@ -615,12 +617,30 @@ namespace HandBrakeWPF.ViewModels public void MoveUp() { - this.errorService.ShowMessageBox("Not Implemented yet. You can drag / drop re-organise the queue for now.", "Coming Soon!", MessageBoxButton.OK, MessageBoxImage.Information); + Dictionary tasks = new Dictionary(); + foreach (var item in this.SelectedItems) + { + tasks.Add(this.QueueTasks.IndexOf(item), item); + } + + foreach (var item in tasks.OrderBy(s => s.Key)) + { + this.QueueTasks.MoveUp(item.Value); + } } public void MoveDown() { - this.errorService.ShowMessageBox("Not Implemented yet. You can drag / drop re-organise the queue for now.", "Coming Soon!", MessageBoxButton.OK, MessageBoxImage.Information); + Dictionary tasks = new Dictionary(); + foreach (var item in this.SelectedItems) + { + tasks.Add(this.QueueTasks.IndexOf(item), item); + } + + foreach (var item in tasks.OrderByDescending(s => s.Key)) + { + this.QueueTasks.MoveDown(item.Value); + } } #endregion -- 2.40.0