]> granicus.if.org Git - handbrake/commitdiff
WinGui: Add "Delete" key shortcut to the queue to delete selected items.
authorsr55 <sr55.hb@outlook.com>
Sat, 18 Apr 2015 15:36:25 +0000 (15:36 +0000)
committersr55 <sr55.hb@outlook.com>
Sat, 18 Apr 2015 15:36:25 +0000 (15:36 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7097 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrakeWPF/Commands/InputBindingTrigger.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs
win/CS/HandBrakeWPF/Views/QueueView.xaml
win/CS/HandBrakeWPF/Views/ShellView.xaml

diff --git a/win/CS/HandBrakeWPF/Commands/InputBindingTrigger.cs b/win/CS/HandBrakeWPF/Commands/InputBindingTrigger.cs
new file mode 100644 (file)
index 0000000..bed67ae
--- /dev/null
@@ -0,0 +1,102 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="InputBindingTrigger.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   The input binding trigger.\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrakeWPF.Commands\r
+{\r
+    using System;\r
+    using System.Diagnostics;\r
+    using System.Windows;\r
+    using System.Windows.Input;\r
+    using System.Windows.Interactivity;\r
+\r
+    /// <summary>\r
+    /// The input binding trigger.\r
+    /// </summary>\r
+    public class InputBindingTrigger : TriggerBase<FrameworkElement>, ICommand\r
+    {\r
+        public static readonly DependencyProperty InputBindingProperty = DependencyProperty.Register("InputBinding", typeof(InputBinding), typeof(InputBindingTrigger), new UIPropertyMetadata(null));\r
+\r
+        /// <summary>\r
+        /// Gets or sets the input binding.\r
+        /// </summary>\r
+        public InputBinding InputBinding\r
+        {\r
+            get { return (InputBinding)GetValue(InputBindingProperty); }\r
+            set { SetValue(InputBindingProperty, value); }\r
+        }\r
+\r
+        /// <summary>\r
+        /// The can execute changed.\r
+        /// </summary>\r
+        public event EventHandler CanExecuteChanged = delegate { };\r
+\r
+        /// <summary>\r
+        /// The can execute.\r
+        /// </summary>\r
+        /// <param name="parameter">\r
+        /// The parameter.\r
+        /// </param>\r
+        /// <returns>\r
+        /// The <see cref="bool"/>.\r
+        /// </returns>\r
+        public bool CanExecute(object parameter)\r
+        {\r
+            // action is anyway blocked by Caliburn at the invoke level\r
+            return true;\r
+        }\r
+\r
+        /// <summary>\r
+        /// The execute.\r
+        /// </summary>\r
+        /// <param name="parameter">\r
+        /// The parameter.\r
+        /// </param>\r
+        public void Execute(object parameter)\r
+        {\r
+            InvokeActions(parameter);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The on attached.\r
+        /// </summary>\r
+        protected override void OnAttached()\r
+        {\r
+            if (InputBinding != null)\r
+            {\r
+                InputBinding.Command = this;\r
+                AssociatedObject.Loaded += delegate\r
+                {\r
+                    var window = GetWindow(AssociatedObject);\r
+                    window.InputBindings.Add(InputBinding);\r
+                };\r
+            }\r
+            base.OnAttached();\r
+        }\r
+\r
+        /// <summary>\r
+        /// The get window.\r
+        /// </summary>\r
+        /// <param name="frameworkElement">\r
+        /// The framework element.\r
+        /// </param>\r
+        /// <returns>\r
+        /// The <see cref="Window"/>.\r
+        /// </returns>\r
+        private Window GetWindow(FrameworkElement frameworkElement)\r
+        {\r
+            if (frameworkElement is Window)\r
+                return frameworkElement as Window;\r
+\r
+            var parent = frameworkElement.Parent as FrameworkElement;\r
+            Debug.Assert(parent != null);\r
+\r
+            return GetWindow(parent);\r
+        }\r
+    }\r
+}\r
index e0d3979e26715535882f812963a86ade5d33faec..38d3e838462b1058fda8fb275fdd426f39c41cc7 100644 (file)
     <Compile Include="AttachedProperties\MenuItemExtensions.cs" />\r
     <Compile Include="Collections\SerializableDictionary.cs" />\r
     <Compile Include="Commands\CancelScanCommand.cs" />\r
+    <Compile Include="Commands\InputBindingTrigger.cs" />\r
     <Compile Include="Commands\Interfaces\IAdvancedEncoderOptionsCommand.cs" />\r
     <Compile Include="Commands\OpenOptionsScreenCommand.cs" />\r
     <Compile Include="Commands\CloseOverlayPanelCommand.cs" />\r
index 52c51419b14df5b65702496fb9f4334661d82532..a5d33aa42bb6a4bbd6f7184f0eaf9dc7dea0a07c 100644 (file)
@@ -10,7 +10,9 @@
 namespace HandBrakeWPF.ViewModels\r
 {\r
     using System;\r
+    using System.Collections.Generic;\r
     using System.ComponentModel;\r
+    using System.Linq;\r
     using System.Windows;\r
 \r
     using Caliburn.Micro;\r
@@ -94,6 +96,7 @@ namespace HandBrakeWPF.ViewModels
             this.Title = "Queue";\r
             this.JobsPending = "No encodes pending";\r
             this.JobStatus = "There are no jobs currently encoding";\r
+            this.SelectedItems = new BindingList<QueueTask>();\r
         }\r
 \r
         #endregion\r
@@ -178,6 +181,11 @@ namespace HandBrakeWPF.ViewModels
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Gets or sets the selected items.\r
+        /// </summary>\r
+        public BindingList<QueueTask> SelectedItems { get; set; } \r
+\r
         #endregion\r
 \r
         #region Public Methods\r
@@ -250,14 +258,44 @@ namespace HandBrakeWPF.ViewModels
                 MessageBoxButton.OK, MessageBoxImage.Information);\r
         }\r
 \r
