diff options
author | sr55 <[email protected]> | 2015-04-18 15:36:25 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2015-04-18 15:36:25 +0000 |
commit | 6ba51b19f630f10180bda723638d2689061945f1 (patch) | |
tree | 816f446278f70fb0e071475064c06b613593d45f /win/CS | |
parent | a39cfcd93434dcc73a67c993fc5020c65b4ef099 (diff) |
WinGui: Add "Delete" key shortcut to the queue to delete selected items.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7097 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS')
-rw-r--r-- | win/CS/HandBrakeWPF/Commands/InputBindingTrigger.cs | 102 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs | 42 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/QueueView.xaml | 15 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/ShellView.xaml | 4 |
5 files changed, 157 insertions, 7 deletions
diff --git a/win/CS/HandBrakeWPF/Commands/InputBindingTrigger.cs b/win/CS/HandBrakeWPF/Commands/InputBindingTrigger.cs new file mode 100644 index 000000000..bed67aed8 --- /dev/null +++ b/win/CS/HandBrakeWPF/Commands/InputBindingTrigger.cs @@ -0,0 +1,102 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="InputBindingTrigger.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>
+// The input binding trigger.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Commands
+{
+ using System;
+ using System.Diagnostics;
+ using System.Windows;
+ using System.Windows.Input;
+ using System.Windows.Interactivity;
+
+ /// <summary>
+ /// The input binding trigger.
+ /// </summary>
+ public class InputBindingTrigger : TriggerBase<FrameworkElement>, ICommand
+ {
+ public static readonly DependencyProperty InputBindingProperty = DependencyProperty.Register("InputBinding", typeof(InputBinding), typeof(InputBindingTrigger), new UIPropertyMetadata(null));
+
+ /// <summary>
+ /// Gets or sets the input binding.
+ /// </summary>
+ public InputBinding InputBinding
+ {
+ get { return (InputBinding)GetValue(InputBindingProperty); }
+ set { SetValue(InputBindingProperty, value); }
+ }
+
+ /// <summary>
+ /// The can execute changed.
+ /// </summary>
+ public event EventHandler CanExecuteChanged = delegate { };
+
+ /// <summary>
+ /// The can execute.
+ /// </summary>
+ /// <param name="parameter">
+ /// The parameter.
+ /// </param>
+ /// <returns>
+ /// The <see cref="bool"/>.
+ /// </returns>
+ public bool CanExecute(object parameter)
+ {
+ // action is anyway blocked by Caliburn at the invoke level
+ return true;
+ }
+
+ /// <summary>
+ /// The execute.
+ /// </summary>
+ /// <param name="parameter">
+ /// The parameter.
+ /// </param>
+ public void Execute(object parameter)
+ {
+ InvokeActions(parameter);
+ }
+
+ /// <summary>
+ /// The on attached.
+ /// </summary>
+ protected override void OnAttached()
+ {
+ if (InputBinding != null)
+ {
+ InputBinding.Command = this;
+ AssociatedObject.Loaded += delegate
+ {
+ var window = GetWindow(AssociatedObject);
+ window.InputBindings.Add(InputBinding);
+ };
+ }
+ base.OnAttached();
+ }
+
+ /// <summary>
+ /// The get window.
+ /// </summary>
+ /// <param name="frameworkElement">
+ /// The framework element.
+ /// </param>
+ /// <returns>
+ /// The <see cref="Window"/>.
+ /// </returns>
+ private Window GetWindow(FrameworkElement frameworkElement)
+ {
+ if (frameworkElement is Window)
+ return frameworkElement as Window;
+
+ var parent = frameworkElement.Parent as FrameworkElement;
+ Debug.Assert(parent != null);
+
+ return GetWindow(parent);
+ }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index e0d3979e2..38d3e8384 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -128,6 +128,7 @@ <Compile Include="AttachedProperties\MenuItemExtensions.cs" />
<Compile Include="Collections\SerializableDictionary.cs" />
<Compile Include="Commands\CancelScanCommand.cs" />
+ <Compile Include="Commands\InputBindingTrigger.cs" />
<Compile Include="Commands\Interfaces\IAdvancedEncoderOptionsCommand.cs" />
<Compile Include="Commands\OpenOptionsScreenCommand.cs" />
<Compile Include="Commands\CloseOverlayPanelCommand.cs" />
diff --git a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs index 52c51419b..a5d33aa42 100644 --- a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs @@ -10,7 +10,9 @@ namespace HandBrakeWPF.ViewModels
{
using System;
+ using System.Collections.Generic;
using System.ComponentModel;
+ using System.Linq;
using System.Windows;
using Caliburn.Micro;
@@ -94,6 +96,7 @@ namespace HandBrakeWPF.ViewModels this.Title = "Queue";
this.JobsPending = "No encodes pending";
this.JobStatus = "There are no jobs currently encoding";
+ this.SelectedItems = new BindingList<QueueTask>();
}
#endregion
@@ -178,6 +181,11 @@ namespace HandBrakeWPF.ViewModels }
}
+ /// <summary>
+ /// Gets or sets the selected items.
+ /// </summary>
+ public BindingList<QueueTask> SelectedItems { get; set; }
+
#endregion
#region Public Methods
@@ -251,13 +259,43 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
+ /// The remove selected jobs.
+ /// </summary>
+ public void RemoveSelectedJobs()
+ {
+ MessageBoxResult result =
+ this.errorService.ShowMessageBox(
+ "Are you sure you want to delete the selected jobs?",
+ Resources.Question,
+ MessageBoxButton.YesNo,
+ MessageBoxImage.Question);
+
+ if (result == MessageBoxResult.No)
+ {
+ return;
+ }
+
+ List<QueueTask> tasksToRemove = this.SelectedItems.ToList();
+ foreach (QueueTask job in tasksToRemove)
+ {
+ this.RemoveJob(job);
+ }
+ }
+
+ /// <summary>
/// Remove a Job from the queue
/// </summary>
- /// <param name="task">
+ /// <param name="queueTask">
/// The Job to remove from the queue
/// </param>
- public void RemoveJob(QueueTask task)
+ public void RemoveJob(object queueTask)
{
+ QueueTask task = queueTask as QueueTask;
+ if (task == null)
+ {
+ return;
+ }
+
if (task.Status == QueueItemStatus.InProgress)
{
MessageBoxResult result =
diff --git a/win/CS/HandBrakeWPF/Views/QueueView.xaml b/win/CS/HandBrakeWPF/Views/QueueView.xaml index 8b86bd34f..e2eda58c9 100644 --- a/win/CS/HandBrakeWPF/Views/QueueView.xaml +++ b/win/CS/HandBrakeWPF/Views/QueueView.xaml @@ -11,6 +11,8 @@ xmlns:Audio="clr-namespace:HandBrakeWPF.Converters.Audio"
xmlns:Subtitles="clr-namespace:HandBrakeWPF.Converters.Subtitles"
xmlns:video="clr-namespace:HandBrakeWPF.Converters.Video"
+ xmlns:commands="clr-namespace:HandBrakeWPF.Commands"
+ xmlns:helpers="clr-namespace:HandBrakeWPF.Helpers"
Title="{Binding Title}"
Width="700"
Height="500"
@@ -190,8 +192,18 @@ dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
ItemsSource="{Binding QueueTasks, Mode=OneWay}"
+ helpers:ListBoxHelper.SelectedItems="{Binding SelectedItems}"
SelectionMode="Extended">
+ <i:Interaction.Triggers>
+ <commands:InputBindingTrigger>
+ <commands:InputBindingTrigger.InputBinding>
+ <KeyBinding Key="Delete"/>
+ </commands:InputBindingTrigger.InputBinding>
+ <cal:ActionMessage MethodName="RemoveSelectedJobs" />
+ </commands:InputBindingTrigger>
+ </i:Interaction.Triggers>
+
<ListBox.Style>
<Style TargetType="ListBox">
<Style.Triggers>
@@ -205,7 +217,8 @@ <ListBox.ContextMenu>
<ContextMenu>
<MenuItem cal:Message.Attach="[Event Click] = [Action ClearCompleted]" Header="Clear Completed" />
- <MenuItem cal:Message.Attach="[Event Click] = [Action Clear]" Header="Clear" />
+ <MenuItem cal:Message.Attach="[Event Click] = [Action Clear]" Header="Clear All" />
+ <MenuItem cal:Message.Attach="[Event Click] = [Action RemoveSelectedJobs]" Header="Clear Selected" />
<Separator />
<MenuItem cal:Message.Attach="[Event Click] = [Action Import]" Header="Import Queue" />
<MenuItem cal:Message.Attach="[Event Click] = [Action Export]" Header="Export Queue" />
diff --git a/win/CS/HandBrakeWPF/Views/ShellView.xaml b/win/CS/HandBrakeWPF/Views/ShellView.xaml index 9524199b9..cdfc8d588 100644 --- a/win/CS/HandBrakeWPF/Views/ShellView.xaml +++ b/win/CS/HandBrakeWPF/Views/ShellView.xaml @@ -38,10 +38,6 @@ <DockPanel Background="Black" Opacity="0.60" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Panel.ZIndex="1"
Visibility="{Binding ShowOverlayPanel, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" />
-
- <!--<ContentControl x:Name="OverlayPanelViewModel" Visibility="{Binding ShowOverlayPanel, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}"
- VerticalAlignment="Center" HorizontalAlignment="Center" Panel.ZIndex="2" MinWidth="900" MinHeight="675" />-->
-
</Grid>
</Window>
|