From: sr55 Date: Sat, 18 Apr 2015 15:36:25 +0000 (+0000) Subject: WinGui: Add "Delete" key shortcut to the queue to delete selected items. X-Git-Tag: 1.0.0~1254 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6ba51b19f630f10180bda723638d2689061945f1;p=handbrake 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 --- 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 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The input binding trigger. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Commands +{ + using System; + using System.Diagnostics; + using System.Windows; + using System.Windows.Input; + using System.Windows.Interactivity; + + /// + /// The input binding trigger. + /// + public class InputBindingTrigger : TriggerBase, ICommand + { + public static readonly DependencyProperty InputBindingProperty = DependencyProperty.Register("InputBinding", typeof(InputBinding), typeof(InputBindingTrigger), new UIPropertyMetadata(null)); + + /// + /// Gets or sets the input binding. + /// + public InputBinding InputBinding + { + get { return (InputBinding)GetValue(InputBindingProperty); } + set { SetValue(InputBindingProperty, value); } + } + + /// + /// The can execute changed. + /// + public event EventHandler CanExecuteChanged = delegate { }; + + /// + /// The can execute. + /// + /// + /// The parameter. + /// + /// + /// The . + /// + public bool CanExecute(object parameter) + { + // action is anyway blocked by Caliburn at the invoke level + return true; + } + + /// + /// The execute. + /// + /// + /// The parameter. + /// + public void Execute(object parameter) + { + InvokeActions(parameter); + } + + /// + /// The on attached. + /// + protected override void OnAttached() + { + if (InputBinding != null) + { + InputBinding.Command = this; + AssociatedObject.Loaded += delegate + { + var window = GetWindow(AssociatedObject); + window.InputBindings.Add(InputBinding); + }; + } + base.OnAttached(); + } + + /// + /// The get window. + /// + /// + /// The framework element. + /// + /// + /// The . + /// + 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 @@ + 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(); } #endregion @@ -178,6 +181,11 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Gets or sets the selected items. + /// + public BindingList SelectedItems { get; set; } + #endregion #region Public Methods @@ -250,14 +258,44 @@ namespace HandBrakeWPF.ViewModels MessageBoxButton.OK, MessageBoxImage.Information); } + /// + /// The remove selected jobs. + /// + 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 tasksToRemove = this.SelectedItems.ToList(); + foreach (QueueTask job in tasksToRemove) + { + this.RemoveJob(job); + } + } + /// /// Remove a Job from the queue /// - /// + /// /// The Job to remove from the queue /// - 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"> + + + + + + + + +