+        /// <summary>\r
+        /// The remove selected jobs.\r
+        /// </summary>\r
+        public void RemoveSelectedJobs()\r
+        {\r
+            MessageBoxResult result =\r
+                  this.errorService.ShowMessageBox(\r
+                      "Are you sure you want to delete the selected jobs?",\r
+                      Resources.Question,\r
+                      MessageBoxButton.YesNo,\r
+                      MessageBoxImage.Question);\r
+\r
+            if (result == MessageBoxResult.No)\r
+            {\r
+                return;\r
+            }\r
+\r
+            List<QueueTask> tasksToRemove = this.SelectedItems.ToList();\r
+            foreach (QueueTask job in tasksToRemove)\r
+            {\r
+                this.RemoveJob(job);\r
+            }\r
+        }\r
+\r
         /// <summary>\r
         /// Remove a Job from the queue\r
         /// </summary>\r
-        /// <param name="task">\r
+        /// <param name="queueTask">\r
         /// The Job to remove from the queue\r
         /// </param>\r
-        public void RemoveJob(QueueTask task)\r
+        public void RemoveJob(object queueTask)\r
         {\r
+            QueueTask task = queueTask as QueueTask;\r
+            if (task == null)\r
+            {\r
+                return;\r
+            }\r
+\r
             if (task.Status == QueueItemStatus.InProgress)\r
             {\r
                 MessageBoxResult result =\r
index 8b86bd34f944a6cb71cbf469f8db7c9481b79485..e2eda58c982e048903b7b7de3c1779fe9ea880d7 100644 (file)
@@ -11,6 +11,8 @@
         xmlns:Audio="clr-namespace:HandBrakeWPF.Converters.Audio"\r
         xmlns:Subtitles="clr-namespace:HandBrakeWPF.Converters.Subtitles"\r
         xmlns:video="clr-namespace:HandBrakeWPF.Converters.Video"\r
+        xmlns:commands="clr-namespace:HandBrakeWPF.Commands"\r
+        xmlns:helpers="clr-namespace:HandBrakeWPF.Helpers"\r
         Title="{Binding Title}"\r
         Width="700"\r
         Height="500"\r
                  dd:DragDrop.IsDragSource="True"\r
                  dd:DragDrop.IsDropTarget="True"\r
                  ItemsSource="{Binding QueueTasks, Mode=OneWay}"\r
+                 helpers:ListBoxHelper.SelectedItems="{Binding SelectedItems}" \r
                  SelectionMode="Extended">\r
 \r
+            <i:Interaction.Triggers>\r
+                <commands:InputBindingTrigger>\r
+                    <commands:InputBindingTrigger.InputBinding>\r
+                        <KeyBinding Key="Delete"/>\r
+                    </commands:InputBindingTrigger.InputBinding>\r
+                    <cal:ActionMessage MethodName="RemoveSelectedJobs" />\r
+                </commands:InputBindingTrigger>\r
+            </i:Interaction.Triggers>\r
+\r
             <ListBox.Style>\r
                 <Style TargetType="ListBox">\r
                     <Style.Triggers>\r
             <ListBox.ContextMenu>\r
                 <ContextMenu>\r
                     <MenuItem cal:Message.Attach="[Event Click] = [Action ClearCompleted]" Header="Clear Completed" />\r
-                    <MenuItem cal:Message.Attach="[Event Click] = [Action Clear]" Header="Clear" />\r
+                    <MenuItem cal:Message.Attach="[Event Click] = [Action Clear]" Header="Clear All" />\r
+                    <MenuItem cal:Message.Attach="[Event Click] = [Action RemoveSelectedJobs]" Header="Clear Selected" />                 \r
                     <Separator />\r
                     <MenuItem cal:Message.Attach="[Event Click] = [Action Import]" Header="Import Queue" />\r
                     <MenuItem cal:Message.Attach="[Event Click] = [Action Export]" Header="Export Queue" />\r
index 9524199b9c89250b50941fec54624b6170c509a3..cdfc8d5880cad5ef87e4617a4ba03ff8974719bd 100644 (file)
 \r
         <DockPanel Background="Black" Opacity="0.60" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Panel.ZIndex="1"\r
                Visibility="{Binding ShowOverlayPanel, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" />\r
-        \r
-        <!--<ContentControl x:Name="OverlayPanelViewModel"  Visibility="{Binding ShowOverlayPanel, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" \r
-                        VerticalAlignment="Center" HorizontalAlignment="Center" Panel.ZIndex="2" MinWidth="900" MinHeight="675"  />-->\r
-\r
 \r
     </Grid>\r
 </Window>\r