]> granicus.if.org Git - handbrake/commitdiff
WinGui: Basic implementation of Queue Up/Down Buttons. Does not yet handle post selec...
authorsr55 <sr55.hb@outlook.com>
Sun, 27 Jan 2019 20:46:19 +0000 (20:46 +0000)
committersr55 <sr55.hb@outlook.com>
Sun, 27 Jan 2019 20:46:42 +0000 (20:46 +0000)
win/CS/HandBrakeWPF/Extensions/ListExtensions.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs
win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs
win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs

diff --git a/win/CS/HandBrakeWPF/Extensions/ListExtensions.cs b/win/CS/HandBrakeWPF/Extensions/ListExtensions.cs
new file mode 100644 (file)
index 0000000..b45b778
--- /dev/null
@@ -0,0 +1,79 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="ListExtensions.cs" company="HandBrake Project (http://handbrake.fr)">
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+//   IList Extensions
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Extensions
+{
+    using System;
+    using System.Collections;
+
+    public static class ListExtensions
+    {
+        public static void Swap<T>(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<T>(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<T>(index, index - 1);
+            }
+        }
+
+        public static void MoveDown<T>(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<T>(index, index + 1);
+            }
+        }
+    }
+}
index 2e4860befff7ba3f1d99c22b4cbbb81455f77cbb..b47ed425c90610ebbb6e3f36327d56c869baf564 100644 (file)
     <Compile Include="EventArgs\SettingChangedEventArgs.cs" />\r
     <Compile Include="EventArgs\TabStatusEventArgs.cs" />\r
     <Compile Include="Exceptions\GeneralApplicationException.cs" />\r
+    <Compile Include="Extensions\ListExtensions.cs" />\r
     <Compile Include="Extensions\StringExtensions.cs" />\r
     <Compile Include="Helpers\TreeViewHelper.cs" />\r
     <Compile Include="Helpers\LogManager.cs" />\r
     <Resource Include="Views\Images\file.png" />\r
   </ItemGroup>\r
   <ItemGroup>\r
-    <BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">\r
+    <BootstrapperPackage Include=".NETFramework,Version=v4.7.1">\r
       <Visible>False</Visible>\r
-      <ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>\r
+      <ProductName>Microsoft .NET Framework 4.7.1 %28x86 and x64%29</ProductName>\r
       <Install>true</Install>\r
     </BootstrapperPackage>\r
     <BootstrapperPackage Include="Microsoft.Net.Client.3.5">\r
       <ProductName>.NET Framework 3.5 SP1</ProductName>\r
       <Install>false</Install>\r
     </BootstrapperPackage>\r
-    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">\r
-      <Visible>False</Visible>\r
-      <ProductName>Windows Installer 3.1</ProductName>\r
-      <Install>true</Install>\r
-    </BootstrapperPackage>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Resource Include="Views\Images\folder32.png" />\r
index 33dc42fe273e07c9c566eca380e365fabc90e20f..90723c7a84c4eae0c4208d96716d3c1f7a723622 100644 (file)
@@ -10,6 +10,7 @@
 namespace HandBrakeWPF.Services.Queue.Interfaces\r
 {\r
     using System;\r
+    using System.Collections.ObjectModel;\r
     using System.ComponentModel;\r
 \r
     using HandBrakeWPF.Services.Queue.Model;\r
@@ -77,7 +78,7 @@ namespace HandBrakeWPF.Services.Queue.Interfaces
         /// <summary>\r
         /// Gets The current queue.\r
         /// </summary>\r
-        BindingList<QueueTask> Queue { get; }\r
+        ObservableCollection<QueueTask> Queue { get; }\r
 \r
         #endregion\r
 \r
index 5e4726bcb2f1a9fe184767afe5a87cb09313ad47..ec0867f2a76d6965cc69e4afea6ee74a6d48008e 100644 (file)
@@ -11,6 +11,7 @@ namespace HandBrakeWPF.Services.Queue
 {\r
     using System;\r
     using System.Collections.Generic;\r
+    using System.Collections.ObjectModel;\r
     using System.ComponentModel;\r
     using System.IO;\r
     using System.Linq;\r
@@ -46,7 +47,7 @@ namespace HandBrakeWPF.Services.Queue
         #region Constants and Fields\r
         private static readonly object QueueLock = new object();\r
         private readonly IUserSettingService userSettingService;\r
-        private readonly BindingList<QueueTask> queue = new BindingList<QueueTask>();\r
+        private readonly ObservableCollection<QueueTask> queue = new ObservableCollection<QueueTask>();\r
         private readonly string queueFile;\r
         private bool clearCompleted;\r
 \r
@@ -174,7 +175,7 @@ namespace HandBrakeWPF.Services.Queue
         /// <summary>\r
         /// Gets The current queue.\r
         /// </summary>\r
-        public BindingList<QueueTask> Queue\r
+        public ObservableCollection<QueueTask> Queue\r
         {\r
             get\r
             {\r
index ee5dfb58344526402ff15ee11def5e6de5917d8c..0b4e954a5640dbd213a86be23d802b9c98154c9c 100644 (file)
@@ -11,6 +11,7 @@ namespace HandBrakeWPF.ViewModels
 {\r
     using System;\r
     using System.Collections.Generic;\r
+    using System.Collections.ObjectModel;\r
     using System.ComponentModel;\r
     using System.Diagnostics;\r
     using System.IO;\r
@@ -21,6 +22,7 @@ namespace HandBrakeWPF.ViewModels
     using Caliburn.Micro;\r
 \r
     using HandBrakeWPF.EventArgs;\r
+    using HandBrakeWPF.Extensions;\r
     using HandBrakeWPF.Properties;\r
     using HandBrakeWPF.Services.Interfaces;\r
     using HandBrakeWPF.Services.Queue.Interfaces;\r
@@ -162,7 +164,7 @@ namespace HandBrakeWPF.ViewModels
         /// <summary>\r
         /// Gets the queue tasks.\r
         /// </summary>\r
-        public BindingList<QueueTask> QueueTasks\r
+        public ObservableCollection<QueueTask> QueueTasks\r
         {\r
             get\r
             {\r
@@ -615,12 +617,30 @@ namespace HandBrakeWPF.ViewModels
 \r
         public void MoveUp()\r
         {\r
-            this.errorService.ShowMessageBox("Not Implemented yet. You can drag / drop re-organise the queue for now.", "Coming Soon!", MessageBoxButton.OK, MessageBoxImage.Information);\r
+            Dictionary<int, QueueTask> tasks = new Dictionary<int, QueueTask>();\r
+            foreach (var item in this.SelectedItems)\r
+            {\r
+                tasks.Add(this.QueueTasks.IndexOf(item), item);\r
+            }\r
+\r
+            foreach (var item in tasks.OrderBy(s => s.Key))\r
+            {\r
+                this.QueueTasks.MoveUp(item.Value);\r
+            }\r
         }\r
 \r
         public void MoveDown()\r
         {\r
-            this.errorService.ShowMessageBox("Not Implemented yet. You can drag / drop re-organise the queue for now.", "Coming Soon!", MessageBoxButton.OK, MessageBoxImage.Information);\r
+            Dictionary<int, QueueTask> tasks = new Dictionary<int, QueueTask>();\r
+            foreach (var item in this.SelectedItems)\r
+            {\r
+                tasks.Add(this.QueueTasks.IndexOf(item), item);\r
+            }\r
+\r
+            foreach (var item in tasks.OrderByDescending(s => s.Key))\r
+            {\r
+                this.QueueTasks.MoveDown(item.Value);\r
+            }\r
         }\r
 \r
         #endregion\r