summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Commands/InputBindingTrigger.cs
diff options
context:
space:
mode:
authorsr55 <[email protected]>2015-04-18 15:36:25 +0000
committersr55 <[email protected]>2015-04-18 15:36:25 +0000
commit6ba51b19f630f10180bda723638d2689061945f1 (patch)
tree816f446278f70fb0e071475064c06b613593d45f /win/CS/HandBrakeWPF/Commands/InputBindingTrigger.cs
parenta39cfcd93434dcc73a67c993fc5020c65b4ef099 (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/HandBrakeWPF/Commands/InputBindingTrigger.cs')
-rw-r--r--win/CS/HandBrakeWPF/Commands/InputBindingTrigger.cs102
1 files changed, 102 insertions, 0 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);
+ }
+ }
+}